@codeleap/query 5.8.3 → 5.8.4

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/src/types.ts DELETED
@@ -1,199 +0,0 @@
1
- import { DefinedInitialDataInfiniteOptions, InfiniteData, QueryKey, UseInfiniteQueryResult, UseMutationOptions, useQueryClient, UseQueryOptions } from '@tanstack/react-query'
2
- import { QueryManager } from './QueryManager'
3
-
4
- export type PageParam = {limit: number; offset: number}
5
-
6
- export type PaginationResponse<T> = {
7
- count: number
8
- next: string | null
9
- previous: string | null
10
- results: T[]
11
- }
12
-
13
- type OmitMutationKeys<O> = Omit<O, 'mutationFn'|'mutationKey'>
14
-
15
- export type QueryManagerMeta = Record<string, any>
16
-
17
- export type CreateOptions<T extends QueryManagerItem> = {
18
- appendTo?: 'start' | 'end' | [number, number] | Record<string, [number, number]>
19
- optimistic?: boolean
20
- mutationOptions?: Partial<OmitMutationKeys<UseMutationOptions<T, unknown, Partial<T>, MutationCtx<T>>>>
21
- onListsWithFilters?: any
22
- }
23
-
24
- export type UpdateOptions<T extends QueryManagerItem> = {
25
- optimistic?: boolean
26
-
27
- mutationOptions?: Partial<OmitMutationKeys<UseMutationOptions<T, unknown, Partial<T>, MutationCtx<T>>>>
28
-
29
- }
30
-
31
- export type DeleteOptions<T extends QueryManagerItem> = {
32
- optimistic?: boolean
33
-
34
- mutationOptions?: Partial<OmitMutationKeys<UseMutationOptions<T, unknown, T, MutationCtx<T>>>>
35
-
36
- }
37
-
38
- export type RetrieveOptions<T extends QueryManagerItem> = {
39
- queryOptions?: Partial<UseQueryOptions<T, unknown, T>>
40
- id?: T['id']
41
- }
42
-
43
- export type ListOptions<T extends QueryManagerItem, ExtraArgs = any> = {
44
- queryOptions?: Partial<
45
- DefinedInitialDataInfiniteOptions<PaginationResponse<T>, Error, UseListSelector<T>, QueryKey, PageParam>
46
- >
47
- filter?: ExtraArgs
48
- limit?: number
49
- }
50
-
51
- export type QueryManagerAction<
52
- T extends QueryManagerItem,
53
- ExtraArgs = any,
54
- Meta extends QueryManagerMeta = QueryManagerMeta,
55
- Args extends any[] = any[]
56
- > = (
57
- manager: QueryManager<T, ExtraArgs, Meta>, ...args: Args
58
- ) => any
59
-
60
- export type QueryManagerActions<
61
- T extends QueryManagerItem,
62
- ExtraArgs = any,
63
- Meta extends QueryManagerMeta = QueryManagerMeta
64
- > = Record<
65
- string, QueryManagerAction<T, ExtraArgs, Meta>
66
- >
67
-
68
- export type UseListEffect<T extends QueryManagerItem = any> = (
69
- listQuery: {
70
- query: UseInfiniteQueryResult<UseListSelector<T>, Error>
71
- refreshQuery: (silent?: boolean) => void
72
- cancelQuery: () => void
73
- }
74
- ) => void
75
-
76
- export type QueryManagerOptions<
77
- T extends QueryManagerItem,
78
- ExtraArgs = any,
79
- Meta extends QueryManagerMeta = QueryManagerMeta,
80
- Actions extends QueryManagerActions<T, ExtraArgs, Meta> = QueryManagerActions<T, ExtraArgs, Meta>
81
- > = {
82
- name: string
83
- itemType: T
84
- queryClient: ReturnType<typeof useQueryClient>
85
-
86
- listItems?: (limit: number, offset: number, args?: ExtraArgs) => Promise<PaginationResponse<T>>
87
- createItem?: (data: Partial<T>, args?: ExtraArgs) => Promise<T>
88
- updateItem?: (data: Partial<T>, args?: ExtraArgs) => Promise<T>
89
- deleteItem?: (data: T, args?: ExtraArgs) => Promise<T>
90
- retrieveItem?: (id: T['id']) => Promise<T>
91
-
92
- useListEffect?: UseListEffect<T>
93
-
94
- limit?: number
95
- creation?: CreateOptions<T>
96
- update?: UpdateOptions<T>
97
- deletion?: DeleteOptions<T>
98
- generateId?: () => T['id']
99
- actions?: Actions
100
- keyExtractor?: (item: T) => string
101
- initialMeta?: Meta
102
- }
103
-
104
- export type QueryManagerActionTrigger<
105
- A extends QueryManagerAction<any, any, any>,
106
- Args extends any[] = A extends QueryManagerAction<any, any, any, infer _Args> ? _Args : any[]
107
- > = (...args: Args) => any
108
-
109
- export type QueryManagerActionTriggers<
110
- Actions extends QueryManagerActions<any, any, any>
111
- > = {
112
- [K in keyof Actions]: QueryManagerActionTrigger<Actions[K]>
113
- }
114
-
115
- export type InfinitePaginationData<T> = InfiniteData<PaginationResponse<T>, PageParam>
116
-
117
- export type UseManagerArgs<T extends QueryManagerItem, ExtraArgs = any> = {
118
- filter?: ExtraArgs
119
- limit?: number
120
- offset?: number
121
-
122
- creation?: CreateOptions<T>
123
- update?: UpdateOptions<T>
124
- deletion?: DeleteOptions<T>
125
-
126
- listOptions?: Pick<ListOptions<T, ExtraArgs>, 'queryOptions'>
127
- }
128
-
129
- export type QueryManagerItem = {
130
- id: string | number
131
- }
132
-
133
- export type AppendToPaginationParams<TItem extends QueryManagerItem, Filters = any> = {
134
- item: TItem|TItem[]
135
- to?: CreateOptions<TItem>['appendTo']
136
- refreshKey?: QueryKey
137
- onListsWithFilters?: Filters
138
- }
139
-
140
- export type AppendToPaginationReturn<TItem = any> = InfiniteData<TItem>
141
-
142
- export type AppendToPagination<TItem extends QueryManagerItem, ExtraArgs = any> = (params: AppendToPaginationParams<TItem, ExtraArgs>) => Promise<void>
143
-
144
- export type MutationCtx<T extends QueryManagerItem> = null | {
145
- previousData?: InfinitePaginationData<T>
146
- addedId?: T['id']
147
- previousItem?: T
148
- optimisticItem?: T
149
- prevItemPages?:Record<string, [number, number]>
150
- }
151
-
152
- export const isInfiniteQueryData = <T>(data: any): data is InfinitePaginationData<T> => {
153
- return !!data?.pages && !!data?.pageParams
154
- }
155
-
156
- export type QueryStateValue<T extends QueryManagerItem> = {
157
- pagesById: Record<T['id'], [number, number]>
158
- itemIndexes: Record<T['id'], number>
159
- key: QueryKey
160
- }
161
-
162
- export type QueryStateSubscriber<T extends QueryManagerItem> = (data: QueryStateValue<T>) => void
163
-
164
- export type FilterKeyOrder = string[]
165
-
166
- export type GetItemOptions<T extends QueryManagerItem> = {
167
- forceRefetch?: boolean
168
- fetchOnNotFoud?: boolean
169
- }
170
-
171
- export type SettableOptions<O extends QueryManagerOptions<any, any, any, any>> = Partial<
172
- Pick<
173
- O,
174
- 'limit' |
175
- 'creation' |
176
- 'update' |
177
- 'deletion'
178
- > & {
179
- meta: O['initialMeta']
180
- }
181
- >
182
-
183
- export type OptionChangeListener<O extends QueryManagerOptions<any, any, any, any>> = (
184
- options: O,
185
- meta: O['initialMeta'],
186
- ) => any
187
-
188
- export type UseActionOptions<T extends QueryManagerAction<any, any, any>> = UseMutationOptions<
189
- Awaited<ReturnType<T>>,
190
- unknown,
191
- Parameters<T>[1]
192
- >
193
-
194
- export type UseListSelector<T> = {
195
- pageParams: PageParam[]
196
- pages: PaginationResponse<T>[]
197
- flatItems: T[]
198
- }
199
-