sequent-promises
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -1,1 +0,74 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const s=()=>!0;exports.default=(r,e=s)=>r.reduce(((s,r)=>s.then((({success:s,errors:t,results:o})=>{let u;return u=e(r)?r():Promise.reject((s=>{const r=new Error("Promise was not running");return r.basePromise=s,r.id="ERROR_NOT_RUNNING",r.name="Not running",r})(r)),u.then((r=>({errors:t,success:[...s,r],results:[...o,r],isSuccessful:!0,isError:!1}))).catch((r=>({success:s,errors:[...t,r],results:[...o,r],isSuccessful:!1,isError:!0})))}))),Promise.resolve({success:[],errors:[],results:[]})),exports.isNotRunningError=({id:s})=>"ERROR_NOT_RUNNING"===s; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isNotRunningError = void 0; | ||
const idError = 'ERROR_NOT_RUNNING'; | ||
const createErrorNotRunning = (basePromise) => { | ||
const error = new Error('Promise was not running'); | ||
error.basePromise = basePromise; | ||
error.id = idError; | ||
error.name = 'Not running'; | ||
return error; | ||
}; | ||
const isNotRunningError = (error) => { | ||
return error && error.id === idError; | ||
}; | ||
exports.isNotRunningError = isNotRunningError; | ||
/** | ||
* sequentPromises resolves Promises sequentially. | ||
* | ||
* @func | ||
* @category Function | ||
* | ||
* @param {array} promises - Functions returns promises | ||
* @param {function} canRunTask - Function returns true, if need run current task | ||
* | ||
* @returns {Promise} resolved object with arrays of success, errors and results. | ||
* isSuccessful, isError - for last result | ||
* | ||
* @example | ||
* const urls = ['/url1', '/url2', '/url3'] | ||
* const fetchUrls = urls.map(url => () => fetch(url)) | ||
* | ||
* sequentPromises(fetchUrls) | ||
* .then(({success, errors, results, isSuccessful, isError}) => { | ||
* console.log(success); | ||
* console.error(errors); | ||
* console.log(results); | ||
* console.log(isSuccessful); | ||
* console.log(isError); | ||
* }) | ||
*/ | ||
const sequentPromises = (promises, canRunTask) => { | ||
return promises.reduce((promiseChain, currentTask) => { | ||
return promiseChain.then(({ success, errors, results }) => { | ||
let taskPromise; | ||
if (!canRunTask || canRunTask(currentTask)) { | ||
taskPromise = currentTask(); | ||
} | ||
else { | ||
taskPromise = Promise.reject(createErrorNotRunning(currentTask)); | ||
} | ||
return taskPromise | ||
.then((currentResult) => { | ||
return { | ||
errors, | ||
success: [...success, currentResult], | ||
results: [...results, currentResult], | ||
isSuccessful: true, | ||
isError: false, | ||
}; | ||
}) | ||
.catch((currentError) => { | ||
return { | ||
success, | ||
errors: [...errors, currentError], | ||
results: [...results, currentError], | ||
isSuccessful: false, | ||
isError: true, | ||
}; | ||
}); | ||
}); | ||
}, Promise.resolve({ success: [], errors: [], results: [], isSuccessful: false, isError: false })); | ||
}; | ||
exports.default = sequentPromises; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "sequent-promises", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "sequentPromises resolves Promises sequentially", | ||
@@ -21,10 +21,5 @@ "keywords": [ | ||
}, | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js" | ||
} | ||
}, | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"main": "dist/index.umd.js", | ||
"module": "dist/index.es5.js", | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
@@ -35,5 +30,8 @@ "dist/**/*", | ||
"scripts": { | ||
"build": "NODE_ENV=production rollup --config", | ||
"format": "prettier --write \"src/**/*.js\"", | ||
"lint": "eslint src/. --ext .js", | ||
"prebuild": "rimraf dist", | ||
"build": "yarn build:ts && yarn build:js", | ||
"build:js": "NODE_ENV=production rollup --config", | ||
"build:ts": "tsc --build tsconfig.build.json", | ||
"format": "prettier --write \"src/**/*.ts\"", | ||
"lint": "eslint src/. --ext .ts", | ||
"prepare": "npm run build", | ||
@@ -44,30 +42,30 @@ "prepublishOnly": "npm test && npm run lint", | ||
}, | ||
"dependencies": { | ||
"promise-delay": "^2.1.0" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@babel/core": "^7.12.10", | ||
"@babel/preset-env": "^7.12.11", | ||
"@commitlint/cli": "^11.0.0", | ||
"@commitlint/config-conventional": "^11.0.0", | ||
"babel-eslint": "10.1.0", | ||
"babel-jest": "^26.6.3", | ||
"eslint": "^7.16.0", | ||
"eslint-config-airbnb": "^18.2.1", | ||
"eslint-config-prettier": "^7.1.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-jest": "^24.1.3", | ||
"eslint-plugin-jsx-a11y": "^6.4.1", | ||
"eslint-plugin-prettier": "^3.3.0", | ||
"eslint-plugin-react": "^7.21.5", | ||
"husky": "^4.3.6", | ||
"jest": "26.6.3", | ||
"lint-staged": "^10.5.3", | ||
"prettier": "^2.2.1", | ||
"rollup": "^2.35.1", | ||
"rollup-plugin-babel": "^4.4.0", | ||
"@commitlint/cli": "^13.1.0", | ||
"@commitlint/config-conventional": "^13.1.0", | ||
"@rollup/plugin-commonjs": "^19.0.2", | ||
"@rollup/plugin-node-resolve": "^13.0.4", | ||
"@types/jest": "^26.0.24", | ||
"@types/node": "^16.4.5", | ||
"@typescript-eslint/eslint-plugin": "^4.28.5", | ||
"@typescript-eslint/parser": "^4.28.5", | ||
"eslint": "^7.31.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-import": "^2.23.4", | ||
"eslint-plugin-jest": "^24.4.0", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"husky": "^7.0.1", | ||
"jest": "27.0.6", | ||
"lint-staged": "^11.1.1", | ||
"prettier": "^2.3.2", | ||
"promise-delay": "^2.1.0", | ||
"rollup": "^2.55.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"standard-version": "^9.0.0" | ||
"rollup-plugin-typescript2": "0.30.0", | ||
"standard-version": "^9.3.1", | ||
"ts-jest": "^27.0.4", | ||
"typescript": "^4.3.5" | ||
}, | ||
"main:src": "src/index.js", | ||
"main:src": "src/index.ts", | ||
"standard-version": { | ||
@@ -74,0 +72,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
19790
0
11
121
0
24
- Removedpromise-delay@^2.1.0
- Removedpromise-delay@2.1.0(transitive)