@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/query.mjs
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
|
|
2
|
-
import { CancelledError as CancelledError$1, DisabledError as DisabledError$1, TypeId as TypeId$1, changes as changes$1, entryOf, fetch as fetch$1, hasNextPageUnsafe as hasNextPageUnsafe$1, hasPreviousPageUnsafe as hasPreviousPageUnsafe$1, invalidate as invalidate$1, isQuery as isQuery$1, isStaleUnsafe as isStaleUnsafe$1, metaOf, provide, readUnsafe as readUnsafe$1, reset as reset$1, revalidate, subscribeUnsafe as subscribeUnsafe$1 } from "./entry.mjs";
|
|
3
|
-
import { Effect } from "effect";
|
|
4
|
-
import { dual } from "effect/Function";
|
|
5
|
-
//#region src/query.ts
|
|
6
|
-
/**
|
|
7
|
-
* One cache entry, as a data type: a `Query` carries its key, handle and
|
|
8
|
-
* options, and the functions here read it, subscribe to it and run its
|
|
9
|
-
* requests. Get one from `QueryCache.getQuery(factory, input)`.
|
|
10
|
-
*
|
|
11
|
-
* Requests are Effects. The `*Unsafe` functions read and subscribe
|
|
12
|
-
* synchronously, for renders and external stores that can't run an Effect.
|
|
13
|
-
*/
|
|
14
|
-
var query_exports = /* @__PURE__ */ __exportAll({
|
|
15
|
-
CancelledError: () => CancelledError,
|
|
16
|
-
DisabledError: () => DisabledError,
|
|
17
|
-
TypeId: () => TypeId,
|
|
18
|
-
changes: () => changes,
|
|
19
|
-
fetch: () => fetch,
|
|
20
|
-
fetchNextPage: () => fetchNextPage,
|
|
21
|
-
fetchPreviousPage: () => fetchPreviousPage,
|
|
22
|
-
get: () => get,
|
|
23
|
-
getUnsafe: () => getUnsafe,
|
|
24
|
-
hasNextPageUnsafe: () => hasNextPageUnsafe,
|
|
25
|
-
hasPreviousPageUnsafe: () => hasPreviousPageUnsafe,
|
|
26
|
-
invalidate: () => invalidate,
|
|
27
|
-
isQuery: () => isQuery,
|
|
28
|
-
isStaleUnsafe: () => isStaleUnsafe,
|
|
29
|
-
metaUnsafe: () => metaUnsafe,
|
|
30
|
-
observerCountUnsafe: () => observerCountUnsafe,
|
|
31
|
-
readUnsafe: () => readUnsafe,
|
|
32
|
-
refetch: () => refetch,
|
|
33
|
-
reset: () => reset,
|
|
34
|
-
returnsEffectUnsafe: () => returnsEffectUnsafe,
|
|
35
|
-
revalidateUnsafe: () => revalidateUnsafe,
|
|
36
|
-
subscribeUnsafe: () => subscribeUnsafe
|
|
37
|
-
});
|
|
38
|
-
const TypeId = TypeId$1;
|
|
39
|
-
const CancelledError = CancelledError$1;
|
|
40
|
-
const DisabledError = DisabledError$1;
|
|
41
|
-
const isQuery = isQuery$1;
|
|
42
|
-
function typed(effect) {
|
|
43
|
-
return effect;
|
|
44
|
-
}
|
|
45
|
-
function typedState(state) {
|
|
46
|
-
return state;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Start a request, or join the one in flight. Fails with the request's
|
|
50
|
-
* error, or a {@link CancelledError} if the entry leaves the cache first.
|
|
51
|
-
* The entry's requests run with this fiber's services from now on, as after
|
|
52
|
-
* a `QueryCache` verb.
|
|
53
|
-
*/
|
|
54
|
-
const fetch = dual((args) => isQuery(args[0]), (self, request) => typed(Effect.contextWith((caller) => {
|
|
55
|
-
const entry = entryOf(self);
|
|
56
|
-
provide(entry, caller);
|
|
57
|
-
return fetch$1(entry, request);
|
|
58
|
-
})));
|
|
59
|
-
/** Refetch now; succeeds when the request settles, whatever its outcome. */
|
|
60
|
-
function refetch(self) {
|
|
61
|
-
return entryOf(self).commands.refetch;
|
|
62
|
-
}
|
|
63
|
-
/** Load the page after the last one; succeeds once it settles. */
|
|
64
|
-
function fetchNextPage(self) {
|
|
65
|
-
return entryOf(self).commands.fetchNextPage;
|
|
66
|
-
}
|
|
67
|
-
/** Load the page before the first one; succeeds once it settles. */
|
|
68
|
-
function fetchPreviousPage(self) {
|
|
69
|
-
return entryOf(self).commands.fetchPreviousPage;
|
|
70
|
-
}
|
|
71
|
-
/** Mark stale, and refetch if read; succeeds once that refetch settles. */
|
|
72
|
-
function invalidate(self) {
|
|
73
|
-
return invalidate$1(entryOf(self));
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Drop data and errors, back to the state of a new entry. Readers suspend
|
|
77
|
-
* and refetch; succeeds when that refetch settles.
|
|
78
|
-
*/
|
|
79
|
-
function reset(self) {
|
|
80
|
-
return reset$1(entryOf(self));
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* The query's `meta`: the latest factory call's (the one it was hydrated
|
|
84
|
-
* with, before any), else the cache default's.
|
|
85
|
-
*/
|
|
86
|
-
function metaUnsafe(self) {
|
|
87
|
-
return metaOf(entryOf(self));
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Whether the query's `queryFn` returns an Effect (`true`) or a promise or
|
|
91
|
-
* plain value (`false`), as of its last call, on this cache or the one its
|
|
92
|
-
* data was hydrated from. `undefined` until one has run. Bindings read typed
|
|
93
|
-
* errors as a `Result` only for Effects.
|
|
94
|
-
*/
|
|
95
|
-
function returnsEffectUnsafe(self) {
|
|
96
|
-
return entryOf(self).returnsEffect;
|
|
97
|
-
}
|
|
98
|
-
/** The entry's current state. */
|
|
99
|
-
function get(self) {
|
|
100
|
-
return Effect.sync(() => getUnsafe(self));
|
|
101
|
-
}
|
|
102
|
-
/** {@link get}, synchronously. */
|
|
103
|
-
function getUnsafe(self) {
|
|
104
|
-
return typedState(entryOf(self).state);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* The entry's current state, then every change. Counts as a reader while
|
|
108
|
-
* the stream runs, so invalidation and focus refetch it.
|
|
109
|
-
*/
|
|
110
|
-
function changes(self) {
|
|
111
|
-
return changes$1(entryOf(self));
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* The promise a render should unwrap. Starts the first request if nothing
|
|
115
|
-
* has, and retries a failed first load once its error has been shown.
|
|
116
|
-
*/
|
|
117
|
-
function readUnsafe(self) {
|
|
118
|
-
return readUnsafe$1(entryOf(self));
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Refetch cached data in the background if it's stale, as `prefetch` does
|
|
122
|
-
* (on a server cache, only if invalidated). Does nothing without data or
|
|
123
|
-
* while a request is in flight.
|
|
124
|
-
*/
|
|
125
|
-
function revalidateUnsafe(self) {
|
|
126
|
-
revalidate(entryOf(self));
|
|
127
|
-
}
|
|
128
|
-
/** Listen for state changes. Subscribed entries count as read. */
|
|
129
|
-
function subscribeUnsafe(self, listener, options) {
|
|
130
|
-
return subscribeUnsafe$1(entryOf(self), listener, options);
|
|
131
|
-
}
|
|
132
|
-
/** Staleness as of now; `state.isStale` is only kept current while read. */
|
|
133
|
-
function isStaleUnsafe(self) {
|
|
134
|
-
return isStaleUnsafe$1(entryOf(self));
|
|
135
|
-
}
|
|
136
|
-
function hasNextPageUnsafe(self) {
|
|
137
|
-
return hasNextPageUnsafe$1(entryOf(self));
|
|
138
|
-
}
|
|
139
|
-
function hasPreviousPageUnsafe(self) {
|
|
140
|
-
return hasPreviousPageUnsafe$1(entryOf(self));
|
|
141
|
-
}
|
|
142
|
-
/** Readers currently subscribed. */
|
|
143
|
-
function observerCountUnsafe(self) {
|
|
144
|
-
return entryOf(self).listeners.size;
|
|
145
|
-
}
|
|
146
|
-
//#endregion
|
|
147
|
-
export { CancelledError, DisabledError, TypeId, changes, fetch, fetchNextPage, fetchPreviousPage, get, getUnsafe, hasNextPageUnsafe, hasPreviousPageUnsafe, invalidate, isQuery, isStaleUnsafe, metaUnsafe, observerCountUnsafe, query_exports, readUnsafe, refetch, reset, returnsEffectUnsafe, revalidateUnsafe, subscribeUnsafe };
|
package/dist/request.mjs
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Context, Effect, Scope } from "effect";
|
|
2
|
-
//#region src/request.ts
|
|
3
|
-
function isEffectResult(result) {
|
|
4
|
-
return Effect.isEffect(result);
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* One `queryFn` call as an Effect. The signal it gets aborts when the fiber
|
|
8
|
-
* is interrupted; a returned Effect runs in the same fiber, so interrupting
|
|
9
|
-
* the request interrupts it. Plain values settle like promises, a microtask
|
|
10
|
-
* later. A `queryFn` that throws instead of returning is a defect, as in
|
|
11
|
-
* `Effect.sync`.
|
|
12
|
-
*/
|
|
13
|
-
function fromQueryFn(call) {
|
|
14
|
-
return Effect.callback((resume, signal) => {
|
|
15
|
-
let result;
|
|
16
|
-
try {
|
|
17
|
-
result = call(signal);
|
|
18
|
-
} catch (error) {
|
|
19
|
-
resume(Effect.die(error));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (isEffectResult(result)) {
|
|
23
|
-
resume(result);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
Promise.resolve(result).then((value) => resume(Effect.succeed(value)), (error) => resume(Effect.fail(error)));
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* The services a request runs with: the cache's, under those of the verb
|
|
31
|
-
* that last called for the entry. The caller's `Scope` is left out: a
|
|
32
|
-
* request outlives the call that started it.
|
|
33
|
-
*/
|
|
34
|
-
function requestServices(cache, caller) {
|
|
35
|
-
return Context.merge(cache, Context.omit(Scope.Scope)(caller));
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* A request as it runs: in a `raf-query.request` span, with `services`,
|
|
39
|
-
* which hold what its `queryFn` Effect needs (entries erase that type with
|
|
40
|
-
* the data's). Typed failures become the query's error; defects are logged
|
|
41
|
-
* too, since nothing else reports them.
|
|
42
|
-
*/
|
|
43
|
-
function runRequest(request, hash, services) {
|
|
44
|
-
return request.pipe(Effect.tapDefect((defect) => Effect.logError("raf-query: queryFn died", defect)), Effect.withSpan("raf-query.request", { attributes: { "raf_query.hash": hash } }), Effect.provideContext(services));
|
|
45
|
-
}
|
|
46
|
-
//#endregion
|
|
47
|
-
export { fromQueryFn, requestServices, runRequest };
|
package/dist/retry.mjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Effect, Predicate, Schedule } from "effect";
|
|
2
|
-
//#region src/retry.ts
|
|
3
|
-
/** Doubling from 1 s, at most 30 s. */
|
|
4
|
-
const defaultDelays = /*#__PURE__*/ Schedule.min([Schedule.exponential("1 second"), Schedule.spaced("30 seconds")]);
|
|
5
|
-
function delays(retryDelay) {
|
|
6
|
-
if (retryDelay === void 0) return defaultDelays;
|
|
7
|
-
if (Predicate.isNumber(retryDelay)) return Schedule.spaced(retryDelay);
|
|
8
|
-
return Schedule.forever.pipe(Schedule.modifyDelay((step) => Effect.succeed(retryDelay(step.attempt, step.input))));
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* A query's retry options as one `Schedule`, or `undefined` when it doesn't
|
|
12
|
-
* retry. `retryDelay` sets the delays; a count or predicate in `retry` stops
|
|
13
|
-
* the schedule, given the attempt number (1 after the first failure) and the
|
|
14
|
-
* error.
|
|
15
|
-
*/
|
|
16
|
-
function retrySchedule(behavior, isServer) {
|
|
17
|
-
const retry = behavior.retry ?? (isServer ? 0 : 3);
|
|
18
|
-
if (Schedule.isSchedule(retry)) return retry;
|
|
19
|
-
if (retry === false || retry === 0) return;
|
|
20
|
-
const schedule = delays(behavior.retryDelay);
|
|
21
|
-
if (retry === true) return schedule;
|
|
22
|
-
return schedule.pipe(Schedule.while((step) => Predicate.isNumber(retry) ? step.attempt <= retry : retry(step.attempt, step.input)));
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
export { retrySchedule };
|
package/dist/share.mjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { isPlainRecord } from "./key.mjs";
|
|
2
|
-
//#region src/share.ts
|
|
3
|
-
function isPlainArray(value) {
|
|
4
|
-
return Array.isArray(value) && value.length === Object.keys(value).length;
|
|
5
|
-
}
|
|
6
|
-
function share(previous, next, depth) {
|
|
7
|
-
if (previous === next || depth > 500) return next;
|
|
8
|
-
if (isPlainArray(previous) && isPlainArray(next)) {
|
|
9
|
-
let equal = previous.length === next.length;
|
|
10
|
-
const copy = next.map((item, index) => {
|
|
11
|
-
const shared = share(previous[index], item, depth + 1);
|
|
12
|
-
equal &&= shared === previous[index];
|
|
13
|
-
return shared;
|
|
14
|
-
});
|
|
15
|
-
return equal ? previous : copy;
|
|
16
|
-
}
|
|
17
|
-
if (isPlainRecord(previous) && isPlainRecord(next)) {
|
|
18
|
-
const names = Object.keys(next);
|
|
19
|
-
let equal = names.length === Object.keys(previous).length;
|
|
20
|
-
const copy = {};
|
|
21
|
-
for (const name of names) {
|
|
22
|
-
const shared = share(previous[name], next[name], depth + 1);
|
|
23
|
-
equal &&= shared === previous[name] && Object.hasOwn(previous, name);
|
|
24
|
-
copy[name] = shared;
|
|
25
|
-
}
|
|
26
|
-
return equal ? previous : copy;
|
|
27
|
-
}
|
|
28
|
-
return next;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* `next`, reusing every part of `previous` that is deeply equal to it: all
|
|
32
|
-
* of `previous` when nothing changed, else a copy of `next` whose unchanged
|
|
33
|
-
* subtrees are `previous`'s. Only plain objects and arrays are compared;
|
|
34
|
-
* anything else is taken from `next`. TanStack Query's `replaceEqualDeep`.
|
|
35
|
-
*/
|
|
36
|
-
function replaceEqualDeep(previous, next) {
|
|
37
|
-
return share(previous, next, 0);
|
|
38
|
-
}
|
|
39
|
-
//#endregion
|
|
40
|
-
export { replaceEqualDeep };
|