@tanstack/query-async-storage-persister 5.0.0-beta.18 → 5.0.0-beta.23
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.
- package/build/legacy/asyncThrottle.cjs.map +1 -1
- package/build/legacy/asyncThrottle.d.cts +1 -1
- package/build/legacy/asyncThrottle.d.ts +1 -1
- package/build/legacy/asyncThrottle.js.map +1 -1
- package/build/modern/asyncThrottle.cjs.map +1 -1
- package/build/modern/asyncThrottle.d.cts +1 -1
- package/build/modern/asyncThrottle.d.ts +1 -1
- package/build/modern/asyncThrottle.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/asyncThrottle.test.ts +3 -3
- package/src/asyncThrottle.ts +1 -1
|
@@ -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
|
|
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":[]}
|
|
@@ -2,6 +2,6 @@ interface AsyncThrottleOptions {
|
|
|
2
2
|
interval?: number;
|
|
3
3
|
onError?: (error: unknown) => void;
|
|
4
4
|
}
|
|
5
|
-
declare function asyncThrottle<Args extends
|
|
5
|
+
declare function asyncThrottle<Args extends ReadonlyArray<unknown>>(func: (...args: Args) => Promise<void>, { interval, onError }?: AsyncThrottleOptions): (...args: Args) => void;
|
|
6
6
|
|
|
7
7
|
export { 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
|
|
5
|
+
declare function asyncThrottle<Args extends ReadonlyArray<unknown>>(func: (...args: Args) => Promise<void>, { interval, onError }?: AsyncThrottleOptions): (...args: Args) => void;
|
|
6
6
|
|
|
7
7
|
export { 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
|
|
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 +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
|
|
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":[]}
|
|
@@ -2,6 +2,6 @@ interface AsyncThrottleOptions {
|
|
|
2
2
|
interval?: number;
|
|
3
3
|
onError?: (error: unknown) => void;
|
|
4
4
|
}
|
|
5
|
-
declare function asyncThrottle<Args extends
|
|
5
|
+
declare function asyncThrottle<Args extends ReadonlyArray<unknown>>(func: (...args: Args) => Promise<void>, { interval, onError }?: AsyncThrottleOptions): (...args: Args) => void;
|
|
6
6
|
|
|
7
7
|
export { 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
|
|
5
|
+
declare function asyncThrottle<Args extends ReadonlyArray<unknown>>(func: (...args: Args) => Promise<void>, { interval, onError }?: AsyncThrottleOptions): (...args: Args) => void;
|
|
6
6
|
|
|
7
7
|
export { 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
|
|
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":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/query-async-storage-persister",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.23",
|
|
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.0.0-beta.
|
|
40
|
+
"@tanstack/query-persist-client-core": "5.0.0-beta.23"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"clean": "rimraf ./build && rimraf ./coverage",
|
|
@@ -5,7 +5,7 @@ import { sleep as delay } from './utils'
|
|
|
5
5
|
describe('asyncThrottle', () => {
|
|
6
6
|
test('basic', async () => {
|
|
7
7
|
const interval = 10
|
|
8
|
-
const execTimeStamps: number
|
|
8
|
+
const execTimeStamps: Array<number> = []
|
|
9
9
|
const mockFunc = vi.fn(
|
|
10
10
|
async (id: number, complete?: (value?: unknown) => void) => {
|
|
11
11
|
await delay(1)
|
|
@@ -33,7 +33,7 @@ describe('asyncThrottle', () => {
|
|
|
33
33
|
|
|
34
34
|
test('Bug #3331 case 1: Special timing', async () => {
|
|
35
35
|
const interval = 1000
|
|
36
|
-
const execTimeStamps: number
|
|
36
|
+
const execTimeStamps: Array<number> = []
|
|
37
37
|
const mockFunc = vi.fn(
|
|
38
38
|
async (id: number, complete?: (value?: unknown) => void) => {
|
|
39
39
|
await delay(30)
|
|
@@ -62,7 +62,7 @@ describe('asyncThrottle', () => {
|
|
|
62
62
|
|
|
63
63
|
test('Bug #3331 case 2: "func" execution time is greater than the interval.', async () => {
|
|
64
64
|
const interval = 1000
|
|
65
|
-
const execTimeStamps: number
|
|
65
|
+
const execTimeStamps: Array<number> = []
|
|
66
66
|
const mockFunc = vi.fn(
|
|
67
67
|
async (id: number, complete?: (value?: unknown) => void) => {
|
|
68
68
|
await delay(interval + 10)
|
package/src/asyncThrottle.ts
CHANGED
|
@@ -7,7 +7,7 @@ const noop = () => {
|
|
|
7
7
|
/* do nothing */
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function asyncThrottle<Args extends
|
|
10
|
+
export function asyncThrottle<Args extends ReadonlyArray<unknown>>(
|
|
11
11
|
func: (...args: Args) => Promise<void>,
|
|
12
12
|
{ interval = 1000, onError = noop }: AsyncThrottleOptions = {},
|
|
13
13
|
) {
|