diff --git a/dist/module/exceptions.js.flow b/dist/module/exceptions.js.flow new file mode 100644 index 0000000..6759510 --- /dev/null +++ b/dist/module/exceptions.js.flow @@ -0,0 +1,8 @@ +/* @flow */ +import type { ZalgoPromise } from './promise'; +const dispatchedErrors = []; +const possiblyUnhandledPromiseHandlers: Array<(mixed, promise?: ZalgoPromise) => void> = []; +declare export function dispatchPossiblyUnhandledError(err: mixed, promise: ZalgoPromise): any; +declare export function onPossiblyUnhandledException(handler: (mixed, promise?: ZalgoPromise) => void): {| + cancel: () => void +|}; \ No newline at end of file diff --git a/dist/module/export.js.flow b/dist/module/export.js.flow new file mode 100644 index 0000000..7c6de17 --- /dev/null +++ b/dist/module/export.js.flow @@ -0,0 +1,6 @@ +/* @flow */ +// $FlowFixMe +module.exports = require('./promise').ZalgoPromise; // eslint-disable-line import/no-commonjs +// $FlowFixMe + +module.exports.ZalgoPromise = require('./promise').ZalgoPromise; // eslint-disable-line import/no-commonjs \ No newline at end of file diff --git a/dist/module/flush.js.flow b/dist/module/flush.js.flow new file mode 100644 index 0000000..0f585de --- /dev/null +++ b/dist/module/flush.js.flow @@ -0,0 +1,8 @@ +/* @flow */ +import type { ZalgoPromise } from './promise'; +let activeCount = 0; +let flushPromise; +declare function flushActive(): any; +declare export function startActive(): any; +declare export function endActive(): any; +declare export function awaitActive(Zalgo: Class>): ZalgoPromise; \ No newline at end of file diff --git a/dist/module/index.js.flow b/dist/module/index.js.flow index 4c283e1..ee4b4ad 100644 --- a/dist/module/index.js.flow +++ b/dist/module/index.js.flow @@ -1,52 +1,2 @@ -// @flow - -declare class Class0 { - static $call(message?: string): Class0; - static captureStackTrace(target: Object, constructor?: Function): void; - static prepareStackTrace: (err: Class0, stack: Array) => mixed; - static stackTraceLimit: number; - - columnNumber?: number; - description?: string; - fileName?: string; - lineNumber?: number; - message: string; - name: string; - number?: number; - stack: string; - constructor(message?: mixed): void; - toString(): string; -} -declare export class ZalgoPromise { - static all>(promises: X): ZalgoPromise; - static asyncReject(error: mixed): ZalgoPromise; - static delay(delay: number): ZalgoPromise; - static flush(): ZalgoPromise; - static hash(promises: O): ZalgoPromise; - static isPromise(value: mixed): boolean; - static map(items: Array, method: (_: T) => ZalgoPromise | X): ZalgoPromise>; - static onPossiblyUnhandledException(handler: (err: mixed) => void): {cancel: () => void}; - static reject(error: mixed): ZalgoPromise; - static resolve(value: X | ZalgoPromise): ZalgoPromise; - static try>(method: (...args: A) => ZalgoPromise | Y, context: ?C, args: ?A): ZalgoPromise; - - dispatching: boolean; - error: mixed; - errorHandled: boolean; - handlers: Array<{onError: void | (error: mixed) => mixed, onSuccess: void | (result: R) => mixed, promise: ZalgoPromise}>; - rejected: boolean; - resolved: boolean; - stack: string; - value: R; - asyncReject(error: mixed): ZalgoPromise; - catch(onError: (error: mixed) => ZalgoPromise | Y): ZalgoPromise; - constructor(handler: ?(resolve: (result: R) => void, reject: (error: mixed) => void) => void): any; - dispatch(): any; - finally(onFinally: () => mixed): ZalgoPromise; - reject(error: mixed): ZalgoPromise; - resolve(result: R): ZalgoPromise; - then(onSuccess: void | (result: R) => ZalgoPromise | Y, onError: void | (error: mixed) => ZalgoPromise | Y): ZalgoPromise; - timeout(time: number, err: ?Class0): ZalgoPromise; - toPromise(): Class> | Class | Promise<+R>; -} - +/* @flow */ +export { ZalgoPromise } from './promise'; \ No newline at end of file diff --git a/dist/module/promise.js.flow b/dist/module/promise.js.flow new file mode 100644 index 0000000..cf0b995 --- /dev/null +++ b/dist/module/promise.js.flow @@ -0,0 +1,42 @@ +/* @flow */ +import { isPromise } from './utils'; +import { onPossiblyUnhandledException, dispatchPossiblyUnhandledError } from './exceptions'; +import { startActive, endActive, awaitActive } from './flush'; +declare export class ZalgoPromise { + resolved: boolean, + rejected: boolean, + errorHandled: boolean, + value: R, + error: mixed, + handlers: Array<{| + promise: ZalgoPromise<*>, + onSuccess: void | ((result: R) => mixed), + onError: void | ((error: mixed) => mixed), + |}>, + dispatching: boolean, + stack: string, + constructor(handler: ?(resolve: (result: R) => void, reject: (error: mixed) => void) => void): any, + resolve(result: R): ZalgoPromise, + reject(error: mixed): ZalgoPromise, + asyncReject(error: mixed): ZalgoPromise, + dispatch(): any, + then(onSuccess: void | ((result: R) => ZalgoPromise | Y), onError: void | ((error: mixed) => ZalgoPromise | Y)): ZalgoPromise, + catch(onError: (error: mixed) => ZalgoPromise | Y): ZalgoPromise, + finally(onFinally: () => mixed): ZalgoPromise, + timeout(time: number, err: ?Error): ZalgoPromise, + toPromise(): Promise, + lazy(): ZalgoPromise, + static resolve(value: ZalgoPromise | Y): ZalgoPromise, + static reject(error: mixed): ZalgoPromise, + static asyncReject(error: mixed): ZalgoPromise, + static all>(promises: X): ZalgoPromise<$TupleMap(ZalgoPromise | Y) => Y>>, + static hash(promises: O): ZalgoPromise<$ObjMap(ZalgoPromise | Y) => Y>>, + static map(items: $ReadOnlyArray, method: (T) => ZalgoPromise | X): ZalgoPromise<$ReadOnlyArray>, + static onPossiblyUnhandledException(handler: (err: mixed) => void): {| + cancel: () => void + |}, + static try>(method: (...args: $ReadOnlyArray) => ZalgoPromise | Y, context?: C, args?: A): ZalgoPromise, + static delay(delay: number): ZalgoPromise, + static isPromise(value: mixed): boolean, + static flush(): ZalgoPromise, +} \ No newline at end of file diff --git a/dist/module/types.js.flow b/dist/module/types.js.flow new file mode 100644 index 0000000..1146ccb --- /dev/null +++ b/dist/module/types.js.flow @@ -0,0 +1,4 @@ +/* @flow */ +export type ZalgoPromiseConstructorType = (resolve: (mixed) => void, reject: (mixed) => void) => void; // export something to force webpack to see this as an ES module + +export const TYPES = true; \ No newline at end of file diff --git a/dist/module/utils.js.flow b/dist/module/utils.js.flow new file mode 100644 index 0000000..3e93aee --- /dev/null +++ b/dist/module/utils.js.flow @@ -0,0 +1,2 @@ +/* @flow */ +declare export function isPromise(item: mixed): boolean; \ No newline at end of file diff --git a/package.json b/package.json index 565e3c0..f8167e8 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,13 @@ "setup": "npm install && npm run flow-typed", "lint": "eslint src/ test/ *.js", "flow-typed": "flow-typed install", + "build:types": "gen-flow-files src --out-dir dist/module", "flow": "flow", "karma": "cross-env NODE_ENV=test babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/karma start", "babel": "babel src/ --out-dir dist/module", "webpack": "babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/webpack --display-optimization-bailout --progress", "test": "npm run lint && npm run flow-typed && npm run flow && npm run karma", - "build": "npm run test && npm run babel && npm run webpack", + "build": "npm run test && npm run babel && npm run webpack && npm run build:types", "release": "./publish.sh", "release:patch": "./publish.sh patch", "release:minor": "./publish.sh minor", @@ -41,6 +42,7 @@ "readmeFilename": "README.md", "devDependencies": { "flow-bin": "0.155.0", + "gen-flow-files": "^0.4.11", "grumbler-scripts": "^3", "mocha": "^4" },