@raf-query/core 0.0.19 → 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/CHANGELOG.md +16 -1
- package/README.md +101 -33
- package/dist/_virtual/_rolldown/runtime.mjs +13 -0
- package/dist/cache.d.mts +140 -0
- package/dist/cache.mjs +176 -0
- package/dist/entry.d.mts +113 -0
- package/dist/entry.mjs +421 -0
- package/dist/hydration.d.mts +37 -13
- package/dist/hydration.mjs +78 -17
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +6 -6
- package/dist/infinite.d.mts +5 -0
- package/dist/infinite.mjs +59 -0
- package/dist/listen.mjs +19 -0
- package/dist/observer.d.mts +57 -39
- package/dist/observer.mjs +215 -133
- package/dist/options.d.mts +50 -14
- package/dist/options.mjs +3 -0
- package/dist/platform.d.mts +27 -0
- package/dist/platform.mjs +44 -0
- package/dist/query.d.mts +77 -49
- package/dist/query.mjs +111 -421
- package/dist/request.mjs +47 -0
- package/dist/retry.mjs +25 -0
- package/dist/thenable.d.mts +5 -0
- package/package.json +1 -1
- package/dist/all-keyed.d.mts +0 -18
- package/dist/all-keyed.mjs +0 -19
- package/dist/client.d.mts +0 -123
- package/dist/client.mjs +0 -264
- package/dist/online.mjs +0 -16
package/dist/query.d.mts
CHANGED
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
import { QueryKey } from "./key.mjs";
|
|
2
|
-
import { AnyQueryOptions, QueryFactory, QueryHandle } from "./options.mjs";
|
|
2
|
+
import { AnyQueryOptions, DataOf, ErrorOf, QueryFactory, QueryHandle, ServicesOf } from "./options.mjs";
|
|
3
3
|
import { Thenable } from "./thenable.mjs";
|
|
4
|
-
|
|
4
|
+
import { CancelledError as CancelledError$1, TypeId as TypeId$1, entry_d_exports } from "./entry.mjs";
|
|
5
|
+
import { Direction } from "./infinite.mjs";
|
|
6
|
+
import { Effect, Pipeable, Stream } from "effect";
|
|
7
|
+
declare namespace query_d_exports {
|
|
8
|
+
export { CancelledError, FetchRequest, Of, Query, State, SubscribeOptions, TypeId, changes, fetch, fetchNextPage, fetchPreviousPage, get, getUnsafe, hasNextPageUnsafe, hasPreviousPageUnsafe, invalidate, isQuery, isStaleUnsafe, observerCountUnsafe, readUnsafe, refetch, reset, subscribeUnsafe };
|
|
9
|
+
}
|
|
10
|
+
export declare const TypeId: typeof TypeId$1;
|
|
11
|
+
export type TypeId = typeof TypeId;
|
|
12
|
+
export interface Query<TData = unknown, TFactory extends QueryFactory = QueryFactory, TError = unknown> extends Pipeable.Pipeable {
|
|
13
|
+
/** The serializable handle for this entry's factory call. */
|
|
14
|
+
readonly handle: QueryHandle<TFactory>;
|
|
15
|
+
/** Stable string form of `key`. */
|
|
16
|
+
readonly hash: string;
|
|
17
|
+
readonly key: QueryKey;
|
|
18
|
+
/** Options from the latest factory call; `undefined` for an entry only hydrated so far. */
|
|
19
|
+
readonly options: AnyQueryOptions | undefined;
|
|
20
|
+
readonly [TypeId]: {
|
|
21
|
+
readonly _A: (_: never) => TData;
|
|
22
|
+
readonly _E: (_: never) => TError;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** The entry of a factory call, typed by the factory. */
|
|
26
|
+
export type Of<TFactory extends QueryFactory> = Query<DataOf<TFactory>, TFactory, ErrorOf<TFactory>>;
|
|
5
27
|
/** A snapshot of one cache entry. Replaced, never mutated, on every change. */
|
|
6
|
-
export interface
|
|
28
|
+
export interface State<TData> {
|
|
7
29
|
/** Last successful data, kept through background errors. */
|
|
8
30
|
readonly data: TData | undefined;
|
|
9
31
|
/** Error of the last failed request, or `null`. */
|
|
@@ -11,7 +33,7 @@ export interface QueryState<TData> {
|
|
|
11
33
|
/** Failed attempts of the current request, retries included. */
|
|
12
34
|
readonly failureCount: number;
|
|
13
35
|
/** Set while a paged query loads a page at one end of the list. */
|
|
14
|
-
readonly fetchDirection:
|
|
36
|
+
readonly fetchDirection: Direction | undefined;
|
|
15
37
|
readonly hasData: boolean;
|
|
16
38
|
/** A request is in flight. */
|
|
17
39
|
readonly isFetching: boolean;
|
|
@@ -28,60 +50,66 @@ export interface QueryState<TData> {
|
|
|
28
50
|
/** When `data` was fetched (ms since epoch); `0` without data. */
|
|
29
51
|
readonly updatedAt: number;
|
|
30
52
|
}
|
|
31
|
-
/** Per-reader preferences, registered with {@link
|
|
53
|
+
/** Per-reader preferences, registered with {@link subscribeUnsafe}. */
|
|
32
54
|
export interface SubscribeOptions {
|
|
33
55
|
readonly refetchOnReconnect?: boolean;
|
|
34
56
|
readonly refetchOnWindowFocus?: boolean;
|
|
35
57
|
}
|
|
36
58
|
export interface FetchRequest {
|
|
37
59
|
/** Load one more page at this end of a paged query. */
|
|
38
|
-
readonly direction?:
|
|
60
|
+
readonly direction?: Direction;
|
|
39
61
|
/** Pages to load when a paged query has none yet. */
|
|
40
62
|
readonly pages?: number;
|
|
41
|
-
/**
|
|
63
|
+
/** Interrupt an in-flight request and start over (used by `invalidate`). */
|
|
42
64
|
readonly restart?: boolean;
|
|
43
65
|
}
|
|
66
|
+
export declare const CancelledError: typeof CancelledError$1;
|
|
67
|
+
export type CancelledError = CancelledError$1;
|
|
68
|
+
export declare const isQuery: (value: unknown) => value is Query;
|
|
44
69
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
70
|
+
* Start a request, or join the one in flight. Fails with the request's
|
|
71
|
+
* error, or a {@link CancelledError} if the entry leaves the cache first.
|
|
72
|
+
* The entry's requests run with this fiber's services from now on, as after
|
|
73
|
+
* a `QueryCache` verb.
|
|
47
74
|
*/
|
|
48
|
-
export
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
export declare
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
//#endregion
|
|
75
|
+
export declare const fetch: {
|
|
76
|
+
(request?: FetchRequest): <TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>) => Effect.Effect<TData, TError | CancelledError, ServicesOf<TFactory>>;
|
|
77
|
+
<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>, request?: FetchRequest): Effect.Effect<TData, TError | CancelledError, ServicesOf<TFactory>>;
|
|
78
|
+
};
|
|
79
|
+
/** Refetch now; succeeds when the request settles, whatever its outcome. */
|
|
80
|
+
export declare function refetch<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Effect.Effect<void>;
|
|
81
|
+
/** Load the page after the last one; succeeds once it settles. */
|
|
82
|
+
export declare function fetchNextPage<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Effect.Effect<void>;
|
|
83
|
+
/** Load the page before the first one; succeeds once it settles. */
|
|
84
|
+
export declare function fetchPreviousPage<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Effect.Effect<void>;
|
|
85
|
+
/** Mark stale, and refetch if read; succeeds once that refetch settles. */
|
|
86
|
+
export declare function invalidate<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Effect.Effect<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Drop data and errors, back to the state of a new entry. Readers suspend
|
|
89
|
+
* and refetch; succeeds when that refetch settles.
|
|
90
|
+
*/
|
|
91
|
+
export declare function reset<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Effect.Effect<void>;
|
|
92
|
+
/** The entry's current state. */
|
|
93
|
+
export declare function get<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Effect.Effect<State<TData>>;
|
|
94
|
+
/** {@link get}, synchronously. */
|
|
95
|
+
export declare function getUnsafe<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): State<TData>;
|
|
96
|
+
/**
|
|
97
|
+
* The entry's current state, then every change. Counts as a reader while
|
|
98
|
+
* the stream runs, so invalidation and focus refetch it.
|
|
99
|
+
*/
|
|
100
|
+
export declare function changes<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Stream.Stream<State<TData>>;
|
|
101
|
+
/**
|
|
102
|
+
* The promise a render should unwrap. Starts the first request if nothing
|
|
103
|
+
* has, and retries a failed first load once its error has been shown.
|
|
104
|
+
*/
|
|
105
|
+
export declare function readUnsafe<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): Thenable<TData>;
|
|
106
|
+
/** Listen for state changes. Subscribed entries count as read. */
|
|
107
|
+
export declare function subscribeUnsafe<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>, listener: () => void, options?: SubscribeOptions): () => void;
|
|
108
|
+
/** Staleness as of now; `state.isStale` is only kept current while read. */
|
|
109
|
+
export declare function isStaleUnsafe<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): boolean;
|
|
110
|
+
export declare function hasNextPageUnsafe<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): boolean;
|
|
111
|
+
export declare function hasPreviousPageUnsafe<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): boolean;
|
|
112
|
+
/** Readers currently subscribed. */
|
|
113
|
+
export declare function observerCountUnsafe<TData, TFactory extends QueryFactory, TError>(self: Query<TData, TFactory, TError>): number;
|
|
114
|
+
//#endregion
|
|
115
|
+
export { query_d_exports };
|