├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── gulpfile.js ├── index.html ├── manifest.json ├── media └── icon.png ├── package.json ├── src └── main.ts ├── temp └── main.js ├── tsconfig.json ├── tslint.json ├── typings.json └── typings ├── globals ├── bluebird │ ├── index.d.ts │ └── typings.json └── mocha │ ├── index.d.ts │ └── typings.json └── index.d.ts /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | 35 | # generated js 36 | src/*.js 37 | fonts 38 | dist -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 'stable' 4 | - '5.4.1' 5 | - '5.4.0' 6 | - '5.3.0' 7 | - '5.2.0' 8 | - '5.1.1' 9 | before_install: 10 | - npm install -g typings 11 | - typings install 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Remo H. Jansen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # inversify-chrome-devtools 2 | A chrome extension that aims to help developers using InversifyJS 3 | 4 | ![](https://raw.githubusercontent.com/inversify/inversify-devtools/master/media/1.png) 5 | ![](https://raw.githubusercontent.com/inversify/inversify-devtools/master/media/2.png) 6 | ![](https://raw.githubusercontent.com/inversify/inversify-devtools/master/media/3.png) 7 | 8 | ### Installation 9 | You can download and install the chrome extension by visiting the following link: 10 | 11 | > TODO URL 12 | 13 | ### Setup 14 | You can connect your InversifyJS `Kernel` instances to the DevTools using the `__inversifyDevtools__` global function: 15 | 16 | ```ts 17 | /// 18 | 19 | import { Kernel } from "inversify"; 20 | 21 | let kernel = new Kernel(); 22 | 23 | let win: any = window; 24 | 25 | if (win.__inversifyDevtools__) { 26 | win.__inversifyDevtools__(kernel); 27 | } 28 | ``` 29 | 30 | The `__inversifyDevtools__` global function is only available if the chrome extension has been installed. 31 | 32 | ### License 33 | 34 | License under the MIT License (MIT) 35 | 36 | Copyright © 2015 [Remo H. Jansen](http://www.remojansen.com) 37 | 38 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software 39 | and associated documentation files (the "Software"), to deal in the Software without restriction, 40 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 41 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software 42 | is furnished to do so, subject to the following conditions: 43 | 44 | The above copyright notice and this permission notice shall be included in all copies or 45 | substantial portions of the Software. 46 | 47 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 48 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 49 | PURPOSE AND NONINFRINGEMENT. 50 | 51 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 52 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 53 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | //****************************************************************************** 4 | //* DEPENDENCIES 5 | //****************************************************************************** 6 | 7 | var gulp = require("gulp"), 8 | tslint = require("gulp-tslint"), 9 | tsc = require("gulp-typescript"), 10 | runSequence = require("run-sequence"), 11 | browserify = require("browserify"), 12 | source = require("vinyl-source-stream"), 13 | buffer = require("vinyl-buffer"), 14 | cleanCSS = require("gulp-clean-css"), 15 | concat = require("gulp-concat"); 16 | 17 | //****************************************************************************** 18 | //* LINT ALL 19 | //****************************************************************************** 20 | gulp.task("lint", function() { 21 | 22 | var config = { emitError: (process.env.CI) ? true : false }; 23 | 24 | return gulp.src([ 25 | "src/**/**.ts", 26 | "test/**/**.test.ts" 27 | ]) 28 | .pipe(tslint()) 29 | .pipe(tslint.report("verbose", config)); 30 | }); 31 | 32 | //****************************************************************************** 33 | //* BUILD SOURCE 34 | //****************************************************************************** 35 | var tsLibProject = tsc.createProject("tsconfig.json"); 36 | 37 | gulp.task("build", function() { 38 | return gulp.src([ 39 | "typings/index.d.ts", 40 | "node_modules/reflect-metadata/reflect-metadata.d.ts", 41 | "node_modules/inversify-dts/inversify-devtools/inversify-devtools.d.ts", 42 | "src/**/**.ts" 43 | ]) 44 | .pipe(tsc(tsLibProject)) 45 | .on("error", function (err) { 46 | process.exit(1); 47 | }) 48 | .js.pipe(gulp.dest("temp/")); 49 | }); 50 | 51 | //****************************************************************************** 52 | //* BUNDLE SOURCE 53 | //****************************************************************************** 54 | gulp.task("bundle", function() { 55 | 56 | var mainFilePath = "temp/main.js"; 57 | var outputFolder = "dist"; 58 | var outputFileName = "app.js"; 59 | 60 | var bundler = browserify({ 61 | debug: true 62 | }); 63 | 64 | // TS compiler options are in tsconfig.json file 65 | return bundler.add(mainFilePath) 66 | .bundle() 67 | .pipe(source(outputFileName)) 68 | .pipe(buffer()) 69 | .pipe(gulp.dest(outputFolder)); 70 | }); 71 | 72 | //****************************************************************************** 73 | //* BUNDLE CSS 74 | //****************************************************************************** 75 | 76 | gulp.task("bundle-css", [ "copy-fonts", "copy-main", "copy-media" ], function() { 77 | 78 | return gulp.src([ 79 | "node_modules/bootstrap/dist/css/bootstrap.min.css", 80 | "node_modules/font-awesome/css/font-awesome.min.css", 81 | "node_modules/inversify-devtools/style/scrollbar.css", 82 | "node_modules/inversify-devtools/style/tree.css", 83 | "node_modules/inversify-devtools/style/site.css" 84 | ]) 85 | .pipe(concat("app.css")) 86 | .pipe(cleanCSS()) 87 | .pipe(gulp.dest("dist/")); 88 | 89 | }); 90 | 91 | gulp.task("copy-fonts", function() { 92 | return gulp.src([ 93 | "node_modules/font-awesome/fonts/**/*" 94 | ]).pipe(gulp.dest("dist/fonts")); 95 | }); 96 | 97 | gulp.task("copy-media", function() { 98 | return gulp.src([ 99 | "media/**/*" 100 | ]).pipe(gulp.dest("dist/media")); 101 | }); 102 | 103 | gulp.task("copy-main", function() { 104 | return gulp.src([ 105 | "devtools.html", 106 | "index.html", 107 | "manifest.json" 108 | ]).pipe(gulp.dest("dist")); 109 | }); 110 | 111 | //****************************************************************************** 112 | //* TASK GROUPS 113 | //****************************************************************************** 114 | gulp.task("default", function (cb) { 115 | runSequence( 116 | "lint", 117 | "build", 118 | "bundle", 119 | "bundle-css", 120 | cb); 121 | }); 122 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | InversifyJS DevTools 8 | 9 | 10 | 11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 2, 3 | "name": "InversifyJS DevTools", 4 | "description": "The official InverisyJS development tools", 5 | "version": "1.0.0", 6 | "devtools_page": "devtools.html", 7 | "permissions": [ 8 | "tabs" 9 | ] 10 | } -------------------------------------------------------------------------------- /media/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inversify/inversify-chrome-devtools/1155e3018497e264c0816b931f68a111c35e3345/media/icon.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "inversify-chrome-devtools", 3 | "version": "1.0.0", 4 | "description": "A chrome extension that aims to help developers working with InversifyJS", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "gulp" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/inversify/inversify-chrome-devtools.git" 12 | }, 13 | "keywords": [ 14 | "chrome", 15 | "extension", 16 | "inversifyjs", 17 | "dependency", 18 | "inversion", 19 | "control", 20 | "ioc" 21 | ], 22 | "author": "Remo H. Jansen (http://www.remojansen.com)", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/inversify/inversify-chrome-devtools/issues" 26 | }, 27 | "homepage": "https://github.com/inversify/inversify-chrome-devtools#readme", 28 | "dependencies": { 29 | "inversify-devtools": "^1.0.0-beta.5" 30 | }, 31 | "devDependencies": { 32 | "browserify": "^13.0.1", 33 | "envify": "^3.4.1", 34 | "gulp": "^3.9.1", 35 | "gulp-clean-css": "^2.0.10", 36 | "gulp-concat": "^2.6.0", 37 | "gulp-tslint": "^5.0.0", 38 | "gulp-typescript": "^2.13.6", 39 | "inversify": "^2.0.0-rc.5", 40 | "inversify-dts": "^1.6.0", 41 | "reflect-metadata": "^0.1.3", 42 | "run-sequence": "^1.2.1", 43 | "tslint": "^3.12.1", 44 | "vinyl-buffer": "^1.0.0", 45 | "vinyl-source-stream": "^1.1.0" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import render from "inversify-devtools"; 2 | 3 | document.addEventListener("DOMContentLoaded", function() { 4 | let connectKernel = render("root"); 5 | let win: any = window; 6 | win.__inversifyDevtools__ = connectKernel; 7 | }); 8 | -------------------------------------------------------------------------------- /temp/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var inversify_devtools_1 = require("inversify-devtools"); 3 | document.addEventListener("DOMContentLoaded", function () { 4 | var connectKernel = inversify_devtools_1.default("root"); 5 | var win = window; 6 | win.__inversifyDevtools__ = connectKernel; 7 | }); 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "isolatedModules": false, 7 | "jsx": "react", 8 | "experimentalDecorators": true, 9 | "emitDecoratorMetadata": true, 10 | "declaration": false, 11 | "noImplicitAny": true, 12 | "removeComments": true, 13 | "noLib": false, 14 | "preserveConstEnums": true, 15 | "suppressImplicitAnyIndexErrors": false 16 | }, 17 | "files": [ 18 | "typings/index.d.ts", 19 | "node_modules/reflect-metadata/reflect-metadata.d.ts", 20 | "node_modules/inversify-dts/inversify-devtools/inversify-devtools.d.ts", 21 | "src/main.ts" 22 | ] 23 | } -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "class-name": true, 4 | "comment-format": [true, "check-space"], 5 | "curly": true, 6 | "eofline": true, 7 | "forin": true, 8 | "indent": [true, "spaces"], 9 | "label-position": true, 10 | "label-undefined": true, 11 | "max-line-length": [true, 140], 12 | "member-access": true, 13 | "member-ordering": [true, 14 | "public-before-private", 15 | "static-before-instance", 16 | "variables-before-functions" 17 | ], 18 | "no-arg": true, 19 | "no-bitwise": true, 20 | "no-console": [true, 21 | "debug", 22 | "info", 23 | "time", 24 | "timeEnd", 25 | "trace" 26 | ], 27 | "no-construct": true, 28 | "no-debugger": true, 29 | "no-duplicate-key": true, 30 | "no-duplicate-variable": true, 31 | "no-empty": true, 32 | "no-eval": true, 33 | "no-inferrable-types": true, 34 | "no-shadowed-variable": true, 35 | "no-string-literal": true, 36 | "no-switch-case-fall-through": false, 37 | "no-trailing-whitespace": true, 38 | "no-unused-expression": true, 39 | "no-unused-variable": false, 40 | "no-unreachable": true, 41 | "no-use-before-declare": true, 42 | "no-var-keyword": true, 43 | "object-literal-sort-keys": true, 44 | "one-line": [true, 45 | "check-open-brace", 46 | "check-catch", 47 | "check-else", 48 | "check-whitespace" 49 | ], 50 | "quotemark": [true, "double", "avoid-escape"], 51 | "radix": true, 52 | "semicolon": true, 53 | "trailing-comma": false, 54 | "triple-equals": [true, "allow-null-check"], 55 | "typedef-whitespace": [true, { 56 | "call-signature": "nospace", 57 | "index-signature": "nospace", 58 | "parameter": "nospace", 59 | "property-declaration": "nospace", 60 | "variable-declaration": "nospace" 61 | }], 62 | "variable-name": false, 63 | "whitespace": [true, 64 | "check-branch", 65 | "check-decl", 66 | "check-operator", 67 | "check-separator", 68 | "check-type" 69 | ] 70 | } 71 | } -------------------------------------------------------------------------------- /typings.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "inversify-chrome-devtools", 3 | "dependencies": {}, 4 | "globalDependencies": { 5 | "bluebird": "registry:dt/bluebird#2.0.0+20160319051630", 6 | "mocha": "registry:dt/mocha#2.2.5+20160619032855" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /typings/globals/bluebird/index.d.ts: -------------------------------------------------------------------------------- 1 | // Generated by typings 2 | // Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/149aa09a23582fb6aac6f5e2518ce19b1efe25b8/bluebird/bluebird.d.ts 3 | declare var Promise: PromiseConstructor; 4 | 5 | interface PromiseConstructor { 6 | /** 7 | * Create a new promise. The passed in function will receive functions `resolve` and `reject` as its arguments which can be called to seal the fate of the created promise. 8 | */ 9 | new (callback: (resolve: (thenableOrResult?: T | PromiseLike) => void, reject: (error: any) => void) => void): Promise; 10 | 11 | config(options: { 12 | warnings?: boolean | {wForgottenReturn?: boolean}; 13 | longStackTraces?: boolean; 14 | cancellation?: boolean; 15 | monitoring?: boolean; 16 | }): void; 17 | 18 | // Ideally, we'd define e.g. "export class RangeError extends Error {}", 19 | // but as Error is defined as an interface (not a class), TypeScript doesn't 20 | // allow extending Error, only implementing it. 21 | // However, if we want to catch() only a specific error type, we need to pass 22 | // a constructor function to it. So, as a workaround, we define them here as such. 23 | RangeError(): RangeError; 24 | CancellationError(): Promise.CancellationError; 25 | TimeoutError(): Promise.TimeoutError; 26 | TypeError(): Promise.TypeError; 27 | RejectionError(): Promise.RejectionError; 28 | OperationalError(): Promise.OperationalError; 29 | 30 | /** 31 | * Changes how bluebird schedules calls a-synchronously. 32 | * 33 | * @param scheduler Should be a function that asynchronously schedules 34 | * the calling of the passed in function 35 | */ 36 | setScheduler(scheduler: (callback: (...args: any[]) => void) => void): void; 37 | 38 | /** 39 | * Start the chain of promises with `Promise.try`. Any synchronous exceptions will be turned into rejections on the returned promise. 40 | * 41 | * Note about second argument: if it's specifically a true array, its values become respective arguments for the function call. Otherwise it is passed as is as the first argument for the function call. 42 | * 43 | * Alias for `attempt();` for compatibility with earlier ECMAScript version. 44 | */ 45 | try(fn: () => T | PromiseLike, args?: any[], ctx?: any): Promise; 46 | 47 | attempt(fn: () => T | PromiseLike, args?: any[], ctx?: any): Promise; 48 | 49 | /** 50 | * Returns a new function that wraps the given function `fn`. The new function will always return a promise that is fulfilled with the original functions return values or rejected with thrown exceptions from the original function. 51 | * This method is convenient when a function can sometimes return synchronously or throw synchronously. 52 | */ 53 | method(fn: Function): Function; 54 | 55 | /** 56 | * Create a promise that is resolved with the given `value`. If `value` is a thenable or promise, the returned promise will assume its state. 57 | */ 58 | resolve(value: T | PromiseLike): Promise; 59 | resolve(): Promise; 60 | 61 | /** 62 | * Create a promise that is rejected with the given `reason`. 63 | */ 64 | reject(reason: any): Promise; 65 | reject(reason: any): Promise; 66 | 67 | /** 68 | * Create a promise with undecided fate and return a `PromiseResolver` to control it. See resolution?: Promise(#promise-resolution). 69 | */ 70 | defer(): Promise.Resolver; 71 | 72 | /** 73 | * Cast the given `value` to a trusted promise. If `value` is already a trusted `Promise`, it is returned as is. If `value` is not a thenable, a fulfilled is: Promise returned with `value` as its fulfillment value. If `value` is a thenable (Promise-like object, like those returned by jQuery's `$.ajax`), returns a trusted that: Promise assimilates the state of the thenable. 74 | */ 75 | cast(value: T | PromiseLike): Promise; 76 | 77 | /** 78 | * Sugar for `Promise.resolve(undefined).bind(thisArg);`. See `.bind()`. 79 | */ 80 | bind(thisArg: any): Promise; 81 | 82 | /** 83 | * See if `value` is a trusted Promise. 84 | */ 85 | is(value: any): boolean; 86 | 87 | /** 88 | * Call this right after the library is loaded to enabled long stack traces. Long stack traces cannot be disabled after being enabled, and cannot be enabled after promises have alread been created. Long stack traces imply a substantial performance penalty, around 4-5x for throughput and 0.5x for latency. 89 | */ 90 | longStackTraces(): void; 91 | 92 | /** 93 | * Returns a promise that will be fulfilled with `value` (or `undefined`) after given `ms` milliseconds. If `value` is a promise, the delay will start counting down when it is fulfilled and the returned promise will be fulfilled with the fulfillment value of the `value` promise. 94 | */ 95 | // TODO enable more overloads 96 | delay(ms: number, value: T | PromiseLike): Promise; 97 | delay(ms: number): Promise; 98 | 99 | /** 100 | * Returns a function that will wrap the given `nodeFunction`. Instead of taking a callback, the returned function will return a promise whose fate is decided by the callback behavior of the given node function. The node function should conform to node.js convention of accepting a callback as last argument and calling that callback with error as the first argument and success value on the second argument. 101 | * 102 | * If the `nodeFunction` calls its callback with multiple success values, the fulfillment value will be an array of them. 103 | * 104 | * If you pass a `receiver`, the `nodeFunction` will be called as a method on the `receiver`. 105 | */ 106 | promisify(func: (callback: (err: any, result: T) => void) => void, receiver?: any): () => Promise; 107 | promisify(func: (arg1: A1, callback: (err: any, result: T) => void) => void, receiver?: any): (arg1: A1) => Promise; 108 | promisify(func: (arg1: A1, arg2: A2, callback: (err: any, result: T) => void) => void, receiver?: any): (arg1: A1, arg2: A2) => Promise; 109 | promisify(func: (arg1: A1, arg2: A2, arg3: A3, callback: (err: any, result: T) => void) => void, receiver?: any): (arg1: A1, arg2: A2, arg3: A3) => Promise; 110 | promisify(func: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, callback: (err: any, result: T) => void) => void, receiver?: any): (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => Promise; 111 | promisify(func: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5, callback: (err: any, result: T) => void) => void, receiver?: any): (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Promise; 112 | promisify(nodeFunction: Function, receiver?: any): Function; 113 | 114 | /** 115 | * Promisifies the entire object by going through the object's properties and creating an async equivalent of each function on the object and its prototype chain. The promisified method name will be the original method name postfixed with `Async`. Returns the input object. 116 | * 117 | * Note that the original methods on the object are not overwritten but new methods are created with the `Async`-postfix. For example, if you `promisifyAll()` the node.js `fs` object use `fs.statAsync()` to call the promisified `stat` method. 118 | */ 119 | // TODO how to model promisifyAll? 120 | promisifyAll(target: Object, options?: Promise.PromisifyAllOptions): any; 121 | 122 | 123 | /** 124 | * Returns a promise that is resolved by a node style callback function. 125 | */ 126 | fromNode(resolver: (callback: (err: any, result?: any) => void) => void, options? : {multiArgs? : boolean}): Promise; 127 | fromCallback(resolver: (callback: (err: any, result?: any) => void) => void, options? : {multiArgs? : boolean}): Promise; 128 | 129 | /** 130 | * Returns a function that can use `yield` to run asynchronous code synchronously. This feature requires the support of generators which are drafted in the next version of the language. Node version greater than `0.11.2` is required and needs to be executed with the `--harmony-generators` (or `--harmony`) command-line switch. 131 | */ 132 | // TODO fix coroutine GeneratorFunction 133 | coroutine(generatorFunction: Function): Function; 134 | 135 | /** 136 | * Spawn a coroutine which may yield promises to run asynchronous code synchronously. This feature requires the support of generators which are drafted in the next version of the language. Node version greater than `0.11.2` is required and needs to be executed with the `--harmony-generators` (or `--harmony`) command-line switch. 137 | */ 138 | // TODO fix spawn GeneratorFunction 139 | spawn(generatorFunction: Function): Promise; 140 | 141 | /** 142 | * This is relevant to browser environments with no module loader. 143 | * 144 | * Release control of the `Promise` namespace to whatever it was before this library was loaded. Returns a reference to the library namespace so you can attach it to something else. 145 | */ 146 | noConflict(): typeof Promise; 147 | 148 | /** 149 | * Add `handler` as the handler to call when there is a possibly unhandled rejection. The default handler logs the error stack to stderr or `console.error` in browsers. 150 | * 151 | * Passing no value or a non-function will have the effect of removing any kind of handling for possibly unhandled rejections. 152 | */ 153 | onPossiblyUnhandledRejection(handler: (reason: any) => any): void; 154 | 155 | /** 156 | * Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled when all the items in the array are fulfilled. The promise's fulfillment value is an array with fulfillment values at respective positions to the original array. If any promise in the array rejects, the returned promise is rejected with the rejection reason. 157 | */ 158 | // TODO enable more overloads 159 | // promise of array with promises of value 160 | all(values: PromiseLike[]>): Promise; 161 | // promise of array with values 162 | all(values: PromiseLike): Promise; 163 | // array with promises of value 164 | all(values: PromiseLike[]): Promise; 165 | // array with promises of different types 166 | all(values: [PromiseLike, PromiseLike, PromiseLike, PromiseLike, PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; 167 | all(values: [PromiseLike, PromiseLike, PromiseLike, PromiseLike]): Promise<[T1, T2, T3, T4]>; 168 | all(values: [PromiseLike, PromiseLike, PromiseLike]): Promise<[T1, T2, T3]>; 169 | all(values: [PromiseLike, PromiseLike]): Promise<[T1, T2]>; 170 | // array with values 171 | all(values: T[]): Promise; 172 | 173 | /** 174 | * Like ``Promise.all`` but for object properties instead of array items. Returns a promise that is fulfilled when all the properties of the object are fulfilled. The promise's fulfillment value is an object with fulfillment values at respective keys to the original object. If any promise in the object rejects, the returned promise is rejected with the rejection reason. 175 | * 176 | * If `object` is a trusted `Promise`, then it will be treated as a promise for object rather than for its properties. All other objects are treated for their properties as is returned by `Object.keys` - the object's own enumerable properties. 177 | * 178 | * *The original object is not modified.* 179 | */ 180 | // TODO verify this is correct 181 | // trusted promise for object 182 | props(object: Promise): Promise; 183 | // object 184 | props(object: Object): Promise; 185 | 186 | /** 187 | * Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled when all the items in the array are either fulfilled or rejected. The fulfillment value is an array of ``PromiseInspection`` instances at respective positions in relation to the input array. 188 | * 189 | * *original: The array is not modified. The input array sparsity is retained in the resulting array.* 190 | */ 191 | // promise of array with promises of value 192 | settle(values: PromiseLike[]>): Promise[]>; 193 | // promise of array with values 194 | settle(values: PromiseLike): Promise[]>; 195 | // array with promises of value 196 | settle(values: PromiseLike[]): Promise[]>; 197 | // array with values 198 | settle(values: T[]): Promise[]>; 199 | 200 | /** 201 | * Like `Promise.some()`, with 1 as `count`. However, if the promise fulfills, the fulfillment value is not an array of 1 but the value directly. 202 | */ 203 | // promise of array with promises of value 204 | any(values: PromiseLike[]>): Promise; 205 | // promise of array with values 206 | any(values: PromiseLike): Promise; 207 | // array with promises of value 208 | any(values: PromiseLike[]): Promise; 209 | // array with values 210 | any(values: T[]): Promise; 211 | 212 | /** 213 | * Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled or rejected as soon as a promise in the array is fulfilled or rejected with the respective rejection reason or fulfillment value. 214 | * 215 | * **Note** If you pass empty array or a sparse array with no values, or a promise/thenable for such, it will be forever pending. 216 | */ 217 | // promise of array with promises of value 218 | race(values: PromiseLike[]>): Promise; 219 | // promise of array with values 220 | race(values: PromiseLike): Promise; 221 | // array with promises of value 222 | race(values: PromiseLike[]): Promise; 223 | // array with values 224 | race(values: T[]): Promise; 225 | 226 | /** 227 | * Initiate a competetive race between multiple promises or values (values will become immediately fulfilled promises). When `count` amount of promises have been fulfilled, the returned promise is fulfilled with an array that contains the fulfillment values of the winners in order of resolution. 228 | * 229 | * If too many promises are rejected so that the promise can never become fulfilled, it will be immediately rejected with an array of rejection reasons in the order they were thrown in. 230 | * 231 | * *The original array is not modified.* 232 | */ 233 | // promise of array with promises of value 234 | some(values: PromiseLike[]>, count: number): Promise; 235 | // promise of array with values 236 | some(values: PromiseLike, count: number): Promise; 237 | // array with promises of value 238 | some(values: PromiseLike[], count: number): Promise; 239 | // array with values 240 | some(values: T[], count: number): Promise; 241 | 242 | /** 243 | * Like `Promise.all()` but instead of having to pass an array, the array is generated from the passed variadic arguments. 244 | */ 245 | // variadic array with promises of value 246 | join(...values: PromiseLike[]): Promise; 247 | // variadic array with values 248 | join(...values: T[]): Promise; 249 | 250 | /** 251 | * Map an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `mapper` function with the signature `(item, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well. 252 | * 253 | * If the `mapper` function returns promises or thenables, the returned promise will wait for all the mapped results to be resolved as well. 254 | * 255 | * *The original array is not modified.* 256 | */ 257 | // promise of array with promises of value 258 | map(values: PromiseLike[]>, mapper: (item: T, index: number, arrayLength: number) => U | PromiseLike, options?: Promise.ConcurrencyOption): Promise; 259 | 260 | // promise of array with values 261 | map(values: PromiseLike, mapper: (item: T, index: number, arrayLength: number) => U | PromiseLike, options?: Promise.ConcurrencyOption): Promise; 262 | 263 | // array with promises of value 264 | map(values: PromiseLike[], mapper: (item: T, index: number, arrayLength: number) => U | PromiseLike, options?: Promise.ConcurrencyOption): Promise; 265 | 266 | // array with values 267 | map(values: T[], mapper: (item: T, index: number, arrayLength: number) => U | PromiseLike, options?: Promise.ConcurrencyOption): Promise; 268 | 269 | /** 270 | * Similar to `map` with concurrency set to 1 but guaranteed to execute in sequential order 271 | * 272 | * If the `mapper` function returns promises or thenables, the returned promise will wait for all the mapped results to be resolved as well. 273 | * 274 | * *The original array is not modified.* 275 | */ 276 | // promise of array with promises of value 277 | mapSeries(values: PromiseLike[]>, mapper: (item: R, index: number, arrayLength: number) => U | PromiseLike): Promise; 278 | 279 | // promise of array with values 280 | mapSeries(values: PromiseLike, mapper: (item: R, index: number, arrayLength: number) => U | PromiseLike): Promise; 281 | 282 | // array with promises of value 283 | mapSeries(values: PromiseLike[], mapper: (item: R, index: number, arrayLength: number) => U | PromiseLike): Promise; 284 | 285 | // array with values 286 | mapSeries(values: R[], mapper: (item: R, index: number, arrayLength: number) => U | PromiseLike): Promise; 287 | 288 | 289 | /** 290 | * Reduce an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `reducer` function with the signature `(total, current, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well. 291 | * 292 | * If the reducer function returns a promise or a thenable, the result for the promise is awaited for before continuing with next iteration. 293 | * 294 | * *The original array is not modified. If no `intialValue` is given and the array doesn't contain at least 2 items, the callback will not be called and `undefined` is returned. If `initialValue` is given and the array doesn't have at least 1 item, `initialValue` is returned.* 295 | */ 296 | // promise of array with promises of value 297 | reduce(values: PromiseLike[]>, reducer: (total: U, current: T, index: number, arrayLength: number) => U | PromiseLike, initialValue?: U): Promise; 298 | 299 | // promise of array with values 300 | reduce(values: PromiseLike, reducer: (total: U, current: T, index: number, arrayLength: number) => U | PromiseLike, initialValue?: U): Promise; 301 | 302 | // array with promises of value 303 | reduce(values: PromiseLike[], reducer: (total: U, current: T, index: number, arrayLength: number) => U | PromiseLike, initialValue?: U): Promise; 304 | 305 | // array with values 306 | reduce(values: T[], reducer: (total: U, current: T, index: number, arrayLength: number) => U | PromiseLike, initialValue?: U): Promise; 307 | 308 | /** 309 | * Filter an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `filterer` function with the signature `(item, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well. 310 | * 311 | * The return values from the filtered functions are coerced to booleans, with the exception of promises and thenables which are awaited for their eventual result. 312 | * 313 | * *The original array is not modified. 314 | */ 315 | // promise of array with promises of value 316 | filter(values: PromiseLike[]>, filterer: (item: T, index: number, arrayLength: number) => boolean | PromiseLike, option?: Promise.ConcurrencyOption): Promise; 317 | 318 | // promise of array with values 319 | filter(values: PromiseLike, filterer: (item: T, index: number, arrayLength: number) => boolean | PromiseLike, option?: Promise.ConcurrencyOption): Promise; 320 | 321 | // array with promises of value 322 | filter(values: PromiseLike[], filterer: (item: T, index: number, arrayLength: number) => boolean | PromiseLike, option?: Promise.ConcurrencyOption): Promise; 323 | 324 | // array with values 325 | filter(values: T[], filterer: (item: T, index: number, arrayLength: number) => boolean | PromiseLike, option?: Promise.ConcurrencyOption): Promise; 326 | 327 | /** 328 | * Iterate over an array, or a promise of an array, which contains promises (or a mix of promises and values) with the given iterator function with the signature (item, index, value) where item is the resolved value of a respective promise in the input array. Iteration happens serially. If any promise in the input array is rejected the returned promise is rejected as well. 329 | * 330 | * Resolves to the original array unmodified, this method is meant to be used for side effects. If the iterator function returns a promise or a thenable, the result for the promise is awaited for before continuing with next iteration. 331 | */ 332 | // promise of array with promises of value 333 | each(values: PromiseLike[]>, iterator: (item: T, index: number, arrayLength: number) => U | PromiseLike): Promise; 334 | // array with promises of value 335 | each(values: PromiseLike[], iterator: (item: T, index: number, arrayLength: number) => U | PromiseLike): Promise; 336 | // array with values OR promise of array with values 337 | each(values: T[] | PromiseLike, iterator: (item: T, index: number, arrayLength: number) => U | PromiseLike): Promise; 338 | } 339 | 340 | interface Promise extends PromiseLike, Promise.Inspection { 341 | /** 342 | * Promises/A+ `.then()` with progress handler. Returns a new promise chained from this promise. The new promise will be rejected or resolved dedefer on the passed `fulfilledHandler`, `rejectedHandler` and the state of this promise. 343 | */ 344 | then(onFulfill: (value: T) => U | PromiseLike, onReject?: (error: any) => U | PromiseLike, onProgress?: (note: any) => any): Promise; 345 | then(onFulfill: (value: T) => U | PromiseLike, onReject?: (error: any) => void | PromiseLike, onProgress?: (note: any) => any): Promise; 346 | 347 | /** 348 | * This is a catch-all exception handler, shortcut for calling `.then(null, handler)` on this promise. Any exception happening in a `.then`-chain will propagate to nearest `.catch` handler. 349 | * 350 | * Alias `.caught();` for compatibility with earlier ECMAScript version. 351 | */ 352 | catch(onReject?: (error: any) => T | PromiseLike | void | PromiseLike): Promise; 353 | caught(onReject?: (error: any) => T | PromiseLike | void | PromiseLike): Promise; 354 | 355 | catch(onReject?: (error: any) => U | PromiseLike): Promise; 356 | caught(onReject?: (error: any) => U | PromiseLike): Promise; 357 | 358 | /** 359 | * This extends `.catch` to work more like catch-clauses in languages like Java or C#. Instead of manually checking `instanceof` or `.name === "SomeError"`, you may specify a number of error constructors which are eligible for this catch handler. The catch handler that is first met that has eligible constructors specified, is the one that will be called. 360 | * 361 | * This method also supports predicate-based filters. If you pass a predicate function instead of an error constructor, the predicate will receive the error as an argument. The return result of the predicate will be used determine whether the error handler should be called. 362 | * 363 | * Alias `.caught();` for compatibility with earlier ECMAScript version. 364 | */ 365 | catch(predicate: (error: any) => boolean, onReject: (error: any) => T | PromiseLike | void | PromiseLike): Promise; 366 | caught(predicate: (error: any) => boolean, onReject: (error: any) => T | PromiseLike | void | PromiseLike): Promise; 367 | 368 | catch(predicate: (error: any) => boolean, onReject: (error: any) => U | PromiseLike): Promise; 369 | caught(predicate: (error: any) => boolean, onReject: (error: any) => U | PromiseLike): Promise; 370 | 371 | catch(ErrorClass: Function, onReject: (error: any) => T | PromiseLike | void | PromiseLike): Promise; 372 | caught(ErrorClass: Function, onReject: (error: any) => T | PromiseLike | void | PromiseLike): Promise; 373 | 374 | catch(ErrorClass: Function, onReject: (error: any) => U | PromiseLike): Promise; 375 | caught(ErrorClass: Function, onReject: (error: any) => U | PromiseLike): Promise; 376 | 377 | 378 | /** 379 | * Like `.catch` but instead of catching all types of exceptions, it only catches those that don't originate from thrown errors but rather from explicit rejections. 380 | */ 381 | error(onReject: (reason: any) => PromiseLike): Promise; 382 | error(onReject: (reason: any) => U): Promise; 383 | 384 | /** 385 | * Pass a handler that will be called regardless of this promise's fate. Returns a new promise chained from this promise. There are special semantics for `.finally()` in that the final value cannot be modified from the handler. 386 | * 387 | * Alias `.lastly();` for compatibility with earlier ECMAScript version. 388 | */ 389 | finally(handler: () => U | PromiseLike): Promise; 390 | 391 | lastly(handler: () => U | PromiseLike): Promise; 392 | 393 | /** 394 | * Create a promise that follows this promise, but is bound to the given `thisArg` value. A bound promise will call its handlers with the bound value set to `this`. Additionally promises derived from a bound promise will also be bound promises with the same `thisArg` binding as the original promise. 395 | */ 396 | bind(thisArg: any): Promise; 397 | 398 | /** 399 | * Like `.then()`, but any unhandled rejection that ends up here will be thrown as an error. 400 | */ 401 | done(onFulfilled?: (value: T) => PromiseLike, onRejected?: (error: any) => U | PromiseLike, onProgress?: (note: any) => any): void; 402 | done(onFulfilled?: (value: T) => U, onRejected?: (error: any) => U | PromiseLike, onProgress?: (note: any) => any): void; 403 | 404 | /** 405 | * Like `.finally()`, but not called for rejections. 406 | */ 407 | tap(onFulFill: (value: T) => U | PromiseLike): Promise; 408 | 409 | /** 410 | * Shorthand for `.then(null, null, handler);`. Attach a progress handler that will be called if this promise is progressed. Returns a new promise chained from this promise. 411 | */ 412 | progressed(handler: (note: any) => any): Promise; 413 | 414 | /** 415 | * Same as calling `Promise.delay(this, ms)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. 416 | */ 417 | delay(ms: number): Promise; 418 | 419 | /** 420 | * Returns a promise that will be fulfilled with this promise's fulfillment value or rejection reason. However, if this promise is not fulfilled or rejected within `ms` milliseconds, the returned promise is rejected with a `Promise.TimeoutError` instance. 421 | * 422 | * You may specify a custom error message with the `message` parameter. 423 | */ 424 | timeout(ms: number, message?: string): Promise; 425 | 426 | /** 427 | * Register a node-style callback on this promise. When this promise is is either fulfilled or rejected, the node callback will be called back with the node.js convention where error reason is the first argument and success value is the second argument. The error argument will be `null` in case of success. 428 | * Returns back this promise instead of creating a new one. If the `callback` argument is not a function, this method does not do anything. 429 | */ 430 | nodeify(callback: (err: any, value?: T) => void, options?: Promise.SpreadOption): Promise; 431 | nodeify(...sink: any[]): Promise; 432 | 433 | /** 434 | * Marks this promise as cancellable. Promises by default are not cancellable after v0.11 and must be marked as such for `.cancel()` to have any effect. Marking a promise as cancellable is infectious and you don't need to remark any descendant promise. 435 | */ 436 | cancellable(): Promise; 437 | 438 | /** 439 | * Cancel this promise. The cancellation will propagate to farthest cancellable ancestor promise which is still pending. 440 | * 441 | * That ancestor will then be rejected with a `CancellationError` (get a reference from `Promise.CancellationError`) object as the rejection reason. 442 | * 443 | * In a promise rejection handler you may check for a cancellation by seeing if the reason object has `.name === "Cancel"`. 444 | * 445 | * Promises are by default not cancellable. Use `.cancellable()` to mark a promise as cancellable. 446 | */ 447 | // TODO what to do with this? 448 | cancel(reason?: any): Promise; 449 | 450 | /** 451 | * Like `.then()`, but cancellation of the the returned promise or any of its descendant will not propagate cancellation to this promise or this promise's ancestors. 452 | */ 453 | fork(onFulfilled?: (value: T) => U | PromiseLike, onRejected?: (error: any) => U | PromiseLike, onProgress?: (note: any) => any): Promise; 454 | 455 | /** 456 | * Create an uncancellable promise based on this promise. 457 | */ 458 | uncancellable(): Promise; 459 | 460 | /** 461 | * See if this promise can be cancelled. 462 | */ 463 | isCancellable(): boolean; 464 | 465 | /** 466 | * See if this `promise` has been fulfilled. 467 | */ 468 | isFulfilled(): boolean; 469 | 470 | /** 471 | * See if this `promise` has been rejected. 472 | */ 473 | isRejected(): boolean; 474 | 475 | /** 476 | * See if this `promise` is still defer. 477 | */ 478 | isPending(): boolean; 479 | 480 | /** 481 | * See if this `promise` is resolved -> either fulfilled or rejected. 482 | */ 483 | isResolved(): boolean; 484 | 485 | /** 486 | * Get the fulfillment value of the underlying promise. Throws if the promise isn't fulfilled yet. 487 | * 488 | * throws `TypeError` 489 | */ 490 | value(): T; 491 | 492 | /** 493 | * Get the rejection reason for the underlying promise. Throws if the promise isn't rejected yet. 494 | * 495 | * throws `TypeError` 496 | */ 497 | reason(): any; 498 | 499 | /** 500 | * Synchronously inspect the state of this `promise`. The `PromiseInspection` will represent the state of the promise as snapshotted at the time of calling `.inspect()`. 501 | */ 502 | inspect(): Promise.Inspection; 503 | 504 | /** 505 | * This is a convenience method for doing: 506 | * 507 | * 508 | * promise.then(function(obj){ 509 | * return obj[propertyName].call(obj, arg...); 510 | * }); 511 | * 512 | */ 513 | call(propertyName: string, ...args: any[]): Promise; 514 | 515 | /** 516 | * This is a convenience method for doing: 517 | * 518 | * 519 | * promise.then(function(obj){ 520 | * return obj[propertyName]; 521 | * }); 522 | * 523 | */ 524 | // TODO find way to fix get() 525 | // get(propertyName: string): Promise; 526 | 527 | /** 528 | * Convenience method for: 529 | * 530 | * 531 | * .then(function() { 532 | * return value; 533 | * }); 534 | * 535 | * 536 | * in the case where `value` doesn't change its value. That means `value` is bound at the time of calling `.return()` 537 | * 538 | * Alias `.thenReturn();` for compatibility with earlier ECMAScript version. 539 | */ 540 | return(): Promise; 541 | thenReturn(): Promise; 542 | return(value: U): Promise; 543 | thenReturn(value: U): Promise; 544 | 545 | /** 546 | * Convenience method for: 547 | * 548 | * 549 | * .then(function() { 550 | * throw reason; 551 | * }); 552 | * 553 | * Same limitations apply as with `.return()`. 554 | * 555 | * Alias `.thenThrow();` for compatibility with earlier ECMAScript version. 556 | */ 557 | throw(reason: Error): Promise; 558 | thenThrow(reason: Error): Promise; 559 | 560 | /** 561 | * Convert to String. 562 | */ 563 | toString(): string; 564 | 565 | /** 566 | * This is implicitly called by `JSON.stringify` when serializing the object. Returns a serialized representation of the `Promise`. 567 | */ 568 | toJSON(): Object; 569 | 570 | /** 571 | * Like calling `.then`, but the fulfillment value or rejection reason is assumed to be an array, which is flattened to the formal parameters of the handlers. 572 | */ 573 | // TODO how to model instance.spread()? like Q? 574 | spread(onFulfill: Function, onReject?: (reason: any) => U | PromiseLike): Promise; 575 | /* 576 | // TODO or something like this? 577 | spread(onFulfill: (...values: W[]) => PromiseLike, onReject?: (reason: any) => PromiseLike): Promise; 578 | spread(onFulfill: (...values: W[]) => PromiseLike, onReject?: (reason: any) => U): Promise; 579 | spread(onFulfill: (...values: W[]) => U, onReject?: (reason: any) => PromiseLike): Promise; 580 | spread(onFulfill: (...values: W[]) => U, onReject?: (reason: any) => U): Promise; 581 | */ 582 | /** 583 | * Same as calling `Promise.all(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. 584 | */ 585 | // TODO type inference from array-resolving promise? 586 | all(): Promise; 587 | 588 | /** 589 | * Same as calling `Promise.props(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. 590 | */ 591 | // TODO how to model instance.props()? 592 | props(): Promise; 593 | 594 | /** 595 | * Same as calling `Promise.settle(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. 596 | */ 597 | // TODO type inference from array-resolving promise? 598 | settle(): Promise[]>; 599 | 600 | /** 601 | * Same as calling `Promise.any(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. 602 | */ 603 | // TODO type inference from array-resolving promise? 604 | any(): Promise; 605 | 606 | /** 607 | * Same as calling `Promise.some(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. 608 | */ 609 | // TODO type inference from array-resolving promise? 610 | some(count: number): Promise; 611 | 612 | /** 613 | * Same as calling `Promise.race(thisPromise, count)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. 614 | */ 615 | // TODO type inference from array-resolving promise? 616 | race(): Promise; 617 | 618 | /** 619 | * Same as calling `Promise.map(thisPromise, mapper)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. 620 | */ 621 | // TODO type inference from array-resolving promise? 622 | map(mapper: (item: Q, index: number, arrayLength: number) => U | PromiseLike, options?: Promise.ConcurrencyOption): Promise; 623 | 624 | /** 625 | * Same as `Promise.mapSeries(thisPromise, mapper)`. 626 | */ 627 | // TODO type inference from array-resolving promise? 628 | mapSeries(mapper: (item: Q, index: number, arrayLength: number) => U | PromiseLike): Promise; 629 | 630 | /** 631 | * Same as calling `Promise.reduce(thisPromise, Function reducer, initialValue)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. 632 | */ 633 | // TODO type inference from array-resolving promise? 634 | reduce(reducer: (memo: U, item: Q, index: number, arrayLength: number) => U | PromiseLike, initialValue?: U): Promise; 635 | 636 | /** 637 | * Same as calling ``Promise.filter(thisPromise, filterer)``. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. 638 | */ 639 | // TODO type inference from array-resolving promise? 640 | filter(filterer: (item: U, index: number, arrayLength: number) => boolean | PromiseLike, options?: Promise.ConcurrencyOption): Promise; 641 | 642 | /** 643 | * Same as calling ``Promise.each(thisPromise, iterator)``. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. 644 | */ 645 | each(iterator: (item: T, index: number, arrayLength: number) => U | PromiseLike): Promise; 646 | } 647 | 648 | /** 649 | * Don't use variable namespace such as variables, functions, and classes. 650 | * If you use this namespace, it will conflict in es6. 651 | */ 652 | declare namespace Promise { 653 | export interface RangeError extends Error { 654 | } 655 | export interface CancellationError extends Error { 656 | } 657 | export interface TimeoutError extends Error { 658 | } 659 | export interface TypeError extends Error { 660 | } 661 | export interface RejectionError extends Error { 662 | } 663 | export interface OperationalError extends Error { 664 | } 665 | 666 | export interface ConcurrencyOption { 667 | concurrency: number; 668 | } 669 | export interface SpreadOption { 670 | spread: boolean; 671 | } 672 | export interface PromisifyAllOptions { 673 | suffix?: string; 674 | filter?: (name: string, func: Function, target?: any, passesDefaultFilter?: boolean) => boolean; 675 | // The promisifier gets a reference to the original method and should return a function which returns a promise 676 | promisifier?: (originalMethod: Function) => () => PromiseLike; 677 | } 678 | 679 | export interface Resolver { 680 | /** 681 | * Returns a reference to the controlled promise that can be passed to clients. 682 | */ 683 | promise: Promise; 684 | 685 | /** 686 | * Resolve the underlying promise with `value` as the resolution value. If `value` is a thenable or a promise, the underlying promise will assume its state. 687 | */ 688 | resolve(value: T): void; 689 | resolve(): void; 690 | 691 | /** 692 | * Reject the underlying promise with `reason` as the rejection reason. 693 | */ 694 | reject(reason: any): void; 695 | 696 | /** 697 | * Progress the underlying promise with `value` as the progression value. 698 | */ 699 | progress(value: any): void; 700 | 701 | /** 702 | * Gives you a callback representation of the `PromiseResolver`. Note that this is not a method but a property. The callback accepts error object in first argument and success values on the 2nd parameter and the rest, I.E. node js conventions. 703 | * 704 | * If the the callback is called with multiple success values, the resolver fullfills its promise with an array of the values. 705 | */ 706 | // TODO specify resolver callback 707 | callback: (err: any, value: T, ...values: T[]) => void; 708 | } 709 | 710 | export interface Inspection { 711 | /** 712 | * See if the underlying promise was fulfilled at the creation time of this inspection object. 713 | */ 714 | isFulfilled(): boolean; 715 | 716 | /** 717 | * See if the underlying promise was rejected at the creation time of this inspection object. 718 | */ 719 | isRejected(): boolean; 720 | 721 | /** 722 | * See if the underlying promise was defer at the creation time of this inspection object. 723 | */ 724 | isPending(): boolean; 725 | 726 | /** 727 | * Get the fulfillment value of the underlying promise. Throws if the promise wasn't fulfilled at the creation time of this inspection object. 728 | * 729 | * throws `TypeError` 730 | */ 731 | value(): T; 732 | 733 | /** 734 | * Get the rejection reason for the underlying promise. Throws if the promise wasn't rejected at the creation time of this inspection object. 735 | * 736 | * throws `TypeError` 737 | */ 738 | reason(): any; 739 | } 740 | } 741 | 742 | declare module 'bluebird' { 743 | export = Promise; 744 | } -------------------------------------------------------------------------------- /typings/globals/bluebird/typings.json: -------------------------------------------------------------------------------- 1 | { 2 | "resolution": "main", 3 | "tree": { 4 | "src": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/149aa09a23582fb6aac6f5e2518ce19b1efe25b8/bluebird/bluebird.d.ts", 5 | "raw": "registry:dt/bluebird#2.0.0+20160319051630", 6 | "typings": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/149aa09a23582fb6aac6f5e2518ce19b1efe25b8/bluebird/bluebird.d.ts" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /typings/globals/mocha/index.d.ts: -------------------------------------------------------------------------------- 1 | // Generated by typings 2 | // Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/b1daff0be8fa53f645365303d8e0145d055370e9/mocha/mocha.d.ts 3 | interface MochaSetupOptions { 4 | //milliseconds to wait before considering a test slow 5 | slow?: number; 6 | 7 | // timeout in milliseconds 8 | timeout?: number; 9 | 10 | // ui name "bdd", "tdd", "exports" etc 11 | ui?: string; 12 | 13 | //array of accepted globals 14 | globals?: any[]; 15 | 16 | // reporter instance (function or string), defaults to `mocha.reporters.Spec` 17 | reporter?: any; 18 | 19 | // bail on the first test failure 20 | bail?: boolean; 21 | 22 | // ignore global leaks 23 | ignoreLeaks?: boolean; 24 | 25 | // grep string or regexp to filter tests with 26 | grep?: any; 27 | } 28 | 29 | interface MochaDone { 30 | (error?: Error): void; 31 | } 32 | 33 | declare var mocha: Mocha; 34 | declare var describe: Mocha.IContextDefinition; 35 | declare var xdescribe: Mocha.IContextDefinition; 36 | // alias for `describe` 37 | declare var context: Mocha.IContextDefinition; 38 | // alias for `describe` 39 | declare var suite: Mocha.IContextDefinition; 40 | declare var it: Mocha.ITestDefinition; 41 | declare var xit: Mocha.ITestDefinition; 42 | // alias for `it` 43 | declare var test: Mocha.ITestDefinition; 44 | declare var specify: Mocha.ITestDefinition; 45 | 46 | declare function before(action: () => void): void; 47 | 48 | declare function before(action: (done: MochaDone) => void): void; 49 | 50 | declare function before(description: string, action: () => void): void; 51 | 52 | declare function before(description: string, action: (done: MochaDone) => void): void; 53 | 54 | declare function setup(action: () => void): void; 55 | 56 | declare function setup(action: (done: MochaDone) => void): void; 57 | 58 | declare function after(action: () => void): void; 59 | 60 | declare function after(action: (done: MochaDone) => void): void; 61 | 62 | declare function after(description: string, action: () => void): void; 63 | 64 | declare function after(description: string, action: (done: MochaDone) => void): void; 65 | 66 | declare function teardown(action: () => void): void; 67 | 68 | declare function teardown(action: (done: MochaDone) => void): void; 69 | 70 | declare function beforeEach(action: () => void): void; 71 | 72 | declare function beforeEach(action: (done: MochaDone) => void): void; 73 | 74 | declare function beforeEach(description: string, action: () => void): void; 75 | 76 | declare function beforeEach(description: string, action: (done: MochaDone) => void): void; 77 | 78 | declare function suiteSetup(action: () => void): void; 79 | 80 | declare function suiteSetup(action: (done: MochaDone) => void): void; 81 | 82 | declare function afterEach(action: () => void): void; 83 | 84 | declare function afterEach(action: (done: MochaDone) => void): void; 85 | 86 | declare function afterEach(description: string, action: () => void): void; 87 | 88 | declare function afterEach(description: string, action: (done: MochaDone) => void): void; 89 | 90 | declare function suiteTeardown(action: () => void): void; 91 | 92 | declare function suiteTeardown(action: (done: MochaDone) => void): void; 93 | 94 | declare class Mocha { 95 | constructor(options?: { 96 | grep?: RegExp; 97 | ui?: string; 98 | reporter?: string; 99 | timeout?: number; 100 | bail?: boolean; 101 | }); 102 | 103 | /** Setup mocha with the given options. */ 104 | setup(options: MochaSetupOptions): Mocha; 105 | bail(value?: boolean): Mocha; 106 | addFile(file: string): Mocha; 107 | /** Sets reporter by name, defaults to "spec". */ 108 | reporter(name: string): Mocha; 109 | /** Sets reporter constructor, defaults to mocha.reporters.Spec. */ 110 | reporter(reporter: (runner: Mocha.IRunner, options: any) => any): Mocha; 111 | ui(value: string): Mocha; 112 | grep(value: string): Mocha; 113 | grep(value: RegExp): Mocha; 114 | invert(): Mocha; 115 | ignoreLeaks(value: boolean): Mocha; 116 | checkLeaks(): Mocha; 117 | /** 118 | * Function to allow assertion libraries to throw errors directly into mocha. 119 | * This is useful when running tests in a browser because window.onerror will 120 | * only receive the 'message' attribute of the Error. 121 | */ 122 | throwError(error: Error): void; 123 | /** Enables growl support. */ 124 | growl(): Mocha; 125 | globals(value: string): Mocha; 126 | globals(values: string[]): Mocha; 127 | useColors(value: boolean): Mocha; 128 | useInlineDiffs(value: boolean): Mocha; 129 | timeout(value: number): Mocha; 130 | slow(value: number): Mocha; 131 | enableTimeouts(value: boolean): Mocha; 132 | asyncOnly(value: boolean): Mocha; 133 | noHighlighting(value: boolean): Mocha; 134 | /** Runs tests and invokes `onComplete()` when finished. */ 135 | run(onComplete?: (failures: number) => void): Mocha.IRunner; 136 | } 137 | 138 | // merge the Mocha class declaration with a module 139 | declare namespace Mocha { 140 | /** Partial interface for Mocha's `Runnable` class. */ 141 | interface IRunnable { 142 | title: string; 143 | fn: Function; 144 | async: boolean; 145 | sync: boolean; 146 | timedOut: boolean; 147 | } 148 | 149 | /** Partial interface for Mocha's `Suite` class. */ 150 | interface ISuite { 151 | parent: ISuite; 152 | title: string; 153 | 154 | fullTitle(): string; 155 | } 156 | 157 | /** Partial interface for Mocha's `Test` class. */ 158 | interface ITest extends IRunnable { 159 | parent: ISuite; 160 | pending: boolean; 161 | 162 | fullTitle(): string; 163 | } 164 | 165 | /** Partial interface for Mocha's `Runner` class. */ 166 | interface IRunner {} 167 | 168 | interface IContextDefinition { 169 | (description: string, spec: () => void): ISuite; 170 | only(description: string, spec: () => void): ISuite; 171 | skip(description: string, spec: () => void): void; 172 | timeout(ms: number): void; 173 | } 174 | 175 | interface ITestDefinition { 176 | (expectation: string, assertion?: () => void): ITest; 177 | (expectation: string, assertion?: (done: MochaDone) => void): ITest; 178 | only(expectation: string, assertion?: () => void): ITest; 179 | only(expectation: string, assertion?: (done: MochaDone) => void): ITest; 180 | skip(expectation: string, assertion?: () => void): void; 181 | skip(expectation: string, assertion?: (done: MochaDone) => void): void; 182 | timeout(ms: number): void; 183 | } 184 | 185 | export module reporters { 186 | export class Base { 187 | stats: { 188 | suites: number; 189 | tests: number; 190 | passes: number; 191 | pending: number; 192 | failures: number; 193 | }; 194 | 195 | constructor(runner: IRunner); 196 | } 197 | 198 | export class Doc extends Base {} 199 | export class Dot extends Base {} 200 | export class HTML extends Base {} 201 | export class HTMLCov extends Base {} 202 | export class JSON extends Base {} 203 | export class JSONCov extends Base {} 204 | export class JSONStream extends Base {} 205 | export class Landing extends Base {} 206 | export class List extends Base {} 207 | export class Markdown extends Base {} 208 | export class Min extends Base {} 209 | export class Nyan extends Base {} 210 | export class Progress extends Base { 211 | /** 212 | * @param options.open String used to indicate the start of the progress bar. 213 | * @param options.complete String used to indicate a complete test on the progress bar. 214 | * @param options.incomplete String used to indicate an incomplete test on the progress bar. 215 | * @param options.close String used to indicate the end of the progress bar. 216 | */ 217 | constructor(runner: IRunner, options?: { 218 | open?: string; 219 | complete?: string; 220 | incomplete?: string; 221 | close?: string; 222 | }); 223 | } 224 | export class Spec extends Base {} 225 | export class TAP extends Base {} 226 | export class XUnit extends Base { 227 | constructor(runner: IRunner, options?: any); 228 | } 229 | } 230 | } 231 | 232 | declare module "mocha" { 233 | export = Mocha; 234 | } -------------------------------------------------------------------------------- /typings/globals/mocha/typings.json: -------------------------------------------------------------------------------- 1 | { 2 | "resolution": "main", 3 | "tree": { 4 | "src": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/b1daff0be8fa53f645365303d8e0145d055370e9/mocha/mocha.d.ts", 5 | "raw": "registry:dt/mocha#2.2.5+20160619032855", 6 | "typings": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/b1daff0be8fa53f645365303d8e0145d055370e9/mocha/mocha.d.ts" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /typings/index.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | --------------------------------------------------------------------------------