Comparing version 1.14.12 to 1.15.0
@@ -1,2 +0,2 @@ | ||
/*! idmp v1.14.12 | (c) github/haozi | MIT */ | ||
/*! idmp v1.15.0 | (c) github/haozi | MIT */ | ||
const p = () => { | ||
@@ -3,0 +3,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
/*! idmp v1.14.12 | (c) github/haozi | MIT */ | ||
/*! idmp v1.15.0 | (c) github/haozi | MIT */ | ||
(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 g=()=>{},l=t=>t<0?0:t>6048e5?6048e5:t;n.g={};const a=t=>{const{maxRetry:f=30,maxAge:u=3e3,onBeforeRetry:c=g}=t||{},m=l(u);return{maxRetry:f,maxAge:m,onBeforeRetry:c,f:u===1/0}},r=t=>{t&&delete n.g[t]},_=()=>{n.g={}},h=(t,f,u)=>{if(!t)return f();const{maxRetry:c,maxAge:m,onBeforeRetry:p,f:R}=a(u);n.g[t]=n.g[t]||{0:0,1:0,4:[]};const e=n.g[t],T=()=>{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]=[],R||setTimeout(()=>{r(t)},m)},y=()=>{const o=e[4].length-c;for(let s=0;s<o;++s)e[4][s][1](e[3]);r(t)},A=()=>new Promise((o,s)=>{if(!e[5]&&(e[5]=f),e[2]){o(e[2]);return}e[1]===0?(e[1]=1,e[4].push([o,s]),e[5]().then(d=>{e[2]=d,M(),e[1]=4}).catch(d=>{e[1]=3,e[3]=d,++e[0],e[0]>c?y():(p(d,{globalKey:t,retryCount:e[0]}),T(),setTimeout(A,(e[0]-1)*50))})):e[1]===1&&e[4].push([o,s])});return A()};h.flush=r,h.flushAll=_,n.default=h,n.getOptions=a,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
@@ -1,2 +0,2 @@ | ||
/*! idmp v1.14.12 | (c) github/haozi | MIT */ | ||
/*! idmp v1.15.0 | (c) github/haozi | MIT */ | ||
const DEFAULT_MAX_AGE = 3e3; | ||
@@ -3,0 +3,0 @@ const _7days = 6048e5; |
@@ -1,2 +0,2 @@ | ||
/*! idmp v1.14.12 | (c) github/haozi | MIT */ | ||
/*! idmp v1.15.0 | (c) github/haozi | MIT */ | ||
const DEFAULT_MAX_AGE = 3e3; | ||
@@ -3,0 +3,0 @@ const _7days = 6048e5; |
{ | ||
"name": "idmp", | ||
"version": "1.14.12", | ||
"version": "1.15.0", | ||
"keywords": [ | ||
@@ -36,4 +36,5 @@ "deduplicate network requests", | ||
"dependencies": { | ||
"fs-extra": "^11.2.0" | ||
"fs-extra": "^11.2.0", | ||
"serialize-javascript": "^6.0.2" | ||
} | ||
} |
@@ -6,2 +6,4 @@ /*! idmp v1.0.0 | (c) github/haozi | MIT */ | ||
import fs from "fs-extra"; | ||
import serialize from "serialize-javascript"; | ||
const deSerialize = (data) => new Function(`return ${data}`)(); | ||
const udf = void 0; | ||
@@ -16,7 +18,10 @@ const encode = encodeURIComponent; | ||
fs.ensureFileSync(cachePath); | ||
fs.outputJSONSync(cachePath, { | ||
t: Date.now(), | ||
a: maxAge, | ||
d: data | ||
}); | ||
fs.outputFileSync( | ||
cachePath, | ||
serialize({ | ||
t: Date.now(), | ||
a: maxAge, | ||
d: data | ||
}) | ||
); | ||
}; | ||
@@ -27,3 +32,7 @@ const getData = async (key) => { | ||
const cachePath = getCachePath(key); | ||
const localData = fs.readJsonSync(cachePath, { throws: false }) ?? udf; | ||
let localData; | ||
try { | ||
localData = deSerialize(fs.readFileSync(cachePath, "utf-8")); | ||
} catch { | ||
} | ||
if (localData === udf) | ||
@@ -30,0 +39,0 @@ return udf; |
@@ -21,7 +21,9 @@ { | ||
"fs-extra": "^11.2.0", | ||
"idmp": "workspace:*" | ||
"idmp": "workspace:*", | ||
"serialize-javascript": "^6.0.2" | ||
}, | ||
"devDependencies": { | ||
"@types/fs-extra": "^11.0.4" | ||
"@types/fs-extra": "^11.0.4", | ||
"@types/serialize-javascript": "^5.0.4" | ||
} | ||
} |
@@ -25,2 +25,2 @@ # idmp/node-fs | ||
Data persistence only supports string type `globalKey` and data structures that can be serialized by `JSON.stringify` | ||
Data persistence only supports string type `globalKey` and data structures that can be serialized by [serialize-javascript](https://www.npmjs.com/package/serialize-javascript) |
@@ -221,2 +221,4 @@ # idmp | ||
`idmp` internally implements an algorithm similar to [Exponential backoff](https://en.m.wikipedia.org/wiki/Exponential_backoff), which dynamically changes the retry time to avoid DDoS to the server. | ||
```typescript | ||
@@ -223,0 +225,0 @@ const getUserData = idmp( |
@@ -67,7 +67,7 @@ # idmp | ||
`idmp` 有一个强大的插件系统。 以下插件是官方维护的,您也可以参考源码创建自己的插件: | ||
`idmp` 有一个强大的插件系统。 以下是官方维护的插件列表,您也可以参考源码创建自己的插件: | ||
与高阶函数的类比优雅地传达了插件可以以非侵入性方式扩展 idmp 的核心功能,类似于数学函数 $g(f)(x)$。 这为插件系统提供了极大的灵活性和可扩展性。 | ||
插件可以以非侵入性方式扩展 `idmp` 的核心功能,类似于数学函数 $g(f)(x)$。 这种优雅的设计为插件系统提供了极大的灵活性和可扩展性。 | ||
- [使用node-fs进行数据持久化](plugins/node-fs/README.md)(将数据持久化到文件系统) | ||
- [使用 node-fs 进行数据持久化](plugins/node-fs/README.md)(将数据持久化到文件系统) | ||
- [使用 localStorage 进行数据持久化](https://github.com/ha0z1/idmp/blob/main/plugins/browser-storage/README.md) | ||
@@ -216,3 +216,3 @@ - [使用 sessionStorage 进行数据持久化](https://github.com/ha0z1/idmp/blob/main/plugins/browser-storage/README.md) | ||
## 健壮性 | ||
## 鲁棒性 | ||
@@ -238,2 +238,4 @@ 假设一个接口的请求失败率为 10%, 那么通过 3 次尝试后,请求仍失败的可能性将降到 0.1% | ||
idmp 内部实现了类似 [指数退避](https://en.m.wikipedia.org/wiki/Exponential_backoff)的算法,会动态改变重试时间,避免对服务器造成 DDoS。 | ||
## 优化大计算 | ||
@@ -240,0 +242,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
89476
1356
344
2
1
+ Addedserialize-javascript@^6.0.2
+ Addedrandombytes@2.1.0(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedserialize-javascript@6.0.2(transitive)