stack-promises
Advanced tools
Comparing version 0.0.10 to 0.0.11
export declare const isEmptyStackError: (error: Error) => boolean; | ||
export declare const promiseIsNotActualError: Error; | ||
export declare const isPromiseIsNotActualError: (error: Error) => boolean; | ||
declare const creteStackPromises: <T = any>() => { | ||
declare const creteStackPromises: <T = any>({ noRejectIsNotActual, }?: { | ||
noRejectIsNotActual?: boolean | undefined; | ||
}) => { | ||
(): Promise<Error | T>; | ||
add: (task: () => Promise<T>) => any; | ||
run: (task: () => Promise<T>) => Promise<Error | T>; | ||
stop: () => void; | ||
@@ -8,0 +11,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import e from"sequent-promises";const t=new Error("Stack is empty"),s=e=>e===t,n=new Error("Promise is not actual"),r=e=>e===n,o=new Error("stackPromises only works with functions that returns a Promise"),i=()=>{const s=[],r=[],i=({task:e,index:t})=>()=>{let s=(({task:e,index:t})=>{const s=r.find((({task:s,index:n})=>e===s&&t===n));if(s)return s.promise})({task:e,index:t});return s||(s=e(),(({task:e,promise:t,index:s})=>{r.push({task:e,promise:t,index:s})})({promise:s,task:e,index:t})),s};let c=!1;const a=()=>c,l=()=>(c=!0,e(s,a)),u=()=>0===s.length?Promise.reject(t):new Promise(((e,t)=>{const r=(({resolve:e,reject:t})=>({results:r,isSuccessful:o})=>{if(r.length===s.length){const s=r[r.length-1];o?e(s):t(s)}else t(n)})({resolve:e,reject:t});l().then(r).catch(r)}));return u.add=e=>{if("function"!=typeof e)throw o;const t=s.length;return s.push(i({task:e,index:t})),u},u.stop=()=>{c=!1,s.length=0,r.length=0},u};export{i as default,s as isEmptyStackError,r as isPromiseIsNotActualError,n as promiseIsNotActualError}; | ||
import e from"sequent-promises";const t=new Error("Stack is empty"),s=e=>e===t,n=new Error("Promise is not actual"),r=e=>e===n,o=new Error("stackPromises only works with functions that returns a Promise"),i=({noRejectIsNotActual:s=!1}={})=>{const r=[],i=[],c=({task:e,index:t})=>()=>{let s=(({task:e,index:t})=>{const s=i.find((({task:s,index:n})=>e===s&&t===n));if(s)return s.promise})({task:e,index:t});return s||(s=e(),(({task:e,promise:t,index:s})=>{i.push({task:e,promise:t,index:s})})({promise:s,task:e,index:t})),s};let a=!1;const u=()=>a,l=()=>(a=!0,e(r,u)),h=()=>0===r.length?Promise.reject(t):new Promise(((e,t)=>{const o=(({resolve:e,reject:t})=>({results:o,isSuccessful:i})=>{if(o.length===r.length){const s=o[o.length-1];return i?e(s):t(s)}if(s){const t=o[o.length-1];return e(t)}t(n)})({resolve:e,reject:t});l().then(o).catch(o)})),m=e=>{if("function"!=typeof e)throw o;const t=r.length;return r.push(c({task:e,index:t})),h};return h.add=m,h.run=e=>(m(e),h()),h.stop=()=>{a=!1,r.length=0,i.length=0},h};export{i as default,s as isEmptyStackError,r as isPromiseIsNotActualError,n as promiseIsNotActualError}; | ||
//# sourceMappingURL=index.es5.js.map |
@@ -19,3 +19,3 @@ "use strict"; | ||
const notFunctionError = new Error('stackPromises only works with functions that returns a Promise'); | ||
const creteStackPromises = () => { | ||
const creteStackPromises = ({ noRejectIsNotActual = false, } = {}) => { | ||
const runnersStack = []; | ||
@@ -49,14 +49,16 @@ const tasksStack = []; | ||
const sizeStackPromises = runnersStack.length; | ||
if (sizePromises === sizeStackPromises) { | ||
const isActual = sizePromises === sizeStackPromises; | ||
if (isActual) { | ||
const lastResult = results[results.length - 1]; | ||
if (isSuccessful) { | ||
resolve(lastResult); | ||
return resolve(lastResult); | ||
} | ||
else { | ||
reject(lastResult); | ||
} | ||
return reject(lastResult); | ||
} | ||
else { | ||
reject(exports.promiseIsNotActualError); | ||
if (noRejectIsNotActual) { | ||
const lastResult = results[results.length - 1]; | ||
return resolve(lastResult); | ||
} | ||
reject(exports.promiseIsNotActualError); | ||
return undefined; | ||
}; | ||
@@ -95,2 +97,6 @@ }; | ||
}; | ||
const run = (task) => { | ||
addTaskToStack(task); | ||
return result(); | ||
}; | ||
const clearStacks = () => { | ||
@@ -105,2 +111,3 @@ runnersStack.length = 0; | ||
result.add = addTaskToStack; | ||
result.run = run; | ||
result.stop = stop; | ||
@@ -107,0 +114,0 @@ return result; |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("sequent-promises")):"function"==typeof define&&define.amd?define(["exports","sequent-promises"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).sipConnector={},e.sequentPromisesList)}(this,(function(e,t){"use strict";function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=s(t);const r=new Error("Stack is empty"),o=new Error("Promise is not actual"),i=new Error("stackPromises only works with functions that returns a Promise");e.default=()=>{const e=[],t=[],s=({task:e,index:s})=>()=>{let n=(({task:e,index:s})=>{const n=t.find((({task:t,index:n})=>e===t&&s===n));if(n)return n.promise})({task:e,index:s});return n||(n=e(),(({task:e,promise:s,index:n})=>{t.push({task:e,promise:s,index:n})})({promise:n,task:e,index:s})),n};let u=!1;const c=()=>u,l=()=>(u=!0,n.default(e,c)),a=()=>0===e.length?Promise.reject(r):new Promise(((t,s)=>{const n=(({resolve:t,reject:s})=>({results:n,isSuccessful:r})=>{if(n.length===e.length){const e=n[n.length-1];r?t(e):s(e)}else s(o)})({resolve:t,reject:s});l().then(n).catch(n)}));return a.add=t=>{if("function"!=typeof t)throw i;const n=e.length;return e.push(s({task:t,index:n})),a},a.stop=()=>{u=!1,e.length=0,t.length=0},a},e.isEmptyStackError=e=>e===r,e.isPromiseIsNotActualError=e=>e===o,e.promiseIsNotActualError=o,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("sequent-promises")):"function"==typeof define&&define.amd?define(["exports","sequent-promises"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).sipConnector={},e.sequentPromisesList)}(this,(function(e,t){"use strict";const s=new Error("Stack is empty"),n=new Error("Promise is not actual"),r=new Error("stackPromises only works with functions that returns a Promise");e.default=({noRejectIsNotActual:e=!1}={})=>{const o=[],i=[],u=({task:e,index:t})=>()=>{let s=(({task:e,index:t})=>{const s=i.find((({task:s,index:n})=>e===s&&t===n));if(s)return s.promise})({task:e,index:t});return s||(s=e(),(({task:e,promise:t,index:s})=>{i.push({task:e,promise:t,index:s})})({promise:s,task:e,index:t})),s};let c=!1;const l=()=>c,a=()=>(c=!0,t(o,l)),f=()=>0===o.length?Promise.reject(s):new Promise(((t,s)=>{const r=(({resolve:t,reject:s})=>({results:r,isSuccessful:i})=>{if(r.length===o.length){const e=r[r.length-1];return i?t(e):s(e)}if(e){const e=r[r.length-1];return t(e)}s(n)})({resolve:t,reject:s});a().then(r).catch(r)})),d=e=>{if("function"!=typeof e)throw r;const t=o.length;return o.push(u({task:e,index:t})),f};return f.add=d,f.run=e=>(d(e),f()),f.stop=()=>{c=!1,o.length=0,i.length=0},f},e.isEmptyStackError=e=>e===s,e.isPromiseIsNotActualError=e=>e===n,e.promiseIsNotActualError=n,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "stack-promises", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "sequentPromises resolves Promises sequentially", | ||
@@ -44,28 +44,28 @@ "keywords": [ | ||
"devDependencies": { | ||
"@commitlint/cli": "^17.1.2", | ||
"@commitlint/config-conventional": "^17.1.0", | ||
"@rollup/plugin-commonjs": "^21.0.1", | ||
"@rollup/plugin-node-resolve": "^13.1.3", | ||
"@types/jest": "^29.1.2", | ||
"@types/node": "^18.8.5", | ||
"@typescript-eslint/eslint-plugin": "^5.40.0", | ||
"@typescript-eslint/parser": "^5.40.0", | ||
"eslint": "^8.25.0", | ||
"@commitlint/cli": "^17.4.4", | ||
"@commitlint/config-conventional": "^17.4.4", | ||
"@rollup/plugin-commonjs": "^24.0.1", | ||
"@rollup/plugin-node-resolve": "^15.0.1", | ||
"@types/jest": "^29.4.2", | ||
"@types/node": "^18.15.3", | ||
"@typescript-eslint/eslint-plugin": "^5.55.0", | ||
"@typescript-eslint/parser": "^5.55.0", | ||
"eslint": "^8.36.0", | ||
"eslint-config-airbnb": "^19.0.4", | ||
"eslint-config-airbnb-typescript": "17.0.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jest": "^27.1.1", | ||
"eslint-config-prettier": "^8.7.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-jest": "^27.2.1", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"husky": "^8.0.1", | ||
"jest": "29.1.2", | ||
"lint-staged": "^13.0.3", | ||
"prettier": "^2.7.1", | ||
"husky": "^8.0.3", | ||
"jest": "29.5.0", | ||
"lint-staged": "^13.2.0", | ||
"prettier": "^2.8.4", | ||
"promise-delay": "^2.1.0", | ||
"rollup": "^2.64.0", | ||
"rollup": "^3.19.1", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"rollup-plugin-typescript2": "0.31.1", | ||
"rollup-plugin-typescript2": "0.34.1", | ||
"standard-version": "^9.5.0", | ||
"ts-jest": "^29.0.3", | ||
"typescript": "^4.8.4" | ||
"ts-jest": "^29.0.5", | ||
"typescript": "^4.9.5" | ||
}, | ||
@@ -72,0 +72,0 @@ "main:src": "src/index.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
29080
137