@mmstack/resource 21.5.0 → 21.5.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/resource",
3
- "version": "21.5.0",
3
+ "version": "21.5.1",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -273,6 +273,26 @@ type CacheOptions = {
273
273
  */
274
274
  version?: number;
275
275
  };
276
+ /**
277
+ * Provides a deterministic, in-memory `QueryCache` for unit tests.
278
+ *
279
+ * Unlike {@link provideQueryCache} this never touches IndexedDB or BroadcastChannel
280
+ * and disables the cleanup sweep interval (`checkInterval: Infinity`), so it plays
281
+ * nicely with `vi.useFakeTimers()`. It's a real cache (not a stub), so you can
282
+ * assert cache hits via {@link injectQueryCache} / its `stats` signal.
283
+ *
284
+ * @example
285
+ * TestBed.configureTestingModule({
286
+ * providers: [
287
+ * provideMockQueryCache(),
288
+ * provideHttpClient(withInterceptors([createCacheInterceptor()])),
289
+ * ],
290
+ * });
291
+ */
292
+ declare function provideMockQueryCache(opt?: {
293
+ ttl?: number;
294
+ staleTime?: number;
295
+ }): Provider;
276
296
  /**
277
297
  * Provides the instance of the QueryCache for queryResource. This should probably be called
278
298
  * in your application's root configuration, but can also be overriden with component/module providers.
@@ -606,6 +626,29 @@ type RetryOptions = number | {
606
626
  backoff?: number;
607
627
  };
608
628
 
629
+ /**
630
+ * Provides controllable {@link ResourceSensors} for unit tests, letting you drive a
631
+ * resource's offline / page-hidden behavior deterministically instead of relying on
632
+ * the real `navigator.onLine` / `document.visibilityState`.
633
+ *
634
+ * Pass your own writable signals to toggle state mid-test; omit them for a static
635
+ * online + visible environment.
636
+ *
637
+ * @example
638
+ * import { signal } from '@angular/core';
639
+ *
640
+ * const online = signal(true);
641
+ * TestBed.configureTestingModule({
642
+ * providers: [provideMockResourceSensors({ networkStatus: online })],
643
+ * });
644
+ * // ...later in the test
645
+ * online.set(false); // the resource now sees the network as down
646
+ */
647
+ declare function provideMockResourceSensors(opt?: {
648
+ networkStatus?: Signal<boolean>;
649
+ pageVisibility?: Signal<DocumentVisibilityState>;
650
+ }): Provider;
651
+
609
652
  /**
610
653
  * Options for enabling and configuring caching for a resource.
611
654
  *
@@ -1314,5 +1357,5 @@ declare function mutationResource<TResult, TRaw = TResult, TMutation = TResult,
1314
1357
  body: TMutation;
1315
1358
  }) | undefined | void, options0?: MutationResourceOptions<TResult, TRaw, TMutation, TCTX, TICTX>): MutationResourceRef<TResult, TMutation, TICTX>;
1316
1359
 
1317
- export { Cache, MutationCancelledError, PAUSED, applyResourceRegistration, createCacheInterceptor, createCircuitBreaker, createDedupeRequestsInterceptor, hashRequest, infiniteQueryResource, injectQueryCache, injectResourceOptions, manualQueryResource, mutationResource, noDedupe, provideCircuitBreakerDefaultOptions, provideMutationResourceOptions, provideQueryCache, provideQueryResourceOptions, provideResourceOptions, provideTypedResourceOptions, queryResource };
1360
+ export { Cache, MutationCancelledError, PAUSED, applyResourceRegistration, createCacheInterceptor, createCircuitBreaker, createDedupeRequestsInterceptor, hashRequest, infiniteQueryResource, injectQueryCache, injectResourceOptions, manualQueryResource, mutationResource, noDedupe, provideCircuitBreakerDefaultOptions, provideMockQueryCache, provideMockResourceSensors, provideMutationResourceOptions, provideQueryCache, provideQueryResourceOptions, provideResourceOptions, provideTypedResourceOptions, queryResource };
1318
1361
  export type { CacheEntry, CleanupType, CommonResourceOptions, DisabledReason, InfiniteQueryResourceOptions, InfiniteQueryResourceRef, InfiniteRequestContext, ManualQueryResourceRef, MutationCancellationReason, MutationQueueOptions, MutationResourceOptions, MutationResourceRef, QueryResourceOptions, QueryResourceRef, RefreshOptions, RequestContext, ResourceCacheOptions, ResourceRequestFn, TransitionRegistration };