@bevelo/query 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +72 -2
- package/dist/broadcast-DfOq-zMG.d.ts +485 -0
- package/dist/broadcast-G0JvCc7n.d.cts +485 -0
- package/dist/index-C7f4d6Gg.d.cts +485 -0
- package/dist/index-C7f4d6Gg.d.ts +485 -0
- package/dist/key-BtYrMAlu.js +282 -0
- package/dist/key-DS_LgCI1.cjs +371 -0
- package/dist/live/broadcast.cjs +68 -0
- package/dist/live/broadcast.d.cts +2 -0
- package/dist/live/broadcast.d.ts +2 -0
- package/dist/live/broadcast.js +67 -0
- package/dist/live/index.cjs +2184 -0
- package/dist/live/index.d.cts +3 -0
- package/dist/live/index.d.ts +3 -0
- package/dist/live/index.js +2127 -0
- package/dist/live/persist.cjs +91 -0
- package/dist/live/persist.d.cts +2 -0
- package/dist/live/persist.d.ts +2 -0
- package/dist/live/persist.js +89 -0
- package/dist/pure/index.cjs +525 -0
- package/dist/pure/index.d.cts +2 -0
- package/dist/pure/index.d.ts +2 -0
- package/dist/pure/index.js +494 -0
- package/package.json +53 -3
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
declare const DATA_TAG: unique symbol;
|
|
2
|
+
declare const ERROR_TAG: unique symbol;
|
|
3
|
+
/** Query key tuple stored by the cache. */
|
|
4
|
+
type QueryKey = readonly unknown[];
|
|
5
|
+
/** Key carrying phantom data and error types for typed cache reads. */
|
|
6
|
+
type TaggedKey<TKey extends QueryKey, TData, TError = Error> = TKey & {
|
|
7
|
+
readonly [DATA_TAG]?: TData;
|
|
8
|
+
readonly [ERROR_TAG]?: TError;
|
|
9
|
+
};
|
|
10
|
+
/** Infers the resolved data type attached to a tagged query key. */
|
|
11
|
+
type DataOfKey<TKey, TFallback = unknown> = TKey extends {
|
|
12
|
+
readonly [DATA_TAG]?: infer TData;
|
|
13
|
+
} ? TData : TFallback;
|
|
14
|
+
/** Infers the error type attached to a tagged query key. */
|
|
15
|
+
type ErrorOfKey<TKey, TFallback = Error> = TKey extends {
|
|
16
|
+
readonly [ERROR_TAG]?: infer TError;
|
|
17
|
+
} ? TError : TFallback;
|
|
18
|
+
/** Marker value passed instead of `queryFn` to pause a query cleanly. */
|
|
19
|
+
declare const skipToken: unique symbol;
|
|
20
|
+
type SkipToken = typeof skipToken;
|
|
21
|
+
/** Placeholder helper that keeps the previous query data while keys change. */
|
|
22
|
+
declare function keepPrevious<TData>(previousData: TData | undefined): TData | undefined;
|
|
23
|
+
type QueryStatus = "pending" | "error" | "success";
|
|
24
|
+
type FetchPhase = "idle" | "fetching" | "paused";
|
|
25
|
+
type NetworkPolicy = "online" | "always" | "offline-first";
|
|
26
|
+
type MutationStatus = "idle" | "pending" | "error" | "success";
|
|
27
|
+
type FetchDirection = "forward" | "backward";
|
|
28
|
+
type QueryMeta = Readonly<Record<string, unknown>>;
|
|
29
|
+
type MutationMeta = Readonly<Record<string, unknown>>;
|
|
30
|
+
interface QueryFnContext<TQueryKey extends QueryKey = QueryKey, TPageParam = never> {
|
|
31
|
+
readonly queryKey: TQueryKey;
|
|
32
|
+
readonly signal: AbortSignal;
|
|
33
|
+
readonly meta: QueryMeta | undefined;
|
|
34
|
+
readonly pageParam: [TPageParam] extends [never] ? undefined : TPageParam;
|
|
35
|
+
readonly direction: FetchDirection | undefined;
|
|
36
|
+
/** Optional progressive commit hook used by streaming query functions. */
|
|
37
|
+
readonly commitChunk?: ((data: unknown) => void) | undefined;
|
|
38
|
+
}
|
|
39
|
+
type QueryFn<TData = unknown, TQueryKey extends QueryKey = QueryKey, TPageParam = never> = (context: QueryFnContext<TQueryKey, TPageParam>) => TData | Promise<TData>;
|
|
40
|
+
type RetryPolicy<TError = Error> = boolean | number | ((failureCount: number, error: TError) => boolean);
|
|
41
|
+
type RetryDelay<TError = Error> = number | ((failureCount: number, error: TError) => number);
|
|
42
|
+
type StaleWindow<TData = unknown, TError = Error> = number | "static" | ((state: QueryEntryState<TData, TError>) => number | "static");
|
|
43
|
+
interface QueryEntryState<TData = unknown, TError = Error> {
|
|
44
|
+
readonly data: TData | undefined;
|
|
45
|
+
readonly dataUpdatedAt: number;
|
|
46
|
+
readonly dataUpdateCount: number;
|
|
47
|
+
readonly error: TError | null;
|
|
48
|
+
readonly errorUpdatedAt: number;
|
|
49
|
+
readonly errorUpdateCount: number;
|
|
50
|
+
readonly fetchFailureCount: number;
|
|
51
|
+
readonly fetchFailureReason: TError | null;
|
|
52
|
+
readonly fetchMeta: QueryMeta | null;
|
|
53
|
+
readonly invalidated: boolean;
|
|
54
|
+
readonly status: QueryStatus;
|
|
55
|
+
readonly fetchPhase: FetchPhase;
|
|
56
|
+
}
|
|
57
|
+
interface PageData<TPage = unknown, TParam = unknown> {
|
|
58
|
+
readonly pages: readonly TPage[];
|
|
59
|
+
readonly pageParams: readonly TParam[];
|
|
60
|
+
}
|
|
61
|
+
interface QueryRefetchOptions {
|
|
62
|
+
readonly cancelRefetch?: boolean | undefined;
|
|
63
|
+
readonly throwOnError?: boolean | undefined;
|
|
64
|
+
}
|
|
65
|
+
interface SnapshotBase<TData, TError> {
|
|
66
|
+
readonly dataUpdatedAt: number;
|
|
67
|
+
readonly errorUpdatedAt: number;
|
|
68
|
+
readonly failureCount: number;
|
|
69
|
+
readonly failureReason: TError | null;
|
|
70
|
+
readonly errorUpdateCount: number;
|
|
71
|
+
readonly fetchPhase: FetchPhase;
|
|
72
|
+
readonly isFetched: boolean;
|
|
73
|
+
readonly isFetchedAfterMount: boolean;
|
|
74
|
+
readonly isFetching: boolean;
|
|
75
|
+
readonly isLoading: boolean;
|
|
76
|
+
readonly isInitialLoading: boolean;
|
|
77
|
+
readonly isPaused: boolean;
|
|
78
|
+
readonly isPlaceholderData: boolean;
|
|
79
|
+
readonly isRefetching: boolean;
|
|
80
|
+
readonly isStale: boolean;
|
|
81
|
+
readonly refetch: (options?: QueryRefetchOptions) => Promise<QuerySnapshot<TData, TError>>;
|
|
82
|
+
readonly promise: Promise<TData>;
|
|
83
|
+
}
|
|
84
|
+
interface PendingQuerySnapshot<TData, TError> extends SnapshotBase<TData, TError> {
|
|
85
|
+
readonly status: "pending";
|
|
86
|
+
readonly data: undefined;
|
|
87
|
+
readonly error: null;
|
|
88
|
+
readonly isPending: true;
|
|
89
|
+
readonly isError: false;
|
|
90
|
+
readonly isLoadingError: false;
|
|
91
|
+
readonly isRefetchError: false;
|
|
92
|
+
readonly isSuccess: false;
|
|
93
|
+
}
|
|
94
|
+
interface LoadingErrorQuerySnapshot<TData, TError> extends SnapshotBase<TData, TError> {
|
|
95
|
+
readonly status: "error";
|
|
96
|
+
readonly data: undefined;
|
|
97
|
+
readonly error: TError;
|
|
98
|
+
readonly isPending: false;
|
|
99
|
+
readonly isError: true;
|
|
100
|
+
readonly isLoadingError: true;
|
|
101
|
+
readonly isRefetchError: false;
|
|
102
|
+
readonly isSuccess: false;
|
|
103
|
+
}
|
|
104
|
+
interface RefetchErrorQuerySnapshot<TData, TError> extends SnapshotBase<TData, TError> {
|
|
105
|
+
readonly status: "error";
|
|
106
|
+
readonly data: TData;
|
|
107
|
+
readonly error: TError;
|
|
108
|
+
readonly isPending: false;
|
|
109
|
+
readonly isError: true;
|
|
110
|
+
readonly isLoadingError: false;
|
|
111
|
+
readonly isRefetchError: true;
|
|
112
|
+
readonly isSuccess: false;
|
|
113
|
+
}
|
|
114
|
+
interface SuccessQuerySnapshot<TData, TError> extends SnapshotBase<TData, TError> {
|
|
115
|
+
readonly status: "success";
|
|
116
|
+
readonly data: TData;
|
|
117
|
+
readonly error: null;
|
|
118
|
+
readonly isPending: false;
|
|
119
|
+
readonly isError: false;
|
|
120
|
+
readonly isLoadingError: false;
|
|
121
|
+
readonly isRefetchError: false;
|
|
122
|
+
readonly isSuccess: true;
|
|
123
|
+
}
|
|
124
|
+
interface PlaceholderQuerySnapshot<TData, TError> extends SnapshotBase<TData, TError> {
|
|
125
|
+
readonly status: "success";
|
|
126
|
+
readonly data: TData;
|
|
127
|
+
readonly error: null;
|
|
128
|
+
readonly isPending: false;
|
|
129
|
+
readonly isError: false;
|
|
130
|
+
readonly isLoadingError: false;
|
|
131
|
+
readonly isRefetchError: false;
|
|
132
|
+
readonly isSuccess: true;
|
|
133
|
+
readonly isPlaceholderData: true;
|
|
134
|
+
}
|
|
135
|
+
/** Discriminated snapshot returned by a query watcher. */
|
|
136
|
+
type QuerySnapshot<TData = unknown, TError = Error> = PendingQuerySnapshot<TData, TError> | LoadingErrorQuerySnapshot<TData, TError> | RefetchErrorQuerySnapshot<TData, TError> | SuccessQuerySnapshot<TData, TError> | PlaceholderQuerySnapshot<TData, TError>;
|
|
137
|
+
type DefinedQuerySnapshot<TData = unknown, TError = Error> = RefetchErrorQuerySnapshot<TData, TError> | SuccessQuerySnapshot<TData, TError>;
|
|
138
|
+
interface InfiniteExtra<TPage, TParam, TError> {
|
|
139
|
+
readonly hasNextPage: boolean;
|
|
140
|
+
readonly hasPreviousPage: boolean;
|
|
141
|
+
readonly isFetchingNextPage: boolean;
|
|
142
|
+
readonly isFetchingPreviousPage: boolean;
|
|
143
|
+
readonly isFetchNextPageError: boolean;
|
|
144
|
+
readonly isFetchPreviousPageError: boolean;
|
|
145
|
+
readonly fetchNextPage: (options?: QueryRefetchOptions) => Promise<InfiniteSnapshot<TPage, TParam, TError>>;
|
|
146
|
+
readonly fetchPreviousPage: (options?: QueryRefetchOptions) => Promise<InfiniteSnapshot<TPage, TParam, TError>>;
|
|
147
|
+
}
|
|
148
|
+
/** Discriminated snapshot returned by an infinite query watcher. */
|
|
149
|
+
type InfiniteSnapshot<TPage = unknown, TParam = unknown, TError = Error> = QuerySnapshot<PageData<TPage, TParam>, TError> & InfiniteExtra<TPage, TParam, TError>;
|
|
150
|
+
interface MutationEntryState<TData = unknown, TError = Error, TVariables = void, TContext = unknown> {
|
|
151
|
+
readonly context: TContext | undefined;
|
|
152
|
+
readonly data: TData | undefined;
|
|
153
|
+
readonly error: TError | null;
|
|
154
|
+
readonly failureCount: number;
|
|
155
|
+
readonly failureReason: TError | null;
|
|
156
|
+
readonly isPaused: boolean;
|
|
157
|
+
readonly status: MutationStatus;
|
|
158
|
+
readonly variables: TVariables | undefined;
|
|
159
|
+
readonly submittedAt: number;
|
|
160
|
+
}
|
|
161
|
+
interface MutateCallOptions<TData = unknown, TError = Error, TVariables = void, TContext = unknown> {
|
|
162
|
+
readonly onSuccess?: (data: TData, variables: TVariables, context: TContext) => Promise<unknown> | void;
|
|
163
|
+
readonly onError?: (error: TError, variables: TVariables, context: TContext | undefined) => Promise<unknown> | void;
|
|
164
|
+
readonly onSettled?: (data: TData | undefined, error: TError | null, variables: TVariables, context: TContext | undefined) => Promise<unknown> | void;
|
|
165
|
+
}
|
|
166
|
+
interface MutationSnapshotBase<TData, TError, TVariables, TContext> {
|
|
167
|
+
readonly variables: TVariables | undefined;
|
|
168
|
+
readonly context: TContext | undefined;
|
|
169
|
+
readonly failureCount: number;
|
|
170
|
+
readonly failureReason: TError | null;
|
|
171
|
+
readonly isPaused: boolean;
|
|
172
|
+
readonly submittedAt: number;
|
|
173
|
+
readonly reset: () => void;
|
|
174
|
+
readonly mutate: (variables: TVariables, options?: MutateCallOptions<TData, TError, TVariables, TContext>) => void;
|
|
175
|
+
readonly mutateAsync: (variables: TVariables, options?: MutateCallOptions<TData, TError, TVariables, TContext>) => Promise<TData>;
|
|
176
|
+
}
|
|
177
|
+
type MutationSnapshot<TData = unknown, TError = Error, TVariables = void, TContext = unknown> = MutationSnapshotBase<TData, TError, TVariables, TContext> & ({
|
|
178
|
+
readonly status: "idle";
|
|
179
|
+
readonly data: undefined;
|
|
180
|
+
readonly error: null;
|
|
181
|
+
readonly isIdle: true;
|
|
182
|
+
readonly isPending: false;
|
|
183
|
+
readonly isError: false;
|
|
184
|
+
readonly isSuccess: false;
|
|
185
|
+
} | {
|
|
186
|
+
readonly status: "pending";
|
|
187
|
+
readonly data: undefined;
|
|
188
|
+
readonly error: null;
|
|
189
|
+
readonly isIdle: false;
|
|
190
|
+
readonly isPending: true;
|
|
191
|
+
readonly isError: false;
|
|
192
|
+
readonly isSuccess: false;
|
|
193
|
+
readonly variables: TVariables;
|
|
194
|
+
} | {
|
|
195
|
+
readonly status: "error";
|
|
196
|
+
readonly data: undefined;
|
|
197
|
+
readonly error: TError;
|
|
198
|
+
readonly isIdle: false;
|
|
199
|
+
readonly isPending: false;
|
|
200
|
+
readonly isError: true;
|
|
201
|
+
readonly isSuccess: false;
|
|
202
|
+
readonly variables: TVariables;
|
|
203
|
+
} | {
|
|
204
|
+
readonly status: "success";
|
|
205
|
+
readonly data: TData;
|
|
206
|
+
readonly error: null;
|
|
207
|
+
readonly isIdle: false;
|
|
208
|
+
readonly isPending: false;
|
|
209
|
+
readonly isError: false;
|
|
210
|
+
readonly isSuccess: true;
|
|
211
|
+
readonly variables: TVariables;
|
|
212
|
+
});
|
|
213
|
+
type QueryTypeFilter = "all" | "active" | "inactive";
|
|
214
|
+
interface QueryFilterRecord {
|
|
215
|
+
readonly queryKey: QueryKey;
|
|
216
|
+
readonly queryHash: string;
|
|
217
|
+
readonly state: QueryEntryState<unknown, unknown>;
|
|
218
|
+
readonly staleTime: StaleWindow<unknown, unknown> | undefined;
|
|
219
|
+
readonly observerCount: number;
|
|
220
|
+
}
|
|
221
|
+
interface QueryFilter {
|
|
222
|
+
readonly queryKey?: QueryKey | undefined;
|
|
223
|
+
readonly exact?: boolean | undefined;
|
|
224
|
+
readonly type?: QueryTypeFilter | undefined;
|
|
225
|
+
readonly stale?: boolean | undefined;
|
|
226
|
+
readonly fetchPhase?: FetchPhase | undefined;
|
|
227
|
+
readonly predicate?: ((record: QueryFilterRecord) => boolean) | undefined;
|
|
228
|
+
}
|
|
229
|
+
interface MutationFilterRecord {
|
|
230
|
+
readonly mutationKey: QueryKey | undefined;
|
|
231
|
+
readonly mutationHash?: string | undefined;
|
|
232
|
+
readonly state: MutationEntryState<unknown, unknown, unknown, unknown>;
|
|
233
|
+
}
|
|
234
|
+
interface MutationFilter {
|
|
235
|
+
readonly mutationKey?: QueryKey | undefined;
|
|
236
|
+
readonly exact?: boolean | undefined;
|
|
237
|
+
readonly status?: MutationStatus | undefined;
|
|
238
|
+
readonly predicate?: ((record: MutationFilterRecord) => boolean) | undefined;
|
|
239
|
+
}
|
|
240
|
+
type RefetchTrigger = boolean | "always" | ((state: QueryEntryState<unknown, unknown>) => boolean | "always");
|
|
241
|
+
type RefetchIntervalValue<TData = unknown, TError = Error> = number | false | ((state: QueryEntryState<TData, TError>) => number | false);
|
|
242
|
+
interface QuerySpec<TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> {
|
|
243
|
+
readonly queryKey: TQueryKey;
|
|
244
|
+
readonly queryFn?: QueryFn<TQueryFnData, TQueryKey> | SkipToken | undefined;
|
|
245
|
+
readonly staleTime?: StaleWindow<TQueryFnData, TError> | undefined;
|
|
246
|
+
readonly gcTime?: number | undefined;
|
|
247
|
+
readonly retry?: RetryPolicy<TError> | undefined;
|
|
248
|
+
readonly retryDelay?: RetryDelay<TError> | undefined;
|
|
249
|
+
readonly retryOnMount?: boolean | undefined;
|
|
250
|
+
readonly networkMode?: NetworkPolicy | undefined;
|
|
251
|
+
readonly structuralSharing?: boolean | undefined;
|
|
252
|
+
readonly meta?: QueryMeta | undefined;
|
|
253
|
+
readonly initialData?: TQueryFnData | (() => TQueryFnData | undefined) | undefined;
|
|
254
|
+
readonly initialDataUpdatedAt?: number | (() => number | undefined) | undefined;
|
|
255
|
+
readonly select?: ((data: TQueryFnData) => TData) | undefined;
|
|
256
|
+
readonly placeholderData?: TData | ((previousData: TData | undefined) => TData | undefined) | undefined;
|
|
257
|
+
readonly enabled?: boolean | ((state: QueryEntryState<TQueryFnData, TError>) => boolean) | undefined;
|
|
258
|
+
readonly refetchOnMount?: RefetchTrigger | undefined;
|
|
259
|
+
readonly refetchOnFocus?: RefetchTrigger | undefined;
|
|
260
|
+
readonly refetchOnReconnect?: RefetchTrigger | undefined;
|
|
261
|
+
readonly refetchInterval?: RefetchIntervalValue<TQueryFnData, TError> | undefined;
|
|
262
|
+
readonly refetchIntervalInBackground?: boolean | undefined;
|
|
263
|
+
readonly throwOnError?: boolean | ((error: TError, state: QueryEntryState<TQueryFnData, TError>) => boolean) | undefined;
|
|
264
|
+
readonly trackedProps?: readonly (keyof QuerySnapshot<TData, TError>)[] | "all" | undefined;
|
|
265
|
+
}
|
|
266
|
+
interface InfiniteQuerySpec<TQueryFnData = unknown, TError = Error, TData = PageData<TQueryFnData, unknown>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> extends Omit<QuerySpec<PageData<TQueryFnData, TPageParam>, TError, TData, TQueryKey>, "queryFn" | "initialData"> {
|
|
267
|
+
readonly queryFn?: QueryFn<TQueryFnData, TQueryKey, TPageParam> | SkipToken | undefined;
|
|
268
|
+
readonly initialPageParam: TPageParam;
|
|
269
|
+
readonly getNextPageParam: (lastPage: TQueryFnData, allPages: readonly TQueryFnData[], lastPageParam: TPageParam, allPageParams: readonly TPageParam[]) => TPageParam | undefined | null;
|
|
270
|
+
readonly getPreviousPageParam?: ((firstPage: TQueryFnData, allPages: readonly TQueryFnData[], firstPageParam: TPageParam, allPageParams: readonly TPageParam[]) => TPageParam | undefined | null) | undefined;
|
|
271
|
+
readonly maxPages?: number | undefined;
|
|
272
|
+
readonly initialData?: PageData<TQueryFnData, TPageParam> | (() => PageData<TQueryFnData, TPageParam> | undefined) | undefined;
|
|
273
|
+
}
|
|
274
|
+
interface MutationSpec<TData = unknown, TError = Error, TVariables = void, TContext = unknown> {
|
|
275
|
+
readonly mutationKey?: QueryKey | undefined;
|
|
276
|
+
readonly mutationFn?: ((variables: TVariables) => Promise<TData>) | undefined;
|
|
277
|
+
readonly retry?: RetryPolicy<TError> | undefined;
|
|
278
|
+
readonly retryDelay?: RetryDelay<TError> | undefined;
|
|
279
|
+
readonly networkMode?: NetworkPolicy | undefined;
|
|
280
|
+
readonly gcTime?: number | undefined;
|
|
281
|
+
readonly meta?: MutationMeta | undefined;
|
|
282
|
+
readonly scope?: {
|
|
283
|
+
readonly id: string;
|
|
284
|
+
} | undefined;
|
|
285
|
+
readonly onMutate?: ((variables: TVariables) => Promise<TContext | undefined> | TContext | undefined) | undefined;
|
|
286
|
+
readonly onSuccess?: ((data: TData, variables: TVariables, context: TContext) => Promise<unknown> | void) | undefined;
|
|
287
|
+
readonly onError?: ((error: TError, variables: TVariables, context: TContext | undefined) => Promise<unknown> | void) | undefined;
|
|
288
|
+
readonly onSettled?: ((data: TData | undefined, error: TError | null, variables: TVariables, context: TContext | undefined) => Promise<unknown> | void) | undefined;
|
|
289
|
+
readonly throwOnError?: boolean | ((error: TError) => boolean) | undefined;
|
|
290
|
+
}
|
|
291
|
+
interface DehydratedQuery {
|
|
292
|
+
readonly queryHash: string;
|
|
293
|
+
readonly queryKey: QueryKey;
|
|
294
|
+
readonly state: QueryEntryState<unknown, unknown>;
|
|
295
|
+
readonly promise?: Promise<unknown>;
|
|
296
|
+
readonly meta?: QueryMeta;
|
|
297
|
+
}
|
|
298
|
+
interface DehydratedMutation {
|
|
299
|
+
readonly mutationKey?: QueryKey;
|
|
300
|
+
readonly state: MutationEntryState<unknown, unknown, unknown, unknown>;
|
|
301
|
+
readonly meta?: MutationMeta;
|
|
302
|
+
readonly scope?: {
|
|
303
|
+
readonly id: string;
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
interface DehydratedCache {
|
|
307
|
+
readonly queries: readonly DehydratedQuery[];
|
|
308
|
+
readonly mutations: readonly DehydratedMutation[];
|
|
309
|
+
}
|
|
310
|
+
interface DehydrateOptions {
|
|
311
|
+
readonly shouldDehydrateQuery?: (record: {
|
|
312
|
+
readonly queryKey: QueryKey;
|
|
313
|
+
readonly queryHash: string;
|
|
314
|
+
readonly state: QueryEntryState<unknown, unknown>;
|
|
315
|
+
}) => boolean;
|
|
316
|
+
readonly shouldDehydrateMutation?: (record: {
|
|
317
|
+
readonly mutationKey: QueryKey | undefined;
|
|
318
|
+
readonly state: MutationEntryState<unknown, unknown, unknown, unknown>;
|
|
319
|
+
}) => boolean;
|
|
320
|
+
readonly serializeData?: (data: unknown) => unknown;
|
|
321
|
+
}
|
|
322
|
+
interface HydrateOptions {
|
|
323
|
+
readonly deserializeData?: (data: unknown) => unknown;
|
|
324
|
+
}
|
|
325
|
+
/** Creates the initial state record for a cache entry. */
|
|
326
|
+
declare function initialQueryState<TData = unknown, TError = Error>(seed?: {
|
|
327
|
+
readonly data?: TData | undefined;
|
|
328
|
+
readonly dataUpdatedAt?: number | undefined;
|
|
329
|
+
readonly status?: "pending" | "success" | undefined;
|
|
330
|
+
}): QueryEntryState<TData, TError>;
|
|
331
|
+
type QueryAction<TData = unknown, TError = Error> = {
|
|
332
|
+
readonly type: "fetch";
|
|
333
|
+
readonly meta?: QueryMeta | null;
|
|
334
|
+
} | {
|
|
335
|
+
readonly type: "pause";
|
|
336
|
+
} | {
|
|
337
|
+
readonly type: "continue";
|
|
338
|
+
} | {
|
|
339
|
+
readonly type: "fail";
|
|
340
|
+
readonly error: TError;
|
|
341
|
+
} | {
|
|
342
|
+
readonly type: "success";
|
|
343
|
+
readonly data: TData;
|
|
344
|
+
readonly updatedAt: number;
|
|
345
|
+
readonly structuralSharing: boolean;
|
|
346
|
+
} | {
|
|
347
|
+
readonly type: "error";
|
|
348
|
+
readonly error: TError;
|
|
349
|
+
readonly updatedAt: number;
|
|
350
|
+
} | {
|
|
351
|
+
readonly type: "cancel";
|
|
352
|
+
readonly revert?: QueryEntryState<TData, TError>;
|
|
353
|
+
} | {
|
|
354
|
+
readonly type: "invalidate";
|
|
355
|
+
} | {
|
|
356
|
+
readonly type: "setData";
|
|
357
|
+
readonly data: TData;
|
|
358
|
+
readonly updatedAt: number;
|
|
359
|
+
readonly structuralSharing: boolean;
|
|
360
|
+
};
|
|
361
|
+
/** Pure state transition function for a `QueryEntry`. */
|
|
362
|
+
declare function reduceQueryState<TData, TError>(state: QueryEntryState<TData, TError>, action: QueryAction<TData, TError>): QueryEntryState<TData, TError>;
|
|
363
|
+
interface DeriveSnapshotInput<TQueryFnData, TData, TError> {
|
|
364
|
+
readonly state: QueryEntryState<TQueryFnData, TError>;
|
|
365
|
+
readonly selectedData: TData | undefined;
|
|
366
|
+
readonly isPlaceholder: boolean;
|
|
367
|
+
readonly isFetchedAfterMount: boolean;
|
|
368
|
+
readonly staleTime: StaleWindow<TQueryFnData, TError> | undefined;
|
|
369
|
+
readonly now: number;
|
|
370
|
+
readonly refetch: (options?: QueryRefetchOptions) => Promise<QuerySnapshot<TData, TError>>;
|
|
371
|
+
readonly promise: Promise<TData>;
|
|
372
|
+
}
|
|
373
|
+
/** Builds a discriminated `QuerySnapshot` from raw entry state and selected data. */
|
|
374
|
+
declare function deriveQuerySnapshot<TQueryFnData, TData, TError>(input: DeriveSnapshotInput<TQueryFnData, TData, TError>): QuerySnapshot<TData, TError>;
|
|
375
|
+
/** Derives an `InfiniteSnapshot` from a base snapshot plus pagination flags. */
|
|
376
|
+
declare function deriveInfiniteSnapshot<TPage, TParam, TError>(base: QuerySnapshot<PageData<TPage, TParam>, TError>, pagination: {
|
|
377
|
+
readonly hasNextPage: boolean;
|
|
378
|
+
readonly hasPreviousPage: boolean;
|
|
379
|
+
readonly isFetchingNextPage: boolean;
|
|
380
|
+
readonly isFetchingPreviousPage: boolean;
|
|
381
|
+
readonly isFetchNextPageError: boolean;
|
|
382
|
+
readonly isFetchPreviousPageError: boolean;
|
|
383
|
+
readonly fetchNextPage: (options?: QueryRefetchOptions) => Promise<InfiniteSnapshot<TPage, TParam, TError>>;
|
|
384
|
+
readonly fetchPreviousPage: (options?: QueryRefetchOptions) => Promise<InfiniteSnapshot<TPage, TParam, TError>>;
|
|
385
|
+
}): InfiniteSnapshot<TPage, TParam, TError>;
|
|
386
|
+
/** Creates initial state for a `Mutation`. */
|
|
387
|
+
declare function initialMutationState<TData = unknown, TError = Error, TVariables = void, TContext = unknown>(): MutationEntryState<TData, TError, TVariables, TContext>;
|
|
388
|
+
type MutationAction<TData = unknown, TError = Error, TVariables = void, TContext = unknown> = {
|
|
389
|
+
readonly type: "pending";
|
|
390
|
+
readonly variables: TVariables;
|
|
391
|
+
readonly context: TContext | undefined;
|
|
392
|
+
readonly submittedAt: number;
|
|
393
|
+
} | {
|
|
394
|
+
readonly type: "context";
|
|
395
|
+
readonly context: TContext | undefined;
|
|
396
|
+
} | {
|
|
397
|
+
readonly type: "fail";
|
|
398
|
+
readonly error: TError;
|
|
399
|
+
} | {
|
|
400
|
+
readonly type: "pause";
|
|
401
|
+
} | {
|
|
402
|
+
readonly type: "continue";
|
|
403
|
+
} | {
|
|
404
|
+
readonly type: "success";
|
|
405
|
+
readonly data: TData;
|
|
406
|
+
} | {
|
|
407
|
+
readonly type: "error";
|
|
408
|
+
readonly error: TError;
|
|
409
|
+
};
|
|
410
|
+
/** Pure state transition function for a `MutationEntry`. */
|
|
411
|
+
declare function reduceMutationState<TData, TError, TVariables, TContext>(state: MutationEntryState<TData, TError, TVariables, TContext>, action: MutationAction<TData, TError, TVariables, TContext>): MutationEntryState<TData, TError, TVariables, TContext>;
|
|
412
|
+
/** Derives a public discriminated `MutationSnapshot`. */
|
|
413
|
+
declare function deriveMutationSnapshot<TData, TError, TVariables, TContext>(state: MutationEntryState<TData, TError, TVariables, TContext>, commands: Pick<MutationSnapshot<TData, TError, TVariables, TContext>, "reset" | "mutate" | "mutateAsync">): MutationSnapshot<TData, TError, TVariables, TContext>;
|
|
414
|
+
/** Checks whether `value` is a plain JSON-style record object. */
|
|
415
|
+
declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
416
|
+
/**
|
|
417
|
+
* Serializes a `QueryKey` into a deterministic hash string by sorting plain
|
|
418
|
+
* object keys recursively. Object property order never affects cache identity.
|
|
419
|
+
*/
|
|
420
|
+
declare function serializeKey(key: QueryKey): string;
|
|
421
|
+
/** Deep prefix comparison between a candidate value and a filter pattern. */
|
|
422
|
+
declare function partialMatchValue(target: unknown, pattern: unknown): boolean;
|
|
423
|
+
/** Returns true when `target` begins with `prefix` under structural matching. */
|
|
424
|
+
declare function keyStartsWith(target: QueryKey, prefix: QueryKey): boolean;
|
|
425
|
+
/** Evaluates whether a query record matches a `QueryFilter`. */
|
|
426
|
+
declare function matchesQueryFilter(record: QueryFilterRecord, filter: QueryFilter | undefined, now: number, precomputedExactHash?: string): boolean;
|
|
427
|
+
/** Evaluates whether a mutation record matches a `MutationFilter`. */
|
|
428
|
+
declare function matchesMutationFilter(record: MutationFilterRecord, filter: MutationFilter | undefined, precomputedExactHash?: string): boolean;
|
|
429
|
+
/**
|
|
430
|
+
* Compares `prev` and `next` recursively for plain objects and arrays. Whenever every
|
|
431
|
+
* child keeps the same value or reference, `prev` is returned so downstream equality
|
|
432
|
+
* checks (`Object.is`) see zero change.
|
|
433
|
+
*/
|
|
434
|
+
declare function keepEqual<T>(prev: unknown, next: T): T;
|
|
435
|
+
/** Resolves dynamic or static staleness window into milliseconds (`Infinity` for static). */
|
|
436
|
+
declare function resolveStaleMs<TData, TError>(staleTime: StaleWindow<TData, TError> | undefined, state: QueryEntryState<TData, TError>): number;
|
|
437
|
+
/** Returns true when a query entry must be treated as stale at `now`. */
|
|
438
|
+
declare function isEntryStale<TData, TError>(state: QueryEntryState<TData, TError>, staleTime: StaleWindow<TData, TError> | undefined, now: number): boolean;
|
|
439
|
+
/** Decides whether another attempt should run after `failureCount` failures (1-based after failure). */
|
|
440
|
+
declare function shouldRetryAttempt<TError>(policy: RetryPolicy<TError> | undefined, failureCount: number, error: TError, isServer: boolean): boolean;
|
|
441
|
+
/** Computes exponential backoff in milliseconds, capped at 30 seconds by default. */
|
|
442
|
+
declare function computeBackoffMs<TError>(delay: RetryDelay<TError> | undefined, attemptIndex: number, error: TError): number;
|
|
443
|
+
/** Determines whether an attempt can execute immediately or should pause while offline. */
|
|
444
|
+
declare function resolveNetworkAction(policy: NetworkPolicy | undefined, online: boolean, hasRunOnce: boolean): "run" | "pause";
|
|
445
|
+
/** Applies a `maxPages` sliding window after appending/prepending a page. */
|
|
446
|
+
declare function clampPages<TPage, TParam>(data: PageData<TPage, TParam>, maxPages: number | undefined, direction: FetchDirection): PageData<TPage, TParam>;
|
|
447
|
+
/** Reusable builder that tags `queryKey` with phantom data and error types. */
|
|
448
|
+
declare function querySpec<TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(spec: QuerySpec<TQueryFnData, TError, TData, TQueryKey>): Omit<QuerySpec<TQueryFnData, TError, TData, TaggedKey<TQueryKey, TQueryFnData, TError>>, "queryKey"> & {
|
|
449
|
+
readonly queryKey: TaggedKey<TQueryKey, TQueryFnData, TError>;
|
|
450
|
+
};
|
|
451
|
+
/** Reusable infinite query builder that tags `queryKey` with `PageData` types. */
|
|
452
|
+
declare function infiniteQuerySpec<TQueryFnData = unknown, TError = Error, TData = PageData<TQueryFnData, unknown>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(spec: InfiniteQuerySpec<TQueryFnData, TError, TData, TQueryKey, TPageParam>): Omit<InfiniteQuerySpec<TQueryFnData, TError, TData, TaggedKey<TQueryKey, PageData<TQueryFnData, TPageParam>, TError>, TPageParam>, "queryKey"> & {
|
|
453
|
+
readonly queryKey: TaggedKey<TQueryKey, PageData<TQueryFnData, TPageParam>, TError>;
|
|
454
|
+
};
|
|
455
|
+
/** Identity helper for typing reusable mutation specifications. */
|
|
456
|
+
declare function mutationSpec<TData = unknown, TError = Error, TVariables = void, TContext = unknown>(spec: MutationSpec<TData, TError, TVariables, TContext>): MutationSpec<TData, TError, TVariables, TContext>;
|
|
457
|
+
declare function defaultShouldDehydrateQuery(record: {
|
|
458
|
+
readonly queryKey: QueryKey;
|
|
459
|
+
readonly queryHash: string;
|
|
460
|
+
readonly state: QueryEntryState<unknown, unknown>;
|
|
461
|
+
}): boolean;
|
|
462
|
+
declare function defaultShouldDehydrateMutation(record: {
|
|
463
|
+
readonly mutationKey: QueryKey | undefined;
|
|
464
|
+
readonly state: MutationEntryState<unknown, unknown, unknown, unknown>;
|
|
465
|
+
}): boolean;
|
|
466
|
+
interface RawDehydratableQuery {
|
|
467
|
+
readonly queryHash: string;
|
|
468
|
+
readonly queryKey: QueryKey;
|
|
469
|
+
readonly state: QueryEntryState<unknown, unknown>;
|
|
470
|
+
readonly promise?: Promise<unknown> | undefined;
|
|
471
|
+
readonly meta?: QueryMeta | undefined;
|
|
472
|
+
}
|
|
473
|
+
interface RawDehydratableMutation {
|
|
474
|
+
readonly mutationKey?: QueryKey | undefined;
|
|
475
|
+
readonly state: MutationEntryState<unknown, unknown, unknown, unknown>;
|
|
476
|
+
readonly meta?: MutationMeta | undefined;
|
|
477
|
+
readonly scope?: {
|
|
478
|
+
readonly id: string;
|
|
479
|
+
} | undefined;
|
|
480
|
+
}
|
|
481
|
+
/** Converts live cache records into a serializable `DehydratedCache` snapshot. */
|
|
482
|
+
declare function packCache(queries: readonly RawDehydratableQuery[], mutations: readonly RawDehydratableMutation[], options?: DehydrateOptions): DehydratedCache;
|
|
483
|
+
/** Filters dehydrated queries to those fresher than existing cache entries and deserializes data. */
|
|
484
|
+
declare function selectHydrateQueries(cache: DehydratedCache, existingUpdatedAt: (queryHash: string) => number | undefined, options?: HydrateOptions): readonly DehydratedQuery[];
|
|
485
|
+
export { MutationMeta as $, initialQueryState as A, ERROR_TAG as B, DeriveSnapshotInput as C, RetryPolicy as Ct, deriveMutationSnapshot as D, TaggedKey as Dt, deriveInfiniteSnapshot as E, SuccessQuerySnapshot as Et, DefinedQuerySnapshot as F, InfiniteExtra as G, FetchDirection as H, DehydrateOptions as I, LoadingErrorQuerySnapshot as J, InfiniteQuerySpec as K, DehydratedCache as L, reduceQueryState as M, DATA_TAG as N, deriveQuerySnapshot as O, keepPrevious as Ot, DataOfKey as P, MutationFilterRecord as Q, DehydratedMutation as R, serializeKey as S, RetryDelay as St, QueryAction as T, StaleWindow as Tt, FetchPhase as U, ErrorOfKey as V, HydrateOptions as W, MutationEntryState as X, MutateCallOptions as Y, MutationFilter as Z, isPlainObject as _, QueryStatus as _t, packCache as a, PendingQuerySnapshot as at, matchesQueryFilter as b, RefetchIntervalValue as bt, computeBackoffMs as c, QueryFilter as ct, mutationSpec as d, QueryFnContext as dt, MutationSnapshot as et, querySpec as f, QueryKey as ft, keepEqual as g, QuerySpec as gt, shouldRetryAttempt as h, QuerySnapshot as ht, defaultShouldDehydrateQuery as i, PageData as it, reduceMutationState as j, initialMutationState as k, skipToken as kt, infiniteQuerySpec as l, QueryFilterRecord as lt, resolveStaleMs as m, QueryRefetchOptions as mt, RawDehydratableQuery as n, MutationStatus as nt, selectHydrateQueries as o, PlaceholderQuerySnapshot as ot, resolveNetworkAction as p, QueryMeta as pt, InfiniteSnapshot as q, defaultShouldDehydrateMutation as r, NetworkPolicy as rt, clampPages as s, QueryEntryState as st, RawDehydratableMutation as t, MutationSpec as tt, isEntryStale as u, QueryFn as ut, keyStartsWith as v, QueryTypeFilter as vt, MutationAction as w, SkipToken as wt, partialMatchValue as x, RefetchTrigger as xt, matchesMutationFilter as y, RefetchErrorQuerySnapshot as yt, DehydratedQuery as z };
|