@tanstack/query-async-storage-persister 5.59.17 → 5.59.20
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/query-async-storage-persister",
|
|
3
|
-
"version": "5.59.
|
|
3
|
+
"version": "5.59.20",
|
|
4
4
|
"description": "A persister for asynchronous storages, to be used with TanStack/Query",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,10 +34,11 @@
|
|
|
34
34
|
"sideEffects": false,
|
|
35
35
|
"files": [
|
|
36
36
|
"build",
|
|
37
|
-
"src"
|
|
37
|
+
"src",
|
|
38
|
+
"!src/__tests__"
|
|
38
39
|
],
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"@tanstack/query-persist-client-core": "5.59.
|
|
41
|
+
"@tanstack/query-persist-client-core": "5.59.20"
|
|
41
42
|
},
|
|
42
43
|
"scripts": {}
|
|
43
44
|
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
|
|
2
|
-
import { asyncThrottle } from '../asyncThrottle'
|
|
3
|
-
import { sleep as delay } from './utils'
|
|
4
|
-
|
|
5
|
-
describe('asyncThrottle', () => {
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
vi.useFakeTimers()
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
vi.useRealTimers()
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
test('basic', async () => {
|
|
15
|
-
const interval = 10
|
|
16
|
-
const execTimeStamps: Array<number> = []
|
|
17
|
-
const mockFunc = vi.fn(
|
|
18
|
-
async (id: number, complete?: (value?: unknown) => void) => {
|
|
19
|
-
await delay(1)
|
|
20
|
-
execTimeStamps.push(Date.now())
|
|
21
|
-
if (complete) {
|
|
22
|
-
complete(id)
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
)
|
|
26
|
-
const testFunc = asyncThrottle(mockFunc, { interval })
|
|
27
|
-
|
|
28
|
-
testFunc(1)
|
|
29
|
-
await vi.advanceTimersByTimeAsync(1)
|
|
30
|
-
|
|
31
|
-
testFunc(2)
|
|
32
|
-
await vi.advanceTimersByTimeAsync(1)
|
|
33
|
-
|
|
34
|
-
new Promise((resolve) => testFunc(3, resolve))
|
|
35
|
-
|
|
36
|
-
await vi.advanceTimersToNextTimerAsync()
|
|
37
|
-
await vi.advanceTimersByTimeAsync(interval)
|
|
38
|
-
|
|
39
|
-
expect(mockFunc).toBeCalledTimes(2)
|
|
40
|
-
expect(mockFunc.mock.calls[1]?.[0]).toBe(3)
|
|
41
|
-
expect(execTimeStamps.length).toBe(2)
|
|
42
|
-
expect(execTimeStamps[1]! - execTimeStamps[0]!).toBeGreaterThanOrEqual(
|
|
43
|
-
interval,
|
|
44
|
-
)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
test('Bug #3331 case 1: Special timing', async () => {
|
|
48
|
-
const interval = 1000
|
|
49
|
-
const execTimeStamps: Array<number> = []
|
|
50
|
-
const mockFunc = vi.fn(
|
|
51
|
-
async (id: number, complete?: (value?: unknown) => void) => {
|
|
52
|
-
await delay(30)
|
|
53
|
-
execTimeStamps.push(Date.now())
|
|
54
|
-
if (complete) {
|
|
55
|
-
complete(id)
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
)
|
|
59
|
-
const testFunc = asyncThrottle(mockFunc, { interval })
|
|
60
|
-
|
|
61
|
-
testFunc(1)
|
|
62
|
-
testFunc(2)
|
|
63
|
-
await vi.advanceTimersByTimeAsync(35)
|
|
64
|
-
testFunc(3)
|
|
65
|
-
await vi.advanceTimersByTimeAsync(35)
|
|
66
|
-
new Promise((resolve) => testFunc(4, resolve))
|
|
67
|
-
|
|
68
|
-
await vi.advanceTimersToNextTimerAsync()
|
|
69
|
-
await vi.advanceTimersByTimeAsync(interval)
|
|
70
|
-
|
|
71
|
-
expect(mockFunc).toBeCalledTimes(2)
|
|
72
|
-
expect(mockFunc.mock.calls[1]?.[0]).toBe(4)
|
|
73
|
-
expect(execTimeStamps.length).toBe(2)
|
|
74
|
-
expect(execTimeStamps[1]! - execTimeStamps[0]!).toBeGreaterThanOrEqual(
|
|
75
|
-
interval,
|
|
76
|
-
)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test('Bug #3331 case 2: "func" execution time is greater than the interval.', async () => {
|
|
80
|
-
const interval = 1000
|
|
81
|
-
const execTimeStamps: Array<number> = []
|
|
82
|
-
const mockFunc = vi.fn(
|
|
83
|
-
async (id: number, complete?: (value?: unknown) => void) => {
|
|
84
|
-
await delay(interval + 10)
|
|
85
|
-
execTimeStamps.push(Date.now())
|
|
86
|
-
if (complete) {
|
|
87
|
-
complete(id)
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
)
|
|
91
|
-
const testFunc = asyncThrottle(mockFunc, { interval })
|
|
92
|
-
|
|
93
|
-
testFunc(1)
|
|
94
|
-
testFunc(2)
|
|
95
|
-
new Promise((resolve) => testFunc(3, resolve))
|
|
96
|
-
|
|
97
|
-
await vi.advanceTimersToNextTimerAsync()
|
|
98
|
-
await vi.advanceTimersByTimeAsync(interval + 10)
|
|
99
|
-
await vi.advanceTimersByTimeAsync(interval + 10)
|
|
100
|
-
|
|
101
|
-
expect(mockFunc).toBeCalledTimes(2)
|
|
102
|
-
expect(mockFunc.mock.calls[1]?.[0]).toBe(3)
|
|
103
|
-
expect(execTimeStamps.length).toBe(2)
|
|
104
|
-
expect(execTimeStamps[1]! - execTimeStamps[0]!).toBeGreaterThanOrEqual(
|
|
105
|
-
interval,
|
|
106
|
-
)
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
test('"func" throw error not break next invoke', async () => {
|
|
110
|
-
const interval = 10
|
|
111
|
-
|
|
112
|
-
const mockFunc = vi.fn(
|
|
113
|
-
async (id: number, complete?: (value?: unknown) => void) => {
|
|
114
|
-
if (id === 1) throw new Error('error')
|
|
115
|
-
await delay(1)
|
|
116
|
-
if (complete) {
|
|
117
|
-
complete(id)
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
)
|
|
121
|
-
const testFunc = asyncThrottle(mockFunc, { interval })
|
|
122
|
-
|
|
123
|
-
testFunc(1)
|
|
124
|
-
await vi.advanceTimersByTimeAsync(1)
|
|
125
|
-
|
|
126
|
-
new Promise((resolve) => testFunc(2, resolve))
|
|
127
|
-
await vi.advanceTimersByTimeAsync(interval)
|
|
128
|
-
|
|
129
|
-
expect(mockFunc).toBeCalledTimes(2)
|
|
130
|
-
expect(mockFunc.mock.calls[1]?.[0]).toBe(2)
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
test('"onError" should be called when "func" throw error', () => {
|
|
134
|
-
const err = new Error('error')
|
|
135
|
-
const handleError = (e: unknown) => {
|
|
136
|
-
expect(e).toBe(err)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const testFunc = asyncThrottle(
|
|
140
|
-
() => {
|
|
141
|
-
throw err
|
|
142
|
-
},
|
|
143
|
-
{ onError: handleError },
|
|
144
|
-
)
|
|
145
|
-
testFunc()
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
test('should throw error when "func" is not a function', () => {
|
|
149
|
-
expect(() => asyncThrottle(1 as any)).toThrowError()
|
|
150
|
-
})
|
|
151
|
-
})
|