From ba32780f59f64b6ad739247b522fd86db741fc3c Mon Sep 17 00:00:00 2001 From: Forest Trimble Date: Wed, 13 Mar 2019 13:46:06 -0700 Subject: [PATCH] Dont include dist in package (#9) Use `npm publish` to publish the exact artifacts that are needed by consumers --- .github/PULL_REQUEST_TEMPLATE.md | 6 ---- .github/blend.yml | 3 -- .gitignore | 3 +- .npmignore | 22 +++++++++++++ dist/src/delay.d.ts | 19 ----------- dist/src/delay.js | 15 --------- dist/src/delay.js.map | 1 - dist/src/filter.d.ts | 13 -------- dist/src/filter.js | 20 ------------ dist/src/filter.js.map | 1 - dist/src/index.d.ts | 8 ----- dist/src/index.js | 14 -------- dist/src/index.js.map | 1 - dist/src/invert.d.ts | 9 ------ dist/src/invert.js | 20 ------------ dist/src/invert.js.map | 1 - dist/src/map.d.ts | 55 -------------------------------- dist/src/map.js | 48 ---------------------------- dist/src/map.js.map | 1 - dist/src/memoize.d.ts | 15 --------- dist/src/memoize.js | 52 ------------------------------ dist/src/memoize.js.map | 1 - dist/src/retry.d.ts | 22 ------------- dist/src/retry.js | 44 ------------------------- dist/src/retry.js.map | 1 - dist/src/settleAll.d.ts | 15 --------- dist/src/settleAll.js | 31 ------------------ dist/src/settleAll.js.map | 1 - dist/src/timeout.d.ts | 11 ------- dist/src/timeout.js | 28 ---------------- dist/src/timeout.js.map | 1 - package.json | 1 + 32 files changed, 24 insertions(+), 459 deletions(-) delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/blend.yml create mode 100644 .npmignore delete mode 100644 dist/src/delay.d.ts delete mode 100644 dist/src/delay.js delete mode 100644 dist/src/delay.js.map delete mode 100644 dist/src/filter.d.ts delete mode 100644 dist/src/filter.js delete mode 100644 dist/src/filter.js.map delete mode 100644 dist/src/index.d.ts delete mode 100644 dist/src/index.js delete mode 100644 dist/src/index.js.map delete mode 100644 dist/src/invert.d.ts delete mode 100644 dist/src/invert.js delete mode 100644 dist/src/invert.js.map delete mode 100644 dist/src/map.d.ts delete mode 100644 dist/src/map.js delete mode 100644 dist/src/map.js.map delete mode 100644 dist/src/memoize.d.ts delete mode 100644 dist/src/memoize.js delete mode 100644 dist/src/memoize.js.map delete mode 100644 dist/src/retry.d.ts delete mode 100644 dist/src/retry.js delete mode 100644 dist/src/retry.js.map delete mode 100644 dist/src/settleAll.d.ts delete mode 100644 dist/src/settleAll.js delete mode 100644 dist/src/settleAll.js.map delete mode 100644 dist/src/timeout.d.ts delete mode 100644 dist/src/timeout.js delete mode 100644 dist/src/timeout.js.map diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d38b0cf..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,6 +0,0 @@ -```yaml -- change_type: Features|Bugfixes|Improvements|Internal - issue_number: DSP-XXXX - change_level: minor - description: None -``` diff --git a/.github/blend.yml b/.github/blend.yml deleted file mode 100644 index 62335c4..0000000 --- a/.github/blend.yml +++ /dev/null @@ -1,3 +0,0 @@ -codeowners: '.github/CODEOWNERS' -required_status_checks: - - unit-tests diff --git a/.gitignore b/.gitignore index 6ef5057..7fc8a53 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ node_modules venv coverage logs -dist/test +dist resources *.log .nyc_output @@ -10,5 +10,4 @@ resources *.pyc tscommand-* .tscache/ -dist/test docs-build/ diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..b4af1dd --- /dev/null +++ b/.npmignore @@ -0,0 +1,22 @@ +src/ +test/ +Gruntfile.js +Makefile +tsconfig.json +tslint.* +bin/ +docs/ +dist/test + +node_modules +venv +coverage +logs +resources +*.log +.nyc_output +.idea +*.pyc +tscommand-* +.tscache/ +docs-build/ diff --git a/dist/src/delay.d.ts b/dist/src/delay.d.ts deleted file mode 100644 index 4a0f12f..0000000 --- a/dist/src/delay.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Optionally returns a value after a delay. This is useful if you want to add jitter or need to - * wait for some external reason. - * - * @param {number} delayTime - the amount of milliseconds to wait before returning - * @optionalParam {any} value - the value to return after the delay - * @returns value - if defined - */ -export declare function delay(delayTimeMs: number, value: T): Promise; -export declare function delay(delayTimeMs: number): Promise; -/** - * Optionally returns a value after deferring execution. This is useful if you need to wait for - * anything left on the event loop. - * - * @optionalParam {any} value - the value to return - * @returns value - if defined - */ -export declare function immediate(value: T): Promise; -export declare function immediate(): Promise; diff --git a/dist/src/delay.js b/dist/src/delay.js deleted file mode 100644 index 406ca2a..0000000 --- a/dist/src/delay.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -// tslint:disable-next-line:no-any typedef (typed by overload signatures) -async function delay(delayTime, value) { - return new Promise( - // tslint:disable-next-line:no-any (typed by overload signatures) - (resolve) => setTimeout(() => resolve(value), delayTime)); -} -exports.delay = delay; -// tslint:disable-next-line:no-any typedef (typed by overload signatures) -async function immediate(value) { - return delay(0, value); -} -exports.immediate = immediate; -//# sourceMappingURL=delay.js.map \ No newline at end of file diff --git a/dist/src/delay.js.map b/dist/src/delay.js.map deleted file mode 100644 index 2bca1e1..0000000 --- a/dist/src/delay.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"delay.js","sourceRoot":"","sources":["../../src/delay.ts"],"names":[],"mappings":";;AAUA,yEAAyE;AAClE,KAAK,UAAU,KAAK,CAAC,SAAc,EAAE,KAAW;IACrD,OAAO,IAAI,OAAO;IAChB,iEAAiE;IACjE,CAAC,OAA0B,EAAkB,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,CAC5F,CAAC;AACJ,CAAC;AALD,sBAKC;AAWD,yEAAyE;AAClE,KAAK,UAAU,SAAS,CAAC,KAAW;IACzC,OAAO,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACzB,CAAC;AAFD,8BAEC"} \ No newline at end of file diff --git a/dist/src/filter.d.ts b/dist/src/filter.d.ts deleted file mode 100644 index 0eb96a9..0000000 --- a/dist/src/filter.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Returns a new array of all the values in coll which pass an async truth test. This operation is - * performed in parallel, but the results array will be in the same order as the original. - * - * @param coll {Array | Object} A collection to iterate over. - * @param predicate {Function} - A truth test to apply to each item in coll. Invoked with (item, - * key/index), must return a boolean. - * @returns The filtered collection - */ -export declare function filter(input: T[], predicate: (value: T, index: number) => Promise): Promise; -export declare function filter(input: T[], predicate: (value: T) => Promise): Promise; -export declare function filter(input: T, predicate: (value: T[keyof T], key: keyof T) => Promise): Promise; -export declare function filter(input: T, predicate: (value: T[keyof T]) => Promise): Promise; diff --git a/dist/src/filter.js b/dist/src/filter.js deleted file mode 100644 index 6a7202b..0000000 --- a/dist/src/filter.js +++ /dev/null @@ -1,20 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const map_1 = require("./map"); -// tslint:disable-next-line:no-any (types are enforced by overload signatures, validated by tests) -async function filter(input, predicate) { - if (!input) { - return []; - } - // tslint:disable-next-line:no-any - const output = []; - // tslint:disable-next-line:no-any - await map_1.map(input, async (value, key) => { - if (await predicate(value, key)) { - output.push(value); - } - }); - return output; -} -exports.filter = filter; -//# sourceMappingURL=filter.js.map \ No newline at end of file diff --git a/dist/src/filter.js.map b/dist/src/filter.js.map deleted file mode 100644 index 2f3a96e..0000000 --- a/dist/src/filter.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/filter.ts"],"names":[],"mappings":";;AAAA,+BAA4B;AAwB5B,kGAAkG;AAC3F,KAAK,UAAU,MAAM,CAAC,KAAU,EAAE,SAAc;IACrD,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,EAAE,CAAC;KACX;IAED,kCAAkC;IAClC,MAAM,MAAM,GAAU,EAAE,CAAC;IACzB,kCAAkC;IAClC,MAAM,SAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAU,EAAE,GAAQ,EAAE,EAAE;QAC9C,IAAI,MAAM,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE;YAC/B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACpB;IACH,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAdD,wBAcC"} \ No newline at end of file diff --git a/dist/src/index.d.ts b/dist/src/index.d.ts deleted file mode 100644 index 2e9f5bf..0000000 --- a/dist/src/index.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -export * from './delay'; -export * from './filter'; -export * from './invert'; -export * from './map'; -export * from './retry'; -export * from './settleAll'; -export * from './timeout'; -export * from './memoize'; diff --git a/dist/src/index.js b/dist/src/index.js deleted file mode 100644 index bcbb98b..0000000 --- a/dist/src/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; -function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; -} -Object.defineProperty(exports, "__esModule", { value: true }); -__export(require("./delay")); -__export(require("./filter")); -__export(require("./invert")); -__export(require("./map")); -__export(require("./retry")); -__export(require("./settleAll")); -__export(require("./timeout")); -__export(require("./memoize")); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/src/index.js.map b/dist/src/index.js.map deleted file mode 100644 index 40e4331..0000000 --- a/dist/src/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AAAA,6BAAwB;AACxB,8BAAyB;AACzB,8BAAyB;AACzB,2BAAsB;AACtB,6BAAwB;AACxB,iCAA4B;AAC5B,+BAA0B;AAC1B,+BAA0B"} \ No newline at end of file diff --git a/dist/src/invert.d.ts b/dist/src/invert.d.ts deleted file mode 100644 index f87fd30..0000000 --- a/dist/src/invert.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Inverts the given promise - i.e. throws an error if it completes successfully and returns the - * error if it throws one. - * - * @param {Promise} promise - the promise to invert - * @param {string} message - the message to throw if the promise resolves - * @returns the error thrown by the promise - */ -export declare function invert(promise: Promise, message?: string): Promise; diff --git a/dist/src/invert.js b/dist/src/invert.js deleted file mode 100644 index f8f323c..0000000 --- a/dist/src/invert.js +++ /dev/null @@ -1,20 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const _ = require("lodash"); -/** - * Inverts the given promise - i.e. throws an error if it completes successfully and returns the - * error if it throws one. - * - * @param {Promise} promise - the promise to invert - * @param {string} message - the message to throw if the promise resolves - * @returns the error thrown by the promise - */ -// tslint:disable-next-line:no-any (returns the rejection which is untyped) -async function invert(promise, message) { - message = message || 'Expected promise to reject'; - return promise.then((res) => { - throw new Error(message); - }, _.identity); -} -exports.invert = invert; -//# sourceMappingURL=invert.js.map \ No newline at end of file diff --git a/dist/src/invert.js.map b/dist/src/invert.js.map deleted file mode 100644 index 19f2823..0000000 --- a/dist/src/invert.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"invert.js","sourceRoot":"","sources":["../../src/invert.ts"],"names":[],"mappings":";;AAAA,4BAA4B;AAE5B;;;;;;;GAOG;AACH,2EAA2E;AACpE,KAAK,UAAU,MAAM,CAAI,OAAmB,EAAE,OAAgB;IACnE,OAAO,GAAG,OAAO,IAAI,4BAA4B,CAAC;IAClD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,GAAM,EAAQ,EAAE;QACnC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;AACjB,CAAC;AALD,wBAKC"} \ No newline at end of file diff --git a/dist/src/map.d.ts b/dist/src/map.d.ts deleted file mode 100644 index 607fc77..0000000 --- a/dist/src/map.d.ts +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Produces a new collection of values by mapping each value in coll through the iteratee - * function. The iteratee is called with an item from coll and a callback for when it has finished - * processing. Each of these callback takes 2 arguments: an error, and the transformed item from - * coll. If iteratee passes an error to its callback, the main callback (for the map function) is - * immediately called with the error. - * - * Note, that since this function applies the iteratee to each item in parallel, there is no - * guarantee that the iteratee functions will complete in order. However, the results array will be - * in the same order as the original coll. - * - * @param {Array | Iterable | Object} input - A collection to iterate over. - * @param {AsyncFunction} iteratee - An async function to apply to each item in coll. The iteratee - * should return the transformed item. Invoked with (item, key). - */ -export declare function map(input: T[], iteratee: (value: T, index: number) => Promise): Promise; -export declare function map(input: T[], iteratee: (value: T) => Promise): Promise; -export declare function map(input: T, iteratee: (value: T[keyof T], key: string) => Promise): Promise; -export declare function map(input: T, iteratee: (value: T[keyof T]) => Promise): Promise; -/** - * The same as map but runs a maximum of limit async operations at a time. Also does not have the - * same ordering guarantees. - * - * @param {Array | Iterable | Object} input - A collection to iterate over. - * @param {number} limit - The maximum number of async operations at a time. - * @param {AsyncFunction} iteratee - An async function to apply to each item in coll. The iteratee - * should complete with the transformed item. Invoked with (item, key). - */ -export declare function mapLimit(input: T[], limit: number, iteratee: (value: T, index: number) => Promise): Promise; -export declare function mapLimit(input: T[], limit: number, iteratee: (value: T) => Promise): Promise; -export declare function mapLimit(input: T, limit: number, iteratee: (value: T[keyof T], key: string) => Promise): Promise; -export declare function mapLimit(input: T, limit: number, iteratee: (value: T[keyof T]) => Promise): Promise; -/** - * The same as mapLimit but with only 1 operation at a time, and maintains the ordering guarantees - * of map. - * - * @param {Array | Iterable | Object} input - A collection to iterate over. - * @param {AsyncFunction} iteratee - An async function to apply to each item in coll. The iteratee - * should complete with the transformed item. Invoked with (item, key). - */ -export declare function mapSeries(input: T[], iteratee: (value: T, index: number) => Promise): Promise; -export declare function mapSeries(input: T[], iteratee: (value: T) => Promise): Promise; -export declare function mapSeries(input: T, iteratee: (value: T[keyof T], key: string) => Promise): Promise; -export declare function mapSeries(input: T, iteratee: (value: T[keyof T]) => Promise): Promise; -/** - * The same as map but will flatten the results. - * - * @param {Array | Iterable | Object} input - A collection to iterate over. - * @param {AsyncFunction} iteratee - An async function to apply to each item in coll. The iteratee - * should complete with the transformed item. Invoked with (item, key). - */ -export declare function flatMap(input: T[], iteratee: (value: T, index: number) => Promise): Promise; -export declare function flatMap(input: T[], iteratee: (value: T) => Promise): Promise; -export declare function flatMap(input: T, iteratee: (value: T[keyof T], key: string) => Promise): Promise; -export declare function flatMap(input: T, iteratee: (value: T[keyof T]) => Promise): Promise; diff --git a/dist/src/map.js b/dist/src/map.js deleted file mode 100644 index be35f49..0000000 --- a/dist/src/map.js +++ /dev/null @@ -1,48 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const _ = require("lodash"); -// tslint:disable-next-line:no-any (types are enforced by overload signatures, validated by tests) -async function map(input, iteratee) { - if (!input) { - return []; - } - return Promise.all(_.map(input, iteratee)); -} -exports.map = map; -// tslint:disable-next-line:no-any (types are enforced by overload signatures, validated by tests) -async function mapLimit(input, limit, iteratee) { - if (!input) { - return []; - } - // tslint:disable-next-line:no-any - const stack = _.reverse(input.map ? _.clone(input) : _.toPairs(input)); - return await flatMap(_.range(limit), async () => { - const partialOutput = []; - while (!_.isEmpty(stack)) { - // tslint:disable-next-line:no-any - const val = stack.pop(); - if (input.map) { - partialOutput.push(await iteratee(val, stack.length)); - } - else { - partialOutput.push(await iteratee(..._.reverse(val))); - } - } - return partialOutput; - }); -} -exports.mapLimit = mapLimit; -// tslint:disable-next-line:no-any (types are enforced by overload signatures, validated by tests) -async function mapSeries(input, iteratee) { - return mapLimit(input, 1, iteratee); -} -exports.mapSeries = mapSeries; -// tslint:disable-next-line:no-any (types are enforced by overload signatures, validated by tests) -async function flatMap(input, iteratee) { - if (!input) { - return []; - } - return _.flatten(await map(input, iteratee)); -} -exports.flatMap = flatMap; -//# sourceMappingURL=map.js.map \ No newline at end of file diff --git a/dist/src/map.js.map b/dist/src/map.js.map deleted file mode 100644 index 0e67540..0000000 --- a/dist/src/map.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"map.js","sourceRoot":"","sources":["../../src/map.ts"],"names":[],"mappings":";;AAAA,4BAA4B;AA8B5B,kGAAkG;AAC3F,KAAK,UAAU,GAAG,CAAC,KAAU,EAAE,QAAa;IACjD,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,EAAE,CAAC;KACX;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC7C,CAAC;AALD,kBAKC;AA+BD,kGAAkG;AAC3F,KAAK,UAAU,QAAQ,CAAI,KAAU,EAAE,KAAa,EAAE,QAAa;IACxE,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,EAAE,CAAC;KACX;IAED,kCAAkC;IAClC,MAAM,KAAK,GAAU,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9E,OAAO,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,IAAI,EAAE;QAC9C,MAAM,aAAa,GAAQ,EAAE,CAAC;QAC9B,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACxB,kCAAkC;YAClC,MAAM,GAAG,GAAQ,KAAK,CAAC,GAAG,EAAE,CAAC;YAC7B,IAAI,KAAK,CAAC,GAAG,EAAE;gBACb,aAAa,CAAC,IAAI,CAAC,MAAM,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;aACvD;iBAAM;gBACL,aAAa,CAAC,IAAI,CAAC,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACvD;SACF;QACD,OAAO,aAAa,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC;AApBD,4BAoBC;AAuBD,kGAAkG;AAC3F,KAAK,UAAU,SAAS,CAAC,KAAU,EAAE,QAAa;IACvD,OAAO,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC;AAFD,8BAEC;AAyBD,kGAAkG;AAC3F,KAAK,UAAU,OAAO,CAAC,KAAU,EAAE,QAAa;IACrD,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,EAAE,CAAC;KACX;IACD,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC/C,CAAC;AALD,0BAKC"} \ No newline at end of file diff --git a/dist/src/memoize.d.ts b/dist/src/memoize.d.ts deleted file mode 100644 index b5e9129..0000000 --- a/dist/src/memoize.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Caches the results of an async function. When creating a hash to store function results against, - * the callback is omitted from the hash and an optional hash function can be used. - * - * If no hash function is specified, the first argument is used as a hash key, which may work - * reasonably if it is a string or a data type that converts to a distinct string. Note that objects - * and arrays will not behave reasonably. Neither will cases where the other arguments are - * significant. In such cases, specify your own hash function. - * - * @param {AsyncFunction} fn - The async function to proxy and cache results from. - * @param {Function} hasher - An optional function for generating a custom hash for storing - * results. It has all the arguments applied to it and must be synchronous. - * @returns a memoized version of fn - */ -export declare function memoize(fn: FnType, hasher?: Function, timeoutMs?: number): FnType; diff --git a/dist/src/memoize.js b/dist/src/memoize.js deleted file mode 100644 index c36f77d..0000000 --- a/dist/src/memoize.js +++ /dev/null @@ -1,52 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const _ = require("lodash"); -const moment = require("moment"); -/** - * Caches the results of an async function. When creating a hash to store function results against, - * the callback is omitted from the hash and an optional hash function can be used. - * - * If no hash function is specified, the first argument is used as a hash key, which may work - * reasonably if it is a string or a data type that converts to a distinct string. Note that objects - * and arrays will not behave reasonably. Neither will cases where the other arguments are - * significant. In such cases, specify your own hash function. - * - * @param {AsyncFunction} fn - The async function to proxy and cache results from. - * @param {Function} hasher - An optional function for generating a custom hash for storing - * results. It has all the arguments applied to it and must be synchronous. - * @returns a memoized version of fn - */ -function memoize(fn, hasher = _.identity, timeoutMs) { - // tslint:disable:no-any (unfortunately we can't give the FnType any more clarity or it limits - // what you can do with it) - const memos = new Map(); - const queues = new Map(); - return (async (...args) => { - const key = hasher(...args); - if (memos.has(key)) { - if (!timeoutMs || - moment(memos.get(key).timestamp) - .add(timeoutMs, 'milliseconds') - .isAfter(moment())) { - return memos.get(key).value; - } - } - if (queues.has(key)) { - return await queues.get(key); - } - const promise = fn(...args); - queues.set(key, promise); - try { - const ret = await queues.get(key); - memos.set(key, { value: ret, timestamp: Date.now() }); - return ret; - } - finally { - queues.delete(key); - } - }); - // tslint:enable:no-any (unfortunately we can't give the FnType any more clarity or it limits what - // you can do with it) -} -exports.memoize = memoize; -//# sourceMappingURL=memoize.js.map \ No newline at end of file diff --git a/dist/src/memoize.js.map b/dist/src/memoize.js.map deleted file mode 100644 index 661c400..0000000 --- a/dist/src/memoize.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/memoize.ts"],"names":[],"mappings":";;AAAA,4BAA4B;AAC5B,iCAAiC;AAEjC;;;;;;;;;;;;;GAaG;AACH,SAAgB,OAAO,CACrB,EAAU,EACV,SAAmB,CAAC,CAAC,QAAQ,EAC7B,SAAkB;IAElB,8FAA8F;IAC9F,2BAA2B;IAC3B,MAAM,KAAK,GAAgD,IAAI,GAAG,EAAE,CAAC;IACrE,MAAM,MAAM,GAA2B,IAAI,GAAG,EAAE,CAAC;IAEjD,OAAQ,CAAC,KAAK,EAAE,GAAG,IAAW,EAAgB,EAAE;QAC9C,MAAM,GAAG,GAAQ,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;QACjC,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAClB,IACE,CAAC,SAAS;gBACV,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,SAAS,CAAC;qBAC9B,GAAG,CAAC,SAAS,EAAE,cAAc,CAAC;qBAC9B,OAAO,CAAC,MAAM,EAAE,CAAC,EACpB;gBACA,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,KAAK,CAAC;aAC9B;SACF;QAED,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACnB,OAAO,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;SAC/B;QAED,MAAM,OAAO,GAAiB,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QAC1C,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAEzB,IAAI;YACF,MAAM,GAAG,GAAQ,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;YACxC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACtD,OAAO,GAAG,CAAC;SACZ;gBAAS;YACR,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;SACpB;IACH,CAAC,CAAmB,CAAC;IACrB,kGAAkG;IAClG,sBAAsB;AACxB,CAAC;AAxCD,0BAwCC"} \ No newline at end of file diff --git a/dist/src/retry.d.ts b/dist/src/retry.d.ts deleted file mode 100644 index 895c43a..0000000 --- a/dist/src/retry.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -export interface RetryOpts { - maxAttempts: number; - isRetryable?: (err: Error) => boolean; - delayMs?: number; -} -/** - * Attempts to get a successful response from task no more than times times before returning an - * error. If the task is successful, the callback will be passed the result of the successful - * task. If all attempts fail, the callback will be passed the error and result (if any) of the - * final attempt. - * - * @param {AsyncFunction} fn - An async function to retry. - * @param {RetryOpts} opts - * - maxAttempts - The number of attempts to make before giving up. - * - delayMs - The time to wait between retries, in milliseconds. The default is 0. - * - isRetryable - An optional synchronous function that is invoked on erroneous result. If it - * returns true the retry attempts will continue; if the function returns false the retry - * flow is aborted with the current attempt's error and result being returned. Invoked - * with (err). - * @returns A wrapped version of function that performs retries - */ -export declare function retry(fn: T, retryOpts: RetryOpts): T; diff --git a/dist/src/retry.js b/dist/src/retry.js deleted file mode 100644 index c15fe6e..0000000 --- a/dist/src/retry.js +++ /dev/null @@ -1,44 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const _ = require("lodash"); -const delay_1 = require("./delay"); -/** - * Attempts to get a successful response from task no more than times times before returning an - * error. If the task is successful, the callback will be passed the result of the successful - * task. If all attempts fail, the callback will be passed the error and result (if any) of the - * final attempt. - * - * @param {AsyncFunction} fn - An async function to retry. - * @param {RetryOpts} opts - * - maxAttempts - The number of attempts to make before giving up. - * - delayMs - The time to wait between retries, in milliseconds. The default is 0. - * - isRetryable - An optional synchronous function that is invoked on erroneous result. If it - * returns true the retry attempts will continue; if the function returns false the retry - * flow is aborted with the current attempt's error and result being returned. Invoked - * with (err). - * @returns A wrapped version of function that performs retries - */ -function retry(fn, retryOpts) { - // tslint:disable-next-line:no-any (casting as any to preserve original function type) - return (async (...args) => { - let lastErr = new Error(`Could not complete function within ${retryOpts.maxAttempts}`); - for (const __ of _.range(retryOpts.maxAttempts)) { - try { - return await fn(...args); - } - catch (err) { - if (retryOpts.isRetryable && !retryOpts.isRetryable(err)) { - throw err; - } - lastErr = err; - } - if (retryOpts.delayMs) { - await delay_1.delay(retryOpts.delayMs); - } - } - throw lastErr; - // tslint:disable-next-line:no-any (casting as any to preserve original function type) - }); -} -exports.retry = retry; -//# sourceMappingURL=retry.js.map \ No newline at end of file diff --git a/dist/src/retry.js.map b/dist/src/retry.js.map deleted file mode 100644 index 12ff209..0000000 --- a/dist/src/retry.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/retry.ts"],"names":[],"mappings":";;AAAA,4BAA4B;AAE5B,mCAAgC;AAQhC;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,KAAK,CAAqB,EAAK,EAAE,SAAoB;IACnE,sFAAsF;IACtF,OAAQ,CAAC,KAAK,EAAE,GAAG,IAAW,EAAgB,EAAE;QAC9C,IAAI,OAAO,GAAU,IAAI,KAAK,CAAC,sCAAsC,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC;QAC9F,KAAK,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE;YAC/C,IAAI;gBACF,OAAO,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;aAC1B;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,SAAS,CAAC,WAAW,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE;oBACxD,MAAM,GAAG,CAAC;iBACX;gBACD,OAAO,GAAG,GAAG,CAAC;aACf;YACD,IAAI,SAAS,CAAC,OAAO,EAAE;gBACrB,MAAM,aAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;aAChC;SACF;QACD,MAAM,OAAO,CAAC;QACd,sFAAsF;IACxF,CAAC,CAAc,CAAC;AAClB,CAAC;AApBD,sBAoBC"} \ No newline at end of file diff --git a/dist/src/settleAll.d.ts b/dist/src/settleAll.d.ts deleted file mode 100644 index f01245e..0000000 --- a/dist/src/settleAll.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Attempts to settle all promises in promises in parallel, calling errFn when a promise rejects. - * Similar to Promise.all, but does not fail fast. For resolved promises, the result array contains - * the resolved value at the same index as the promise. For rejected promises, the result array - * contains the return value of errFn at the same index as the promise. - * - * @param {Promise[]} promises - An array of promises to attempt to settle. - * @param {Function} errFn - The function to call when a promise rejects. - * - * @returns A list of resolved and rejected values of promises. - */ -export declare function settleAll(promises: Promise[], errFn?: (err: Error) => V): Promise<{ - errors: V[]; - results: T[]; -}>; diff --git a/dist/src/settleAll.js b/dist/src/settleAll.js deleted file mode 100644 index d07c4a2..0000000 --- a/dist/src/settleAll.js +++ /dev/null @@ -1,31 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const _ = require("lodash"); -const map_1 = require("./map"); -/** - * Attempts to settle all promises in promises in parallel, calling errFn when a promise rejects. - * Similar to Promise.all, but does not fail fast. For resolved promises, the result array contains - * the resolved value at the same index as the promise. For rejected promises, the result array - * contains the return value of errFn at the same index as the promise. - * - * @param {Promise[]} promises - An array of promises to attempt to settle. - * @param {Function} errFn - The function to call when a promise rejects. - * - * @returns A list of resolved and rejected values of promises. - */ -async function settleAll(promises, errFn = _.identity) { - const intermediateResults = await map_1.map(promises, async (p) => { - try { - return { results: await p }; - } - catch (err) { - return { errors: errFn(err) }; - } - }); - return _.reduce(intermediateResults, (acc, intermediateResult) => { - _.map(intermediateResult, (value, key) => _.get(acc, key).push(value)); - return acc; - }, { results: [], errors: [] }); -} -exports.settleAll = settleAll; -//# sourceMappingURL=settleAll.js.map \ No newline at end of file diff --git a/dist/src/settleAll.js.map b/dist/src/settleAll.js.map deleted file mode 100644 index f5d9d7a..0000000 --- a/dist/src/settleAll.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"settleAll.js","sourceRoot":"","sources":["../../src/settleAll.ts"],"names":[],"mappings":";;AAAA,4BAA4B;AAC5B,+BAA4B;AAE5B;;;;;;;;;;GAUG;AACI,KAAK,UAAU,SAAS,CAC7B,QAAsB,EACtB,QAA2B,CAAC,CAAC,QAAQ;IAErC,MAAM,mBAAmB,GAAkC,MAAM,SAAG,CAClE,QAAQ,EACR,KAAK,EAAE,CAAa,EAAE,EAAE;QACtB,IAAI;YACF,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC;SAC7B;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;SAC/B;IACH,CAAC,CACF,CAAC;IACF,OAAO,CAAC,CAAC,MAAM,CACb,mBAAmB,EACnB,CAAC,GAAkC,EAAE,kBAA+C,EAAE,EAAE;QACtF,CAAC,CAAC,GAAG,CAAC,kBAAkB,EAAE,CAAC,KAAY,EAAE,GAAW,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACtF,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAC5B,CAAC;AACJ,CAAC;AAtBD,8BAsBC"} \ No newline at end of file diff --git a/dist/src/timeout.d.ts b/dist/src/timeout.d.ts deleted file mode 100644 index e8d0303..0000000 --- a/dist/src/timeout.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Sets a time limit on an asynchronous function. If the function does return callback within - * the specified milliseconds, it will be called with a timeout error. - * - * @param {AsyncFunction} fn - The async function to limit in time. - * @param {number} expirationTime - The specified time limit. - * @param {string} errorMessage - The message that should be sent if the function times out - * @returns Returns a wrapped function that will throw an error if it takes too long. Invoke this - * function with the same parameters as you would fn. - */ -export declare function timeout(fn: T, expirationTime: number, errorMessage?: string): T; diff --git a/dist/src/timeout.js b/dist/src/timeout.js deleted file mode 100644 index 3800c69..0000000 --- a/dist/src/timeout.js +++ /dev/null @@ -1,28 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -/** - * Sets a time limit on an asynchronous function. If the function does return callback within - * the specified milliseconds, it will be called with a timeout error. - * - * @param {AsyncFunction} fn - The async function to limit in time. - * @param {number} expirationTime - The specified time limit. - * @param {string} errorMessage - The message that should be sent if the function times out - * @returns Returns a wrapped function that will throw an error if it takes too long. Invoke this - * function with the same parameters as you would fn. - */ -function timeout(fn, expirationTime, errorMessage) { - errorMessage = - errorMessage || `Could not resolve ${fn.name || ''} within ${expirationTime} ms`; - // tslint:disable-next-line:typedef no-any (typedef is hacked because we're hijacking fn) - return async function race() { - return Promise.race([ - new Promise((__, reject) => { - setTimeout(() => reject(new Error(errorMessage)), expirationTime); - }), - fn.apply(this, arguments), - ]); - // tslint:disable-next-line:no-any (need to cast to any because we hacked together the typedef) - }; -} -exports.timeout = timeout; -//# sourceMappingURL=timeout.js.map \ No newline at end of file diff --git a/dist/src/timeout.js.map b/dist/src/timeout.js.map deleted file mode 100644 index af46422..0000000 --- a/dist/src/timeout.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../src/timeout.ts"],"names":[],"mappings":";;AAAA;;;;;;;;;GASG;AACH,SAAgB,OAAO,CACrB,EAAK,EACL,cAAsB,EACtB,YAAqB;IAErB,YAAY;QACV,YAAY,IAAI,qBAAqB,EAAE,CAAC,IAAI,IAAI,aAAa,WAAW,cAAc,KAAK,CAAC;IAC9F,yFAAyF;IACzF,OAAQ,KAAK,UAAU,IAAI;QACzB,OAAO,OAAO,CAAC,IAAI,CAAC;YAClB,IAAI,OAAO,CACT,CAAC,EAAY,EAAE,MAAgB,EAAQ,EAAE;gBACvC,UAAU,CAAC,GAAS,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;YAC1E,CAAC,CACgB;YACnB,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC;SAC1B,CAAC,CAAC;QACH,+FAA+F;IACjG,CAAc,CAAC;AACjB,CAAC;AAnBD,0BAmBC"} \ No newline at end of file diff --git a/package.json b/package.json index af2fc9a..006ad2f 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "main": "dist/src/index.js", "types": "dist/src/index.d.ts", "scripts": { + "prepare": "tsc", "pretty": "prettier --list-different '{src,test}/**/**/*.ts'", "lintSrc": "tslint --project tsconfig.json --config tslint.js 'src/**/*.ts'", "lintTest": "tslint --project tsconfig.json --config tslint.test.js 'test/**/*.ts'",