@tanstack/query-core 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-core",
3
- "version": "5.59.17",
3
+ "version": "5.59.20",
4
4
  "description": "The framework agnostic core that powers TanStack Query",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -34,7 +34,8 @@
34
34
  "sideEffects": false,
35
35
  "files": [
36
36
  "build",
37
- "src"
37
+ "src",
38
+ "!src/__tests__"
38
39
  ],
39
40
  "scripts": {}
40
41
  }
@@ -1,175 +0,0 @@
1
- import { describe, expectTypeOf, it } from 'vitest'
2
- import type { OmitKeyof } from '..'
3
-
4
- describe('OmitKeyof', () => {
5
- it("'s string key type check", () => {
6
- type A = {
7
- x: string
8
- y: number
9
- }
10
-
11
- type ExpectedType = {
12
- x: string
13
- }
14
-
15
- // Bad point
16
- // 1. original Omit can use 'z' as type parameter with no type error
17
- // 2. original Omit have no auto complete for 2nd type parameter
18
- expectTypeOf<Omit<A, 'z' | 'y'>>().toEqualTypeOf<ExpectedType>()
19
-
20
- // Solution
21
-
22
- // 1. strictly
23
- expectTypeOf<
24
- OmitKeyof<
25
- A,
26
- // OmitKeyof can't use 'z' as type parameter with type error because A don't have key 'z'
27
- // @ts-expect-error Type does not satisfy the constraint keyof A
28
- 'z' | 'y'
29
- >
30
- >().toEqualTypeOf<ExpectedType>()
31
- expectTypeOf<
32
- OmitKeyof<
33
- A,
34
- // OmitKeyof can't use 'z' as type parameter with type error because A don't have key 'z'
35
- // @ts-expect-error Type does not satisfy the constraint keyof A
36
- 'z' | 'y',
37
- 'strictly'
38
- >
39
- >().toEqualTypeOf<ExpectedType>()
40
-
41
- // 2. safely
42
- expectTypeOf<
43
- OmitKeyof<
44
- A,
45
- // OmitKeyof can't use 'z' as type parameter type error with strictly parameter or default parameter
46
- // @ts-expect-error Type does not satisfy the constraint keyof A
47
- 'z' | 'y'
48
- >
49
- >().toEqualTypeOf<ExpectedType>()
50
- expectTypeOf<
51
- OmitKeyof<
52
- A,
53
- // With 'safely', OmitKeyof can use 'z' as type parameter like original Omit but This support autocomplete too yet for DX.
54
- 'z' | 'y',
55
- 'safely'
56
- >
57
- >().toEqualTypeOf<ExpectedType>()
58
- })
59
-
60
- it("'s number key type check", () => {
61
- type A = {
62
- [1]: string
63
- [2]: number
64
- }
65
-
66
- type ExpectedType = {
67
- [1]: string
68
- }
69
-
70
- // Bad point
71
- // 1. original Omit can use 3 as type parameter with no type error
72
- // 2. original Omit have no auto complete for 2nd type parameter
73
- expectTypeOf<Omit<A, 3 | 2>>().toEqualTypeOf<ExpectedType>()
74
-
75
- // Solution
76
-
77
- // 1. strictly
78
- expectTypeOf<
79
- OmitKeyof<
80
- A,
81
- // OmitKeyof can't use 3 as type parameter with type error because A don't have key 3
82
- // @ts-expect-error Type does not satisfy the constraint keyof A
83
- 3 | 2
84
- >
85
- >().toEqualTypeOf<ExpectedType>()
86
- expectTypeOf<
87
- OmitKeyof<
88
- A,
89
- // OmitKeyof can't use 3 as type parameter with type error because A don't have key 3
90
- // @ts-expect-error Type does not satisfy the constraint keyof A
91
- 3 | 2,
92
- 'strictly'
93
- >
94
- >().toEqualTypeOf<ExpectedType>()
95
-
96
- // 2. safely
97
- expectTypeOf<
98
- OmitKeyof<
99
- A,
100
- // OmitKeyof can't use 3 as type parameter type error with strictly parameter or default parameter
101
- // @ts-expect-error Type does not satisfy the constraint keyof A
102
- 3 | 2
103
- >
104
- >().toEqualTypeOf<ExpectedType>()
105
- expectTypeOf<
106
- OmitKeyof<
107
- A,
108
- // With 'safely', OmitKeyof can use 3 as type parameter like original Omit but This support autocomplete too yet for DX.
109
- 3 | 2,
110
- 'safely'
111
- >
112
- >().toEqualTypeOf<ExpectedType>()
113
- })
114
-
115
- it("'s symbol key type check", () => {
116
- const symbol1 = Symbol()
117
- const symbol2 = Symbol()
118
- const symbol3 = Symbol()
119
-
120
- type A = {
121
- [symbol1]: string
122
- [symbol2]: number
123
- }
124
-
125
- type ExpectedType = {
126
- [symbol1]: string
127
- }
128
-
129
- // Bad point
130
- // 1. original Omit can use symbol3 as type parameter with no type error
131
- // 2. original Omit have no auto complete for 2nd type parameter
132
- expectTypeOf<
133
- Omit<A, typeof symbol3 | typeof symbol2>
134
- >().toEqualTypeOf<ExpectedType>()
135
-
136
- // Solution
137
-
138
- // 1. strictly
139
- expectTypeOf<
140
- OmitKeyof<
141
- A,
142
- // OmitKeyof can't use symbol3 as type parameter with type error because A don't have key symbol3
143
- // @ts-expect-error Type does not satisfy the constraint keyof A
144
- typeof symbol3 | typeof symbol2
145
- >
146
- >().toEqualTypeOf<ExpectedType>()
147
- expectTypeOf<
148
- OmitKeyof<
149
- A,
150
- // OmitKeyof can't use symbol3 as type parameter with type error because A don't have key symbol3
151
- // @ts-expect-error Type does not satisfy the constraint keyof A
152
- typeof symbol3 | typeof symbol2,
153
- 'strictly'
154
- >
155
- >().toEqualTypeOf<ExpectedType>()
156
-
157
- // 2. safely
158
- expectTypeOf<
159
- OmitKeyof<
160
- A,
161
- // OmitKeyof can't use symbol3 as type parameter type error with strictly parameter or default parameter
162
- // @ts-expect-error Type does not satisfy the constraint keyof A
163
- typeof symbol3 | typeof symbol2
164
- >
165
- >().toEqualTypeOf<ExpectedType>()
166
- expectTypeOf<
167
- OmitKeyof<
168
- A,
169
- // With 'safely', OmitKeyof can use symbol3 as type parameter like original Omit but This support autocomplete too yet for DX.
170
- typeof symbol3 | typeof symbol2,
171
- 'safely'
172
- >
173
- >().toEqualTypeOf<ExpectedType>()
174
- })
175
- })
@@ -1,163 +0,0 @@
1
- import { beforeEach, describe, expect, it, test, vi } from 'vitest'
2
- import { sleep } from '../utils'
3
- import { FocusManager } from '../focusManager'
4
- import { setIsServer } from './utils'
5
-
6
- describe('focusManager', () => {
7
- let focusManager: FocusManager
8
- beforeEach(() => {
9
- vi.resetModules()
10
- focusManager = new FocusManager()
11
- })
12
-
13
- it('should call previous remove handler when replacing an event listener', () => {
14
- const remove1Spy = vi.fn()
15
- const remove2Spy = vi.fn()
16
-
17
- focusManager.setEventListener(() => remove1Spy)
18
- focusManager.setEventListener(() => remove2Spy)
19
-
20
- expect(remove1Spy).toHaveBeenCalledTimes(1)
21
- expect(remove2Spy).not.toHaveBeenCalled()
22
- })
23
-
24
- it('should use focused boolean arg', async () => {
25
- let count = 0
26
-
27
- const setup = (setFocused: (focused?: boolean) => void) => {
28
- setTimeout(() => {
29
- count++
30
- setFocused(true)
31
- }, 20)
32
- return () => void 0
33
- }
34
-
35
- focusManager.setEventListener(setup)
36
-
37
- await sleep(30)
38
- expect(count).toEqual(1)
39
- expect(focusManager.isFocused()).toBeTruthy()
40
- })
41
-
42
- it('should return true for isFocused if document is undefined', async () => {
43
- const { document } = globalThis
44
-
45
- // @ts-expect-error
46
- delete globalThis.document
47
-
48
- focusManager.setFocused()
49
- expect(focusManager.isFocused()).toBeTruthy()
50
- globalThis.document = document
51
- })
52
-
53
- test('cleanup (removeEventListener) should not be called if window is not defined', async () => {
54
- const restoreIsServer = setIsServer(true)
55
-
56
- const removeEventListenerSpy = vi.spyOn(globalThis, 'removeEventListener')
57
-
58
- const unsubscribe = focusManager.subscribe(() => undefined)
59
-
60
- unsubscribe()
61
-
62
- expect(removeEventListenerSpy).not.toHaveBeenCalled()
63
-
64
- restoreIsServer()
65
- })
66
-
67
- test('cleanup (removeEventListener) should not be called if window.addEventListener is not defined', async () => {
68
- const { addEventListener } = globalThis.window
69
-
70
- // @ts-expect-error
71
- globalThis.window.addEventListener = undefined
72
-
73
- const removeEventListenerSpy = vi.spyOn(globalThis, 'removeEventListener')
74
-
75
- const unsubscribe = focusManager.subscribe(() => undefined)
76
-
77
- unsubscribe()
78
-
79
- expect(removeEventListenerSpy).not.toHaveBeenCalled()
80
-
81
- globalThis.window.addEventListener = addEventListener
82
- })
83
-
84
- it('should replace default window listener when a new event listener is set', async () => {
85
- const unsubscribeSpy = vi.fn().mockImplementation(() => undefined)
86
- const handlerSpy = vi.fn().mockImplementation(() => unsubscribeSpy)
87
-
88
- focusManager.setEventListener(() => handlerSpy())
89
-
90
- const unsubscribe = focusManager.subscribe(() => undefined)
91
-
92
- // Should call the custom event once
93
- expect(handlerSpy).toHaveBeenCalledTimes(1)
94
-
95
- unsubscribe()
96
-
97
- // Should unsubscribe our event event
98
- expect(unsubscribeSpy).toHaveBeenCalledTimes(1)
99
-
100
- handlerSpy.mockRestore()
101
- unsubscribeSpy.mockRestore()
102
- })
103
-
104
- test('should call removeEventListener when last listener unsubscribes', () => {
105
- const addEventListenerSpy = vi.spyOn(globalThis.window, 'addEventListener')
106
-
107
- const removeEventListenerSpy = vi.spyOn(
108
- globalThis.window,
109
- 'removeEventListener',
110
- )
111
-
112
- const unsubscribe1 = focusManager.subscribe(() => undefined)
113
- const unsubscribe2 = focusManager.subscribe(() => undefined)
114
- expect(addEventListenerSpy).toHaveBeenCalledTimes(1) // visibilitychange event
115
-
116
- unsubscribe1()
117
- expect(removeEventListenerSpy).toHaveBeenCalledTimes(0)
118
- unsubscribe2()
119
- expect(removeEventListenerSpy).toHaveBeenCalledTimes(1) // visibilitychange event
120
- })
121
-
122
- test('should keep setup function even if last listener unsubscribes', () => {
123
- const setupSpy = vi.fn().mockImplementation(() => () => undefined)
124
-
125
- focusManager.setEventListener(setupSpy)
126
-
127
- const unsubscribe1 = focusManager.subscribe(() => undefined)
128
-
129
- expect(setupSpy).toHaveBeenCalledTimes(1)
130
-
131
- unsubscribe1()
132
-
133
- const unsubscribe2 = focusManager.subscribe(() => undefined)
134
-
135
- expect(setupSpy).toHaveBeenCalledTimes(2)
136
-
137
- unsubscribe2()
138
- })
139
-
140
- test('should call listeners when setFocused is called', () => {
141
- const listener = vi.fn()
142
-
143
- focusManager.subscribe(listener)
144
-
145
- focusManager.setFocused(true)
146
- focusManager.setFocused(true)
147
-
148
- expect(listener).toHaveBeenCalledTimes(1)
149
- expect(listener).toHaveBeenNthCalledWith(1, true)
150
-
151
- focusManager.setFocused(false)
152
- focusManager.setFocused(false)
153
-
154
- expect(listener).toHaveBeenCalledTimes(2)
155
- expect(listener).toHaveBeenNthCalledWith(2, false)
156
-
157
- focusManager.setFocused(undefined)
158
- focusManager.setFocused(undefined)
159
-
160
- expect(listener).toHaveBeenCalledTimes(3)
161
- expect(listener).toHaveBeenNthCalledWith(3, true)
162
- })
163
- })