@braine/quantum-query 1.1.0 → 1.2.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/dist/index.d.cts CHANGED
@@ -1,10 +1,25 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
1
4
  declare function subscribe(store: object, callback: (target: any, prop: any, value: any) => void): () => boolean;
2
5
  declare function createState<T extends object>(initialState: T): T;
3
6
 
7
+ interface StorageAdapter {
8
+ getItem(key: string): string | null | Promise<string | null>;
9
+ setItem(key: string, value: string): void | Promise<void>;
10
+ removeItem(key: string): void | Promise<void>;
11
+ }
12
+ type PersistOptions<S> = {
13
+ key: string;
14
+ storage?: 'local' | 'session' | StorageAdapter;
15
+ paths?: (keyof S)[];
16
+ debug?: boolean;
17
+ };
4
18
  type ModelDefinition<S, A, C> = {
5
19
  state: S;
6
20
  actions?: A & ThisType<S & A & C>;
7
21
  computed?: C & ThisType<S & A & C>;
22
+ persist?: PersistOptions<S>;
8
23
  };
9
24
  type ComputedValues<T> = {
10
25
  [K in keyof T]: T[K] extends (...args: any[]) => infer R ? R : never;
@@ -27,6 +42,11 @@ type RetryConfig = {
27
42
  maxDelay: number;
28
43
  shouldRetry?: (error: unknown, attempt: number) => boolean;
29
44
  };
45
+ type CacheConfig = {
46
+ ttl: number;
47
+ force?: boolean;
48
+ };
49
+ type HttpClient$1 = any;
30
50
  type HttpClientConfig = {
31
51
  baseURL?: string;
32
52
  headers?: Record<string, string>;
@@ -34,7 +54,7 @@ type HttpClientConfig = {
34
54
  retry?: number | RetryConfig;
35
55
  auth?: {
36
56
  getToken: () => string | Promise<string | null>;
37
- onTokenExpired: (client: HttpClient) => Promise<string | null>;
57
+ onTokenExpired: (client: HttpClient$1) => Promise<string | null>;
38
58
  onAuthFailed?: () => void;
39
59
  };
40
60
  interceptors?: {
@@ -47,10 +67,12 @@ type Validator<T> = {
47
67
  validateSync?: (data: unknown) => T;
48
68
  };
49
69
  type RequestConfig<T> = RequestInit & {
50
- schema?: Validator<T>;
51
- timeout?: number;
52
- retry?: number | RetryConfig;
70
+ schema?: Validator<T> | undefined;
71
+ timeout?: number | undefined;
72
+ retry?: number | RetryConfig | undefined;
73
+ cache?: CacheConfig;
53
74
  };
75
+
54
76
  type HttpClient = {
55
77
  get: <T>(url: string, config?: RequestConfig<T>) => Promise<T>;
56
78
  post: <T>(url: string, data?: unknown, config?: RequestConfig<T>) => Promise<T>;
@@ -58,6 +80,7 @@ type HttpClient = {
58
80
  delete: <T>(url: string, config?: RequestConfig<T>) => Promise<T>;
59
81
  patch: <T>(url: string, data?: unknown, config?: RequestConfig<T>) => Promise<T>;
60
82
  request: <T>(url: string, config?: RequestConfig<T>) => Promise<T>;
83
+ config: HttpClientConfig;
61
84
  };
62
85
  declare function createHttpClient(config: HttpClientConfig): HttpClient;
63
86
 
@@ -70,4 +93,274 @@ declare function getPromiseState(promise: Promise<any>): {
70
93
  error: any;
71
94
  };
72
95
 
73
- export { computed, createHttpClient, createState, defineModel, enableDevTools, getPromiseState, handlePromise, isPromise, scheduleUpdate, subscribe, unwrapPromise, useStore };
96
+ /**
97
+ * Generic Schema Interface
98
+ * Compatible with Zod, Valibot, ArkType, etc.
99
+ */
100
+ interface Schema<T> {
101
+ parse: (data: unknown) => T;
102
+ }
103
+ interface QueryClientConfig {
104
+ defaultStaleTime?: number;
105
+ defaultCacheTime?: number;
106
+ }
107
+ /**
108
+ * Middleware Plugin Interface
109
+ */
110
+ interface QueryPlugin {
111
+ name: string;
112
+ onFetchStart?: (queryKey: any[]) => void;
113
+ onFetchSuccess?: (queryKey: any[], data: any) => void;
114
+ onFetchError?: (queryKey: any[], error: Error) => void;
115
+ onInvalidate?: (queryKey: any[]) => void;
116
+ onQueryUpdated?: (queryKey: any[], data: any) => void;
117
+ }
118
+
119
+ /**
120
+ * Micro-Signals with Batching (Zero Dependency Reactivity)
121
+ *
122
+ * A minimal implementation of the Signals pattern with micro-batching for O(1) state updates.
123
+ * Uses queueMicrotask to coalesce multiple updates into a single notification cycle.
124
+ */
125
+ interface Signal<T> {
126
+ get: () => T;
127
+ set: (value: T) => void;
128
+ subscribe: (fn: (value: T) => void) => () => void;
129
+ }
130
+
131
+ interface CacheEntry<T = any> {
132
+ data: T;
133
+ timestamp: number;
134
+ staleTime: number;
135
+ cacheTime: number;
136
+ key: any[];
137
+ }
138
+ interface QueryKey {
139
+ key: any[];
140
+ params?: Record<string, any>;
141
+ }
142
+ type QueryKeyInput = any[] | QueryKey;
143
+ declare class QueryCache {
144
+ private signals;
145
+ private gcInterval;
146
+ private readonly defaultStaleTime;
147
+ private readonly defaultCacheTime;
148
+ constructor(config?: {
149
+ enableGC?: boolean;
150
+ });
151
+ /**
152
+ * Generate cache key from query key array
153
+ */
154
+ private generateKey;
155
+ /**
156
+ * Get data (wrapper around signal.get)
157
+ */
158
+ get<T>(queryKey: QueryKeyInput): T | undefined;
159
+ /**
160
+ * Get Signal for a key (Low level API for hooks)
161
+ * Automatically creates a signal if one doesn't exist
162
+ */
163
+ getSignal<T>(queryKey: QueryKeyInput): Signal<CacheEntry<T> | undefined>;
164
+ /**
165
+ * Check if data is stale
166
+ */
167
+ isStale(queryKey: QueryKeyInput): boolean;
168
+ /**
169
+ * Set cached data (updates signal)
170
+ */
171
+ set<T>(queryKey: QueryKeyInput, data: T, options?: {
172
+ staleTime?: number;
173
+ cacheTime?: number;
174
+ }): void;
175
+ private deduplicationCache;
176
+ private plugins;
177
+ /**
178
+ * Register a middleware plugin
179
+ */
180
+ use(plugin: QueryPlugin): this;
181
+ /**
182
+ * Fetch data with deduplication.
183
+ * If a request for the same key is already in flight, returns the existing promise.
184
+ */
185
+ fetch<T>(queryKey: QueryKeyInput, fn: () => Promise<T>): Promise<T>;
186
+ /**
187
+ * Invalidate queries matching the key prefix
188
+ * Marks them as undefined to trigger refetches without breaking subscriptions
189
+ */
190
+ invalidate(queryKey: QueryKeyInput): void;
191
+ /**
192
+ * Remove all cache entries
193
+ */
194
+ clear(): void;
195
+ /**
196
+ * Prefetch data (same as set but explicit intent)
197
+ */
198
+ prefetch<T>(queryKey: QueryKeyInput, data: T, options?: {
199
+ staleTime?: number;
200
+ cacheTime?: number;
201
+ }): void;
202
+ /**
203
+ * Garbage collection - remove expired entries
204
+ */
205
+ private startGarbageCollection;
206
+ /**
207
+ * Stop garbage collection
208
+ */
209
+ destroy(): void;
210
+ /**
211
+ * Get cache stats (for debugging)
212
+ */
213
+ getStats(): {
214
+ size: number;
215
+ keys: string[];
216
+ };
217
+ /**
218
+ * Get all entries (wrapper for DevTools)
219
+ */
220
+ getAll(): Map<string, CacheEntry>;
221
+ }
222
+ declare const queryCache: QueryCache;
223
+
224
+ /**
225
+ * Pagination Hook
226
+ * Provides offset-based and cursor-based pagination
227
+ */
228
+ interface UsePaginatedQueryOptions<T> {
229
+ queryKey: string[];
230
+ queryFn: (page: number) => Promise<T>;
231
+ pageSize?: number;
232
+ staleTime?: number;
233
+ cacheTime?: number;
234
+ enabled?: boolean;
235
+ }
236
+ interface PaginatedQueryResult<T> {
237
+ data: T | undefined;
238
+ isLoading: boolean;
239
+ isError: boolean;
240
+ error: Error | null;
241
+ page: number;
242
+ setPage: (page: number) => void;
243
+ nextPage: () => void;
244
+ previousPage: () => void;
245
+ hasNext: boolean;
246
+ hasPrevious: boolean;
247
+ refetch: () => Promise<void>;
248
+ }
249
+ declare function usePaginatedQuery<T>({ queryKey, queryFn, pageSize, staleTime, cacheTime, enabled }: UsePaginatedQueryOptions<T>): PaginatedQueryResult<T>;
250
+
251
+ /**
252
+ * useQuery Hook
253
+ * Base query hook with stale-while-revalidate and background refetching
254
+ */
255
+
256
+ interface UseQueryOptions<T> {
257
+ queryKey: any[];
258
+ queryFn: () => Promise<unknown>;
259
+ schema?: Schema<T>;
260
+ staleTime?: number;
261
+ cacheTime?: number;
262
+ enabled?: boolean;
263
+ refetchOnWindowFocus?: boolean;
264
+ refetchOnReconnect?: boolean;
265
+ refetchInterval?: number;
266
+ }
267
+ interface QueryResult<T> {
268
+ data: T | undefined;
269
+ isLoading: boolean;
270
+ isError: boolean;
271
+ isFetching: boolean;
272
+ isStale: boolean;
273
+ error: Error | null;
274
+ refetch: () => Promise<void>;
275
+ }
276
+ declare function useQuery<T>({ queryKey, queryFn, schema, staleTime, cacheTime, enabled, refetchOnWindowFocus, refetchOnReconnect, refetchInterval }: UseQueryOptions<T>): QueryResult<T>;
277
+
278
+ /**
279
+ * useMutation Hook
280
+ * Handles mutations with optimistic updates and rollback
281
+ */
282
+ interface UseMutationOptions<TData, TVariables, TContext = any> {
283
+ mutationFn: (variables: TVariables) => Promise<TData>;
284
+ onMutate?: (variables: TVariables) => Promise<TContext> | TContext;
285
+ onSuccess?: (data: TData, variables: TVariables, context: TContext | undefined) => void;
286
+ onError?: (error: Error, variables: TVariables, context: TContext | undefined) => void;
287
+ onSettled?: (data: TData | undefined, error: Error | null, variables: TVariables, context: TContext | undefined) => void;
288
+ }
289
+ interface MutationResult<TData, TVariables> {
290
+ mutate: (variables: TVariables) => Promise<void>;
291
+ mutateAsync: (variables: TVariables) => Promise<TData>;
292
+ data: TData | undefined;
293
+ error: Error | null;
294
+ isLoading: boolean;
295
+ isError: boolean;
296
+ isSuccess: boolean;
297
+ reset: () => void;
298
+ }
299
+ declare function useMutation<TData = unknown, TVariables = void, TContext = any>({ mutationFn, onMutate, onSuccess, onError, onSettled }: UseMutationOptions<TData, TVariables, TContext>): MutationResult<TData, TVariables>;
300
+ declare const optimisticHelpers: {
301
+ /**
302
+ * Cancel ongoing queries for a key
303
+ */
304
+ cancelQueries(queryKey: any[]): Promise<void>;
305
+ /**
306
+ * Get current query data
307
+ */
308
+ getQueryData<T>(queryKey: any[]): T | undefined;
309
+ /**
310
+ * Set query data (for optimistic updates)
311
+ */
312
+ setQueryData<T>(queryKey: any[], updater: T | ((old: T | undefined) => T)): T | undefined;
313
+ /**
314
+ * Invalidate queries (trigger refetch)
315
+ */
316
+ invalidateQueries(queryKey: any[]): void;
317
+ };
318
+
319
+ type QueryClient = QueryCache;
320
+ declare const QueryClientProvider: ({ client, children }: {
321
+ client: QueryClient;
322
+ children: ReactNode;
323
+ }) => react_jsx_runtime.JSX.Element;
324
+ declare const useQueryClient: () => QueryClient;
325
+
326
+ /**
327
+ * Infinite Query Hook (Reactive)
328
+ * Provides infinite scroll with Signal-based reactivity
329
+ */
330
+ interface UseInfiniteQueryOptions<T, TPageParam = any> {
331
+ queryKey: any[];
332
+ queryFn: (context: {
333
+ pageParam: TPageParam;
334
+ }) => Promise<T>;
335
+ getNextPageParam?: (lastPage: T, allPages: T[]) => TPageParam | undefined;
336
+ getPreviousPageParam?: (firstPage: T, allPages: T[]) => TPageParam | undefined;
337
+ initialPageParam?: TPageParam;
338
+ staleTime?: number;
339
+ cacheTime?: number;
340
+ enabled?: boolean;
341
+ }
342
+ interface InfiniteData<T> {
343
+ pages: T[];
344
+ pageParams: any[];
345
+ }
346
+ interface InfiniteQueryResult<T> {
347
+ data: InfiniteData<T> | undefined;
348
+ fetchNextPage: () => Promise<void>;
349
+ fetchPreviousPage: () => Promise<void>;
350
+ hasNextPage: boolean;
351
+ hasPreviousPage: boolean;
352
+ isFetching: boolean;
353
+ isFetchingNextPage: boolean;
354
+ isFetchingPreviousPage: boolean;
355
+ isLoading: boolean;
356
+ isError: boolean;
357
+ error: Error | null;
358
+ refetch: () => Promise<void>;
359
+ }
360
+ declare function useInfiniteQuery<T, TPageParam = any>({ queryKey, queryFn, getNextPageParam, getPreviousPageParam, initialPageParam, staleTime, cacheTime, enabled }: UseInfiniteQueryOptions<T, TPageParam>): InfiniteQueryResult<T>;
361
+
362
+ declare function QuantumDevTools(): react_jsx_runtime.JSX.Element;
363
+
364
+ declare function useQueryCache(): Map<string, CacheEntry<any>>;
365
+
366
+ export { type CacheEntry, type HttpClient, type InfiniteData, type InfiniteQueryResult, type MutationResult, type PaginatedQueryResult, QuantumDevTools, QueryCache, type QueryClient, type QueryClientConfig, QueryClientProvider, type QueryKey, type QueryKeyInput, type QueryResult, type Schema, type UseInfiniteQueryOptions, type UseMutationOptions, type UsePaginatedQueryOptions, type UseQueryOptions, computed, createHttpClient, createState, defineModel, enableDevTools, getPromiseState, handlePromise, isPromise, optimisticHelpers, queryCache, scheduleUpdate, subscribe, unwrapPromise, useInfiniteQuery, useMutation, usePaginatedQuery, useQuery, useQueryCache, useQueryClient, useStore };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,25 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
1
4
  declare function subscribe(store: object, callback: (target: any, prop: any, value: any) => void): () => boolean;
2
5
  declare function createState<T extends object>(initialState: T): T;
3
6
 
7
+ interface StorageAdapter {
8
+ getItem(key: string): string | null | Promise<string | null>;
9
+ setItem(key: string, value: string): void | Promise<void>;
10
+ removeItem(key: string): void | Promise<void>;
11
+ }
12
+ type PersistOptions<S> = {
13
+ key: string;
14
+ storage?: 'local' | 'session' | StorageAdapter;
15
+ paths?: (keyof S)[];
16
+ debug?: boolean;
17
+ };
4
18
  type ModelDefinition<S, A, C> = {
5
19
  state: S;
6
20
  actions?: A & ThisType<S & A & C>;
7
21
  computed?: C & ThisType<S & A & C>;
22
+ persist?: PersistOptions<S>;
8
23
  };
9
24
  type ComputedValues<T> = {
10
25
  [K in keyof T]: T[K] extends (...args: any[]) => infer R ? R : never;
@@ -27,6 +42,11 @@ type RetryConfig = {
27
42
  maxDelay: number;
28
43
  shouldRetry?: (error: unknown, attempt: number) => boolean;
29
44
  };
45
+ type CacheConfig = {
46
+ ttl: number;
47
+ force?: boolean;
48
+ };
49
+ type HttpClient$1 = any;
30
50
  type HttpClientConfig = {
31
51
  baseURL?: string;
32
52
  headers?: Record<string, string>;
@@ -34,7 +54,7 @@ type HttpClientConfig = {
34
54
  retry?: number | RetryConfig;
35
55
  auth?: {
36
56
  getToken: () => string | Promise<string | null>;
37
- onTokenExpired: (client: HttpClient) => Promise<string | null>;
57
+ onTokenExpired: (client: HttpClient$1) => Promise<string | null>;
38
58
  onAuthFailed?: () => void;
39
59
  };
40
60
  interceptors?: {
@@ -47,10 +67,12 @@ type Validator<T> = {
47
67
  validateSync?: (data: unknown) => T;
48
68
  };
49
69
  type RequestConfig<T> = RequestInit & {
50
- schema?: Validator<T>;
51
- timeout?: number;
52
- retry?: number | RetryConfig;
70
+ schema?: Validator<T> | undefined;
71
+ timeout?: number | undefined;
72
+ retry?: number | RetryConfig | undefined;
73
+ cache?: CacheConfig;
53
74
  };
75
+
54
76
  type HttpClient = {
55
77
  get: <T>(url: string, config?: RequestConfig<T>) => Promise<T>;
56
78
  post: <T>(url: string, data?: unknown, config?: RequestConfig<T>) => Promise<T>;
@@ -58,6 +80,7 @@ type HttpClient = {
58
80
  delete: <T>(url: string, config?: RequestConfig<T>) => Promise<T>;
59
81
  patch: <T>(url: string, data?: unknown, config?: RequestConfig<T>) => Promise<T>;
60
82
  request: <T>(url: string, config?: RequestConfig<T>) => Promise<T>;
83
+ config: HttpClientConfig;
61
84
  };
62
85
  declare function createHttpClient(config: HttpClientConfig): HttpClient;
63
86
 
@@ -70,4 +93,274 @@ declare function getPromiseState(promise: Promise<any>): {
70
93
  error: any;
71
94
  };
72
95
 
73
- export { computed, createHttpClient, createState, defineModel, enableDevTools, getPromiseState, handlePromise, isPromise, scheduleUpdate, subscribe, unwrapPromise, useStore };
96
+ /**
97
+ * Generic Schema Interface
98
+ * Compatible with Zod, Valibot, ArkType, etc.
99
+ */
100
+ interface Schema<T> {
101
+ parse: (data: unknown) => T;
102
+ }
103
+ interface QueryClientConfig {
104
+ defaultStaleTime?: number;
105
+ defaultCacheTime?: number;
106
+ }
107
+ /**
108
+ * Middleware Plugin Interface
109
+ */
110
+ interface QueryPlugin {
111
+ name: string;
112
+ onFetchStart?: (queryKey: any[]) => void;
113
+ onFetchSuccess?: (queryKey: any[], data: any) => void;
114
+ onFetchError?: (queryKey: any[], error: Error) => void;
115
+ onInvalidate?: (queryKey: any[]) => void;
116
+ onQueryUpdated?: (queryKey: any[], data: any) => void;
117
+ }
118
+
119
+ /**
120
+ * Micro-Signals with Batching (Zero Dependency Reactivity)
121
+ *
122
+ * A minimal implementation of the Signals pattern with micro-batching for O(1) state updates.
123
+ * Uses queueMicrotask to coalesce multiple updates into a single notification cycle.
124
+ */
125
+ interface Signal<T> {
126
+ get: () => T;
127
+ set: (value: T) => void;
128
+ subscribe: (fn: (value: T) => void) => () => void;
129
+ }
130
+
131
+ interface CacheEntry<T = any> {
132
+ data: T;
133
+ timestamp: number;
134
+ staleTime: number;
135
+ cacheTime: number;
136
+ key: any[];
137
+ }
138
+ interface QueryKey {
139
+ key: any[];
140
+ params?: Record<string, any>;
141
+ }
142
+ type QueryKeyInput = any[] | QueryKey;
143
+ declare class QueryCache {
144
+ private signals;
145
+ private gcInterval;
146
+ private readonly defaultStaleTime;
147
+ private readonly defaultCacheTime;
148
+ constructor(config?: {
149
+ enableGC?: boolean;
150
+ });
151
+ /**
152
+ * Generate cache key from query key array
153
+ */
154
+ private generateKey;
155
+ /**
156
+ * Get data (wrapper around signal.get)
157
+ */
158
+ get<T>(queryKey: QueryKeyInput): T | undefined;
159
+ /**
160
+ * Get Signal for a key (Low level API for hooks)
161
+ * Automatically creates a signal if one doesn't exist
162
+ */
163
+ getSignal<T>(queryKey: QueryKeyInput): Signal<CacheEntry<T> | undefined>;
164
+ /**
165
+ * Check if data is stale
166
+ */
167
+ isStale(queryKey: QueryKeyInput): boolean;
168
+ /**
169
+ * Set cached data (updates signal)
170
+ */
171
+ set<T>(queryKey: QueryKeyInput, data: T, options?: {
172
+ staleTime?: number;
173
+ cacheTime?: number;
174
+ }): void;
175
+ private deduplicationCache;
176
+ private plugins;
177
+ /**
178
+ * Register a middleware plugin
179
+ */
180
+ use(plugin: QueryPlugin): this;
181
+ /**
182
+ * Fetch data with deduplication.
183
+ * If a request for the same key is already in flight, returns the existing promise.
184
+ */
185
+ fetch<T>(queryKey: QueryKeyInput, fn: () => Promise<T>): Promise<T>;
186
+ /**
187
+ * Invalidate queries matching the key prefix
188
+ * Marks them as undefined to trigger refetches without breaking subscriptions
189
+ */
190
+ invalidate(queryKey: QueryKeyInput): void;
191
+ /**
192
+ * Remove all cache entries
193
+ */
194
+ clear(): void;
195
+ /**
196
+ * Prefetch data (same as set but explicit intent)
197
+ */
198
+ prefetch<T>(queryKey: QueryKeyInput, data: T, options?: {
199
+ staleTime?: number;
200
+ cacheTime?: number;
201
+ }): void;
202
+ /**
203
+ * Garbage collection - remove expired entries
204
+ */
205
+ private startGarbageCollection;
206
+ /**
207
+ * Stop garbage collection
208
+ */
209
+ destroy(): void;
210
+ /**
211
+ * Get cache stats (for debugging)
212
+ */
213
+ getStats(): {
214
+ size: number;
215
+ keys: string[];
216
+ };
217
+ /**
218
+ * Get all entries (wrapper for DevTools)
219
+ */
220
+ getAll(): Map<string, CacheEntry>;
221
+ }
222
+ declare const queryCache: QueryCache;
223
+
224
+ /**
225
+ * Pagination Hook
226
+ * Provides offset-based and cursor-based pagination
227
+ */
228
+ interface UsePaginatedQueryOptions<T> {
229
+ queryKey: string[];
230
+ queryFn: (page: number) => Promise<T>;
231
+ pageSize?: number;
232
+ staleTime?: number;
233
+ cacheTime?: number;
234
+ enabled?: boolean;
235
+ }
236
+ interface PaginatedQueryResult<T> {
237
+ data: T | undefined;
238
+ isLoading: boolean;
239
+ isError: boolean;
240
+ error: Error | null;
241
+ page: number;
242
+ setPage: (page: number) => void;
243
+ nextPage: () => void;
244
+ previousPage: () => void;
245
+ hasNext: boolean;
246
+ hasPrevious: boolean;
247
+ refetch: () => Promise<void>;
248
+ }
249
+ declare function usePaginatedQuery<T>({ queryKey, queryFn, pageSize, staleTime, cacheTime, enabled }: UsePaginatedQueryOptions<T>): PaginatedQueryResult<T>;
250
+
251
+ /**
252
+ * useQuery Hook
253
+ * Base query hook with stale-while-revalidate and background refetching
254
+ */
255
+
256
+ interface UseQueryOptions<T> {
257
+ queryKey: any[];
258
+ queryFn: () => Promise<unknown>;
259
+ schema?: Schema<T>;
260
+ staleTime?: number;
261
+ cacheTime?: number;
262
+ enabled?: boolean;
263
+ refetchOnWindowFocus?: boolean;
264
+ refetchOnReconnect?: boolean;
265
+ refetchInterval?: number;
266
+ }
267
+ interface QueryResult<T> {
268
+ data: T | undefined;
269
+ isLoading: boolean;
270
+ isError: boolean;
271
+ isFetching: boolean;
272
+ isStale: boolean;
273
+ error: Error | null;
274
+ refetch: () => Promise<void>;
275
+ }
276
+ declare function useQuery<T>({ queryKey, queryFn, schema, staleTime, cacheTime, enabled, refetchOnWindowFocus, refetchOnReconnect, refetchInterval }: UseQueryOptions<T>): QueryResult<T>;
277
+
278
+ /**
279
+ * useMutation Hook
280
+ * Handles mutations with optimistic updates and rollback
281
+ */
282
+ interface UseMutationOptions<TData, TVariables, TContext = any> {
283
+ mutationFn: (variables: TVariables) => Promise<TData>;
284
+ onMutate?: (variables: TVariables) => Promise<TContext> | TContext;
285
+ onSuccess?: (data: TData, variables: TVariables, context: TContext | undefined) => void;
286
+ onError?: (error: Error, variables: TVariables, context: TContext | undefined) => void;
287
+ onSettled?: (data: TData | undefined, error: Error | null, variables: TVariables, context: TContext | undefined) => void;
288
+ }
289
+ interface MutationResult<TData, TVariables> {
290
+ mutate: (variables: TVariables) => Promise<void>;
291
+ mutateAsync: (variables: TVariables) => Promise<TData>;
292
+ data: TData | undefined;
293
+ error: Error | null;
294
+ isLoading: boolean;
295
+ isError: boolean;
296
+ isSuccess: boolean;
297
+ reset: () => void;
298
+ }
299
+ declare function useMutation<TData = unknown, TVariables = void, TContext = any>({ mutationFn, onMutate, onSuccess, onError, onSettled }: UseMutationOptions<TData, TVariables, TContext>): MutationResult<TData, TVariables>;
300
+ declare const optimisticHelpers: {
301
+ /**
302
+ * Cancel ongoing queries for a key
303
+ */
304
+ cancelQueries(queryKey: any[]): Promise<void>;
305
+ /**
306
+ * Get current query data
307
+ */
308
+ getQueryData<T>(queryKey: any[]): T | undefined;
309
+ /**
310
+ * Set query data (for optimistic updates)
311
+ */
312
+ setQueryData<T>(queryKey: any[], updater: T | ((old: T | undefined) => T)): T | undefined;
313
+ /**
314
+ * Invalidate queries (trigger refetch)
315
+ */
316
+ invalidateQueries(queryKey: any[]): void;
317
+ };
318
+
319
+ type QueryClient = QueryCache;
320
+ declare const QueryClientProvider: ({ client, children }: {
321
+ client: QueryClient;
322
+ children: ReactNode;
323
+ }) => react_jsx_runtime.JSX.Element;
324
+ declare const useQueryClient: () => QueryClient;
325
+
326
+ /**
327
+ * Infinite Query Hook (Reactive)
328
+ * Provides infinite scroll with Signal-based reactivity
329
+ */
330
+ interface UseInfiniteQueryOptions<T, TPageParam = any> {
331
+ queryKey: any[];
332
+ queryFn: (context: {
333
+ pageParam: TPageParam;
334
+ }) => Promise<T>;
335
+ getNextPageParam?: (lastPage: T, allPages: T[]) => TPageParam | undefined;
336
+ getPreviousPageParam?: (firstPage: T, allPages: T[]) => TPageParam | undefined;
337
+ initialPageParam?: TPageParam;
338
+ staleTime?: number;
339
+ cacheTime?: number;
340
+ enabled?: boolean;
341
+ }
342
+ interface InfiniteData<T> {
343
+ pages: T[];
344
+ pageParams: any[];
345
+ }
346
+ interface InfiniteQueryResult<T> {
347
+ data: InfiniteData<T> | undefined;
348
+ fetchNextPage: () => Promise<void>;
349
+ fetchPreviousPage: () => Promise<void>;
350
+ hasNextPage: boolean;
351
+ hasPreviousPage: boolean;
352
+ isFetching: boolean;
353
+ isFetchingNextPage: boolean;
354
+ isFetchingPreviousPage: boolean;
355
+ isLoading: boolean;
356
+ isError: boolean;
357
+ error: Error | null;
358
+ refetch: () => Promise<void>;
359
+ }
360
+ declare function useInfiniteQuery<T, TPageParam = any>({ queryKey, queryFn, getNextPageParam, getPreviousPageParam, initialPageParam, staleTime, cacheTime, enabled }: UseInfiniteQueryOptions<T, TPageParam>): InfiniteQueryResult<T>;
361
+
362
+ declare function QuantumDevTools(): react_jsx_runtime.JSX.Element;
363
+
364
+ declare function useQueryCache(): Map<string, CacheEntry<any>>;
365
+
366
+ export { type CacheEntry, type HttpClient, type InfiniteData, type InfiniteQueryResult, type MutationResult, type PaginatedQueryResult, QuantumDevTools, QueryCache, type QueryClient, type QueryClientConfig, QueryClientProvider, type QueryKey, type QueryKeyInput, type QueryResult, type Schema, type UseInfiniteQueryOptions, type UseMutationOptions, type UsePaginatedQueryOptions, type UseQueryOptions, computed, createHttpClient, createState, defineModel, enableDevTools, getPromiseState, handlePromise, isPromise, optimisticHelpers, queryCache, scheduleUpdate, subscribe, unwrapPromise, useInfiniteQuery, useMutation, usePaginatedQuery, useQuery, useQueryCache, useQueryClient, useStore };