sequent-promises
Advanced tools
Comparing version 0.1.4 to 1.0.0
@@ -1,7 +0,7 @@ | ||
declare type TTask<T> = () => Promise<T>; | ||
declare type TCustomError<T> = Error & { | ||
type TTask<T> = () => Promise<T>; | ||
type TCustomError<T> = Error & { | ||
basePromise: TTask<T>; | ||
id: string; | ||
}; | ||
export declare const isNotRunningError: (error: any) => any; | ||
export declare const isNotRunningError: (error?: unknown) => boolean; | ||
/** | ||
@@ -40,2 +40,1 @@ * sequentPromises resolves Promises sequentially. | ||
export default sequentPromises; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,74 +0,29 @@ | ||
"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 u = "ERROR_NOT_RUNNING", a = (s) => { | ||
const e = new Error("Promise was not running"); | ||
return e.basePromise = s, e.id = u, e.name = "Not running", e; | ||
}, f = (s) => s != null && typeof s == "object" && "id" in s && s.id === u, m = async (s, e) => s.reduce( | ||
async (c, n) => c.then(async ({ success: t, errors: o, results: i }) => (!e || e(n) ? n() : Promise.reject(a(n))).then((r) => ({ | ||
errors: o, | ||
success: [...t, r], | ||
results: [...i, r], | ||
isSuccessful: !0, | ||
isError: !1 | ||
})).catch((r) => ({ | ||
success: t, | ||
errors: [...o, r], | ||
results: [...i, r], | ||
isSuccessful: !1, | ||
isError: !0 | ||
}))), | ||
Promise.resolve({ | ||
success: [], | ||
errors: [], | ||
results: [], | ||
isSuccessful: !1, | ||
isError: !1 | ||
}) | ||
); | ||
export { | ||
m as default, | ||
f as isNotRunningError | ||
}; | ||
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 |
109
package.json
{ | ||
"name": "sequent-promises", | ||
"version": "0.1.4", | ||
"version": "1.0.0", | ||
"description": "sequentPromises resolves Promises sequentially", | ||
@@ -21,57 +21,68 @@ "keywords": [ | ||
}, | ||
"main": "dist/index.umd.js", | ||
"module": "dist/index.es5.js", | ||
"typings": "dist/index.d.ts", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.cjs", | ||
"import": "./dist/index.js" | ||
} | ||
}, | ||
"main": "./dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist/**/*", | ||
"README.md" | ||
"dist" | ||
], | ||
"scripts": { | ||
"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", | ||
"prepublishOnly": "npm test && npm run lint", | ||
"release": "standard-version", | ||
"test": "jest" | ||
"build": "vite build", | ||
"lint": "yarn lint:js && yarn lint:ts", | ||
"lint:js": "eslint src --ext ts,tsx --ignore-path .gitignore --report-unused-disable-directives --max-warnings 0", | ||
"lint:ts": "tsc", | ||
"prepare": "husky install", | ||
"prepublishOnly": "yarn build", | ||
"preview": "vite preview", | ||
"release": "standard-version && yarn release:publish", | ||
"release:major": "standard-version --release-as major && yarn release:publish", | ||
"release:pre": "standard-version --prerelease && yarn release:publish", | ||
"release:publish": "git push --follow-tags origin master && npm publish", | ||
"test": "jest --watch", | ||
"test:ci": "cross-env CI=true jest --passWithNoTests", | ||
"test:coverage": "yarn test:ci --coverage --reporters=default --reporters=jest-junit" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^16.0.2", | ||
"@commitlint/config-conventional": "^16.0.0", | ||
"@rollup/plugin-commonjs": "^21.0.1", | ||
"@rollup/plugin-node-resolve": "^13.1.3", | ||
"@types/jest": "^27.4.0", | ||
"@types/node": "^17.0.9", | ||
"@typescript-eslint/eslint-plugin": "^5.10.0", | ||
"@typescript-eslint/parser": "^5.10.0", | ||
"eslint": "^8.7.0", | ||
"eslint-config-airbnb": "^19.0.4", | ||
"eslint-config-airbnb-typescript": "16.1.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-import": "^2.25.4", | ||
"eslint-plugin-jest": "^25.7.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"husky": "^7.0.4", | ||
"jest": "27.4.7", | ||
"lint-staged": "^12.1.7", | ||
"prettier": "^2.5.1", | ||
"promise-delay": "^2.1.0", | ||
"rollup": "^2.64.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"rollup-plugin-typescript2": "0.31.1", | ||
"standard-version": "^9.3.2", | ||
"ts-jest": "^27.1.3", | ||
"typescript": "^4.5.4" | ||
"@babel/preset-typescript": "^7.23.2", | ||
"@commitlint/cli": "^18.0.0", | ||
"@commitlint/config-conventional": "^18.0.0", | ||
"@nabla/vite-plugin-eslint": "^1.5.0", | ||
"@types/jest": "^29.5.6", | ||
"@typescript-eslint/eslint-plugin": "^6.9.0", | ||
"@typescript-eslint/parser": "^6.9.0", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.52.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-config-airbnb-typescript": "^17.1.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-import-resolver-typescript": "^3.6.1", | ||
"eslint-plugin-flowtype": "^8.0.3", | ||
"eslint-plugin-import": "^2.29.0", | ||
"eslint-plugin-jest": "^27.4.3", | ||
"eslint-plugin-prettier": "^5.0.1", | ||
"eslint-plugin-unicorn": "^48.0.1", | ||
"husky": "^8.0.3", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"jest-extended": "^4.0.2", | ||
"jest-junit": "^16.0.0", | ||
"lint-staged": "^15.0.2", | ||
"prettier": "^3.0.3", | ||
"standard-version": "^9.5.0", | ||
"ts-jest": "^29.1.1", | ||
"ts-node": "^10.9.1", | ||
"tsc-files": "^1.1.4", | ||
"typescript": "^5.2.2", | ||
"vite": "^4.5.0", | ||
"vite-plugin-dts": "^3.6.1", | ||
"vite-tsconfig-paths": "^4.2.1" | ||
}, | ||
"main:src": "src/index.ts", | ||
"standard-version": { | ||
"scripts": { | ||
"prerelease": "npm run lint && CI=true npm test", | ||
"postchangelog": "prettier --write \"CHANGELOG.md\"" | ||
} | ||
} | ||
"peerDependencies": {}, | ||
"main:src": "src/index.ts" | ||
} |
@@ -40,3 +40,3 @@ # sequent-promises | ||
console.log(isNotRunningError(errors[0])); //true; | ||
} | ||
}, | ||
); | ||
@@ -55,3 +55,3 @@ ``` | ||
- Website: https://krivega.com | ||
- Website: <https://krivega.com> | ||
- Github: [@Krivega](https://github.com/Krivega) | ||
@@ -58,0 +58,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
Yes
8436
33
6
71
1