ngx-signal-query 1.4.0 → 1.5.0-dev.2
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/README.md +58 -28
- package/fesm2022/ngx-signal-query.mjs +212 -56
- package/fesm2022/ngx-signal-query.mjs.map +1 -1
- package/index.d.ts +33 -9
- package/package.json +7 -2
package/index.d.ts
CHANGED
|
@@ -105,6 +105,20 @@ type QueryOptions<TData, TError = Error> = {
|
|
|
105
105
|
* interval changes. See {@link RefetchIntervalValue}.
|
|
106
106
|
*/
|
|
107
107
|
refetchInterval?: RefetchIntervalValue<TData, TError>;
|
|
108
|
+
/**
|
|
109
|
+
* Whether the query refetches when the user comes back to the page, as the
|
|
110
|
+
* tab or window turns visible again: `true` refetches stale data (see
|
|
111
|
+
* `staleTime`), `'always'` fresh data too, `false` never. Default `true`.
|
|
112
|
+
* However many components show the query, it refetches once.
|
|
113
|
+
*/
|
|
114
|
+
refetchOnWindowFocus?: boolean | 'always';
|
|
115
|
+
/**
|
|
116
|
+
* Whether the query refetches when the network comes back (the browser's
|
|
117
|
+
* `online` event): `true` refetches stale data (see `staleTime`), so a
|
|
118
|
+
* query that failed while offline loads again; `'always'` refetches fresh
|
|
119
|
+
* data too, `false` never. Default `true`.
|
|
120
|
+
*/
|
|
121
|
+
refetchOnReconnect?: boolean | 'always';
|
|
108
122
|
/**
|
|
109
123
|
* Seed data to render immediately (treated as already-resolved). A
|
|
110
124
|
* function runs only while the query has no data yet; returning `undefined`
|
|
@@ -140,6 +154,8 @@ type DefaultedQueryOptions<TData, TError = Error> = QueryOptions<TData, TError>
|
|
|
140
154
|
retry: RetryValue<TError>;
|
|
141
155
|
retryDelay: RetryDelayValue<TError>;
|
|
142
156
|
structuralSharing: StructuralSharingValue<TData>;
|
|
157
|
+
refetchOnWindowFocus: boolean | 'always';
|
|
158
|
+
refetchOnReconnect: boolean | 'always';
|
|
143
159
|
};
|
|
144
160
|
/** Reactive result returned by {@link injectQuery}; every field is a signal. */
|
|
145
161
|
type QueryResult<TData, TError = Error> = {
|
|
@@ -183,6 +199,10 @@ interface DefaultQueryOptions {
|
|
|
183
199
|
retryDelay?: RetryDelayValue<unknown>;
|
|
184
200
|
/** Whether new data keeps the parts of the cached data that didn't change. Defaults to `true`. */
|
|
185
201
|
structuralSharing?: StructuralSharingValue<unknown>;
|
|
202
|
+
/** Whether queries refetch when the user comes back to the page. Defaults to `true`. */
|
|
203
|
+
refetchOnWindowFocus?: boolean | 'always';
|
|
204
|
+
/** Whether queries refetch when the network comes back. Defaults to `true`. */
|
|
205
|
+
refetchOnReconnect?: boolean | 'always';
|
|
186
206
|
}
|
|
187
207
|
/**
|
|
188
208
|
* Default mutation options applied to every mutation. A mutation's own value
|
|
@@ -215,18 +235,19 @@ interface DefaultOptions {
|
|
|
215
235
|
|
|
216
236
|
/**
|
|
217
237
|
* An observer of a query, as the query sees it: the query asks its observers
|
|
218
|
-
* how to fetch it when it refetches on their behalf (after invalidation
|
|
219
|
-
* how data written into it by hand merges.
|
|
238
|
+
* how to fetch it when it refetches on their behalf (after invalidation, on
|
|
239
|
+
* window focus or reconnect), and how data written into it by hand merges.
|
|
220
240
|
*
|
|
221
241
|
* @internal
|
|
222
242
|
*/
|
|
223
243
|
interface QuerySubscriber<TData, TError = Error> {
|
|
224
244
|
/**
|
|
225
|
-
* How this observer would fetch the query right now,
|
|
226
|
-
* options; `null` while it doesn't want the
|
|
227
|
-
* or its key has already moved on to another
|
|
245
|
+
* How this observer would fetch the query right now, and when it wants it
|
|
246
|
+
* refetched, read from its live options; `null` while it doesn't want the
|
|
247
|
+
* query fetched: it is disabled, or its key has already moved on to another
|
|
248
|
+
* query.
|
|
228
249
|
*/
|
|
229
|
-
fetchOptions(): Pick<DefaultedQueryOptions<TData, TError>, 'queryFn' | 'retry' | 'retryDelay' | 'structuralSharing'> | null;
|
|
250
|
+
fetchOptions(): Pick<DefaultedQueryOptions<TData, TError>, 'queryFn' | 'retry' | 'retryDelay' | 'structuralSharing' | 'staleTime' | 'refetchOnWindowFocus' | 'refetchOnReconnect'> | null;
|
|
230
251
|
/**
|
|
231
252
|
* How this observer merges data written into the query by hand, read from
|
|
232
253
|
* its live options, whether it's enabled or not.
|
|
@@ -245,10 +266,12 @@ declare class Query<TData, TError = Error> {
|
|
|
245
266
|
addObserver(observer: QuerySubscriber<TData, TError>): void;
|
|
246
267
|
removeObserver(observer: QuerySubscriber<TData, TError>): void;
|
|
247
268
|
activeFetchOptions(): ReturnType<QuerySubscriber<TData, TError>['fetchOptions']>;
|
|
269
|
+
onFocus(): void;
|
|
270
|
+
onOnline(): void;
|
|
248
271
|
structuralSharing(): StructuralSharingValue<TData> | undefined;
|
|
249
272
|
fetch({ queryFn, retry, retryDelay, structuralSharing, }: Pick<QueryOptions<TData, TError>, 'queryFn' | 'retry' | 'retryDelay' | 'structuralSharing'>, { cancelRefetch }?: {
|
|
250
273
|
cancelRefetch?: boolean;
|
|
251
|
-
}):
|
|
274
|
+
}): Promise<TData>;
|
|
252
275
|
setData(data: TData, { updatedAt, structuralSharing, }?: {
|
|
253
276
|
updatedAt?: number;
|
|
254
277
|
structuralSharing?: StructuralSharingValue<TData>;
|
|
@@ -423,8 +446,9 @@ declare class QueryClient {
|
|
|
423
446
|
getMutationCache(): MutationCache;
|
|
424
447
|
/**
|
|
425
448
|
* Merges per-query options with the configured defaults, filling in
|
|
426
|
-
* `staleTime`, `gcTime`, `retry`, `retryDelay
|
|
427
|
-
* Used internally by
|
|
449
|
+
* `staleTime`, `gcTime`, `retry`, `retryDelay`, `structuralSharing`,
|
|
450
|
+
* `refetchOnWindowFocus` and `refetchOnReconnect`. Used internally by
|
|
451
|
+
* {@link injectQuery}.
|
|
428
452
|
*/
|
|
429
453
|
defaultQueryOptions<TData, TError = Error>(options: QueryOptions<TData, TError>): DefaultedQueryOptions<TData, TError>;
|
|
430
454
|
/**
|
package/package.json
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ngx-signal-query",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.5.0-dev.2",
|
|
4
|
+
"description": "Data fetching, caching and mutations for Angular, built on signals and RxJS. Observables end to end, TanStack Query concepts.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
7
7
|
"signals",
|
|
8
|
+
"rxjs",
|
|
9
|
+
"observable",
|
|
10
|
+
"httpclient",
|
|
8
11
|
"query",
|
|
9
12
|
"tanstack",
|
|
10
13
|
"tanstack-query",
|
|
11
14
|
"data-fetching",
|
|
15
|
+
"server-state",
|
|
12
16
|
"cache",
|
|
13
17
|
"mutations",
|
|
14
18
|
"async-state"
|
|
@@ -25,6 +29,7 @@
|
|
|
25
29
|
"url": "https://github.com/dhutaryan/ngx-signal-query/issues"
|
|
26
30
|
},
|
|
27
31
|
"peerDependencies": {
|
|
32
|
+
"@angular/common": ">=19.0.0",
|
|
28
33
|
"@angular/core": ">=19.0.0",
|
|
29
34
|
"rxjs": "^7.4.0"
|
|
30
35
|
},
|