@tanstack/query-async-storage-persister 5.17.19 → 5.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["export interface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nconst noop = () => {\n /* do nothing */\n}\n\nexport function asyncThrottle<Args extends ReadonlyArray<unknown>>(\n func: (...args: Args) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let running = false\n let lastTime = 0\n let timeout: ReturnType<typeof setTimeout>\n let currentArgs: Args | null = null\n\n const execFunc = async () => {\n if (currentArgs) {\n const args = currentArgs\n currentArgs = null\n try {\n running = true\n await func(...args)\n } catch (error) {\n onError(error)\n } finally {\n lastTime = Date.now() // this line must after 'func' executed to avoid two 'func' running in concurrent.\n running = false\n }\n }\n }\n\n const delayFunc = async () => {\n clearTimeout(timeout)\n timeout = setTimeout(() => {\n if (running) {\n delayFunc() // Will come here when 'func' execution time is greater than the interval.\n } else {\n execFunc()\n }\n }, interval)\n }\n\n return (...args: Args) => {\n currentArgs = args\n\n const tooSoon = Date.now() - lastTime < interval\n if (running || tooSoon) {\n delayFunc()\n } else {\n execFunc()\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,IAAM,OAAO,MAAM;AAEnB;AAEO,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,KAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS;AAAY,UAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,UAAU;AACd,MAAI,WAAW;AACf,MAAI;AACJ,MAAI,cAA2B;AAE/B,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf,YAAM,OAAO;AACb,oBAAc;AACd,UAAI;AACF,kBAAU;AACV,cAAM,KAAK,GAAG,IAAI;AAAA,MACpB,SAAS,OAAO;AACd,gBAAQ,KAAK;AAAA,MACf,UAAE;AACA,mBAAW,KAAK,IAAI;AACpB,kBAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAEA,QAAM,YAAY,YAAY;AAC5B,iBAAa,OAAO;AACpB,cAAU,WAAW,MAAM;AACzB,UAAI,SAAS;AACX,kBAAU;AAAA,MACZ,OAAO;AACL,iBAAS;AAAA,MACX;AAAA,IACF,GAAG,QAAQ;AAAA,EACb;AAEA,SAAO,IAAI,SAAe;AACxB,kBAAc;AAEd,UAAM,UAAU,KAAK,IAAI,IAAI,WAAW;AACxC,QAAI,WAAW,SAAS;AACtB,gBAAU;AAAA,IACZ,OAAO;AACL,eAAS;AAAA,IACX;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["export interface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nconst noop = () => {\n /* do nothing */\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let running = false\n let lastTime = 0\n let timeout: ReturnType<typeof setTimeout>\n let currentArgs: TArgs | null = null\n\n const execFunc = async () => {\n if (currentArgs) {\n const args = currentArgs\n currentArgs = null\n try {\n running = true\n await func(...args)\n } catch (error) {\n onError(error)\n } finally {\n lastTime = Date.now() // this line must after 'func' executed to avoid two 'func' running in concurrent.\n running = false\n }\n }\n }\n\n const delayFunc = async () => {\n clearTimeout(timeout)\n timeout = setTimeout(() => {\n if (running) {\n delayFunc() // Will come here when 'func' execution time is greater than the interval.\n } else {\n execFunc()\n }\n }, interval)\n }\n\n return (...args: TArgs) => {\n currentArgs = args\n\n const tooSoon = Date.now() - lastTime < interval\n if (running || tooSoon) {\n delayFunc()\n } else {\n execFunc()\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,IAAM,OAAO,MAAM;AAEnB;AAEO,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,KAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS;AAAY,UAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,UAAU;AACd,MAAI,WAAW;AACf,MAAI;AACJ,MAAI,cAA4B;AAEhC,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf,YAAM,OAAO;AACb,oBAAc;AACd,UAAI;AACF,kBAAU;AACV,cAAM,KAAK,GAAG,IAAI;AAAA,MACpB,SAAS,OAAO;AACd,gBAAQ,KAAK;AAAA,MACf,UAAE;AACA,mBAAW,KAAK,IAAI;AACpB,kBAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAEA,QAAM,YAAY,YAAY;AAC5B,iBAAa,OAAO;AACpB,cAAU,WAAW,MAAM;AACzB,UAAI,SAAS;AACX,kBAAU;AAAA,MACZ,OAAO;AACL,iBAAS;AAAA,MACX;AAAA,IACF,GAAG,QAAQ;AAAA,EACb;AAEA,SAAO,IAAI,SAAgB;AACzB,kBAAc;AAEd,UAAM,UAAU,KAAK,IAAI,IAAI,WAAW;AACxC,QAAI,WAAW,SAAS;AACtB,gBAAU;AAAA,IACZ,OAAO;AACL,eAAS;AAAA,IACX;AAAA,EACF;AACF;","names":[]}
@@ -2,6 +2,6 @@ interface AsyncThrottleOptions {
2
2
  interval?: number;
3
3
  onError?: (error: unknown) => void;
4
4
  }
5
- declare function asyncThrottle<Args extends ReadonlyArray<unknown>>(func: (...args: Args) => Promise<void>, { interval, onError }?: AsyncThrottleOptions): (...args: Args) => void;
5
+ declare function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(func: (...args: TArgs) => Promise<void>, { interval, onError }?: AsyncThrottleOptions): (...args: TArgs) => void;
6
6
 
7
7
  export { type AsyncThrottleOptions, asyncThrottle };
@@ -2,6 +2,6 @@ interface AsyncThrottleOptions {
2
2
  interval?: number;
3
3
  onError?: (error: unknown) => void;
4
4
  }
5
- declare function asyncThrottle<Args extends ReadonlyArray<unknown>>(func: (...args: Args) => Promise<void>, { interval, onError }?: AsyncThrottleOptions): (...args: Args) => void;
5
+ declare function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(func: (...args: TArgs) => Promise<void>, { interval, onError }?: AsyncThrottleOptions): (...args: TArgs) => void;
6
6
 
7
7
  export { type AsyncThrottleOptions, asyncThrottle };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["export interface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nconst noop = () => {\n /* do nothing */\n}\n\nexport function asyncThrottle<Args extends ReadonlyArray<unknown>>(\n func: (...args: Args) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let running = false\n let lastTime = 0\n let timeout: ReturnType<typeof setTimeout>\n let currentArgs: Args | null = null\n\n const execFunc = async () => {\n if (currentArgs) {\n const args = currentArgs\n currentArgs = null\n try {\n running = true\n await func(...args)\n } catch (error) {\n onError(error)\n } finally {\n lastTime = Date.now() // this line must after 'func' executed to avoid two 'func' running in concurrent.\n running = false\n }\n }\n }\n\n const delayFunc = async () => {\n clearTimeout(timeout)\n timeout = setTimeout(() => {\n if (running) {\n delayFunc() // Will come here when 'func' execution time is greater than the interval.\n } else {\n execFunc()\n }\n }, interval)\n }\n\n return (...args: Args) => {\n currentArgs = args\n\n const tooSoon = Date.now() - lastTime < interval\n if (running || tooSoon) {\n delayFunc()\n } else {\n execFunc()\n }\n }\n}\n"],"mappings":";AAKA,IAAM,OAAO,MAAM;AAEnB;AAEO,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,KAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS;AAAY,UAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,UAAU;AACd,MAAI,WAAW;AACf,MAAI;AACJ,MAAI,cAA2B;AAE/B,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf,YAAM,OAAO;AACb,oBAAc;AACd,UAAI;AACF,kBAAU;AACV,cAAM,KAAK,GAAG,IAAI;AAAA,MACpB,SAAS,OAAO;AACd,gBAAQ,KAAK;AAAA,MACf,UAAE;AACA,mBAAW,KAAK,IAAI;AACpB,kBAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAEA,QAAM,YAAY,YAAY;AAC5B,iBAAa,OAAO;AACpB,cAAU,WAAW,MAAM;AACzB,UAAI,SAAS;AACX,kBAAU;AAAA,MACZ,OAAO;AACL,iBAAS;AAAA,MACX;AAAA,IACF,GAAG,QAAQ;AAAA,EACb;AAEA,SAAO,IAAI,SAAe;AACxB,kBAAc;AAEd,UAAM,UAAU,KAAK,IAAI,IAAI,WAAW;AACxC,QAAI,WAAW,SAAS;AACtB,gBAAU;AAAA,IACZ,OAAO;AACL,eAAS;AAAA,IACX;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["export interface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nconst noop = () => {\n /* do nothing */\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let running = false\n let lastTime = 0\n let timeout: ReturnType<typeof setTimeout>\n let currentArgs: TArgs | null = null\n\n const execFunc = async () => {\n if (currentArgs) {\n const args = currentArgs\n currentArgs = null\n try {\n running = true\n await func(...args)\n } catch (error) {\n onError(error)\n } finally {\n lastTime = Date.now() // this line must after 'func' executed to avoid two 'func' running in concurrent.\n running = false\n }\n }\n }\n\n const delayFunc = async () => {\n clearTimeout(timeout)\n timeout = setTimeout(() => {\n if (running) {\n delayFunc() // Will come here when 'func' execution time is greater than the interval.\n } else {\n execFunc()\n }\n }, interval)\n }\n\n return (...args: TArgs) => {\n currentArgs = args\n\n const tooSoon = Date.now() - lastTime < interval\n if (running || tooSoon) {\n delayFunc()\n } else {\n execFunc()\n }\n }\n}\n"],"mappings":";AAKA,IAAM,OAAO,MAAM;AAEnB;AAEO,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,KAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS;AAAY,UAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,UAAU;AACd,MAAI,WAAW;AACf,MAAI;AACJ,MAAI,cAA4B;AAEhC,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf,YAAM,OAAO;AACb,oBAAc;AACd,UAAI;AACF,kBAAU;AACV,cAAM,KAAK,GAAG,IAAI;AAAA,MACpB,SAAS,OAAO;AACd,gBAAQ,KAAK;AAAA,MACf,UAAE;AACA,mBAAW,KAAK,IAAI;AACpB,kBAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAEA,QAAM,YAAY,YAAY;AAC5B,iBAAa,OAAO;AACpB,cAAU,WAAW,MAAM;AACzB,UAAI,SAAS;AACX,kBAAU;AAAA,MACZ,OAAO;AACL,iBAAS;AAAA,MACX;AAAA,IACF,GAAG,QAAQ;AAAA,EACb;AAEA,SAAO,IAAI,SAAgB;AACzB,kBAAc;AAEd,UAAM,UAAU,KAAK,IAAI,IAAI,WAAW;AACxC,QAAI,WAAW,SAAS;AACtB,gBAAU;AAAA,IACZ,OAAO;AACL,eAAS;AAAA,IACX;AAAA,EACF;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["export interface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nconst noop = () => {\n /* do nothing */\n}\n\nexport function asyncThrottle<Args extends ReadonlyArray<unknown>>(\n func: (...args: Args) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let running = false\n let lastTime = 0\n let timeout: ReturnType<typeof setTimeout>\n let currentArgs: Args | null = null\n\n const execFunc = async () => {\n if (currentArgs) {\n const args = currentArgs\n currentArgs = null\n try {\n running = true\n await func(...args)\n } catch (error) {\n onError(error)\n } finally {\n lastTime = Date.now() // this line must after 'func' executed to avoid two 'func' running in concurrent.\n running = false\n }\n }\n }\n\n const delayFunc = async () => {\n clearTimeout(timeout)\n timeout = setTimeout(() => {\n if (running) {\n delayFunc() // Will come here when 'func' execution time is greater than the interval.\n } else {\n execFunc()\n }\n }, interval)\n }\n\n return (...args: Args) => {\n currentArgs = args\n\n const tooSoon = Date.now() - lastTime < interval\n if (running || tooSoon) {\n delayFunc()\n } else {\n execFunc()\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,IAAM,OAAO,MAAM;AAEnB;AAEO,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,KAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS;AAAY,UAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,UAAU;AACd,MAAI,WAAW;AACf,MAAI;AACJ,MAAI,cAA2B;AAE/B,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf,YAAM,OAAO;AACb,oBAAc;AACd,UAAI;AACF,kBAAU;AACV,cAAM,KAAK,GAAG,IAAI;AAAA,MACpB,SAAS,OAAO;AACd,gBAAQ,KAAK;AAAA,MACf,UAAE;AACA,mBAAW,KAAK,IAAI;AACpB,kBAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAEA,QAAM,YAAY,YAAY;AAC5B,iBAAa,OAAO;AACpB,cAAU,WAAW,MAAM;AACzB,UAAI,SAAS;AACX,kBAAU;AAAA,MACZ,OAAO;AACL,iBAAS;AAAA,MACX;AAAA,IACF,GAAG,QAAQ;AAAA,EACb;AAEA,SAAO,IAAI,SAAe;AACxB,kBAAc;AAEd,UAAM,UAAU,KAAK,IAAI,IAAI,WAAW;AACxC,QAAI,WAAW,SAAS;AACtB,gBAAU;AAAA,IACZ,OAAO;AACL,eAAS;AAAA,IACX;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["export interface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nconst noop = () => {\n /* do nothing */\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let running = false\n let lastTime = 0\n let timeout: ReturnType<typeof setTimeout>\n let currentArgs: TArgs | null = null\n\n const execFunc = async () => {\n if (currentArgs) {\n const args = currentArgs\n currentArgs = null\n try {\n running = true\n await func(...args)\n } catch (error) {\n onError(error)\n } finally {\n lastTime = Date.now() // this line must after 'func' executed to avoid two 'func' running in concurrent.\n running = false\n }\n }\n }\n\n const delayFunc = async () => {\n clearTimeout(timeout)\n timeout = setTimeout(() => {\n if (running) {\n delayFunc() // Will come here when 'func' execution time is greater than the interval.\n } else {\n execFunc()\n }\n }, interval)\n }\n\n return (...args: TArgs) => {\n currentArgs = args\n\n const tooSoon = Date.now() - lastTime < interval\n if (running || tooSoon) {\n delayFunc()\n } else {\n execFunc()\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,IAAM,OAAO,MAAM;AAEnB;AAEO,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,KAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS;AAAY,UAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,UAAU;AACd,MAAI,WAAW;AACf,MAAI;AACJ,MAAI,cAA4B;AAEhC,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf,YAAM,OAAO;AACb,oBAAc;AACd,UAAI;AACF,kBAAU;AACV,cAAM,KAAK,GAAG,IAAI;AAAA,MACpB,SAAS,OAAO;AACd,gBAAQ,KAAK;AAAA,MACf,UAAE;AACA,mBAAW,KAAK,IAAI;AACpB,kBAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAEA,QAAM,YAAY,YAAY;AAC5B,iBAAa,OAAO;AACpB,cAAU,WAAW,MAAM;AACzB,UAAI,SAAS;AACX,kBAAU;AAAA,MACZ,OAAO;AACL,iBAAS;AAAA,MACX;AAAA,IACF,GAAG,QAAQ;AAAA,EACb;AAEA,SAAO,IAAI,SAAgB;AACzB,kBAAc;AAEd,UAAM,UAAU,KAAK,IAAI,IAAI,WAAW;AACxC,QAAI,WAAW,SAAS;AACtB,gBAAU;AAAA,IACZ,OAAO;AACL,eAAS;AAAA,IACX;AAAA,EACF;AACF;","names":[]}
@@ -2,6 +2,6 @@ interface AsyncThrottleOptions {
2
2
  interval?: number;
3
3
  onError?: (error: unknown) => void;
4
4
  }
5
- declare function asyncThrottle<Args extends ReadonlyArray<unknown>>(func: (...args: Args) => Promise<void>, { interval, onError }?: AsyncThrottleOptions): (...args: Args) => void;
5
+ declare function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(func: (...args: TArgs) => Promise<void>, { interval, onError }?: AsyncThrottleOptions): (...args: TArgs) => void;
6
6
 
7
7
  export { type AsyncThrottleOptions, asyncThrottle };
@@ -2,6 +2,6 @@ interface AsyncThrottleOptions {
2
2
  interval?: number;
3
3
  onError?: (error: unknown) => void;
4
4
  }
5
- declare function asyncThrottle<Args extends ReadonlyArray<unknown>>(func: (...args: Args) => Promise<void>, { interval, onError }?: AsyncThrottleOptions): (...args: Args) => void;
5
+ declare function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(func: (...args: TArgs) => Promise<void>, { interval, onError }?: AsyncThrottleOptions): (...args: TArgs) => void;
6
6
 
7
7
  export { type AsyncThrottleOptions, asyncThrottle };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["export interface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nconst noop = () => {\n /* do nothing */\n}\n\nexport function asyncThrottle<Args extends ReadonlyArray<unknown>>(\n func: (...args: Args) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let running = false\n let lastTime = 0\n let timeout: ReturnType<typeof setTimeout>\n let currentArgs: Args | null = null\n\n const execFunc = async () => {\n if (currentArgs) {\n const args = currentArgs\n currentArgs = null\n try {\n running = true\n await func(...args)\n } catch (error) {\n onError(error)\n } finally {\n lastTime = Date.now() // this line must after 'func' executed to avoid two 'func' running in concurrent.\n running = false\n }\n }\n }\n\n const delayFunc = async () => {\n clearTimeout(timeout)\n timeout = setTimeout(() => {\n if (running) {\n delayFunc() // Will come here when 'func' execution time is greater than the interval.\n } else {\n execFunc()\n }\n }, interval)\n }\n\n return (...args: Args) => {\n currentArgs = args\n\n const tooSoon = Date.now() - lastTime < interval\n if (running || tooSoon) {\n delayFunc()\n } else {\n execFunc()\n }\n }\n}\n"],"mappings":";AAKA,IAAM,OAAO,MAAM;AAEnB;AAEO,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,KAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS;AAAY,UAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,UAAU;AACd,MAAI,WAAW;AACf,MAAI;AACJ,MAAI,cAA2B;AAE/B,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf,YAAM,OAAO;AACb,oBAAc;AACd,UAAI;AACF,kBAAU;AACV,cAAM,KAAK,GAAG,IAAI;AAAA,MACpB,SAAS,OAAO;AACd,gBAAQ,KAAK;AAAA,MACf,UAAE;AACA,mBAAW,KAAK,IAAI;AACpB,kBAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAEA,QAAM,YAAY,YAAY;AAC5B,iBAAa,OAAO;AACpB,cAAU,WAAW,MAAM;AACzB,UAAI,SAAS;AACX,kBAAU;AAAA,MACZ,OAAO;AACL,iBAAS;AAAA,MACX;AAAA,IACF,GAAG,QAAQ;AAAA,EACb;AAEA,SAAO,IAAI,SAAe;AACxB,kBAAc;AAEd,UAAM,UAAU,KAAK,IAAI,IAAI,WAAW;AACxC,QAAI,WAAW,SAAS;AACtB,gBAAU;AAAA,IACZ,OAAO;AACL,eAAS;AAAA,IACX;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["export interface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nconst noop = () => {\n /* do nothing */\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let running = false\n let lastTime = 0\n let timeout: ReturnType<typeof setTimeout>\n let currentArgs: TArgs | null = null\n\n const execFunc = async () => {\n if (currentArgs) {\n const args = currentArgs\n currentArgs = null\n try {\n running = true\n await func(...args)\n } catch (error) {\n onError(error)\n } finally {\n lastTime = Date.now() // this line must after 'func' executed to avoid two 'func' running in concurrent.\n running = false\n }\n }\n }\n\n const delayFunc = async () => {\n clearTimeout(timeout)\n timeout = setTimeout(() => {\n if (running) {\n delayFunc() // Will come here when 'func' execution time is greater than the interval.\n } else {\n execFunc()\n }\n }, interval)\n }\n\n return (...args: TArgs) => {\n currentArgs = args\n\n const tooSoon = Date.now() - lastTime < interval\n if (running || tooSoon) {\n delayFunc()\n } else {\n execFunc()\n }\n }\n}\n"],"mappings":";AAKA,IAAM,OAAO,MAAM;AAEnB;AAEO,SAAS,cACd,MACA,EAAE,WAAW,KAAM,UAAU,KAAK,IAA0B,CAAC,GAC7D;AACA,MAAI,OAAO,SAAS;AAAY,UAAM,IAAI,MAAM,2BAA2B;AAE3E,MAAI,UAAU;AACd,MAAI,WAAW;AACf,MAAI;AACJ,MAAI,cAA4B;AAEhC,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf,YAAM,OAAO;AACb,oBAAc;AACd,UAAI;AACF,kBAAU;AACV,cAAM,KAAK,GAAG,IAAI;AAAA,MACpB,SAAS,OAAO;AACd,gBAAQ,KAAK;AAAA,MACf,UAAE;AACA,mBAAW,KAAK,IAAI;AACpB,kBAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAEA,QAAM,YAAY,YAAY;AAC5B,iBAAa,OAAO;AACpB,cAAU,WAAW,MAAM;AACzB,UAAI,SAAS;AACX,kBAAU;AAAA,MACZ,OAAO;AACL,iBAAS;AAAA,MACX;AAAA,IACF,GAAG,QAAQ;AAAA,EACb;AAEA,SAAO,IAAI,SAAgB;AACzB,kBAAc;AAEd,UAAM,UAAU,KAAK,IAAI,IAAI,WAAW;AACxC,QAAI,WAAW,SAAS;AACtB,gBAAU;AAAA,IACZ,OAAO;AACL,eAAS;AAAA,IACX;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-async-storage-persister",
3
- "version": "5.17.19",
3
+ "version": "5.18.0",
4
4
  "description": "A persister for asynchronous storages, to be used with TanStack/Query",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -37,7 +37,7 @@
37
37
  "src"
38
38
  ],
39
39
  "dependencies": {
40
- "@tanstack/query-persist-client-core": "5.17.19"
40
+ "@tanstack/query-persist-client-core": "5.18.0"
41
41
  },
42
42
  "scripts": {
43
43
  "clean": "rimraf ./build && rimraf ./coverage",
@@ -7,8 +7,8 @@ const noop = () => {
7
7
  /* do nothing */
8
8
  }
9
9
 
10
- export function asyncThrottle<Args extends ReadonlyArray<unknown>>(
11
- func: (...args: Args) => Promise<void>,
10
+ export function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(
11
+ func: (...args: TArgs) => Promise<void>,
12
12
  { interval = 1000, onError = noop }: AsyncThrottleOptions = {},
13
13
  ) {
14
14
  if (typeof func !== 'function') throw new Error('argument is not function.')
@@ -16,7 +16,7 @@ export function asyncThrottle<Args extends ReadonlyArray<unknown>>(
16
16
  let running = false
17
17
  let lastTime = 0
18
18
  let timeout: ReturnType<typeof setTimeout>
19
- let currentArgs: Args | null = null
19
+ let currentArgs: TArgs | null = null
20
20
 
21
21
  const execFunc = async () => {
22
22
  if (currentArgs) {
@@ -45,7 +45,7 @@ export function asyncThrottle<Args extends ReadonlyArray<unknown>>(
45
45
  }, interval)
46
46
  }
47
47
 
48
- return (...args: Args) => {
48
+ return (...args: TArgs) => {
49
49
  currentArgs = args
50
50
 
51
51
  const tooSoon = Date.now() - lastTime < interval