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

idmp

Package Overview
Dependencies
Maintainers
1
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

idmp - npm Package Compare versions

Comparing version 1.7.0 to 1.7.1

dist/index.d.ts

62

dist/index.browser.esm.js

@@ -5,14 +5,14 @@ const R = () => {

let o = {};
const f = (e) => {
const c = (e) => {
e && delete o[e];
}, T = () => {
o = {};
}, A = (e, c, l) => {
}, d = (e, f, h) => {
const {
maxRetry: u = 30,
maxAge: _ = 3e3,
onBeforeRetry: a = R
} = l || {}, m = E(_);
maxAge: A = 3e3,
onBeforeRetry: _ = R
} = h || {}, a = E(A);
if (!e)
return c();
return f();
o[e] = o[e] || {

@@ -23,3 +23,3 @@ 0: 0,

};
const t = o[e], p = () => {
const t = o[e], l = () => {
t[

@@ -35,3 +35,3 @@ 1

] = void 0;
}, i = () => {
}, m = () => {
const n = t[

@@ -53,5 +53,5 @@ 4

] = [], setTimeout(() => {
f(e);
}, m);
}, d = () => {
c(e);
}, a);
}, p = () => {
const n = t[

@@ -69,4 +69,4 @@ 4

]);
f(e);
}, h = () => new Promise((n, s) => {
c(e);
}, i = () => new Promise((n, s) => {
if (!t[

@@ -78,3 +78,3 @@ 5

/* oneCallPromiseFunc */
] = c), t[
] = f), t[
2

@@ -89,12 +89,2 @@ /* resData */

}
if (t[
3
/* resError */
]) {
s(t[
3
/* resError */
]);
return;
}
t[

@@ -119,3 +109,3 @@ 1

/* resData */
] = r, i();
] = r, m();
}).catch((r) => {

@@ -134,3 +124,3 @@ t[

/* retryCount */
] > u ? d() : (a(r, {
] > u ? p() : (_(r, {
globalKey: e,

@@ -141,3 +131,3 @@ retryCount: t[

]
}), p(), setTimeout(h, (t[
}), l(), setTimeout(i, (t[
0

@@ -149,20 +139,14 @@ /* retryCount */

/* status */
] === 1 ? t[
] === 1 && t[
4
/* pendingList */
].push([n, s]) : t[
1
/* status */
] === 4 ? i() : t[
1
/* status */
] === 3 && d();
].push([n, s]);
});
return h();
return i();
};
A.flush = f;
A.flushAll = T;
d.flush = c;
d.flushAll = T;
export {
A as default,
d as default,
o as g
};

@@ -1,1 +0,1 @@

(function(n,i){typeof exports=="object"&&typeof module!="undefined"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(n=typeof globalThis!="undefined"?globalThis:n||self,i(n.idmp={}))})(this,function(n){"use strict";const A=()=>{},_=t=>t<0?0:t>6048e5?6048e5:t;n.g={};const u=t=>{t&&delete n.g[t]},T=()=>{n.g={}},d=(t,c,a)=>{const{maxRetry:r=30,maxAge:g=3e3,onBeforeRetry:p=A}=a||{},M=_(g);if(!t)return c();n.g[t]=n.g[t]||{0:0,1:0,4:[]};const e=n.g[t],R=()=>{e[1]=0,e[2]=void 0,e[3]=void 0},h=()=>{const f=e[4].length;for(let s=0;s<f;++s)e[4][s][0](e[2]);e[4]=[],setTimeout(()=>{u(t)},M)},l=()=>{const f=e[4].length-r;for(let s=0;s<f;++s)e[4][s][1](e[3]);u(t)},m=()=>new Promise((f,s)=>{if(!e[5]&&(e[5]=c),e[2]){f(e[2]);return}if(e[3]){s(e[3]);return}e[1]===0?(e[1]=1,e[4].push([f,s]),e[5]().then(o=>{e[1]=4,e[2]=o,h()}).catch(o=>{e[1]=3,e[3]=o,++e[0],e[0]>r?l():(p(o,{globalKey:t,retryCount:e[0]}),R(),setTimeout(m,(e[0]-1)*50))})):e[1]===1?e[4].push([f,s]):e[1]===4?h():e[1]===3&&l()});return m()};d.flush=u,d.flushAll=T,n.default=d,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
(function(n,f){typeof exports=="object"&&typeof module!="undefined"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(n=typeof globalThis!="undefined"?globalThis:n||self,f(n.idmp={}))})(this,function(n){"use strict";const l=()=>{},m=t=>t<0?0:t>6048e5?6048e5:t;n.g={};const i=t=>{t&&delete n.g[t]},A=()=>{n.g={}},d=(t,c,_)=>{const{maxRetry:r=30,maxAge:T=3e3,onBeforeRetry:a=l}=_||{},g=m(T);if(!t)return c();n.g[t]=n.g[t]||{0:0,1:0,4:[]};const e=n.g[t],p=()=>{e[1]=0,e[2]=void 0,e[3]=void 0},M=()=>{const o=e[4].length;for(let s=0;s<o;++s)e[4][s][0](e[2]);e[4]=[],setTimeout(()=>{i(t)},g)},R=()=>{const o=e[4].length-r;for(let s=0;s<o;++s)e[4][s][1](e[3]);i(t)},h=()=>new Promise((o,s)=>{if(!e[5]&&(e[5]=c),e[2]){o(e[2]);return}e[1]===0?(e[1]=1,e[4].push([o,s]),e[5]().then(u=>{e[1]=4,e[2]=u,M()}).catch(u=>{e[1]=3,e[3]=u,++e[0],e[0]>r?R():(a(u,{globalKey:t,retryCount:e[0]}),p(),setTimeout(h,(e[0]-1)*50))})):e[1]===1&&e[4].push([o,s])});return h()};d.flush=i,d.flushAll=A,n.default=d,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});

@@ -118,12 +118,2 @@ const DEFAULT_MAX_AGE = 3e3;

if (cache[
3
/* resError */
]) {
reject(cache[
3
/* resError */
]);
return;
}
if (cache[
1

@@ -196,12 +186,2 @@ /* status */

].push([resolve, reject]);
} else if (cache[
1
/* status */
] === 4) {
doResolves();
} else if (cache[
1
/* status */
] === 3) {
doRejects();
}

@@ -208,0 +188,0 @@ });

@@ -146,14 +146,18 @@ const DEFAULT_MAX_AGE = 3e3;

let idx = Infinity;
for (let key of [
"idmp/src/index.ts",
"idmp/",
"idmp\\",
"idmp"
]) {
const _idx = arr.findLastIndex((o) => o.includes(key));
if (_idx > -1) {
idx = _idx;
break;
$0:
for (let key of [
"idmp/src/index.ts",
"idmp/",
"idmp\\",
"idmp"
]) {
let _idx = arr.length - 1;
$1:
for (; _idx >= 0; --_idx) {
if (arr[_idx].indexOf(key) > -1) {
idx = _idx;
break $0;
}
}
}
}
const line = arr[idx + 1] || "";

@@ -163,3 +167,2 @@ return line;

}
return "";
};

@@ -195,12 +198,2 @@ const line1 = getCodeLine(cache[

if (cache[
3
/* resError */
]) {
reject(cache[
3
/* resError */
]);
return;
}
if (cache[
1

@@ -278,12 +271,2 @@ /* status */

].push([resolve, reject]);
} else if (cache[
1
/* status */
] === 4) {
doResolves();
} else if (cache[
1
/* status */
] === 3) {
doRejects();
}

@@ -290,0 +273,0 @@ });

{
"name": "idmp",
"version": "1.7.0",
"version": "1.7.1",
"keywords": [

@@ -5,0 +5,0 @@ "cache response",

@@ -5,4 +5,8 @@ # idmp

An elegant library to solve duplicate and concurrent calls for idempotent functions, pure function. Less than 200b after Gzip
[![codecov](https://codecov.io/gh/ha0z1/idmp/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ha0z1/idmp/blob/main/src%2Findex.ts)
[![npm](https://img.shields.io/npm/v/idmp.svg)](https://www.npmjs.com/package/idmp)
[![contributors](https://img.shields.io/github/contributors/ha0z1/idmp)](https://github.com/ha0z1/idmp/graphs/contributors)
An elegant library to solve duplicate and concurrent calls for idempotent functions, pure function. Less than 200 Bytes after Gzip
English | [简体中文](README.zh-CN.md)

@@ -44,13 +48,13 @@

// Handle params
// 处理有入参的场景
export const getInfoByIdIdmp = (id: string) =>
idmp(`/api/your-info?${id}`, () => getInfo(id))
idmp(`/api/your-info?${id}`, () => getInfoById(id))
// Or a more generic type juggling, for complex params, idmp will infer the return type automatically, keep it consistent with the original function
// 或者更通用的类型体操写法,用于复杂的入参,idmp 会自动推导返回值类型,与原函数保持一致
export const getInfoByIdIdmp = (...args: Parameters<typeof getInfoById>) =>
idmp(`/api/your-info?${JSON.stringify(args)}`, () => getInfo(...args))
idmp(`/api/your-info?${JSON.stringify(args)}`, () => getInfoById(...args))
// More options
// 增加更多配置项
export const getInfoByIdIdmp = (id: string) =>
idmp(`/api/your-info?${id}`, () => getInfo(id), {
idmp(`/api/your-info?${id}`, () => getInfoById(id), {
maxAge: 86400 * 1000,

@@ -60,3 +64,3 @@ })

Then replace `getInfo` with `getInfoIdmp`.
Then replace `getInfoByIdIdmp` with `getInfoById`.

@@ -63,0 +67,0 @@ ## Options

@@ -5,4 +5,8 @@ # idmp

一个优雅地解决幂等(idempotent) 函数的重复和并发调用的小库,纯函数,Gzip 后不到 200b
[![codecov](https://codecov.io/gh/ha0z1/idmp/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ha0z1/idmp/blob/main/src%2Findex.ts)
[![npm](https://img.shields.io/npm/v/idmp.svg)](https://www.npmjs.com/package/idmp)
[![contributors](https://img.shields.io/github/contributors/ha0z1/idmp)](https://github.com/ha0z1/idmp/graphs/contributors)
一个优雅地解决幂等(idempotent) 函数的重复和并发调用的小库,纯函数,Gzip 后不到 200 Bytes
[English](README.md) | 简体中文

@@ -46,11 +50,11 @@

export const getInfoByIdIdmp = (id: string) =>
idmp(`/api/your-info?${id}`, () => getInfo(id))
idmp(`/api/your-info?${id}`, () => getInfoById(id))
// 或者更通用的类型体操写法,用于复杂的入参,idmp 会自动推导返回值类型,与原函数保持一致
export const getInfoByIdIdmp = (...args: Parameters<typeof getInfoById>) =>
idmp(`/api/your-info?${JSON.stringify(args)}`, () => getInfo(...args))
idmp(`/api/your-info?${JSON.stringify(args)}`, () => getInfoById(...args))
// 增加更多配置项
export const getInfoByIdIdmp = (id: string) =>
idmp(`/api/your-info?${id}`, () => getInfo(id), {
idmp(`/api/your-info?${id}`, () => getInfoById(id), {
maxAge: 86400 * 1000,

@@ -60,3 +64,3 @@ })

然后用 `getInfoIdmp` 替换 `getInfo` 方法。
然后用 `getInfoByIdIdmp` 替换 `getInfoById` 方法。

@@ -63,0 +67,0 @@ ## Options

Sorry, the diff of this file is not supported yet

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