@raf-query/core 0.11.1 → 0.13.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 +39 -1
- package/README.md +28 -18
- package/dist/client.d.mts +163 -119
- package/dist/client.mjs +90 -162
- package/dist/entry.d.mts +73 -147
- package/dist/entry.mjs +314 -471
- package/dist/features/focus-refetch/focus-refetch.d.mts +17 -0
- package/dist/features/focus-refetch/focus-refetch.mjs +20 -0
- package/dist/features/polling/polling.d.mts +16 -0
- package/dist/features/polling/polling.mjs +39 -0
- package/dist/features/reconnect-refetch/reconnect-refetch.d.mts +17 -0
- package/dist/features/reconnect-refetch/reconnect-refetch.mjs +16 -0
- package/dist/features/shared.mjs +13 -0
- package/dist/guards.mjs +23 -0
- package/dist/hydration/hydration.d.mts +108 -0
- package/dist/hydration/hydration.mjs +142 -0
- package/dist/index.d.mts +19 -13
- package/dist/index.mjs +16 -13
- package/dist/infinite/infinite.d.mts +83 -0
- package/dist/infinite/infinite.mjs +120 -0
- package/dist/infinite/paging.d.mts +71 -0
- package/dist/infinite/paging.mjs +62 -0
- package/dist/internal.d.mts +13 -0
- package/dist/internal.mjs +7 -0
- package/dist/keys/keys.d.mts +54 -0
- package/dist/keys/keys.mjs +53 -0
- package/dist/keys/targets.d.mts +62 -0
- package/dist/keys/targets.mjs +85 -0
- package/dist/links/retry/retry.d.mts +33 -0
- package/dist/links/retry/retry.mjs +53 -0
- package/dist/links/timeout/timeout.d.mts +17 -0
- package/dist/links/timeout/timeout.mjs +35 -0
- package/dist/load.d.mts +149 -0
- package/dist/load.mjs +179 -0
- package/dist/options.d.mts +161 -332
- package/dist/options.mjs +28 -40
- package/dist/presets.d.mts +35 -0
- package/dist/presets.mjs +27 -0
- package/dist/root.d.mts +86 -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 +15 -17
- package/dist/thenable.mjs +25 -6
- package/dist/verbs.d.mts +150 -0
- package/dist/verbs.mjs +115 -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 -95
- package/dist/controls.mjs +0 -70
- 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/client.mjs
CHANGED
|
@@ -1,176 +1,104 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Context, Effect, Exit, Layer, Option, Predicate, Scope } from "effect";
|
|
1
|
+
import { listeners } from "./subscribe.mjs";
|
|
3
2
|
//#region src/client.ts
|
|
3
|
+
const systemClock = {
|
|
4
|
+
clearTimeout: (handle) => {
|
|
5
|
+
clearTimeout(handle);
|
|
6
|
+
},
|
|
7
|
+
now: () => Date.now(),
|
|
8
|
+
setTimeout: (callback, ms) => setTimeout(callback, ms)
|
|
9
|
+
};
|
|
4
10
|
/**
|
|
5
|
-
* A
|
|
6
|
-
*
|
|
7
|
-
*
|
|
11
|
+
* A link that declares the `meta` fields it reads. A root's queries take
|
|
12
|
+
* those fields only when the root has the link.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const traced = link<{ meta: { traceId?: string } }>((op, next) =>
|
|
16
|
+
* withTrace(op.meta.traceId, () => next(op)),
|
|
17
|
+
* );
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @see https://raf-query.katt.dev/docs/links-and-features#links-and-features
|
|
8
21
|
*/
|
|
9
|
-
function
|
|
10
|
-
return
|
|
22
|
+
function link(run) {
|
|
23
|
+
return run;
|
|
11
24
|
}
|
|
25
|
+
const noop = () => {};
|
|
12
26
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
27
|
+
* A feature that declares the `meta` fields it reads. Without `setup`, it
|
|
28
|
+
* only declares them: a root's own fields, such as an `owner` its targets
|
|
29
|
+
* match on.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const ownership = feature<{ meta: { owner?: "posts-team" | "users-team" } }>();
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @see https://raf-query.katt.dev/docs/links-and-features#links-and-features
|
|
16
36
|
*/
|
|
17
|
-
function
|
|
18
|
-
return
|
|
19
|
-
throw Predicate.isTagged(error, "CancelledError") ? new DOMException("The query was cancelled", "AbortError") : error;
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
/** `ensure` / `fetch` arguments, forwarded to the cache's same verb. */
|
|
23
|
-
function loadArgs(input, options) {
|
|
24
|
-
return [input, options];
|
|
37
|
+
function feature(setup = noop) {
|
|
38
|
+
return setup;
|
|
25
39
|
}
|
|
26
40
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
41
|
+
* Create a query client. Behaviors are opt-in: pass `links` and `features`,
|
|
42
|
+
* or spread `recommended()`. The client's `meta` type is what they declare.
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* const ownership = feature<{ meta: { owner?: "posts-team" | "users-team" } }>();
|
|
46
|
+
* export const makeQueryClient = () =>
|
|
47
|
+
* createQueryClient({ links: [retry()], features: [ownership], staleTime: 30_000 });
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* Make one per request on the server (in a loader or a request-scoped
|
|
51
|
+
* cache), never at module level.
|
|
52
|
+
*
|
|
53
|
+
* @see https://raf-query.katt.dev/docs/important-defaults
|
|
31
54
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const services = Effect.runSync(Layer.buildWithScope(config.layer ? Layer.provideMerge(cache, config.layer) : cache, this.#scope));
|
|
54
|
-
this.#context = services;
|
|
55
|
-
this.effect = Context.get(services, QueryCache);
|
|
56
|
-
this.isServer = this.effect.isServer;
|
|
57
|
-
this.throwOnError = config.throwOnError ?? config.layer === void 0;
|
|
58
|
-
const onError = config.onError;
|
|
59
|
-
if (onError) this.effect.subscribeUnsafe((event) => {
|
|
60
|
-
if (event.type === "failed") onError(event.error, event.query);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* The cache entry for a factory call, created if missing. Doesn't fetch.
|
|
65
|
-
* For bindings; apps use the verbs.
|
|
66
|
-
*/
|
|
67
|
-
getQuery(factory, ...args) {
|
|
68
|
-
return this.effect.getQueryUnsafe(factory, ...args);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Start a query without waiting and return its handle. Fresh data is
|
|
72
|
-
* reused; stale data refetches in the background (in the browser only).
|
|
73
|
-
* Errors surface where the data is read, never here.
|
|
74
|
-
*/
|
|
75
|
-
prefetch(factory, ...args) {
|
|
76
|
-
return Effect.runSync(provided(this.effect.prefetch(factory, ...args)));
|
|
77
|
-
}
|
|
78
|
-
ensure(factory, input, options) {
|
|
79
|
-
return runLoad(provided(this.effect.ensure(factory, ...loadArgs(input, options))));
|
|
80
|
-
}
|
|
81
|
-
fetch(factory, input, options) {
|
|
82
|
-
return runLoad(provided(this.effect.fetch(factory, ...loadArgs(input, options))));
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Mark queries stale and refetch the ones being read. Resolves once those
|
|
86
|
-
* refetches settle, so an action stays pending until fresh data is on
|
|
87
|
-
* screen. Takes a factory and its input, or a {@link QueryCache.Filter}.
|
|
88
|
-
*/
|
|
89
|
-
invalidate(...target) {
|
|
90
|
-
return Effect.runPromise(this.effect.invalidate(...target));
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Drop queries' data and errors, as if they were never fetched. Read ones
|
|
94
|
-
* suspend and refetch; resolves once those refetches settle.
|
|
95
|
-
*/
|
|
96
|
-
reset(...target) {
|
|
97
|
-
return Effect.runPromise(this.effect.reset(...target));
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Remove queries from the cache and abort their requests. Readers keep the
|
|
101
|
-
* removed entry until they render again.
|
|
102
|
-
*/
|
|
103
|
-
remove(...target) {
|
|
104
|
-
Effect.runSync(this.effect.remove(...target));
|
|
105
|
-
}
|
|
106
|
-
/** Write data for a factory call. Readers re-render without suspending. */
|
|
107
|
-
setData(factory, input, updater) {
|
|
108
|
-
Effect.runSync(this.effect.setData(factory, input, updater));
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Cached data for a factory call, or `undefined` if there is none. Data can
|
|
112
|
-
* itself be `undefined`; `Query.getUnsafe(getQuery(...)).hasData` tells
|
|
113
|
-
* them apart.
|
|
114
|
-
*/
|
|
115
|
-
getData(factory, ...args) {
|
|
116
|
-
return Option.getOrUndefined(Effect.runSync(this.effect.getData(factory, ...args)));
|
|
117
|
-
}
|
|
118
|
-
/** Every entry, for devtools and integrations. */
|
|
119
|
-
getAll() {
|
|
120
|
-
return Effect.runSync(this.effect.all);
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* How many entries have a request in flight: all of them, or those
|
|
124
|
-
* matching `filter`. For global loading indicators.
|
|
125
|
-
*/
|
|
126
|
-
isFetching(filter) {
|
|
127
|
-
return this.effect.isFetchingUnsafe(filter);
|
|
128
|
-
}
|
|
129
|
-
/** Listen to entries being added, updated, and removed. */
|
|
130
|
-
subscribe(listener) {
|
|
131
|
-
return this.effect.subscribeUnsafe(listener);
|
|
132
|
-
}
|
|
133
|
-
/** Drop every entry and abort in-flight requests. */
|
|
134
|
-
clear() {
|
|
135
|
-
Effect.runSync(this.effect.clear);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Start refetching read, stale queries on window focus and reconnect.
|
|
139
|
-
* Returns the matching unmount. Providers call this; mounts are counted.
|
|
140
|
-
*/
|
|
141
|
-
mount() {
|
|
142
|
-
const scope = Scope.forkUnsafe(this.#scope);
|
|
143
|
-
Effect.runSync(this.effect.mount.pipe(Scope.provide(scope)));
|
|
144
|
-
return () => {
|
|
145
|
-
Effect.runSync(Scope.close(scope, Exit.void));
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Run an Effect with the cache (`QueryCache`) and the services of
|
|
150
|
-
* `config.layer`, as `Effect.runPromise` does: it rejects with the
|
|
151
|
-
* Effect's failure, or its defect. For an app's loaders and actions.
|
|
152
|
-
*/
|
|
153
|
-
runPromise(effect) {
|
|
154
|
-
return Effect.runPromiseWith(this.#context)(effect);
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Close the client: interrupt every request and timer, and release the
|
|
158
|
-
* layer's services. Resolves once the layer's finalizers have run.
|
|
159
|
-
*/
|
|
160
|
-
dispose() {
|
|
161
|
-
return Effect.runPromise(Scope.close(this.#scope, Exit.void));
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
/** Snapshot the cache for transfer to another client (server → browser). */
|
|
165
|
-
function dehydrate(client, options) {
|
|
166
|
-
return Effect.runSync(client.effect.dehydrate(options));
|
|
55
|
+
function createQueryClient(config = {}) {
|
|
56
|
+
const events = listeners();
|
|
57
|
+
const entries = /* @__PURE__ */ new Map();
|
|
58
|
+
return {
|
|
59
|
+
"~changed": /* @__PURE__ */ new Set(),
|
|
60
|
+
"~entries": entries,
|
|
61
|
+
"~events": events,
|
|
62
|
+
"~seq": 0,
|
|
63
|
+
"~stamps": [],
|
|
64
|
+
clock: config.clock ?? systemClock,
|
|
65
|
+
config,
|
|
66
|
+
isServer: config.isServer ?? !("window" in globalThis),
|
|
67
|
+
subscribe: (listener, options) => {
|
|
68
|
+
const unsubscribe = events.subscribe(listener, options);
|
|
69
|
+
if (options?.replay && !options.signal?.aborted) for (const entry of entries.values()) listener({
|
|
70
|
+
entry,
|
|
71
|
+
type: "added"
|
|
72
|
+
});
|
|
73
|
+
return unsubscribe;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
167
76
|
}
|
|
77
|
+
const mounted = /* @__PURE__ */ new WeakMap();
|
|
168
78
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
79
|
+
* Start the client's features. Providers call it while mounted; the
|
|
80
|
+
* returned function stops them. Mounts are counted, so features start once
|
|
81
|
+
* however many providers share the client, and stop with the last.
|
|
171
82
|
*/
|
|
172
|
-
function
|
|
173
|
-
|
|
83
|
+
function mount(client) {
|
|
84
|
+
let current = mounted.get(client);
|
|
85
|
+
if (!current) {
|
|
86
|
+
current = {
|
|
87
|
+
controller: new AbortController(),
|
|
88
|
+
count: 0
|
|
89
|
+
};
|
|
90
|
+
mounted.set(client, current);
|
|
91
|
+
for (const start of client.config.features ?? []) start(client, current.controller.signal);
|
|
92
|
+
}
|
|
93
|
+
const shared = current;
|
|
94
|
+
shared.count += 1;
|
|
95
|
+
return () => {
|
|
96
|
+
shared.count -= 1;
|
|
97
|
+
if (shared.count === 0) {
|
|
98
|
+
mounted.delete(client);
|
|
99
|
+
shared.controller.abort();
|
|
100
|
+
}
|
|
101
|
+
};
|
|
174
102
|
}
|
|
175
103
|
//#endregion
|
|
176
|
-
export {
|
|
104
|
+
export { createQueryClient, feature, link, mount, systemClock };
|
package/dist/entry.d.mts
CHANGED
|
@@ -1,159 +1,85 @@
|
|
|
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
|
}
|
|
34
49
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
50
|
+
* Make the `AbortError` (a `DOMException`) that a `load` waiting on a removed query rejects with.
|
|
51
|
+
*
|
|
52
|
+
* @see https://raf-query.katt.dev/docs/query-cancellation#when-requests-are-aborted
|
|
38
53
|
*/
|
|
39
|
-
export
|
|
40
|
-
readonly clock: Clock.Clock;
|
|
41
|
-
readonly defaults: QueryBehavior;
|
|
42
|
-
readonly entries: Map<string, Entry>;
|
|
43
|
-
readonly isServer: boolean;
|
|
44
|
-
readonly listeners: Set<(event: Event) => void>;
|
|
45
|
-
readonly platform: Platform;
|
|
46
|
-
readonly scope: Scope.Scope;
|
|
47
|
-
readonly services: Context.Context<never>;
|
|
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;
|
|
102
|
-
}
|
|
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
|
-
/**
|
|
119
|
-
* Run this entry's requests with the services of `caller`, a verb's fiber
|
|
120
|
-
* context, over the cache's: every request from now on, including ones a
|
|
121
|
-
* render, a refetch or `invalidate` starts.
|
|
122
|
-
*/
|
|
123
|
-
export declare function provide(entry: Entry, caller: Context.Context<never>): void;
|
|
124
|
-
/** Attach the options and input of the latest factory call. */
|
|
125
|
-
export declare function setOptions(entry: Entry, options: AnyQueryOptions, input: unknown): void;
|
|
54
|
+
export declare function abortError(): DOMException;
|
|
126
55
|
/**
|
|
127
|
-
* The
|
|
128
|
-
*
|
|
56
|
+
* The entry for a factory's input, created if missing, with the factory's
|
|
57
|
+
* current options. Every read goes through here, which links an entry that
|
|
58
|
+
* was only hydrated to its factory.
|
|
129
59
|
*/
|
|
130
|
-
export declare function
|
|
131
|
-
/**
|
|
132
|
-
export declare function
|
|
133
|
-
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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;
|
|
60
|
+
export declare function entryOf(client: QueryClient, factory: AnyFactory, input: unknown): Entry;
|
|
61
|
+
/** Whether an invalidation newer than the entry's data covers it. */
|
|
62
|
+
export declare function isInvalidated(entry: Entry): boolean;
|
|
63
|
+
/** Whether the entry is a browser-only query (`ssr: false`) on a server client: nothing starts it there. */
|
|
64
|
+
export declare function isBrowserOnly(entry: Entry): boolean;
|
|
65
|
+
/** Whether the entry's data should be refetched before it's trusted. */
|
|
66
|
+
export declare function isStale(entry: Entry): boolean;
|
|
67
|
+
export interface FetchRequest {
|
|
68
|
+
readonly direction?: "next" | "previous";
|
|
69
|
+
readonly pages?: number;
|
|
70
|
+
/** Abort a request in flight and start over (an invalidation). */
|
|
71
|
+
readonly restart?: boolean;
|
|
72
|
+
}
|
|
146
73
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
74
|
+
* Run the entry's request, or join the one in flight. Resolves with how it
|
|
75
|
+
* ended, never rejects: a removed entry's request ends with an `AbortError`.
|
|
76
|
+
* Whoever waited on a restarted request gets the new one's outcome.
|
|
149
77
|
*/
|
|
150
|
-
export declare function
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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. */
|
|
78
|
+
export declare function fetchEntry(entry: Entry, request?: FetchRequest): Promise<Outcome>;
|
|
79
|
+
/** Subscribe to an entry's state. Subscribers are its readers: an entry with none can be gc'd. */
|
|
80
|
+
export declare function subscribeEntry(entry: Entry, listener: (state: EntryState) => void, options?: SubscribeOptions): () => void;
|
|
81
|
+
/** Drop the entry, aborting its request. Waiters get an `AbortError`. */
|
|
157
82
|
export declare function remove(entry: Entry): void;
|
|
158
|
-
|
|
159
|
-
export
|
|
83
|
+
/** Drop data and errors. Read entries (or ones loading) refetch; resolves when they settle. */
|
|
84
|
+
export declare function reset(entry: Entry): Promise<Outcome>;
|
|
85
|
+
//#endregion
|