@raf-query/core 0.11.0 → 0.12.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/CHANGELOG.md +18 -2
- package/README.md +28 -18
- package/dist/client.d.mts +132 -119
- package/dist/client.mjs +59 -162
- package/dist/entry.d.mts +67 -148
- package/dist/entry.mjs +303 -474
- package/dist/features/focus-refetch/focus-refetch.d.mts +15 -0
- package/dist/features/focus-refetch/focus-refetch.mjs +18 -0
- package/dist/features/polling/polling.d.mts +12 -0
- package/dist/features/polling/polling.mjs +35 -0
- package/dist/features/reconnect-refetch/reconnect-refetch.d.mts +15 -0
- package/dist/features/reconnect-refetch/reconnect-refetch.mjs +14 -0
- package/dist/features/shared.mjs +13 -0
- package/dist/guards.mjs +23 -0
- package/dist/hydration/hydration.d.mts +73 -0
- package/dist/hydration/hydration.mjs +128 -0
- package/dist/index.d.mts +18 -13
- package/dist/index.mjs +15 -13
- package/dist/infinite/infinite.d.mts +71 -0
- package/dist/infinite/infinite.mjs +88 -0
- package/dist/internal.d.mts +13 -0
- package/dist/internal.mjs +7 -0
- package/dist/keys/keys.d.mts +46 -0
- package/dist/keys/keys.mjs +53 -0
- package/dist/keys/targets.d.mts +56 -0
- package/dist/keys/targets.mjs +85 -0
- package/dist/links/retry/retry.d.mts +26 -0
- package/dist/links/retry/retry.mjs +51 -0
- package/dist/links/timeout/timeout.d.mts +9 -0
- package/dist/links/timeout/timeout.mjs +27 -0
- package/dist/load.d.mts +124 -0
- package/dist/load.mjs +165 -0
- package/dist/options.d.mts +112 -338
- package/dist/options.mjs +25 -36
- package/dist/presets.d.mts +29 -0
- package/dist/presets.mjs +25 -0
- package/dist/root.d.mts +82 -0
- package/dist/structural-sharing/structural-sharing.mjs +32 -0
- package/dist/subscribe.d.mts +15 -0
- package/dist/subscribe.mjs +29 -0
- package/dist/thenable.d.mts +13 -17
- package/dist/thenable.mjs +25 -6
- package/dist/verbs.d.mts +109 -0
- package/dist/verbs.mjs +87 -0
- package/package.json +13 -9
- package/dist/_virtual/_rolldown/runtime.mjs +0 -13
- package/dist/all-keyed.d.mts +0 -18
- package/dist/all-keyed.mjs +0 -19
- package/dist/binding.d.mts +0 -92
- package/dist/binding.mjs +0 -186
- package/dist/cache.d.mts +0 -164
- package/dist/cache.mjs +0 -184
- package/dist/controls.d.mts +0 -93
- package/dist/controls.mjs +0 -69
- package/dist/hydration.d.mts +0 -84
- package/dist/hydration.mjs +0 -148
- package/dist/infinite.d.mts +0 -5
- package/dist/infinite.mjs +0 -103
- package/dist/key.d.mts +0 -18
- package/dist/key.mjs +0 -36
- package/dist/listen.mjs +0 -19
- package/dist/notify.mjs +0 -21
- package/dist/observer.d.mts +0 -110
- package/dist/observer.mjs +0 -300
- package/dist/platform.d.mts +0 -27
- package/dist/platform.mjs +0 -44
- package/dist/query.d.mts +0 -137
- package/dist/query.mjs +0 -147
- package/dist/request.mjs +0 -47
- package/dist/retry.mjs +0 -25
- package/dist/share.mjs +0 -40
package/dist/entry.d.mts
CHANGED
|
@@ -1,159 +1,78 @@
|
|
|
1
|
-
import { QueryKey } from "./
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { AnyFactory, QueryKey } from "./keys/keys.mjs";
|
|
2
|
+
import { QueryOptions } from "./options.mjs";
|
|
3
|
+
import { Listeners, SubscribeOptions } from "./subscribe.mjs";
|
|
4
4
|
import { Pending, Thenable } from "./thenable.mjs";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { QueryClient } from "./client.mjs";
|
|
6
|
+
//#region src/entry.d.ts
|
|
7
|
+
/** An entry's state. A new object on every change, so it works as a snapshot. */
|
|
8
|
+
export interface EntryState {
|
|
9
|
+
readonly data: unknown;
|
|
10
|
+
/** The last request's error, while it's the latest outcome. */
|
|
11
|
+
readonly error: unknown;
|
|
12
|
+
readonly fetchingDirection: "next" | "previous" | undefined;
|
|
13
|
+
readonly hasData: boolean;
|
|
14
|
+
readonly isFetching: boolean;
|
|
15
|
+
readonly status: "error" | "pending" | "success";
|
|
16
|
+
/** When the data was written (ms since epoch); `0` without data. */
|
|
17
|
+
readonly updatedAt: number;
|
|
10
18
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
readonly
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
readonly
|
|
19
|
+
/** How a request ended, for whoever waited on it. */
|
|
20
|
+
export type Outcome = {
|
|
21
|
+
readonly error: unknown;
|
|
22
|
+
readonly ok: false;
|
|
23
|
+
} | {
|
|
24
|
+
readonly ok: true;
|
|
25
|
+
};
|
|
26
|
+
interface Run {
|
|
27
|
+
readonly controller: AbortController;
|
|
28
|
+
readonly done: PromiseWithResolvers<Outcome>;
|
|
29
|
+
/** Resolve `done` at the first chunk of a stream, not its end. */
|
|
30
|
+
settled: boolean;
|
|
31
|
+
readonly startedAt: number;
|
|
21
32
|
}
|
|
22
|
-
|
|
23
|
-
readonly
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* Why a query with `enabled: false` has no data: `ensure` / `fetch` die
|
|
27
|
-
* with it, and on a server its promise rejects with it.
|
|
28
|
-
*/
|
|
29
|
-
export declare class DisabledError extends DisabledError_base<{
|
|
33
|
+
export interface Entry {
|
|
34
|
+
readonly client: QueryClient;
|
|
35
|
+
factory: AnyFactory | undefined;
|
|
36
|
+
gcTimer: unknown;
|
|
30
37
|
readonly hash: string;
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
input: unknown;
|
|
39
|
+
readonly key: QueryKey;
|
|
40
|
+
options: QueryOptions | undefined;
|
|
41
|
+
pendingThenable: Pending<unknown> | undefined;
|
|
42
|
+
readonly readers: Listeners<EntryState>;
|
|
43
|
+
/** `~seq` when the request behind the data started; invalidations after it make it stale. */
|
|
44
|
+
requestedAt: number;
|
|
45
|
+
run: Run | undefined;
|
|
46
|
+
state: EntryState;
|
|
47
|
+
thenable: Thenable<unknown>;
|
|
33
48
|
}
|
|
49
|
+
export declare function abortError(): DOMException;
|
|
34
50
|
/**
|
|
35
|
-
* The
|
|
36
|
-
*
|
|
37
|
-
*
|
|
51
|
+
* The entry for a factory's input, created if missing, with the factory's
|
|
52
|
+
* current options. Every read goes through here, which links an entry that
|
|
53
|
+
* was only hydrated to its factory.
|
|
38
54
|
*/
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
readonly
|
|
46
|
-
readonly
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/** The background work of an entry, one fiber per kind. */
|
|
50
|
-
type Task = "errorShown" | "gc" | "request" | "stale";
|
|
51
|
-
interface Tasks {
|
|
52
|
-
cancel(task: Task): void;
|
|
53
|
-
fork(task: Task, effect: Effect.Effect<void>, options?: {
|
|
54
|
-
readonly onlyIfMissing?: boolean;
|
|
55
|
-
}): void;
|
|
56
|
-
}
|
|
57
|
-
interface Commands {
|
|
58
|
-
readonly fetchNextPage: Effect.Effect<void>;
|
|
59
|
-
readonly fetchPreviousPage: Effect.Effect<void>;
|
|
60
|
-
readonly refetch: Effect.Effect<void>;
|
|
61
|
-
}
|
|
62
|
-
/** A cache entry: a {@link Query} and the state behind it. */
|
|
63
|
-
export interface Entry extends Query {
|
|
64
|
-
readonly cache: CacheState;
|
|
65
|
-
/** One Effect per command, so readers can compare them by identity. */
|
|
66
|
-
readonly commands: Commands;
|
|
67
|
-
/** A failed first load was shown; the next read retries it. */
|
|
68
|
-
errorShown: boolean;
|
|
69
|
-
/** `failureCount` before the request in flight, restored if it's cancelled. */
|
|
70
|
-
failureCountBefore: number;
|
|
71
|
-
handle: QueryHandle;
|
|
72
|
-
/** `meta` sent with dehydrated state, for an entry no factory call has reached. */
|
|
73
|
-
hydratedMeta: QueryMeta | undefined;
|
|
74
|
-
/** Awaited by every caller of the request in flight; outlives restarts. */
|
|
75
|
-
inFlight: Deferred.Deferred<unknown, unknown> | undefined;
|
|
76
|
-
readonly listeners: Map<() => void, SubscribeOptions>;
|
|
77
|
-
options: AnyQueryOptions | undefined;
|
|
78
|
-
/** The first load's promise, until it settles. */
|
|
79
|
-
pending: Pending<unknown> | undefined;
|
|
80
|
-
/** The last reader left during the request in flight: it retries no more. */
|
|
81
|
-
retriesStopped: boolean;
|
|
82
|
-
/**
|
|
83
|
-
* The last `queryFn` call returned an Effect (`true`) or a promise or
|
|
84
|
-
* plain value (`false`), here or on the cache it was hydrated from.
|
|
85
|
-
* `undefined` until one has run.
|
|
86
|
-
*/
|
|
87
|
-
returnsEffect: boolean | undefined;
|
|
88
|
-
/** Open while the entry is cached; owns its fibers. */
|
|
89
|
-
readonly scope: Scope.Closeable;
|
|
90
|
-
/**
|
|
91
|
-
* What its requests run with: the cache's services, under those of the
|
|
92
|
-
* latest verb that called for this entry ({@link provide}).
|
|
93
|
-
*/
|
|
94
|
-
services: Context.Context<never>;
|
|
95
|
-
/**
|
|
96
|
-
* The request in flight read its `signal`, or returned an Effect, so
|
|
97
|
-
* interrupting it cancels its work (TanStack's `abortSignalConsumed`).
|
|
98
|
-
*/
|
|
99
|
-
signalRead: boolean;
|
|
100
|
-
state: State<unknown>;
|
|
101
|
-
readonly tasks: Tasks;
|
|
55
|
+
export declare function entryOf(client: QueryClient, factory: AnyFactory, input: unknown): Entry;
|
|
56
|
+
/** Whether an invalidation newer than the entry's data covers it. */
|
|
57
|
+
export declare function isInvalidated(entry: Entry): boolean;
|
|
58
|
+
/** Whether the entry's data should be refetched before it's trusted. */
|
|
59
|
+
export declare function isStale(entry: Entry): boolean;
|
|
60
|
+
export interface FetchRequest {
|
|
61
|
+
readonly direction?: "next" | "previous";
|
|
62
|
+
readonly pages?: number;
|
|
63
|
+
/** Abort a request in flight and start over (an invalidation). */
|
|
64
|
+
readonly restart?: boolean;
|
|
102
65
|
}
|
|
103
|
-
export declare function isQuery(value: unknown): value is Query;
|
|
104
|
-
export declare function entryOf<TFactory extends QueryFactory>(query: Query<TFactory>): Entry;
|
|
105
|
-
export declare function emit(cache: CacheState, event: Event): void;
|
|
106
|
-
export declare function make(cache: CacheState, key: QueryKey, hash: string): Entry;
|
|
107
|
-
/** Readers are subscribed; `invalidate` and focus refetch only what is read. */
|
|
108
|
-
export declare function isObserved(entry: Entry): boolean;
|
|
109
|
-
/** The entry's latest factory call returned `enabled: false`: it doesn't run. */
|
|
110
|
-
export declare function isDisabled(entry: Entry): boolean;
|
|
111
|
-
/** Until a factory call attaches options, `meta` comes from hydration. */
|
|
112
|
-
export declare function metaOf(entry: Entry): QueryMeta | undefined;
|
|
113
|
-
export declare function isStaleUnsafe(entry: Entry): boolean;
|
|
114
|
-
export declare function hasNextPageUnsafe(entry: Entry): boolean;
|
|
115
|
-
export declare function hasPreviousPageUnsafe(entry: Entry): boolean;
|
|
116
|
-
export declare function subscribeUnsafe(entry: Entry, listener: () => void, options?: SubscribeOptions): () => void;
|
|
117
|
-
export declare function changes(entry: Entry): Stream.Stream<State<unknown>>;
|
|
118
66
|
/**
|
|
119
|
-
* Run
|
|
120
|
-
*
|
|
121
|
-
*
|
|
67
|
+
* Run the entry's request, or join the one in flight. Resolves with how it
|
|
68
|
+
* ended, never rejects: a removed entry's request ends with an `AbortError`.
|
|
69
|
+
* Whoever waited on a restarted request gets the new one's outcome.
|
|
122
70
|
*/
|
|
123
|
-
export declare function
|
|
124
|
-
/**
|
|
125
|
-
export declare function
|
|
126
|
-
/**
|
|
127
|
-
* The promise a render should unwrap. Starts the first request if nothing
|
|
128
|
-
* has, and retries a failed first load once its error has been shown.
|
|
129
|
-
*/
|
|
130
|
-
export declare function readUnsafe(entry: Entry): Thenable<unknown>;
|
|
131
|
-
/** Start a request unless one is in flight, without waiting for it. */
|
|
132
|
-
export declare function start(entry: Entry): void;
|
|
133
|
-
/**
|
|
134
|
-
* Whether cached data that was asked for again should be refetched. A server
|
|
135
|
-
* cache renders once, so a refetch there could only duplicate a request whose
|
|
136
|
-
* result is never shown; it refetches only what `invalidate` marked.
|
|
137
|
-
*/
|
|
138
|
-
export declare function needsRefetch(entry: Entry): boolean;
|
|
139
|
-
/** Background refetch of cached data that was asked for again. */
|
|
140
|
-
export declare function revalidate(entry: Entry): void;
|
|
141
|
-
export declare function fetch(entry: Entry, request?: FetchRequest): Effect.Effect<unknown, unknown>;
|
|
142
|
-
export declare function invalidate(entry: Entry): Effect.Effect<void>;
|
|
143
|
-
export declare function reset(entry: Entry): Effect.Effect<void>;
|
|
144
|
-
/** Write data directly, as if a request had returned it. */
|
|
145
|
-
export declare function setData(entry: Entry, data: unknown, updatedAt?: number): void;
|
|
146
|
-
/**
|
|
147
|
-
* Adopt a request started elsewhere (the server's, during hydration). Its
|
|
148
|
-
* data counts as fetched when the sender got it, not when it arrived.
|
|
149
|
-
*/
|
|
150
|
-
export declare function resume(entry: Entry, promise: PromiseLike<{
|
|
151
|
-
readonly data?: unknown;
|
|
152
|
-
readonly updatedAt: number;
|
|
153
|
-
}>): void;
|
|
154
|
-
/** Refetch a read, stale entry whose readers want it on this event. */
|
|
155
|
-
export declare function onPlatformEvent(entry: Entry, event: PlatformEvent): void;
|
|
156
|
-
/** Take `entry` out of its cache: interrupt its fibers and fail its awaiters. */
|
|
71
|
+
export declare function fetchEntry(entry: Entry, request?: FetchRequest): Promise<Outcome>;
|
|
72
|
+
/** Subscribe to an entry's state. Subscribers are its readers: an entry with none can be gc'd. */
|
|
73
|
+
export declare function subscribeEntry(entry: Entry, listener: (state: EntryState) => void, options?: SubscribeOptions): () => void;
|
|
74
|
+
/** Drop the entry, aborting its request. Waiters get an `AbortError`. */
|
|
157
75
|
export declare function remove(entry: Entry): void;
|
|
158
|
-
|
|
159
|
-
export
|
|
76
|
+
/** Drop data and errors. Read entries (or ones loading) refetch; resolves when they settle. */
|
|
77
|
+
export declare function reset(entry: Entry): Promise<Outcome>;
|
|
78
|
+
//#endregion
|