@gaddario98/react-core 2.0.2 → 2.0.3
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/dist/form/index.d.ts +236 -0
- package/dist/localization/index.d.ts +155 -0
- package/dist/notifications/index.d.ts +37 -0
- package/dist/pages/index.d.ts +1827 -0
- package/dist/queries/index.d.ts +372 -0
- package/dist/state/index.d.ts +28 -0
- package/package.json +1 -1
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import * as jotai from 'jotai';
|
|
2
|
+
import * as jotai_utils from 'jotai/utils';
|
|
3
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
4
|
+
import { UseQueryOptions, useQuery, UseMutationOptions, MutateOptions, useMutation, UseMutationResult, QueryClient } from '@tanstack/react-query';
|
|
5
|
+
import { NotificationConfig } from '@gaddario98/react-notifications';
|
|
6
|
+
import { AxiosRequestConfig } from 'axios';
|
|
7
|
+
import * as _gaddario98_react_state from '@gaddario98/react-state';
|
|
8
|
+
import { PersistQueryClientOptions } from '@tanstack/react-query-persist-client';
|
|
9
|
+
import { PropsWithChildren } from 'react';
|
|
10
|
+
|
|
11
|
+
type ApiMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
12
|
+
type Endpoint = Record<string, string>;
|
|
13
|
+
interface QueriesProps<TProps, TResponse, TConverter = null> {
|
|
14
|
+
endpoint: [keyof Endpoint, string] | [keyof Endpoint];
|
|
15
|
+
queryKeyToInvalidate?: Array<string>;
|
|
16
|
+
headers?: AxiosRequestConfig['headers'];
|
|
17
|
+
method: ApiMethod;
|
|
18
|
+
converter?: (props: TProps) => TConverter;
|
|
19
|
+
customRequest?: (url: string, method: string, data: TProps) => Promise<TResponse>;
|
|
20
|
+
mutateOptions?: MutateOptions<TResponse, Error, TProps, unknown>;
|
|
21
|
+
isTest?: boolean;
|
|
22
|
+
notification?: {
|
|
23
|
+
success?: NotificationConfig | ((res: TResponse) => NotificationConfig);
|
|
24
|
+
error?: NotificationConfig | ((error: string) => NotificationConfig);
|
|
25
|
+
translationOption?: Record<string, any>;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
interface QueryProps<Key extends string, TResponse> {
|
|
29
|
+
endpoint: [keyof Endpoint, string] | [keyof Endpoint];
|
|
30
|
+
queryKey: Array<string>;
|
|
31
|
+
enabled: boolean;
|
|
32
|
+
keyToMap: Key;
|
|
33
|
+
disableLoading?: boolean;
|
|
34
|
+
customQueryFn?: () => Promise<TResponse>;
|
|
35
|
+
headers?: AxiosRequestConfig['headers'];
|
|
36
|
+
disableAuthControl?: boolean;
|
|
37
|
+
onDataChanged?: (data: TResponse) => void;
|
|
38
|
+
onStateChange?: (state: QueryResult<TResponse>) => void;
|
|
39
|
+
options?: Omit<Parameters<typeof useQuery<TResponse>>['0'], 'queryKey' | 'queryFn'>;
|
|
40
|
+
}
|
|
41
|
+
interface CustomQueryOptions<TResponse> extends Omit<UseQueryOptions<TResponse, Error>, 'queryKey' | 'queryFn'> {
|
|
42
|
+
endpoint: [keyof Endpoint, string] | [keyof Endpoint];
|
|
43
|
+
queryKey: Array<string>;
|
|
44
|
+
headers?: AxiosRequestConfig['headers'];
|
|
45
|
+
disableAuthControl?: boolean;
|
|
46
|
+
onDataChanged?: (data: TResponse | undefined) => void;
|
|
47
|
+
onStateChange?: (state: QueryResult<TResponse>) => void;
|
|
48
|
+
options?: Omit<Parameters<typeof useQuery<TResponse>>['0'], 'queryKey' | 'queryFn'>;
|
|
49
|
+
keyToMap?: string;
|
|
50
|
+
disableLoading?: boolean;
|
|
51
|
+
customQueryFn?: () => Promise<TResponse>;
|
|
52
|
+
}
|
|
53
|
+
interface CustomMutationOptions<TProps, TResponse> extends UseMutationOptions<TResponse, Error, TProps, unknown> {
|
|
54
|
+
endpoint: [keyof Endpoint, string] | [keyof Endpoint];
|
|
55
|
+
method: ApiMethod;
|
|
56
|
+
headers?: AxiosRequestConfig['headers'];
|
|
57
|
+
queryKeyToInvalidate?: Array<string>;
|
|
58
|
+
customRequest?: (url: string, method: string, data: TProps) => Promise<TResponse>;
|
|
59
|
+
converter?: (props: TProps) => any;
|
|
60
|
+
isTest?: boolean;
|
|
61
|
+
notification?: {
|
|
62
|
+
success?: NotificationConfig | ((res: TResponse) => NotificationConfig);
|
|
63
|
+
error?: NotificationConfig | ((error: string) => NotificationConfig);
|
|
64
|
+
translationOption?: Record<string, any>;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
type QueryDefinition<K extends string, T extends 'query' | 'mutation' | 'websocket', P, R, C = any> = {
|
|
68
|
+
key: K;
|
|
69
|
+
props: P;
|
|
70
|
+
response?: R;
|
|
71
|
+
converter: C;
|
|
72
|
+
type: T;
|
|
73
|
+
};
|
|
74
|
+
type QueriesArray = Array<QueryDefinition<string, any, any, any, any>>;
|
|
75
|
+
type ExtractQuery<Q extends QueriesArray> = Extract<Q[number], {
|
|
76
|
+
type: 'query';
|
|
77
|
+
}>;
|
|
78
|
+
type ExtractWebSocket<Q extends QueriesArray> = Extract<Q[number], {
|
|
79
|
+
type: 'websocket';
|
|
80
|
+
}>;
|
|
81
|
+
type ExtractQueryResponse<Q extends QueriesArray, K extends Q[number]['key']> = Extract<Q[number], {
|
|
82
|
+
key: K;
|
|
83
|
+
}>;
|
|
84
|
+
type ExtractMutation<Q extends QueriesArray> = Extract<Q[number], {
|
|
85
|
+
type: 'mutation';
|
|
86
|
+
}>;
|
|
87
|
+
type CustomMutation<TData = unknown, TError = Error, TVariables = void, TOnMutateResult = unknown> = typeof useMutation<TData, TError, TVariables, TOnMutateResult> & {
|
|
88
|
+
endpoint: string;
|
|
89
|
+
};
|
|
90
|
+
type AllMutation<Q extends QueriesArray = QueriesArray> = {
|
|
91
|
+
[K in ExtractMutation<Q>['key']]: ReturnType<CustomMutation<ExtractQueryResponse<Q, K>['response'], Error, ExtractQueryResponse<Q, K>['props'], unknown>> & {
|
|
92
|
+
endpoint: QueriesProps<any, any>['endpoint'];
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
type ExtractMutationByKey<Q extends QueriesArray = QueriesArray, K extends ExtractMutation<Q>['key'] = ExtractMutation<Q>['key']> = ReturnType<CustomMutation<ExtractQueryResponse<Q, K>['response'], Error, ExtractQueryResponse<Q, K>['props'], unknown>>;
|
|
96
|
+
type ExtractQueryByKey<Q extends QueriesArray = QueriesArray, K extends ExtractQuery<Q>['key'] = ExtractQuery<Q>['key']> = {
|
|
97
|
+
data?: ExtractQueryResponse<Q, K>['response'];
|
|
98
|
+
isLoading: boolean;
|
|
99
|
+
isLoadingMapped: boolean;
|
|
100
|
+
isFetching: boolean;
|
|
101
|
+
isPending: boolean;
|
|
102
|
+
error: Error | null;
|
|
103
|
+
refetch: () => Promise<unknown>;
|
|
104
|
+
};
|
|
105
|
+
interface MutationConfig<TProps = unknown, TResponse = unknown, TConverter = any> extends QueriesProps<TProps, TResponse, TConverter> {
|
|
106
|
+
method: 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
107
|
+
onStateChange?: (state: MutationStateInternal<TResponse>) => void;
|
|
108
|
+
}
|
|
109
|
+
interface QueryResult<TResponse> {
|
|
110
|
+
data?: TResponse;
|
|
111
|
+
isLoading: boolean;
|
|
112
|
+
isLoadingMapped: boolean;
|
|
113
|
+
isFetching: boolean;
|
|
114
|
+
isPending: boolean;
|
|
115
|
+
error: Error | null;
|
|
116
|
+
refetch: () => Promise<unknown>;
|
|
117
|
+
}
|
|
118
|
+
type MultipleQueryResponse<Q extends QueriesArray> = {
|
|
119
|
+
[K in ExtractQuery<Q>['key']]: {
|
|
120
|
+
data: ExtractQueryResponse<Q, K>['response'];
|
|
121
|
+
isLoading: boolean;
|
|
122
|
+
isLoadingMapped: boolean;
|
|
123
|
+
isFetching: boolean;
|
|
124
|
+
isPending: boolean;
|
|
125
|
+
error: Error | null;
|
|
126
|
+
refetch: () => Promise<unknown>;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
interface QueryConfig<K extends string, TResponse> extends CustomQueryOptions<TResponse> {
|
|
130
|
+
keyToMap: K;
|
|
131
|
+
}
|
|
132
|
+
type SingleQueryConfig<Q extends QueryDefinition<any, any, any, any>> = Q extends QueryDefinition<infer K, infer T, infer P, infer R, infer C> ? T extends 'mutation' ? {
|
|
133
|
+
type: 'mutation';
|
|
134
|
+
mutationConfig: MutationConfig<P, R, C>;
|
|
135
|
+
key: K;
|
|
136
|
+
} : T extends 'query' ? {
|
|
137
|
+
type: 'query';
|
|
138
|
+
queryConfig?: Omit<QueryConfig<K, R>, 'keyToMap'>;
|
|
139
|
+
key: K;
|
|
140
|
+
} : WebSocketDefinition<K> : never;
|
|
141
|
+
type QueryAtIndex<Q extends QueriesArray, I extends keyof Q> = Q[I] extends QueryDefinition<infer K, infer T, infer P, infer R, infer C> ? QueryDefinition<K, T, P, R, C> : never;
|
|
142
|
+
type QueryConfigArray<Q extends QueriesArray> = {
|
|
143
|
+
[I in keyof Q]: SingleQueryConfig<QueryAtIndex<Q, I>>;
|
|
144
|
+
};
|
|
145
|
+
interface ContextValue<Q extends QueriesArray> {
|
|
146
|
+
allMutation: AllMutation<Q>;
|
|
147
|
+
allQuery: MultipleQueryResponse<Q>;
|
|
148
|
+
allWebSocket: MultipleWebSocketResponse<Q[number]['key']>;
|
|
149
|
+
refreshQueries: () => void;
|
|
150
|
+
}
|
|
151
|
+
type MultipleWebSocketResponse<K extends string = string> = {
|
|
152
|
+
[key in K]: WebSocketResult;
|
|
153
|
+
};
|
|
154
|
+
type MutationItem<Q extends QueriesArray> = Extract<QueryConfigArray<Q>[number], {
|
|
155
|
+
type: 'mutation';
|
|
156
|
+
mutationConfig: any;
|
|
157
|
+
}>;
|
|
158
|
+
type QueryItem<Q extends QueriesArray> = Extract<QueryConfigArray<Q>[number], {
|
|
159
|
+
type: 'query';
|
|
160
|
+
}>;
|
|
161
|
+
interface WebSocketDefinition<TKey extends string = string> {
|
|
162
|
+
key: TKey;
|
|
163
|
+
endpoint?: string;
|
|
164
|
+
onMessage?: (data: any) => void;
|
|
165
|
+
invalidateQueriesOnMessage?: Array<string>;
|
|
166
|
+
autoConnect?: boolean;
|
|
167
|
+
type: 'websocket';
|
|
168
|
+
}
|
|
169
|
+
type WebSocketsArray = Array<WebSocketDefinition<string>>;
|
|
170
|
+
interface WebSocketResult {
|
|
171
|
+
lastMessage: any;
|
|
172
|
+
sendMessage: (message: any) => void;
|
|
173
|
+
status: 'connecting' | 'open' | 'closed';
|
|
174
|
+
}
|
|
175
|
+
interface MutationStateInternal<TData = unknown> {
|
|
176
|
+
status: 'idle' | 'pending' | 'success' | 'error';
|
|
177
|
+
data: TData | undefined;
|
|
178
|
+
error: Error | null;
|
|
179
|
+
submittedAt: number | null;
|
|
180
|
+
variables: unknown | undefined;
|
|
181
|
+
}
|
|
182
|
+
type MutationActionInternal = {
|
|
183
|
+
type: 'RESET';
|
|
184
|
+
key: string;
|
|
185
|
+
} | {
|
|
186
|
+
type: 'PENDING';
|
|
187
|
+
key: string;
|
|
188
|
+
submittedAt: number;
|
|
189
|
+
variables: unknown;
|
|
190
|
+
} | {
|
|
191
|
+
type: 'SUCCESS';
|
|
192
|
+
key: string;
|
|
193
|
+
data: unknown;
|
|
194
|
+
} | {
|
|
195
|
+
type: 'ERROR';
|
|
196
|
+
key: string;
|
|
197
|
+
error: Error;
|
|
198
|
+
};
|
|
199
|
+
type StringKey<T> = Extract<keyof T, string>;
|
|
200
|
+
type QueryTopKey<Q extends QueriesArray> = StringKey<MultipleQueryResponse<Q>>;
|
|
201
|
+
type QuerySubKey<Q extends QueriesArray, K extends QueryTopKey<Q>> = StringKey<MultipleQueryResponse<Q>[K]>;
|
|
202
|
+
type QueryCompositeKey<Q extends QueriesArray> = {
|
|
203
|
+
[K in QueryTopKey<Q>]: K | `${K}.${QuerySubKey<Q, K>}`;
|
|
204
|
+
}[QueryTopKey<Q>];
|
|
205
|
+
type QueryValue<Q extends QueriesArray, K extends QueryCompositeKey<Q>> = K extends `${infer Top}.${infer Sub}` ? Top extends QueryTopKey<Q> ? Sub extends QuerySubKey<Q, Top> ? MultipleQueryResponse<Q>[Top][Sub] : never : never : K extends QueryTopKey<Q> ? MultipleQueryResponse<Q>[K] : never;
|
|
206
|
+
type MutationTopKey<Q extends QueriesArray> = StringKey<AllMutation<Q>>;
|
|
207
|
+
type MutationSubKey<Q extends QueriesArray, K extends MutationTopKey<Q>> = StringKey<AllMutation<Q>[K]>;
|
|
208
|
+
type MutationCompositeKey<Q extends QueriesArray> = {
|
|
209
|
+
[K in MutationTopKey<Q>]: K | `${K}.${MutationSubKey<Q, K>}`;
|
|
210
|
+
}[MutationTopKey<Q>];
|
|
211
|
+
type MutationValue<Q extends QueriesArray, K extends MutationCompositeKey<Q>> = K extends `${infer Top}.${infer Sub}` ? Top extends MutationTopKey<Q> ? Sub extends MutationSubKey<Q, Top> ? AllMutation<Q>[Top][Sub] : never : never : K extends MutationTopKey<Q> ? AllMutation<Q>[K] : never;
|
|
212
|
+
type GetApiValuesFunction<Q extends QueriesArray> = {
|
|
213
|
+
<K extends QueryTopKey<Q>>(type: 'query', key: K): MultipleQueryResponse<Q>[K];
|
|
214
|
+
<K extends QueryCompositeKey<Q>>(type: 'query', key: K): QueryValue<Q, K>;
|
|
215
|
+
<K extends QueryCompositeKey<Q>>(type: 'query', key: K, defaultValue: unknown): NonNullable<QueryValue<Q, K>>;
|
|
216
|
+
<K extends MutationCompositeKey<Q>>(type: 'mutation', key: K, defaultValue: unknown): NonNullable<MutationValue<Q, K>>;
|
|
217
|
+
<K extends QueryTopKey<Q>>(type: 'query', key: K, defaultValue: MultipleQueryResponse<Q>[K]['data']): MultipleQueryResponse<Q>[K]['data'];
|
|
218
|
+
<K extends QueryCompositeKey<Q>>(type: 'query', key: K, defaultValue: QueryValue<Q, K>): NonNullable<QueryValue<Q, K>>;
|
|
219
|
+
<K extends MutationTopKey<Q>>(type: 'mutation', key: K): AllMutation<Q>[K];
|
|
220
|
+
<K extends MutationCompositeKey<Q>>(type: 'mutation', key: K): MutationValue<Q, K>;
|
|
221
|
+
<K extends MutationTopKey<Q>>(type: 'mutation', key: K, defaultValue: AllMutation<Q>[K]['data']): AllMutation<Q>[K]['data'];
|
|
222
|
+
<K extends MutationCompositeKey<Q>>(type: 'mutation', key: K, defaultValue: MutationValue<Q, K>): NonNullable<MutationValue<Q, K>>;
|
|
223
|
+
(type: 'query' | 'mutation', key: string, defaultValue?: unknown): unknown;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
type QueryStoreEntry<Q extends QueriesArray = QueriesArray> = QueryResult<Q[number]['response']>;
|
|
227
|
+
type MutationStoreEntry<Q extends QueriesArray = QueriesArray> = UseMutationResult<Q[number]['response'], Error, Q[number]['props'], unknown>;
|
|
228
|
+
declare const DEFAULT_QUERY_ENTRY: QueryStoreEntry;
|
|
229
|
+
declare const DEFAULT_MUTATION_ENTRY: MutationStoreEntry;
|
|
230
|
+
/**
|
|
231
|
+
* Global atom storing all query results.
|
|
232
|
+
* Key format: "scopeId:queryKey"
|
|
233
|
+
*/
|
|
234
|
+
declare const queriesAtom: jotai.WritableAtom<Record<string, QueryStoreEntry<QueriesArray>>, [Record<string, QueryStoreEntry<QueriesArray>> | typeof jotai_utils.RESET | ((prev: Record<string, QueryStoreEntry<QueriesArray>>) => Record<string, QueryStoreEntry<QueriesArray>> | typeof jotai_utils.RESET)], void>;
|
|
235
|
+
/**
|
|
236
|
+
* Global atom storing all mutation results.
|
|
237
|
+
* Key format: "scopeId:mutationKey"
|
|
238
|
+
*/
|
|
239
|
+
declare const mutationsAtom: jotai.PrimitiveAtom<Record<string, MutationStoreEntry<QueriesArray>>> & {
|
|
240
|
+
init: Record<string, MutationStoreEntry<QueriesArray>>;
|
|
241
|
+
};
|
|
242
|
+
declare const getCompositeKey: (scopeId: string, key: string) => string;
|
|
243
|
+
/**
|
|
244
|
+
* Creates a derived atom for accessing queries of a specific scope.
|
|
245
|
+
*/
|
|
246
|
+
declare const createScopeQueriesAtom: (scopeId: string) => jotai.WritableAtom<Record<string, QueryStoreEntry<QueriesArray>>, [update: Record<string, QueryStoreEntry<QueriesArray>>], void>;
|
|
247
|
+
/**
|
|
248
|
+
* Creates a derived atom for accessing mutations of a specific scope.
|
|
249
|
+
*/
|
|
250
|
+
declare const createScopeMutationsAtom: (scopeId: string) => jotai.WritableAtom<Record<string, MutationStoreEntry<QueriesArray>>, [update: Record<string, MutationStoreEntry<QueriesArray>>], void>;
|
|
251
|
+
declare const createQuerySelector: <Q extends QueriesArray>(scopeId: string, queryKey: string) => jotai.Atom<QueryStoreEntry<Q>>;
|
|
252
|
+
declare const createMutationSelector: <Q extends QueriesArray>(scopeId: string, mutationKey: string) => jotai.Atom<MutationStoreEntry<Q>>;
|
|
253
|
+
|
|
254
|
+
interface EncryptionConfig {
|
|
255
|
+
secretKey: string;
|
|
256
|
+
enabled?: boolean;
|
|
257
|
+
encryptFn?: (data: unknown, key: string) => Promise<string>;
|
|
258
|
+
decryptFn?: (data: string, key: string) => Promise<unknown>;
|
|
259
|
+
}
|
|
260
|
+
type ApiConverter<TProps, TConverter> = (props: TProps) => TConverter;
|
|
261
|
+
interface ApiRequestFnProps<TProps, TConverter = TProps> {
|
|
262
|
+
url: string;
|
|
263
|
+
method: ApiMethod;
|
|
264
|
+
body?: TProps;
|
|
265
|
+
headers?: AxiosRequestConfig['headers'];
|
|
266
|
+
converter?: ApiConverter<TProps, TConverter>;
|
|
267
|
+
}
|
|
268
|
+
interface ApiNotificationMessage {
|
|
269
|
+
message: string;
|
|
270
|
+
type: 'success' | 'error' | 'info' | 'warning';
|
|
271
|
+
autoHideDuration?: number;
|
|
272
|
+
textTransOption?: Record<string, unknown>;
|
|
273
|
+
ns?: string;
|
|
274
|
+
}
|
|
275
|
+
interface ApiConfig {
|
|
276
|
+
endpoints: Endpoint;
|
|
277
|
+
requestFn: <TProps, TResponse, TConverter = TProps>(props: ApiRequestFnProps<TProps, TConverter>) => Promise<TResponse>;
|
|
278
|
+
validateAuthFn?: () => boolean;
|
|
279
|
+
defaultHeaders?: Record<string, string>;
|
|
280
|
+
persistOptions?: Omit<PersistQueryClientOptions, 'queryClient'>;
|
|
281
|
+
queryClient: QueryClient;
|
|
282
|
+
websocketConfig?: {
|
|
283
|
+
url: string;
|
|
284
|
+
onMessage?: (message: unknown) => void;
|
|
285
|
+
autoConnect?: boolean;
|
|
286
|
+
};
|
|
287
|
+
encryption?: EncryptionConfig;
|
|
288
|
+
showNotification?: (notification: ApiNotificationMessage) => void;
|
|
289
|
+
}
|
|
290
|
+
declare const apiConfigAtom: _gaddario98_react_state.PrimitiveAtom<ApiConfig>;
|
|
291
|
+
declare const useApiConfigValue: () => ApiConfig;
|
|
292
|
+
declare const useApiConfigState: () => [ApiConfig, (value: ApiConfig) => void];
|
|
293
|
+
declare const useApiConfigReset: () => () => void;
|
|
294
|
+
|
|
295
|
+
declare const useQueryApi: <TResponse>(options: CustomQueryOptions<TResponse>, id?: string) => QueryResult<TResponse>;
|
|
296
|
+
|
|
297
|
+
declare const useMutateApi: <TProps, TResponse>(options: CustomMutationOptions<TProps, TResponse>, id?: string) => _tanstack_react_query.UseMutationResult<TResponse, Error, TProps, unknown>;
|
|
298
|
+
|
|
299
|
+
declare const useMultipleQuery: <Q extends QueriesArray>(settings?: Array<QueryProps<Q[number]["key"], Q[number]["response"]>>) => MultipleQueryResponse<Q>;
|
|
300
|
+
|
|
301
|
+
declare const useMultipleMutation: <Q extends QueriesArray>(configs: Array<MutationItem<Q>>) => AllMutation<Q>;
|
|
302
|
+
|
|
303
|
+
declare const useMultipleWebSocket: <K extends string>(configs?: Array<WebSocketDefinition<K>>) => MultipleWebSocketResponse<K>;
|
|
304
|
+
|
|
305
|
+
interface UseApiOptions {
|
|
306
|
+
/**
|
|
307
|
+
* Unique identifier for this scope. Used as the key prefix for Jotai atoms.
|
|
308
|
+
* @default 'default'
|
|
309
|
+
*/
|
|
310
|
+
scopeId?: string;
|
|
311
|
+
/**
|
|
312
|
+
* Whether to persist query/mutation results to Jotai atoms.
|
|
313
|
+
* @default true
|
|
314
|
+
*/
|
|
315
|
+
persistToAtoms?: boolean;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Main hook that integrates TanStack Query with Jotai for state persistence.
|
|
319
|
+
*/
|
|
320
|
+
declare function useApi<Q extends QueriesArray>(configs: QueryConfigArray<Q>, options?: UseApiOptions): ContextValue<Q>;
|
|
321
|
+
/**
|
|
322
|
+
* @deprecated Use options object instead: useApi(configs, { scopeId: 'my-scope' })
|
|
323
|
+
*/
|
|
324
|
+
declare function useApi<Q extends QueriesArray>(configs: QueryConfigArray<Q>, id?: string): ContextValue<Q>;
|
|
325
|
+
|
|
326
|
+
declare const useWebSocket: (endpoint?: string, // specific socket endpoint if different from default
|
|
327
|
+
options?: {
|
|
328
|
+
onMessage?: (data: unknown) => void;
|
|
329
|
+
invalidateQueriesOnMessage?: Array<string>;
|
|
330
|
+
}) => WebSocketResult;
|
|
331
|
+
|
|
332
|
+
declare const useInvalidateQueries: () => {
|
|
333
|
+
invalidateQueries: (queryKeys: Array<Array<string>>) => Promise<void>;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Hook to read all queries for a scope.
|
|
338
|
+
*/
|
|
339
|
+
declare function useJotaiQueries<Q extends QueriesArray>(options: {
|
|
340
|
+
scopeId: string;
|
|
341
|
+
}): Record<string, QueryStoreEntry<Q>>;
|
|
342
|
+
/**
|
|
343
|
+
* Hook to read all mutations for a scope.
|
|
344
|
+
*/
|
|
345
|
+
declare function useJotaiMutations<Q extends QueriesArray>(options: {
|
|
346
|
+
scopeId: string;
|
|
347
|
+
}): Record<string, MutationStoreEntry<Q>>;
|
|
348
|
+
|
|
349
|
+
interface UseApiValuesProps {
|
|
350
|
+
scopeId: string;
|
|
351
|
+
}
|
|
352
|
+
declare const useApiValues: <Q extends QueriesArray>({ scopeId, }: UseApiValuesProps) => {
|
|
353
|
+
get: GetApiValuesFunction<Q>;
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
declare const QueriesProvider: React.FC<PropsWithChildren>;
|
|
357
|
+
|
|
358
|
+
declare const algorithm: {
|
|
359
|
+
name: string;
|
|
360
|
+
length: number;
|
|
361
|
+
};
|
|
362
|
+
declare const str2ab: (str: string) => ArrayBuffer;
|
|
363
|
+
declare const ab2str: (buf: ArrayBuffer) => string;
|
|
364
|
+
declare const importKey: (secretKey: string) => Promise<CryptoKey>;
|
|
365
|
+
declare const encryptData: (data: any, secretKey: string) => Promise<string>;
|
|
366
|
+
declare const decryptData: (encryptedData: string, secretKey: string) => Promise<any>;
|
|
367
|
+
|
|
368
|
+
declare const apiRequest: <TProps, TResponse, TConverter = TProps>({ method, url, body, headers, converter, }: ApiRequestFnProps<TProps, TConverter>) => Promise<TResponse>;
|
|
369
|
+
declare const fetchRequest: <TProps, TResponse>(url: string, headers?: AxiosRequestConfig["headers"]) => Promise<TResponse>;
|
|
370
|
+
|
|
371
|
+
export { DEFAULT_MUTATION_ENTRY, DEFAULT_QUERY_ENTRY, QueriesProvider, ab2str, algorithm, apiConfigAtom, apiRequest, createMutationSelector, createQuerySelector, createScopeMutationsAtom, createScopeQueriesAtom, decryptData, encryptData, fetchRequest, getCompositeKey, importKey, mutationsAtom, queriesAtom, str2ab, useApi, useApiConfigReset, useApiConfigState, useApiConfigValue, useApiValues, useInvalidateQueries, useJotaiMutations, useJotaiQueries, useMultipleMutation, useMultipleQuery, useMultipleWebSocket, useMutateApi, useQueryApi, useWebSocket };
|
|
372
|
+
export type { AllMutation, ApiConfig, ApiConverter, ApiMethod, ApiNotificationMessage, ApiRequestFnProps, ContextValue, CustomMutation, CustomMutationOptions, CustomQueryOptions, EncryptionConfig, Endpoint, ExtractMutation, ExtractMutationByKey, ExtractQuery, ExtractQueryByKey, ExtractQueryResponse, ExtractWebSocket, GetApiValuesFunction, MultipleQueryResponse, MultipleWebSocketResponse, MutationActionInternal, MutationConfig, MutationItem, MutationStateInternal, MutationStoreEntry, QueriesArray, QueriesProps, QueryAtIndex, QueryConfig, QueryConfigArray, QueryDefinition, QueryItem, QueryProps, QueryResult, QueryStoreEntry, SingleQueryConfig, UseApiOptions, WebSocketDefinition, WebSocketResult, WebSocketsArray };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PrimitiveAtom } from 'jotai';
|
|
2
|
+
export { PrimitiveAtom } from 'jotai';
|
|
3
|
+
|
|
4
|
+
type SyncStorage = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
|
|
5
|
+
declare let storage: SyncStorage;
|
|
6
|
+
declare const setCustomStorage: (newStorage: SyncStorage) => void;
|
|
7
|
+
|
|
8
|
+
type AtomGeneratorOptions<T> = {
|
|
9
|
+
key: string;
|
|
10
|
+
defaultValue: T;
|
|
11
|
+
persist?: boolean;
|
|
12
|
+
storage?: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
|
|
13
|
+
};
|
|
14
|
+
type AtomState<T> = {
|
|
15
|
+
atom: PrimitiveAtom<T>;
|
|
16
|
+
useValue: () => T;
|
|
17
|
+
useState: () => [T, (value: T) => void];
|
|
18
|
+
useReset: () => () => void;
|
|
19
|
+
};
|
|
20
|
+
declare function atomStateGenerator<T>(options: AtomGeneratorOptions<T> & {
|
|
21
|
+
persist: true;
|
|
22
|
+
}): AtomState<T>;
|
|
23
|
+
declare function atomStateGenerator<T>(options: AtomGeneratorOptions<T> & {
|
|
24
|
+
persist?: false;
|
|
25
|
+
}): AtomState<T>;
|
|
26
|
+
|
|
27
|
+
export { atomStateGenerator, setCustomStorage, storage };
|
|
28
|
+
export type { AtomGeneratorOptions, AtomState, SyncStorage };
|