Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stack-promises

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stack-promises - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

7

dist/index.d.ts
export declare const isEmptyStackError: (error: Error) => boolean;
export declare const promiseIsNotActualError: Error;
export declare const isPromiseIsNotActualError: (error: Error) => boolean;
declare const creteStackPromises: <T>({ noRejectIsNotActual, noRunIsNotActual, }?: {
noRejectIsNotActual?: boolean | undefined;
noRunIsNotActual?: boolean | undefined;
export declare const creteStackPromises: <T>({ noRejectIsNotActual, noRunIsNotActual, }?: {
noRejectIsNotActual?: boolean;
noRunIsNotActual?: boolean;
}) => {

@@ -17,2 +17,1 @@ (): Promise<T>;

};
export default creteStackPromises;

@@ -1,104 +0,83 @@

const L = "ERROR_NOT_RUNNING", b = (n) => {
const o = new Error("Promise was not running");
return o.basePromise = n, o.id = L, o.name = "Not running", o;
}, x = async (n, o) => n.reduce(
async (a, c) => a.then(async ({ success: k, errors: m, results: f }) => (!o || o(c) ? c() : Promise.reject(b(c))).then((u) => ({
errors: m,
success: [...k, u],
results: [...f, u],
isSuccessful: !0,
isError: !1
})).catch((u) => ({
success: k,
errors: [...m, u],
results: [...f, u],
isSuccessful: !1,
isError: !0
}))),
Promise.resolve({
success: [],
errors: [],
results: [],
isSuccessful: !1,
isError: !1
})
), E = new Error("Stack is empty"), T = (n) => n[n.length - 1], O = (n) => n === E, y = new Error("Promise is not actual"), _ = (n) => n === y, z = new Error(
import { sequentPromises as b } from "sequent-promises";
const h = new Error("Stack is empty"), m = (o) => o[o.length - 1], N = (o) => o === h, T = new Error("Promise is not actual"), q = (o) => o === T, x = new Error(
"stackPromises only works with functions that returns a Promise"
), C = ({
noRejectIsNotActual: n = !1,
noRunIsNotActual: o = !1
noRejectIsNotActual: o = !1,
noRunIsNotActual: d = !1
} = {}) => {
const a = [], c = [], k = ({ task: s, index: r }) => {
c.push({ task: s, index: r });
}, m = (s, { task: r, index: t }) => {
const e = c.find(({ task: l, index: P }) => r === l && t === P);
if (!e)
const e = [], a = [], p = ({ task: s, index: t }) => {
a.push({ task: s, index: t });
}, P = (s, { task: t, index: r }) => {
const n = a.find(({ task: i, index: l }) => t === i && r === l);
if (!n)
throw new Error("Task not found");
if (e.promise)
if (n.promise)
throw new Error("Task is already running");
e.promise = s;
}, f = ({
n.promise = s;
}, S = ({
task: s,
index: r
index: t
}) => {
const t = c.find(({ task: e, index: l }) => s === e && r === l);
if (t)
return t.promise;
}, u = ({ task: s }) => {
const r = T(c);
return (r == null ? void 0 : r.task) === s;
}, p = ({ task: s, index: r }) => (k({ task: s, index: r }), async () => {
let t = f({ task: s, index: r });
const e = u({ task: s });
return !t && o && !e ? Promise.resolve() : (t || (t = s({ isActual: e }), m(t, { task: s, index: r })), t);
}), w = ({
const r = a.find(({ task: n, index: i }) => s === n && t === i);
if (r)
return r.promise;
}, w = ({ task: s }) => {
const t = m(a);
return (t == null ? void 0 : t.task) === s;
}, y = ({ task: s, index: t }) => (p({ task: s, index: t }), async () => {
let r = S({ task: s, index: t });
const n = w({ task: s });
return !r && d && !n ? Promise.resolve() : (r || (r = s({ isActual: n }), P(r, { task: s, index: t })), r);
}), E = ({
resolve: s,
reject: r
}) => ({ results: t, isSuccessful: e }) => {
const l = t.length, P = a.length;
if (l === P) {
const h = T(t);
if (e) {
s(h);
reject: t
}) => ({ results: r, isSuccessful: n }) => {
const i = r.length, l = e.length;
if (i === l) {
const u = m(r);
if (n) {
s(u);
return;
}
r(h);
t(u);
return;
}
if (n) {
const h = T(t);
s(h);
if (o) {
const u = m(r);
s(u);
return;
}
r(y);
t(T);
};
let d = !1;
const R = () => {
d = !0;
}, g = () => {
d = !1;
}, N = () => d, A = async () => (R(), x(a, N)), i = async () => {
if (a.length === 0)
throw E;
return new Promise((s, r) => {
const t = w({ resolve: s, reject: r });
A().then(t).catch(t);
let k = !1;
const g = () => {
k = !0;
}, R = () => {
k = !1;
}, A = () => k, F = async () => (g(), b(e, A)), c = async () => {
if (e.length === 0)
throw h;
return new Promise((s, t) => {
const r = E({ resolve: s, reject: t });
F().then(r).catch((n) => {
r(n);
});
});
}, S = (s) => {
}, f = (s) => {
if (typeof s != "function")
throw z;
const r = a.length;
return a.push(p({ task: s, index: r })), i;
}, v = async (s) => (S(s), i()), F = () => {
a.length = 0, c.length = 0;
throw x;
const t = e.length;
return e.push(y({ task: s, index: t })), c;
}, L = async (s) => (f(s), c()), v = () => {
e.length = 0, a.length = 0;
}, I = () => {
g(), F();
R(), v();
};
return i.add = S, i.run = v, i.stop = I, i;
return c.add = f, c.run = L, c.stop = I, c;
};
export {
C as default,
O as isEmptyStackError,
_ as isPromiseIsNotActualError,
y as promiseIsNotActualError
C as creteStackPromises,
N as isEmptyStackError,
q as isPromiseIsNotActualError,
T as promiseIsNotActualError
};
{
"name": "stack-promises",
"version": "1.0.2",
"version": "2.0.0",
"description": "sequentPromises resolves Promises sequentially",

@@ -61,16 +61,16 @@ "keywords": [

"dependencies": {
"sequent-promises": "^1.0.0"
"sequent-promises": "^2.0.0"
},
"devDependencies": {
"@babel/preset-typescript": "^7.23.3",
"@commitlint/cli": "^18.6.0",
"@commitlint/config-conventional": "^18.6.0",
"@nabla/vite-plugin-eslint": "^2.0.2",
"@types/jest": "^29.5.11",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"@babel/preset-typescript": "^7.24.1",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@nabla/vite-plugin-eslint": "^2.0.4",
"@types/jest": "^29.5.12",
"@typescript-eslint/eslint-plugin": "^7.9.0",
"@typescript-eslint/parser": "^7.9.0",
"cross-env": "^7.0.3",
"eslint": "^8.56.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-config-prettier": "^9.1.0",

@@ -80,6 +80,6 @@ "eslint-import-resolver-typescript": "^3.6.1",

"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-jest": "^28.5.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^50.0.1",
"husky": "^9.0.7",
"eslint-plugin-unicorn": "^53.0.0",
"husky": "^9.0.11",
"jest": "^29.7.0",

@@ -89,4 +89,4 @@ "jest-environment-jsdom": "^29.7.0",

"jest-junit": "^16.0.0",
"lint-staged": "^15.2.1",
"prettier": "^3.2.4",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"standard-version": "^9.5.0",

@@ -96,9 +96,11 @@ "ts-jest": "^29.1.2",

"tsc-files": "^1.1.4",
"typescript": "^5.3.3",
"vite": "^5.0.12",
"vite-plugin-dts": "^3.7.2",
"vite-tsconfig-paths": "^4.3.1"
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vite-plugin-dts": "^3.9.1",
"vite-tsconfig-paths": "^4.3.2"
},
"peerDependencies": {},
"peerDependencies": {
"sequent-promises": "^2.0.0"
},
"main:src": "src/index.ts"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc