@tanstack/angular-query-experimental 5.34.1 → 5.35.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.
- package/README.md +19 -2
- package/build/README.md +19 -2
- package/build/esm2022/create-base-query.mjs +3 -3
- package/build/esm2022/index.mjs +2 -2
- package/build/esm2022/infinite-query-options.mjs +9 -1
- package/build/esm2022/inject-infinite-query.mjs +11 -3
- package/build/esm2022/inject-is-fetching.mjs +11 -1
- package/build/esm2022/inject-is-mutating.mjs +10 -1
- package/build/esm2022/inject-mutation-state.mjs +8 -1
- package/build/esm2022/inject-mutation.mjs +13 -4
- package/build/esm2022/inject-queries.mjs +4 -1
- package/build/esm2022/inject-query-client.mjs +21 -3
- package/build/esm2022/inject-query.mjs +36 -3
- package/build/esm2022/providers.mjs +40 -1
- package/build/esm2022/query-options.mjs +23 -1
- package/build/esm2022/signal-proxy.mjs +2 -4
- package/build/esm2022/types.mjs +1 -1
- package/build/fesm2022/tanstack-angular-query-experimental.mjs +179 -14
- package/build/fesm2022/tanstack-angular-query-experimental.mjs.map +1 -1
- package/build/rollup.d.ts +591 -0
- package/package.json +10 -6
- package/build/create-base-query.d.ts +0 -6
- package/build/index.d.ts +0 -14
- package/build/infinite-query-options.d.ts +0 -18
- package/build/inject-infinite-query.d.ts +0 -7
- package/build/inject-is-fetching.d.ts +0 -3
- package/build/inject-is-mutating.d.ts +0 -3
- package/build/inject-mutation-state.d.ts +0 -11
- package/build/inject-mutation.d.ts +0 -4
- package/build/inject-queries.d.ts +0 -71
- package/build/inject-query-client.d.ts +0 -13
- package/build/inject-query.d.ts +0 -7
- package/build/providers.d.ts +0 -3
- package/build/query-options.d.ts +0 -16
- package/build/signal-proxy.d.ts +0 -13
- package/build/types.d.ts +0 -44
- package/build/util/assert-injector/assert-injector.d.ts +0 -54
- package/build/util/create-injection-token/create-injection-token.d.ts +0 -52
- package/build/util/index.d.ts +0 -2
- package/build/util/lazy-init/lazy-init.d.ts +0 -1
- package/build/util/lazy-signal-initializer/lazy-signal-initializer.d.ts +0 -4
- package/src/__tests__/inject-infinite-query.test.ts +0 -64
- package/src/__tests__/inject-is-fetching.test.ts +0 -35
- package/src/__tests__/inject-is-mutating.test.ts +0 -39
- package/src/__tests__/inject-mutation-state.test-d.ts +0 -22
- package/src/__tests__/inject-mutation-state.test.ts +0 -177
- package/src/__tests__/inject-mutation.test-d.ts +0 -71
- package/src/__tests__/inject-mutation.test.ts +0 -458
- package/src/__tests__/inject-query.test-d.ts +0 -59
- package/src/__tests__/inject-query.test.ts +0 -349
- package/src/__tests__/query-options.test-d.ts +0 -127
- package/src/__tests__/signal-proxy.test.ts +0 -27
- package/src/__tests__/test-utils.ts +0 -131
- package/src/__tests__/util/lazy-init/lazy-init.test.ts +0 -126
- package/src/__tests__/util/lazy-signal-initializer/lazy-signal-initializer.test.ts +0 -130
- package/src/create-base-query.ts +0 -116
- package/src/index.ts +0 -28
- package/src/infinite-query-options.ts +0 -94
- package/src/inject-infinite-query.ts +0 -93
- package/src/inject-is-fetching.ts +0 -39
- package/src/inject-is-mutating.ts +0 -39
- package/src/inject-mutation-state.ts +0 -97
- package/src/inject-mutation.ts +0 -109
- package/src/inject-queries.ts +0 -260
- package/src/inject-query-client.ts +0 -7
- package/src/inject-query.ts +0 -68
- package/src/providers.ts +0 -26
- package/src/query-options.ts +0 -50
- package/src/signal-proxy.ts +0 -48
- package/src/test-setup.ts +0 -12
- package/src/types.ts +0 -260
- package/src/util/assert-injector/assert-injector.test.ts +0 -74
- package/src/util/assert-injector/assert-injector.ts +0 -81
- package/src/util/create-injection-token/create-injection-token.test.ts +0 -32
- package/src/util/create-injection-token/create-injection-token.ts +0 -185
- package/src/util/index.ts +0 -13
- package/src/util/lazy-init/lazy-init.ts +0 -34
- package/src/util/lazy-signal-initializer/lazy-signal-initializer.ts +0 -28
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
ChangeDetectionStrategy,
|
|
4
|
-
Component,
|
|
5
|
-
type WritableSignal,
|
|
6
|
-
computed,
|
|
7
|
-
effect,
|
|
8
|
-
input,
|
|
9
|
-
signal,
|
|
10
|
-
} from '@angular/core'
|
|
11
|
-
import { TestBed } from '@angular/core/testing'
|
|
12
|
-
import { flushQueue, setFixtureSignalInputs } from '../../test-utils'
|
|
13
|
-
import { lazyInit } from '../../../util/lazy-init/lazy-init'
|
|
14
|
-
|
|
15
|
-
describe('lazyInit', () => {
|
|
16
|
-
test('should init lazily in next tick when not accessing manually', async () => {
|
|
17
|
-
const mockFn = vi.fn()
|
|
18
|
-
|
|
19
|
-
TestBed.runInInjectionContext(() => {
|
|
20
|
-
lazyInit(() => {
|
|
21
|
-
mockFn()
|
|
22
|
-
return {
|
|
23
|
-
data: signal(true),
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
expect(mockFn).not.toHaveBeenCalled()
|
|
29
|
-
|
|
30
|
-
await new Promise(setImmediate)
|
|
31
|
-
|
|
32
|
-
expect(mockFn).toHaveBeenCalled()
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
test('should init eagerly accessing manually', async () => {
|
|
36
|
-
const mockFn = vi.fn()
|
|
37
|
-
|
|
38
|
-
TestBed.runInInjectionContext(() => {
|
|
39
|
-
const lazySignal = lazyInit(() => {
|
|
40
|
-
mockFn()
|
|
41
|
-
return {
|
|
42
|
-
data: signal(true),
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
lazySignal.data()
|
|
47
|
-
|
|
48
|
-
console.log(lazySignal)
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
expect(mockFn).toHaveBeenCalled()
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
test('should init lazily and only once', async () => {
|
|
55
|
-
const initCallFn = vi.fn()
|
|
56
|
-
const registerDataValue = vi.fn<[number]>()
|
|
57
|
-
|
|
58
|
-
let value!: { data: WritableSignal<number> }
|
|
59
|
-
const outerSignal = signal(0)
|
|
60
|
-
|
|
61
|
-
TestBed.runInInjectionContext(() => {
|
|
62
|
-
value = lazyInit(() => {
|
|
63
|
-
initCallFn()
|
|
64
|
-
|
|
65
|
-
void outerSignal()
|
|
66
|
-
|
|
67
|
-
return { data: signal(0) }
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
effect(() => registerDataValue(value.data()))
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
value.data()
|
|
74
|
-
|
|
75
|
-
await flushQueue()
|
|
76
|
-
|
|
77
|
-
expect(outerSignal).toBeDefined()
|
|
78
|
-
|
|
79
|
-
expect(initCallFn).toHaveBeenCalledTimes(1)
|
|
80
|
-
|
|
81
|
-
outerSignal.set(1)
|
|
82
|
-
await flushQueue()
|
|
83
|
-
outerSignal.set(2)
|
|
84
|
-
await flushQueue()
|
|
85
|
-
value.data.set(4)
|
|
86
|
-
await flushQueue()
|
|
87
|
-
|
|
88
|
-
expect(initCallFn).toHaveBeenCalledTimes(1)
|
|
89
|
-
expect(registerDataValue).toHaveBeenCalledTimes(2)
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
test('should support required signal input', async () => {
|
|
93
|
-
@Component({
|
|
94
|
-
standalone: true,
|
|
95
|
-
template: `{{ call }} - {{ lazySignal.data() }}`,
|
|
96
|
-
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
97
|
-
})
|
|
98
|
-
class Test {
|
|
99
|
-
readonly title = input.required<string>()
|
|
100
|
-
call = 0
|
|
101
|
-
|
|
102
|
-
lazySignal = lazyInit(() => {
|
|
103
|
-
this.call++
|
|
104
|
-
return {
|
|
105
|
-
data: computed(() => this.title()),
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const fixture = TestBed.createComponent(Test)
|
|
111
|
-
|
|
112
|
-
setFixtureSignalInputs(fixture, { title: 'newValue' })
|
|
113
|
-
expect(fixture.debugElement.nativeElement.textContent).toBe('0 - newValue')
|
|
114
|
-
await flushQueue()
|
|
115
|
-
|
|
116
|
-
setFixtureSignalInputs(fixture, { title: 'updatedValue' })
|
|
117
|
-
expect(fixture.debugElement.nativeElement.textContent).toBe(
|
|
118
|
-
'1 - updatedValue',
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
setFixtureSignalInputs(fixture, { title: 'newUpdatedValue' })
|
|
122
|
-
expect(fixture.debugElement.nativeElement.textContent).toBe(
|
|
123
|
-
'1 - newUpdatedValue',
|
|
124
|
-
)
|
|
125
|
-
})
|
|
126
|
-
})
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
Component,
|
|
4
|
-
type Signal,
|
|
5
|
-
type WritableSignal,
|
|
6
|
-
effect,
|
|
7
|
-
input,
|
|
8
|
-
signal,
|
|
9
|
-
} from '@angular/core'
|
|
10
|
-
import { TestBed } from '@angular/core/testing'
|
|
11
|
-
import { lazySignalInitializer } from '../../../util/lazy-signal-initializer/lazy-signal-initializer'
|
|
12
|
-
import { flushQueue, setFixtureSignalInputs } from '../../test-utils'
|
|
13
|
-
|
|
14
|
-
describe('lazySignalInitializer', () => {
|
|
15
|
-
test('should init lazily in next tick when not accessing manually', async () => {
|
|
16
|
-
const mockFn = vi.fn()
|
|
17
|
-
|
|
18
|
-
TestBed.runInInjectionContext(() => {
|
|
19
|
-
lazySignalInitializer(() => {
|
|
20
|
-
mockFn()
|
|
21
|
-
return signal(true)
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
expect(mockFn).not.toHaveBeenCalled()
|
|
26
|
-
|
|
27
|
-
await new Promise(setImmediate)
|
|
28
|
-
|
|
29
|
-
expect(mockFn).toHaveBeenCalled()
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
test('should init eagerly accessing manually', async () => {
|
|
33
|
-
const mockFn = vi.fn()
|
|
34
|
-
|
|
35
|
-
TestBed.runInInjectionContext(() => {
|
|
36
|
-
const lazySignal = lazySignalInitializer(() => {
|
|
37
|
-
mockFn()
|
|
38
|
-
return signal(true)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
lazySignal()
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
expect(mockFn).toHaveBeenCalled()
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
test('should init lazily and only once', async () => {
|
|
48
|
-
const initCallFn = vi.fn()
|
|
49
|
-
const registerEffectValue = vi.fn<[number]>()
|
|
50
|
-
|
|
51
|
-
let value!: Signal<number>
|
|
52
|
-
const outerSignal = signal(0)
|
|
53
|
-
let innerSignal!: WritableSignal<number>
|
|
54
|
-
|
|
55
|
-
TestBed.runInInjectionContext(() => {
|
|
56
|
-
value = lazySignalInitializer(() => {
|
|
57
|
-
initCallFn()
|
|
58
|
-
innerSignal = signal(0)
|
|
59
|
-
|
|
60
|
-
void outerSignal()
|
|
61
|
-
|
|
62
|
-
return innerSignal
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
effect(() => registerEffectValue(value()))
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
value()
|
|
69
|
-
|
|
70
|
-
await flushQueue()
|
|
71
|
-
|
|
72
|
-
expect(outerSignal).toBeDefined()
|
|
73
|
-
expect(innerSignal).toBeDefined()
|
|
74
|
-
|
|
75
|
-
expect(initCallFn).toHaveBeenCalledTimes(1)
|
|
76
|
-
|
|
77
|
-
innerSignal.set(1)
|
|
78
|
-
await flushQueue()
|
|
79
|
-
outerSignal.set(2)
|
|
80
|
-
await flushQueue()
|
|
81
|
-
|
|
82
|
-
expect(initCallFn).toHaveBeenCalledTimes(1)
|
|
83
|
-
expect(registerEffectValue).toHaveBeenCalledTimes(2)
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
test('should init lazily', async () => {
|
|
87
|
-
@Component({
|
|
88
|
-
standalone: true,
|
|
89
|
-
template: `{{ subscribed }}`,
|
|
90
|
-
})
|
|
91
|
-
class Test {
|
|
92
|
-
subscribed = false
|
|
93
|
-
|
|
94
|
-
lazySignal = lazySignalInitializer(() => {
|
|
95
|
-
this.subscribed = true
|
|
96
|
-
return signal('value')
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const fixture = TestBed.createComponent(Test)
|
|
101
|
-
const { debugElement } = fixture
|
|
102
|
-
fixture.detectChanges()
|
|
103
|
-
|
|
104
|
-
expect(debugElement.nativeElement.textContent).toBe('false')
|
|
105
|
-
|
|
106
|
-
await new Promise(setImmediate)
|
|
107
|
-
|
|
108
|
-
fixture.detectChanges()
|
|
109
|
-
|
|
110
|
-
expect(debugElement.nativeElement.textContent).toBe('true')
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
test('should support required signal input', () => {
|
|
114
|
-
@Component({
|
|
115
|
-
standalone: true,
|
|
116
|
-
template: `{{ subscribed }}`,
|
|
117
|
-
})
|
|
118
|
-
class Test {
|
|
119
|
-
readonly title = input.required<string>()
|
|
120
|
-
subscribed = false
|
|
121
|
-
|
|
122
|
-
lazySignal = lazySignalInitializer(() => {
|
|
123
|
-
return signal(this.title())
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const fixture = TestBed.createComponent(Test)
|
|
128
|
-
setFixtureSignalInputs(fixture, { title: 'newValue' })
|
|
129
|
-
})
|
|
130
|
-
})
|
package/src/create-base-query.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DestroyRef,
|
|
3
|
-
Injector,
|
|
4
|
-
NgZone,
|
|
5
|
-
computed,
|
|
6
|
-
effect,
|
|
7
|
-
inject,
|
|
8
|
-
runInInjectionContext,
|
|
9
|
-
signal,
|
|
10
|
-
untracked,
|
|
11
|
-
} from '@angular/core'
|
|
12
|
-
import { notifyManager } from '@tanstack/query-core'
|
|
13
|
-
import { signalProxy } from './signal-proxy'
|
|
14
|
-
import { shouldThrowError } from './util'
|
|
15
|
-
import { lazyInit } from './util/lazy-init/lazy-init'
|
|
16
|
-
import type {
|
|
17
|
-
QueryClient,
|
|
18
|
-
QueryKey,
|
|
19
|
-
QueryObserver,
|
|
20
|
-
QueryObserverResult,
|
|
21
|
-
} from '@tanstack/query-core'
|
|
22
|
-
import type { CreateBaseQueryOptions, CreateBaseQueryResult } from './types'
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Base implementation for `injectQuery` and `injectInfiniteQuery`.
|
|
26
|
-
*/
|
|
27
|
-
export function createBaseQuery<
|
|
28
|
-
TQueryFnData,
|
|
29
|
-
TError,
|
|
30
|
-
TData,
|
|
31
|
-
TQueryData,
|
|
32
|
-
TQueryKey extends QueryKey,
|
|
33
|
-
>(
|
|
34
|
-
options: (
|
|
35
|
-
client: QueryClient,
|
|
36
|
-
) => CreateBaseQueryOptions<
|
|
37
|
-
TQueryFnData,
|
|
38
|
-
TError,
|
|
39
|
-
TData,
|
|
40
|
-
TQueryData,
|
|
41
|
-
TQueryKey
|
|
42
|
-
>,
|
|
43
|
-
Observer: typeof QueryObserver,
|
|
44
|
-
queryClient: QueryClient,
|
|
45
|
-
): CreateBaseQueryResult<TData, TError> {
|
|
46
|
-
const injector = inject(Injector)
|
|
47
|
-
const ngZone = inject(NgZone)
|
|
48
|
-
|
|
49
|
-
return lazyInit(() => {
|
|
50
|
-
return runInInjectionContext(injector, () => {
|
|
51
|
-
const destroyRef = inject(DestroyRef)
|
|
52
|
-
/**
|
|
53
|
-
* Signal that has the default options from query client applied
|
|
54
|
-
* computed() is used so signals can be inserted into the options
|
|
55
|
-
* making it reactive. Wrapping options in a function ensures embedded expressions
|
|
56
|
-
* are preserved and can keep being applied after signal changes
|
|
57
|
-
*/
|
|
58
|
-
const defaultedOptionsSignal = computed(() => {
|
|
59
|
-
const defaultedOptions = queryClient.defaultQueryOptions(
|
|
60
|
-
options(queryClient),
|
|
61
|
-
)
|
|
62
|
-
defaultedOptions._optimisticResults = 'optimistic'
|
|
63
|
-
return defaultedOptions
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
const observer = new Observer<
|
|
67
|
-
TQueryFnData,
|
|
68
|
-
TError,
|
|
69
|
-
TData,
|
|
70
|
-
TQueryData,
|
|
71
|
-
TQueryKey
|
|
72
|
-
>(queryClient, defaultedOptionsSignal())
|
|
73
|
-
|
|
74
|
-
const resultSignal = signal(
|
|
75
|
-
observer.getOptimisticResult(defaultedOptionsSignal()),
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
effect(() => {
|
|
79
|
-
const defaultedOptions = defaultedOptionsSignal()
|
|
80
|
-
observer.setOptions(defaultedOptions, {
|
|
81
|
-
// Do not notify on updates because of changes in the options because
|
|
82
|
-
// these changes should already be reflected in the optimistic result.
|
|
83
|
-
listeners: false,
|
|
84
|
-
})
|
|
85
|
-
untracked(() => {
|
|
86
|
-
resultSignal.set(observer.getOptimisticResult(defaultedOptions))
|
|
87
|
-
})
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
// observer.trackResult is not used as this optimization is not needed for Angular
|
|
91
|
-
const unsubscribe = observer.subscribe(
|
|
92
|
-
notifyManager.batchCalls(
|
|
93
|
-
(state: QueryObserverResult<TData, TError>) => {
|
|
94
|
-
ngZone.run(() => {
|
|
95
|
-
if (
|
|
96
|
-
state.isError &&
|
|
97
|
-
!state.isFetching &&
|
|
98
|
-
// !isRestoring() && // todo: enable when client persistence is implemented
|
|
99
|
-
shouldThrowError(observer.options.throwOnError, [
|
|
100
|
-
state.error,
|
|
101
|
-
observer.getCurrentQuery(),
|
|
102
|
-
])
|
|
103
|
-
) {
|
|
104
|
-
throw state.error
|
|
105
|
-
}
|
|
106
|
-
resultSignal.set(state)
|
|
107
|
-
})
|
|
108
|
-
},
|
|
109
|
-
),
|
|
110
|
-
)
|
|
111
|
-
destroyRef.onDestroy(unsubscribe)
|
|
112
|
-
|
|
113
|
-
return signalProxy(resultSignal) as CreateBaseQueryResult<TData, TError>
|
|
114
|
-
})
|
|
115
|
-
})
|
|
116
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
|
|
3
|
-
// Re-export core
|
|
4
|
-
export * from '@tanstack/query-core'
|
|
5
|
-
|
|
6
|
-
export * from './types'
|
|
7
|
-
|
|
8
|
-
export type {
|
|
9
|
-
DefinedInitialDataOptions,
|
|
10
|
-
UndefinedInitialDataOptions,
|
|
11
|
-
} from './query-options'
|
|
12
|
-
export { queryOptions } from './query-options'
|
|
13
|
-
|
|
14
|
-
export { infiniteQueryOptions } from './infinite-query-options'
|
|
15
|
-
|
|
16
|
-
export * from './inject-infinite-query'
|
|
17
|
-
export * from './inject-is-fetching'
|
|
18
|
-
export * from './inject-is-mutating'
|
|
19
|
-
export * from './inject-mutation'
|
|
20
|
-
export * from './inject-mutation-state'
|
|
21
|
-
export * from './inject-queries'
|
|
22
|
-
export * from './inject-query'
|
|
23
|
-
export {
|
|
24
|
-
injectQueryClient,
|
|
25
|
-
provideQueryClient,
|
|
26
|
-
QUERY_CLIENT,
|
|
27
|
-
} from './inject-query-client'
|
|
28
|
-
export { provideAngularQuery } from './providers'
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { DataTag } from '@tanstack/query-core'
|
|
2
|
-
import type { InfiniteData } from '@tanstack/query-core'
|
|
3
|
-
import type { CreateInfiniteQueryOptions } from './types'
|
|
4
|
-
import type { DefaultError, QueryKey } from '@tanstack/query-core'
|
|
5
|
-
|
|
6
|
-
export type UndefinedInitialDataInfiniteOptions<
|
|
7
|
-
TQueryFnData,
|
|
8
|
-
TError = DefaultError,
|
|
9
|
-
TData = InfiniteData<TQueryFnData>,
|
|
10
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
11
|
-
TPageParam = unknown,
|
|
12
|
-
> = CreateInfiniteQueryOptions<
|
|
13
|
-
TQueryFnData,
|
|
14
|
-
TError,
|
|
15
|
-
TData,
|
|
16
|
-
TQueryFnData,
|
|
17
|
-
TQueryKey,
|
|
18
|
-
TPageParam
|
|
19
|
-
> & {
|
|
20
|
-
initialData?: undefined
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type NonUndefinedGuard<T> = T extends undefined ? never : T
|
|
24
|
-
|
|
25
|
-
export type DefinedInitialDataInfiniteOptions<
|
|
26
|
-
TQueryFnData,
|
|
27
|
-
TError = DefaultError,
|
|
28
|
-
TData = InfiniteData<TQueryFnData>,
|
|
29
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
30
|
-
TPageParam = unknown,
|
|
31
|
-
> = CreateInfiniteQueryOptions<
|
|
32
|
-
TQueryFnData,
|
|
33
|
-
TError,
|
|
34
|
-
TData,
|
|
35
|
-
TQueryFnData,
|
|
36
|
-
TQueryKey,
|
|
37
|
-
TPageParam
|
|
38
|
-
> & {
|
|
39
|
-
initialData:
|
|
40
|
-
| NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
|
|
41
|
-
| (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function infiniteQueryOptions<
|
|
45
|
-
TQueryFnData,
|
|
46
|
-
TError = DefaultError,
|
|
47
|
-
TData = InfiniteData<TQueryFnData>,
|
|
48
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
49
|
-
TPageParam = unknown,
|
|
50
|
-
>(
|
|
51
|
-
options: UndefinedInitialDataInfiniteOptions<
|
|
52
|
-
TQueryFnData,
|
|
53
|
-
TError,
|
|
54
|
-
TData,
|
|
55
|
-
TQueryKey,
|
|
56
|
-
TPageParam
|
|
57
|
-
>,
|
|
58
|
-
): UndefinedInitialDataInfiniteOptions<
|
|
59
|
-
TQueryFnData,
|
|
60
|
-
TError,
|
|
61
|
-
TData,
|
|
62
|
-
TQueryKey,
|
|
63
|
-
TPageParam
|
|
64
|
-
> & {
|
|
65
|
-
queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function infiniteQueryOptions<
|
|
69
|
-
TQueryFnData,
|
|
70
|
-
TError = DefaultError,
|
|
71
|
-
TData = InfiniteData<TQueryFnData>,
|
|
72
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
73
|
-
TPageParam = unknown,
|
|
74
|
-
>(
|
|
75
|
-
options: DefinedInitialDataInfiniteOptions<
|
|
76
|
-
TQueryFnData,
|
|
77
|
-
TError,
|
|
78
|
-
TData,
|
|
79
|
-
TQueryKey,
|
|
80
|
-
TPageParam
|
|
81
|
-
>,
|
|
82
|
-
): DefinedInitialDataInfiniteOptions<
|
|
83
|
-
TQueryFnData,
|
|
84
|
-
TError,
|
|
85
|
-
TData,
|
|
86
|
-
TQueryKey,
|
|
87
|
-
TPageParam
|
|
88
|
-
> & {
|
|
89
|
-
queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function infiniteQueryOptions(options: unknown) {
|
|
93
|
-
return options
|
|
94
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { InfiniteQueryObserver } from '@tanstack/query-core'
|
|
2
|
-
import { createBaseQuery } from './create-base-query'
|
|
3
|
-
import { injectQueryClient } from './inject-query-client'
|
|
4
|
-
import { assertInjector } from './util/assert-injector/assert-injector'
|
|
5
|
-
import type { Injector } from '@angular/core'
|
|
6
|
-
import type {
|
|
7
|
-
DefaultError,
|
|
8
|
-
InfiniteData,
|
|
9
|
-
QueryClient,
|
|
10
|
-
QueryKey,
|
|
11
|
-
QueryObserver,
|
|
12
|
-
} from '@tanstack/query-core'
|
|
13
|
-
import type {
|
|
14
|
-
CreateInfiniteQueryOptions,
|
|
15
|
-
CreateInfiniteQueryResult,
|
|
16
|
-
DefinedCreateInfiniteQueryResult,
|
|
17
|
-
} from './types'
|
|
18
|
-
import type {
|
|
19
|
-
DefinedInitialDataInfiniteOptions,
|
|
20
|
-
UndefinedInitialDataInfiniteOptions,
|
|
21
|
-
} from './infinite-query-options'
|
|
22
|
-
|
|
23
|
-
export function injectInfiniteQuery<
|
|
24
|
-
TQueryFnData,
|
|
25
|
-
TError = DefaultError,
|
|
26
|
-
TData = InfiniteData<TQueryFnData>,
|
|
27
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
28
|
-
TPageParam = unknown,
|
|
29
|
-
>(
|
|
30
|
-
options: (
|
|
31
|
-
client: QueryClient,
|
|
32
|
-
) => UndefinedInitialDataInfiniteOptions<
|
|
33
|
-
TQueryFnData,
|
|
34
|
-
TError,
|
|
35
|
-
TData,
|
|
36
|
-
TQueryKey,
|
|
37
|
-
TPageParam
|
|
38
|
-
>,
|
|
39
|
-
injector?: Injector,
|
|
40
|
-
): CreateInfiniteQueryResult<TData, TError>
|
|
41
|
-
|
|
42
|
-
export function injectInfiniteQuery<
|
|
43
|
-
TQueryFnData,
|
|
44
|
-
TError = DefaultError,
|
|
45
|
-
TData = InfiniteData<TQueryFnData>,
|
|
46
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
47
|
-
TPageParam = unknown,
|
|
48
|
-
>(
|
|
49
|
-
options: (
|
|
50
|
-
client: QueryClient,
|
|
51
|
-
) => DefinedInitialDataInfiniteOptions<
|
|
52
|
-
TQueryFnData,
|
|
53
|
-
TError,
|
|
54
|
-
TData,
|
|
55
|
-
TQueryKey,
|
|
56
|
-
TPageParam
|
|
57
|
-
>,
|
|
58
|
-
injector?: Injector,
|
|
59
|
-
): DefinedCreateInfiniteQueryResult<TData, TError>
|
|
60
|
-
|
|
61
|
-
export function injectInfiniteQuery<
|
|
62
|
-
TQueryFnData,
|
|
63
|
-
TError = DefaultError,
|
|
64
|
-
TData = InfiniteData<TQueryFnData>,
|
|
65
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
66
|
-
TPageParam = unknown,
|
|
67
|
-
>(
|
|
68
|
-
options: (
|
|
69
|
-
client: QueryClient,
|
|
70
|
-
) => CreateInfiniteQueryOptions<
|
|
71
|
-
TQueryFnData,
|
|
72
|
-
TError,
|
|
73
|
-
TData,
|
|
74
|
-
TQueryFnData,
|
|
75
|
-
TQueryKey,
|
|
76
|
-
TPageParam
|
|
77
|
-
>,
|
|
78
|
-
injector?: Injector,
|
|
79
|
-
): CreateInfiniteQueryResult<TData, TError>
|
|
80
|
-
|
|
81
|
-
export function injectInfiniteQuery(
|
|
82
|
-
options: (client: QueryClient) => CreateInfiniteQueryOptions,
|
|
83
|
-
injector?: Injector,
|
|
84
|
-
) {
|
|
85
|
-
return assertInjector(injectInfiniteQuery, injector, () => {
|
|
86
|
-
const queryClient = injectQueryClient()
|
|
87
|
-
return createBaseQuery(
|
|
88
|
-
options,
|
|
89
|
-
InfiniteQueryObserver as typeof QueryObserver,
|
|
90
|
-
queryClient,
|
|
91
|
-
)
|
|
92
|
-
})
|
|
93
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { DestroyRef, NgZone, inject, signal } from '@angular/core'
|
|
2
|
-
import { type QueryFilters, notifyManager } from '@tanstack/query-core'
|
|
3
|
-
import { assertInjector } from './util/assert-injector/assert-injector'
|
|
4
|
-
import { injectQueryClient } from './inject-query-client'
|
|
5
|
-
import type { Injector, Signal } from '@angular/core'
|
|
6
|
-
|
|
7
|
-
export function injectIsFetching(
|
|
8
|
-
filters?: QueryFilters,
|
|
9
|
-
injector?: Injector,
|
|
10
|
-
): Signal<number> {
|
|
11
|
-
return assertInjector(injectIsFetching, injector, () => {
|
|
12
|
-
const queryClient = injectQueryClient()
|
|
13
|
-
const destroyRef = inject(DestroyRef)
|
|
14
|
-
const ngZone = inject(NgZone)
|
|
15
|
-
|
|
16
|
-
const cache = queryClient.getQueryCache()
|
|
17
|
-
// isFetching is the prev value initialized on mount *
|
|
18
|
-
let isFetching = queryClient.isFetching(filters)
|
|
19
|
-
|
|
20
|
-
const result = signal(isFetching)
|
|
21
|
-
|
|
22
|
-
const unsubscribe = cache.subscribe(
|
|
23
|
-
notifyManager.batchCalls(() => {
|
|
24
|
-
const newIsFetching = queryClient.isFetching(filters)
|
|
25
|
-
if (isFetching !== newIsFetching) {
|
|
26
|
-
// * and update with each change
|
|
27
|
-
isFetching = newIsFetching
|
|
28
|
-
ngZone.run(() => {
|
|
29
|
-
result.set(isFetching)
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
}),
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
destroyRef.onDestroy(unsubscribe)
|
|
36
|
-
|
|
37
|
-
return result
|
|
38
|
-
})
|
|
39
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { DestroyRef, NgZone, inject, signal } from '@angular/core'
|
|
2
|
-
import { type MutationFilters, notifyManager } from '@tanstack/query-core'
|
|
3
|
-
import { assertInjector } from './util/assert-injector/assert-injector'
|
|
4
|
-
import { injectQueryClient } from './inject-query-client'
|
|
5
|
-
import type { Injector, Signal } from '@angular/core'
|
|
6
|
-
|
|
7
|
-
export function injectIsMutating(
|
|
8
|
-
filters?: MutationFilters,
|
|
9
|
-
injector?: Injector,
|
|
10
|
-
): Signal<number> {
|
|
11
|
-
return assertInjector(injectIsMutating, injector, () => {
|
|
12
|
-
const queryClient = injectQueryClient()
|
|
13
|
-
const destroyRef = inject(DestroyRef)
|
|
14
|
-
const ngZone = inject(NgZone)
|
|
15
|
-
|
|
16
|
-
const cache = queryClient.getMutationCache()
|
|
17
|
-
// isMutating is the prev value initialized on mount *
|
|
18
|
-
let isMutating = queryClient.isMutating(filters)
|
|
19
|
-
|
|
20
|
-
const result = signal(isMutating)
|
|
21
|
-
|
|
22
|
-
const unsubscribe = cache.subscribe(
|
|
23
|
-
notifyManager.batchCalls(() => {
|
|
24
|
-
const newIsMutating = queryClient.isMutating(filters)
|
|
25
|
-
if (isMutating !== newIsMutating) {
|
|
26
|
-
// * and update with each change
|
|
27
|
-
isMutating = newIsMutating
|
|
28
|
-
ngZone.run(() => {
|
|
29
|
-
result.set(isMutating)
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
}),
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
destroyRef.onDestroy(unsubscribe)
|
|
36
|
-
|
|
37
|
-
return result
|
|
38
|
-
})
|
|
39
|
-
}
|