@mmstack/resource 19.7.0 → 19.7.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 +95 -2
- package/fesm2022/mmstack-resource.mjs +125 -37
- package/fesm2022/mmstack-resource.mjs.map +1 -1
- package/lib/mutation-resource.d.ts +1 -7
- package/lib/util/cache/cache.d.ts +20 -0
- package/lib/util/cache/index.d.ts +1 -1
- package/lib/util/cache/public_api.d.ts +1 -1
- package/lib/util/public_api.d.ts +1 -0
- package/lib/util/sensors.d.ts +25 -2
- package/package.json +1 -1
|
@@ -193,7 +193,6 @@ export type MutationResourceRef<TResult, TMutation = TResult, TICTX = void> = Om
|
|
|
193
193
|
* @typeParam TMutation - The type of the mutation value (the request body).
|
|
194
194
|
* @typeParam TICTX - The type of the initial context value passed to `onMutate`.
|
|
195
195
|
* @typeParam TCTX - The type of the context value returned by `onMutate`.
|
|
196
|
-
* @typeParam TMethod - The HTTP method to be used for the mutation (defaults to `HttpResourceRequest['method']`).
|
|
197
196
|
* @returns A `MutationResourceRef` instance, which provides methods for triggering the mutation
|
|
198
197
|
* and observing its status.
|
|
199
198
|
*
|
|
@@ -227,9 +226,4 @@ export type MutationResourceRef<TResult, TMutation = TResult, TICTX = void> = Om
|
|
|
227
226
|
* );
|
|
228
227
|
* ```
|
|
229
228
|
*/
|
|
230
|
-
export declare function mutationResource<TResult, TRaw = TResult, TMutation = TResult, TCTX = void, TICTX = TCTX>(request: (params: TMutation) =>
|
|
231
|
-
method: 'DELETE' | 'delete';
|
|
232
|
-
}) | undefined | void, options0?: MutationResourceOptions<TResult, TRaw, TMutation, TCTX, TICTX>): MutationResourceRef<TResult, TMutation, TICTX>;
|
|
233
|
-
export declare function mutationResource<TResult, TRaw = TResult, TMutation = TResult, TCTX = void, TICTX = TCTX>(request: (params: TMutation) => (Omit<HttpResourceRequest, 'body'> & {
|
|
234
|
-
body: TMutation;
|
|
235
|
-
}) | undefined | void, options0?: MutationResourceOptions<TResult, TRaw, TMutation, TCTX, TICTX>): MutationResourceRef<TResult, TMutation, TICTX>;
|
|
229
|
+
export declare function mutationResource<TResult, TRaw = TResult, TMutation = TResult, TCTX = void, TICTX = TCTX>(request: (params: TMutation) => HttpResourceRequest | undefined | void, options0?: MutationResourceOptions<TResult, TRaw, TMutation, TCTX, TICTX>): MutationResourceRef<TResult, TMutation, TICTX>;
|
|
@@ -265,6 +265,26 @@ type CacheOptions = {
|
|
|
265
265
|
*/
|
|
266
266
|
version?: number;
|
|
267
267
|
};
|
|
268
|
+
/**
|
|
269
|
+
* Provides a deterministic, in-memory `QueryCache` for unit tests.
|
|
270
|
+
*
|
|
271
|
+
* Unlike {@link provideQueryCache} this never touches IndexedDB or BroadcastChannel
|
|
272
|
+
* and disables the cleanup sweep interval (`checkInterval: Infinity`), so it plays
|
|
273
|
+
* nicely with `vi.useFakeTimers()`. It's a real cache (not a stub), so you can
|
|
274
|
+
* assert cache hits via {@link injectQueryCache} / its `stats` signal.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* TestBed.configureTestingModule({
|
|
278
|
+
* providers: [
|
|
279
|
+
* provideMockQueryCache(),
|
|
280
|
+
* provideHttpClient(withInterceptors([createCacheInterceptor()])),
|
|
281
|
+
* ],
|
|
282
|
+
* });
|
|
283
|
+
*/
|
|
284
|
+
export declare function provideMockQueryCache(opt?: {
|
|
285
|
+
ttl?: number;
|
|
286
|
+
staleTime?: number;
|
|
287
|
+
}): Provider;
|
|
268
288
|
/**
|
|
269
289
|
* Provides the instance of the QueryCache for queryResource. This should probably be called
|
|
270
290
|
* in your application's root configuration, but can also be overriden with component/module providers.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Cache, injectCacheStats, injectQueryCache, provideQueryCache, } from './cache';
|
|
1
|
+
export { Cache, injectCacheStats, injectQueryCache, provideMockQueryCache, provideQueryCache, } from './cache';
|
|
2
2
|
export * from './cache-interceptor';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Cache, injectQueryCache, provideQueryCache, type CacheEntry, type CleanupType, } from './cache';
|
|
1
|
+
export { Cache, injectQueryCache, provideMockQueryCache, provideQueryCache, type CacheEntry, type CleanupType, } from './cache';
|
|
2
2
|
export { createCacheInterceptor } from './cache-interceptor';
|
package/lib/util/public_api.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export * from './cache/public_api';
|
|
|
2
2
|
export { createCircuitBreaker, provideCircuitBreakerDefaultOptions, } from './circuit-breaker';
|
|
3
3
|
export { createDedupeRequestsInterceptor, noDedupe, } from './dedupe-interceptor';
|
|
4
4
|
export { hashRequest } from './hash-request';
|
|
5
|
+
export { provideMockResourceSensors } from './sensors';
|
package/lib/util/sensors.d.ts
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
|
+
import { type Provider, type Signal } from '@angular/core';
|
|
1
2
|
import * as i0 from "@angular/core";
|
|
2
3
|
export declare class ResourceSensors {
|
|
3
4
|
readonly networkStatus: import("@mmstack/primitives").NetworkStatusSignal;
|
|
4
|
-
readonly pageVisibility:
|
|
5
|
+
readonly pageVisibility: Signal<DocumentVisibilityState>;
|
|
5
6
|
static ɵfac: i0.ɵɵFactoryDeclaration<ResourceSensors, never>;
|
|
6
7
|
static ɵprov: i0.ɵɵInjectableDeclaration<ResourceSensors>;
|
|
7
8
|
}
|
|
8
9
|
export declare function injectNetworkStatus(): import("@mmstack/primitives").NetworkStatusSignal;
|
|
9
|
-
export declare function injectPageVisibility():
|
|
10
|
+
export declare function injectPageVisibility(): Signal<DocumentVisibilityState>;
|
|
11
|
+
/**
|
|
12
|
+
* Provides controllable {@link ResourceSensors} for unit tests, letting you drive a
|
|
13
|
+
* resource's offline / page-hidden behavior deterministically instead of relying on
|
|
14
|
+
* the real `navigator.onLine` / `document.visibilityState`.
|
|
15
|
+
*
|
|
16
|
+
* Pass your own writable signals to toggle state mid-test; omit them for a static
|
|
17
|
+
* online + visible environment.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import { signal } from '@angular/core';
|
|
21
|
+
*
|
|
22
|
+
* const online = signal(true);
|
|
23
|
+
* TestBed.configureTestingModule({
|
|
24
|
+
* providers: [provideMockResourceSensors({ networkStatus: online })],
|
|
25
|
+
* });
|
|
26
|
+
* // ...later in the test
|
|
27
|
+
* online.set(false); // the resource now sees the network as down
|
|
28
|
+
*/
|
|
29
|
+
export declare function provideMockResourceSensors(opt?: {
|
|
30
|
+
networkStatus?: Signal<boolean>;
|
|
31
|
+
pageVisibility?: Signal<DocumentVisibilityState>;
|
|
32
|
+
}): Provider;
|