@mmstack/resource 19.2.0 → 19.3.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.
@@ -6,10 +6,10 @@ import { type QueryResourceOptions, type QueryResourceRef } from './query-resour
6
6
  * Helper type for inferring the request body type based on the HTTP method.
7
7
  */
8
8
  type NextRequest<TMethod extends HttpResourceRequest['method'], TMutation> = TMethod extends 'DELETE' | 'delete' ? Omit<HttpResourceRequest, 'body' | 'method'> & {
9
- method?: TMethod;
9
+ method: TMethod;
10
10
  } : Omit<HttpResourceRequest, 'body' | 'method'> & {
11
11
  body: TMutation;
12
- method?: TMethod;
12
+ method: TMethod;
13
13
  };
14
14
  /**
15
15
  * Options for configuring a `mutationResource`.
@@ -18,7 +18,7 @@ type NextRequest<TMethod extends HttpResourceRequest['method'], TMutation> = TMe
18
18
  * @typeParam TRaw - The raw response type from the HTTP request (defaults to TResult).
19
19
  * @typeParam TCTX - The type of the context value returned by `onMutate`.
20
20
  */
21
- export type MutationResourceOptions<TResult, TRaw = TResult, TMutation = TResult, TCTX = void, TICTX = TCTX> = Omit<QueryResourceOptions<TResult, TRaw>, 'equal' | 'onError' | 'keepPrevious' | 'refresh' | 'cache'> & {
21
+ export type MutationResourceOptions<TResult, TRaw = TResult, TMutation = TResult, TCTX = void, TICTX = TCTX, TError = unknown> = Omit<QueryResourceOptions<TResult, TRaw>, 'equal' | 'onError' | 'keepPrevious' | 'refresh' | 'cache'> & {
22
22
  /**
23
23
  * A callback function that is called before the mutation request is made.
24
24
  * @param value The value being mutated (the `body` of the request).
@@ -31,18 +31,23 @@ export type MutationResourceOptions<TResult, TRaw = TResult, TMutation = TResult
31
31
  * @param error The error that occurred.
32
32
  * @param ctx The context value returned by the `onMutate` callback (or `undefined` if `onMutate` was not provided or returned `undefined`).
33
33
  */
34
- onError?: (error: unknown, ctx: NoInfer<TCTX>) => void;
34
+ onError?: (error: TError, ctx: NoInfer<TCTX>) => void;
35
35
  /**
36
36
  * A callback function that is called if the mutation request succeeds.
37
37
  * @param value The result of the mutation (the parsed response body).
38
38
  * @param ctx The context value returned by the `onMutate` callback (or `undefined` if `onMutate` was not provided or returned `undefined`).
39
39
  */
40
- onSuccess?: (value: NoInfer<TResult>, ctx: NoInfer<TCTX>) => void;
40
+ onSuccess?: (value: TResult, ctx: NoInfer<TCTX>) => void;
41
41
  /**
42
42
  * A callback function that is called when the mutation request settles (either succeeds or fails).
43
43
  * @param ctx The context value returned by the `onMutate` callback (or `undefined` if `onMutate` was not provided or returned `undefined`).
44
44
  */
45
45
  onSettled?: (ctx: NoInfer<TCTX>) => void;
46
+ /**
47
+ * Whether to queue the mutation requests and execute them in series. For example if network is unavailable or circuit breaker is open.
48
+ * @default false
49
+ */
50
+ queue?: boolean;
46
51
  equal?: ValueEqualityFn<TMutation>;
47
52
  };
48
53
  /**
@@ -51,22 +56,19 @@ export type MutationResourceOptions<TResult, TRaw = TResult, TMutation = TResult
51
56
  *
52
57
  * @typeParam TResult - The type of the expected result from the mutation.
53
58
  */
54
- export type MutationResourceRef<TResult, TMutation = TResult, TICTX = void, TMethod extends HttpResourceRequest['method'] = HttpResourceRequest['method']> = Omit<QueryResourceRef<TResult>, 'prefetch' | 'value' | 'hasValue' | 'set' | 'update'> & {
59
+ export type MutationResourceRef<TResult, TMutation = TResult, TICTX = void> = Omit<QueryResourceRef<TResult>, 'prefetch' | 'value' | 'hasValue' | 'set' | 'update'> & {
55
60
  /**
56
61
  * Executes the mutation.
57
62
  *
58
- * @param value The request body and any other request parameters to use for the mutation. The `body` property is *required*.
63
+ * @param value The mutation value (usually the request body).
64
+ * @param ctx An optional initial context value that will be passed to the `onMutate` callback.
59
65
  */
60
- mutate: (value: Omit<NextRequest<TMethod, TMutation>, 'url'> & {
61
- url?: string;
62
- }, ctx?: TICTX) => void;
66
+ mutate: (value: TMutation, ctx?: TICTX) => void;
63
67
  /**
64
68
  * A signal that holds the current mutation request, or `null` if no mutation is in progress.
65
69
  * This can be useful for tracking the state of the mutation or for displaying loading indicators.
66
70
  */
67
- current: Signal<(Omit<NextRequest<TMethod, TMutation>, 'url'> & {
68
- url?: string;
69
- }) | null>;
71
+ current: Signal<TMutation | null>;
70
72
  };
71
73
  /**
72
74
  * Creates a resource for performing mutations (e.g., POST, PUT, PATCH, DELETE requests).
@@ -75,18 +77,17 @@ export type MutationResourceRef<TResult, TMutation = TResult, TICTX = void, TMet
75
77
  * managing the mutation lifecycle (pending, error, success) and provides callbacks for handling
76
78
  * these states.
77
79
  *
78
- * @param request A function that returns the base `HttpResourceRequest` to be made. This
79
- * function is called reactively. Unlike `queryResource`, the `body` property
80
- * of the request is provided when `mutate` is called, *not* here. If the
81
- * function returns `undefined`, the mutation is considered "disabled." All properties,
82
- * except the body, can be set here.
80
+ * @param request A function that returns the base `HttpResourceRequest` to be made. This function is called reactively. The parameter is the mutation value provided by the `mutate` method.
83
81
  * @param options Configuration options for the mutation resource. This includes callbacks
84
82
  * for `onMutate`, `onError`, `onSuccess`, and `onSettled`.
85
83
  * @typeParam TResult - The type of the expected result from the mutation.
86
84
  * @typeParam TRaw - The raw response type from the HTTP request (defaults to TResult).
85
+ * @typeParam TMutation - The type of the mutation value (the request body).
86
+ * @typeParam TICTX - The type of the initial context value passed to `onMutate`.
87
87
  * @typeParam TCTX - The type of the context value returned by `onMutate`.
88
+ * @typeParam TMethod - The HTTP method to be used for the mutation (defaults to `HttpResourceRequest['method']`).
88
89
  * @returns A `MutationResourceRef` instance, which provides methods for triggering the mutation
89
90
  * and observing its status.
90
91
  */
91
- export declare function mutationResource<TResult, TRaw = TResult, TMutation = TResult, TCTX = void, TICTX = TCTX, TMethod extends HttpResourceRequest['method'] = HttpResourceRequest['method']>(request: () => Omit<NextRequest<TMethod, TMutation>, 'body'> | undefined | void, options?: MutationResourceOptions<TResult, TRaw, TMutation, TCTX, TICTX>): MutationResourceRef<TResult, TMutation, TICTX, TMethod>;
92
+ export declare function mutationResource<TResult, TRaw = TResult, TMutation = TResult, TCTX = void, TICTX = TCTX, TMethod extends HttpResourceRequest['method'] = HttpResourceRequest['method']>(request: (params: TMutation) => Omit<NextRequest<TMethod, TMutation>, 'body'> | undefined | void, options?: MutationResourceOptions<TResult, TRaw, TMutation, TCTX, TICTX>): MutationResourceRef<TResult, TMutation, TICTX>;
92
93
  export {};
@@ -1,5 +1,5 @@
1
- import { type HttpResourceOptions, type HttpResourceRef, type HttpResourceRequest } from '@angular/common/http';
2
- import { Signal } from '@angular/core';
1
+ import { HttpHeaders, type HttpResourceOptions, type HttpResourceRef, type HttpResourceRequest } from '@angular/common/http';
2
+ import { Signal, WritableSignal } from '@angular/core';
3
3
  import { CircuitBreakerOptions, type RetryOptions } from './util';
4
4
  /**
5
5
  * Options for configuring caching behavior of a `queryResource`.
@@ -23,6 +23,25 @@ type ResourceCacheOptions = true | {
23
23
  * for instance, to ignore certain query parameters or to use request body for the cache key.
24
24
  */
25
25
  hash?: (req: HttpResourceRequest) => string;
26
+ /**
27
+ * Whether to bust the browser cache by appending a unique query parameter to the request URL.
28
+ * This is useful for ensuring that the latest data is fetched from the server, bypassing any
29
+ * cached responses in the browser. The unique parameter is removed before calling the cache function, so it does not affect the cache key.
30
+ * @default false - By default, the resource will not bust the browser cache.
31
+ */
32
+ bustBrowserCache?: boolean;
33
+ /**
34
+ * Whether to ignore the `Cache-Control` headers from the server when caching responses.
35
+ * If set to `true`, the resource will not respect any cache directives from the server,
36
+ * allowing you to control caching behavior entirely through the resource options.
37
+ * @default false - By default the resource will respect `Cache-Control` headers.
38
+ */
39
+ ignoreCacheControl?: boolean;
40
+ /**
41
+ * Whether to persist the cache entry in the local DB instance.
42
+ * @default false - By default, the cache entry is not persisted.
43
+ */
44
+ persist?: boolean;
26
45
  };
27
46
  /**
28
47
  * Options for configuring a `queryResource`.
@@ -55,11 +74,24 @@ export type QueryResourceOptions<TResult, TRaw = TResult> = HttpResourceOptions<
55
74
  * Options for enabling and configuring caching for the resource.
56
75
  */
57
76
  cache?: ResourceCacheOptions;
77
+ /**
78
+ * Trigger a request every time the request function is triggered, even if the request parameters are the same.
79
+ * @default false
80
+ */
81
+ triggerOnSameRequest?: boolean;
58
82
  };
59
83
  /**
60
84
  * Represents a resource created by `queryResource`. Extends `HttpResourceRef` with additional properties.
61
85
  */
62
- export type QueryResourceRef<TResult> = HttpResourceRef<TResult> & {
86
+ export type QueryResourceRef<TResult> = Omit<HttpResourceRef<TResult>, 'headers' | 'statusCode'> & {
87
+ /**
88
+ * Linkedsignal of the response headers, when available.
89
+ */
90
+ readonly headers: WritableSignal<HttpHeaders | undefined>;
91
+ /**
92
+ * Linkedsignal of the response status code, when available.
93
+ */
94
+ readonly statusCode: WritableSignal<number | undefined>;
63
95
  /**
64
96
  * A signal indicating whether the resource is currently disabled (due to circuit breaker or undefined request).
65
97
  */
@@ -71,16 +103,27 @@ export type QueryResourceRef<TResult> = HttpResourceRef<TResult> & {
71
103
  * @param req - Optional partial request parameters to use for the prefetch. This allows you
72
104
  * to prefetch data with different parameters than the main resource request.
73
105
  */
74
- prefetch: (req?: Partial<HttpResourceRequest>) => Promise<void>;
106
+ prefetch: (req?: Partial<HttpResourceRequest> | string) => Promise<void>;
75
107
  };
76
- export declare function queryResource<TResult, TRaw = TResult>(request: () => HttpResourceRequest | undefined | void, options: QueryResourceOptions<TResult, TRaw> & {
108
+ /**
109
+ * Creates an HTTP resource with features like caching, retries, refresh intervals, circuit breaker, and optimistic updates. Without additional options it is equivalent to simply calling `httpResource`.
110
+ * This overload is for when a `defaultValue` is provided, ensuring that the resource's value is always defined.
111
+ * @param request A function that returns the `HttpResourceRequest` or a URL string to be made. This function
112
+ * is called reactively, so the request can change over time. If the function
113
+ * returns `undefined`, the resource is considered "disabled" and no request will be made.
114
+ * @param options Configuration options for the resource. These options extend the basic
115
+ * `HttpResourceOptions` and add features like `keepPrevious`, `refresh`, `retry`,
116
+ * `onError`, `circuitBreaker`, and `cache`. Additionally, when a `defaultValue` is provided, the resource's value will always be defined, even if the underlying HTTP request fails or is disabled.
117
+ * @returns An `QueryResourceRef` instance, which extends the basic `HttpResourceRef` with additional features.
118
+ */
119
+ export declare function queryResource<TResult, TRaw = TResult>(request: () => HttpResourceRequest | string | undefined | void, options: QueryResourceOptions<TResult, TRaw> & {
77
120
  defaultValue: NoInfer<TResult>;
78
121
  }): QueryResourceRef<TResult>;
79
122
  /**
80
123
  * Creates an extended HTTP resource with features like caching, retries, refresh intervals,
81
124
  * circuit breaker, and optimistic updates. Without additional options it is equivalent to simply calling `httpResource`.
82
125
  *
83
- * @param request A function that returns the `HttpResourceRequest` to be made. This function
126
+ * @param request A function that returns the `HttpResourceRequest` or a URL string to be made. This function
84
127
  * is called reactively, so the request can change over time. If the function
85
128
  * returns `undefined`, the resource is considered "disabled" and no request will be made.
86
129
  * @param options Configuration options for the resource. These options extend the basic
@@ -88,5 +131,5 @@ export declare function queryResource<TResult, TRaw = TResult>(request: () => Ht
88
131
  * `onError`, `circuitBreaker`, and `cache`.
89
132
  * @returns An `QueryResourceRef` instance, which extends the basic `HttpResourceRef` with additional features.
90
133
  */
91
- export declare function queryResource<TResult, TRaw = TResult>(request: () => HttpResourceRequest | undefined | void, options?: QueryResourceOptions<TResult, TRaw>): QueryResourceRef<TResult | undefined>;
134
+ export declare function queryResource<TResult, TRaw = TResult>(request: () => HttpResourceRequest | string | undefined | void, options?: QueryResourceOptions<TResult, TRaw>): QueryResourceRef<TResult | undefined>;
92
135
  export {};
@@ -4,6 +4,10 @@ type CacheEntryOptions = {
4
4
  ttl?: number;
5
5
  staleTime?: number;
6
6
  cache: boolean;
7
+ bustBrowserCache?: boolean;
8
+ ignoreCacheControl?: boolean;
9
+ parse?: (val: unknown) => unknown;
10
+ persist?: boolean;
7
11
  };
8
12
  export declare function setCacheContext(ctx: HttpContext | undefined, opt: Omit<CacheEntryOptions, 'cache' | 'key'> & {
9
13
  key: Required<CacheEntryOptions>['key'];
@@ -1,5 +1,6 @@
1
- import type { HttpResponse } from '@angular/common/http';
1
+ import { HttpResponse } from '@angular/common/http';
2
2
  import { Injector, type Provider, type Signal } from '@angular/core';
3
+ import { CacheDB } from './persistence';
3
4
  /**
4
5
  * Options for configuring the Least Recently Used (LRU) cache cleanup strategy.
5
6
  * @internal
@@ -36,13 +37,15 @@ type OldsetCleanupType = {
36
37
  * Represents an entry in the cache.
37
38
  * @internal
38
39
  */
39
- type CacheEntry<T> = {
40
+ export type CacheEntry<T> = {
40
41
  value: T;
41
42
  created: number;
43
+ updated: number;
42
44
  stale: number;
43
45
  useCount: number;
44
46
  expiresAt: number;
45
47
  timeout: ReturnType<typeof setTimeout>;
48
+ key: string;
46
49
  };
47
50
  /**
48
51
  * Defines the types of cleanup strategies available for the cache.
@@ -58,8 +61,16 @@ export type CleanupType = LRUCleanupType | OldsetCleanupType;
58
61
  export declare class Cache<T> {
59
62
  protected readonly ttl: number;
60
63
  protected readonly staleTime: number;
64
+ private readonly db;
61
65
  private readonly internal;
62
66
  private readonly cleanupOpt;
67
+ private readonly id;
68
+ /**
69
+ * Destroys the cache instance, cleaning up any resources used by the cache.
70
+ * This method is called automatically when the cache instance is garbage collected.
71
+ */
72
+ readonly destroy: () => void;
73
+ private readonly broadcast;
63
74
  /**
64
75
  * Creates a new `Cache` instance.
65
76
  *
@@ -68,8 +79,14 @@ export declare class Cache<T> {
68
79
  * stale but can still be used while revalidation occurs in the background. Defaults to 1 hour.
69
80
  * @param cleanupOpt - Options for configuring the cache cleanup strategy. Defaults to LRU with a
70
81
  * `maxSize` of 200 and a `checkInterval` of one hour.
82
+ * @param syncTabs - If provided, the cache will use the options a BroadcastChannel to send updates between tabs.
83
+ * Defaults to `undefined`, meaning no synchronization across tabs.
71
84
  */
72
- constructor(ttl?: number, staleTime?: number, cleanupOpt?: Partial<CleanupType>);
85
+ constructor(ttl?: number, staleTime?: number, cleanupOpt?: Partial<CleanupType>, syncTabs?: {
86
+ id: string;
87
+ serialize: (value: T) => string;
88
+ deserialize: (value: string) => T | null;
89
+ }, db?: Promise<CacheDB<T>>);
73
90
  /** @internal */
74
91
  private getInternal;
75
92
  /**
@@ -92,6 +109,16 @@ export declare class Cache<T> {
92
109
  get(key: () => string | null): Signal<(CacheEntry<T> & {
93
110
  isStale: boolean;
94
111
  }) | null>;
112
+ /**
113
+ * Retrieves a cache entry or an object with the key if not found.
114
+ *
115
+ * @param key - A function that returns the cache key. The key is a signal, allowing for dynamic keys. If the function returns null the value is also null.
116
+ * @returns A signal that holds the cache entry or an object with the key if not found. The signal
117
+ * updates whenever the cache entry changes (e.g., due to revalidation or expiration).
118
+ */
119
+ getEntryOrKey(key: () => string | null): Signal<(CacheEntry<T> & {
120
+ isStale: boolean;
121
+ }) | string | null>;
95
122
  /**
96
123
  * Stores a value in the cache.
97
124
  *
@@ -100,13 +127,15 @@ export declare class Cache<T> {
100
127
  * @param staleTime - (Optional) The stale time for this entry, in milliseconds. Overrides the default `staleTime`.
101
128
  * @param ttl - (Optional) The TTL for this entry, in milliseconds. Overrides the default `ttl`.
102
129
  */
103
- store(key: string, value: T, staleTime?: number, ttl?: number): void;
130
+ store(key: string, value: T, staleTime?: number, ttl?: number, persist?: boolean): void;
131
+ private storeInternal;
104
132
  /**
105
133
  * Invalidates (removes) a cache entry.
106
134
  *
107
135
  * @param key - The key of the entry to invalidate.
108
136
  */
109
137
  invalidate(key: string): void;
138
+ private invalidateInternal;
110
139
  /** @internal */
111
140
  private cleanup;
112
141
  }
@@ -127,6 +156,23 @@ type CacheOptions = {
127
156
  * Options for configuring the cache cleanup strategy.
128
157
  */
129
158
  cleanup?: Partial<CleanupType>;
159
+ /**
160
+ * Whether to synchronize cache across tabs. If true, the cache will use a BroadcastChannel to send updates between tabs.
161
+ */
162
+ syncTabs?: boolean;
163
+ /**
164
+ * Globally disable persistence of cache entries.
165
+ * If set to `false`, cache entries will not be persisted to the database.
166
+ * `true` means, cache entries can be persisted, they must still be opted into on the resource level & allowed by server headers.
167
+ * @default true
168
+ */
169
+ persist?: boolean;
170
+ /**
171
+ * Version of the caches database, increment this if the interfaces change, this will cause the old data to be deleted.
172
+ * Minimum value is 1, so first increment should be 2.
173
+ * @default 1
174
+ */
175
+ version?: number;
130
176
  };
131
177
  /**
132
178
  * Provides the instance of the QueryCache for queryResource. This should probably be called
@@ -173,5 +219,5 @@ export declare function provideQueryCache(opt?: CacheOptions): Provider;
173
219
  * }
174
220
  * }
175
221
  */
176
- export declare function injectQueryCache(injector?: Injector): Cache<HttpResponse<unknown>>;
222
+ export declare function injectQueryCache<TRaw = unknown>(injector?: Injector): Cache<HttpResponse<TRaw>>;
177
223
  export {};
@@ -1,2 +1,2 @@
1
1
  export { Cache, injectQueryCache, provideQueryCache } from './cache';
2
- export * from './cache.interceptor';
2
+ export * from './cache-interceptor';
@@ -0,0 +1,10 @@
1
+ import { CacheEntry } from './cache';
2
+ type StoredEntry<T> = Omit<CacheEntry<T>, 'timeout'>;
3
+ export type CacheDB<T> = {
4
+ getAll: () => Promise<StoredEntry<T>[]>;
5
+ store: (value: StoredEntry<T>) => Promise<void>;
6
+ remove: (key: string) => Promise<void>;
7
+ };
8
+ export declare function createNoopDB<T>(): CacheDB<T>;
9
+ export declare function createSingleStoreDB<T>(name: string, getStoreName: (version: number) => string, version?: number): Promise<CacheDB<T>>;
10
+ export {};
@@ -1,2 +1,2 @@
1
1
  export { Cache, injectQueryCache, provideQueryCache } from './cache';
2
- export { createCacheInterceptor } from './cache.interceptor';
2
+ export { createCacheInterceptor } from './cache-interceptor';
@@ -0,0 +1,2 @@
1
+ import { HttpResourceRef } from '@angular/common/http';
2
+ export declare function catchValueError<T>(resource: HttpResourceRef<T>, fallback: T): HttpResourceRef<T>;
@@ -1,4 +1,4 @@
1
- import { Signal } from '@angular/core';
1
+ import { Injector, Provider, Signal } from '@angular/core';
2
2
  /**
3
3
  * Represents the possible states of a circuit breaker.
4
4
  * - `CLOSED`: The circuit breaker is closed, and operations are allowed to proceed.
@@ -14,6 +14,12 @@ export type CircuitBreaker = {
14
14
  * A signal indicating whether the circuit breaker is currently closed (allowing operations).
15
15
  */
16
16
  isClosed: Signal<boolean>;
17
+ /**
18
+ * A signal indicating whether the circuit breaker is either open or in a half-open state.
19
+ * This is useful for checking if operations are blocked.
20
+ * If the circuit breaker is open, operations should not proceed.
21
+ */
22
+ isOpen: Signal<boolean>;
17
23
  /**
18
24
  * A signal representing the current state of the circuit breaker.
19
25
  */
@@ -21,7 +27,7 @@ export type CircuitBreaker = {
21
27
  /**
22
28
  * Signals a failure to the circuit breaker. This may cause the circuit breaker to open.
23
29
  */
24
- fail: () => void;
30
+ fail: (err?: Error) => void;
25
31
  /**
26
32
  * Signals a success to the circuit breaker. This may cause the circuit breaker to close.
27
33
  */
@@ -36,6 +42,31 @@ export type CircuitBreaker = {
36
42
  */
37
43
  destroy: () => void;
38
44
  };
45
+ /**
46
+ * Options for creating a circuit breaker.
47
+ */
48
+ type CreateCircuitBreakerOptions = {
49
+ /**
50
+ * The number of failures that will cause the circuit breaker to open.
51
+ * @default 5
52
+ */
53
+ treshold?: number;
54
+ /**
55
+ * The time in milliseconds after which the circuit breaker will reset and allow operations to proceed again.
56
+ * @default 30000 (30 seconds)
57
+ */
58
+ timeout?: number;
59
+ /**
60
+ * A function that determines whether an error should cause the circuit breaker to increment the failure count.
61
+ * @default Always returns true
62
+ */
63
+ shouldFail?: (err?: Error) => boolean;
64
+ /**
65
+ * A function that determines whether an error should cause the circuit breaker to be open forever.
66
+ * @default Always returns false
67
+ */
68
+ shouldFailForever?: (err?: Error) => boolean;
69
+ };
39
70
  /**
40
71
  * Options for creating a circuit breaker.
41
72
  * - `false`: Disables circuit breaker functionality (always open).
@@ -43,10 +74,8 @@ export type CircuitBreaker = {
43
74
  * - `CircuitBreaker`: Provides an existing `CircuitBreaker` instance to use.
44
75
  * - `{ treshold?: number; timeout?: number; }`: Creates a new circuit breaker with the specified options.
45
76
  */
46
- export type CircuitBreakerOptions = false | CircuitBreaker | {
47
- treshold?: number;
48
- timeout?: number;
49
- };
77
+ export type CircuitBreakerOptions = false | CircuitBreaker | CreateCircuitBreakerOptions;
78
+ export declare function provideCircuitBreakerDefaultOptions(options: CircuitBreakerOptions): Provider;
50
79
  /**
51
80
  * Creates a circuit breaker instance.
52
81
  *
@@ -70,5 +99,5 @@ export type CircuitBreakerOptions = false | CircuitBreaker | {
70
99
  * const resource1 = queryResource(..., { circuitBreaker: sharedBreaker });
71
100
  * const resource2 = mutationResource(..., { circuitBreaker: sharedBreaker });
72
101
  */
73
- export declare function createCircuitBreaker(opt?: CircuitBreakerOptions): CircuitBreaker;
102
+ export declare function createCircuitBreaker(opt?: CircuitBreakerOptions, injector?: Injector): CircuitBreaker;
74
103
  export {};
@@ -1,9 +1,12 @@
1
1
  export * from './cache';
2
+ export * from './catch-value-error';
2
3
  export * from './circuit-breaker';
3
- export * from './dedupe.interceptor';
4
+ export * from './dedupe-interceptor';
4
5
  export * from './equality';
5
6
  export * from './has-slow-connection';
6
7
  export * from './persist';
7
8
  export * from './refresh';
8
9
  export * from './retry-on-error';
10
+ export * from './sensors';
11
+ export * from './to-resource-object';
9
12
  export * from './url-with-params';
@@ -1,3 +1,3 @@
1
1
  import { type HttpResourceRef } from '@angular/common/http';
2
2
  import { type ValueEqualityFn } from '@angular/core';
3
- export declare function persistResourceValues<T>(resource: HttpResourceRef<T>, persist?: boolean, equal?: ValueEqualityFn<T>): HttpResourceRef<T>;
3
+ export declare function persistResourceValues<T>(resource: HttpResourceRef<T>, shouldPersist?: boolean, equal?: ValueEqualityFn<T>): HttpResourceRef<T>;
@@ -1,3 +1,3 @@
1
1
  export * from './cache/public_api';
2
- export { createCircuitBreaker } from './circuit-breaker';
3
- export { createDedupeRequestsInterceptor, noDedupe, } from './dedupe.interceptor';
2
+ export { createCircuitBreaker, provideCircuitBreakerDefaultOptions, } from './circuit-breaker';
3
+ export { createDedupeRequestsInterceptor, noDedupe, } from './dedupe-interceptor';
@@ -0,0 +1,7 @@
1
+ import * as i0 from "@angular/core";
2
+ export declare class ResourceSensors {
3
+ readonly networkStatus: import("@mmstack/primitives").NetworkStatusSignal;
4
+ static ɵfac: i0.ɵɵFactoryDeclaration<ResourceSensors, never>;
5
+ static ɵprov: i0.ɵɵInjectableDeclaration<ResourceSensors>;
6
+ }
7
+ export declare function injectNetworkStatus(): import("@mmstack/primitives").NetworkStatusSignal;
@@ -0,0 +1,2 @@
1
+ import { HttpResourceRef } from '@angular/common/http';
2
+ export declare function toResourceObject<T>(res: HttpResourceRef<T>): HttpResourceRef<T>;
@@ -1,2 +1,2 @@
1
- import { HttpResourceRequest } from '@angular/common/http';
1
+ import { type HttpResourceRequest } from '@angular/common/http';
2
2
  export declare function urlWithParams(req: HttpResourceRequest): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/resource",
3
- "version": "19.2.0",
3
+ "version": "19.3.1",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -17,14 +17,12 @@
17
17
  },
18
18
  "homepage": "https://github.com/mihajm/mmstack/blob/master/packages/resource",
19
19
  "dependencies": {
20
- "uuid": "~11.1.0",
21
- "@mmstack/primitives": "^19.2.1",
22
- "@mmstack/object": "^19.2.0",
20
+ "@mmstack/primitives": "^19.3.0",
23
21
  "tslib": "^2.3.0"
24
22
  },
25
23
  "peerDependencies": {
26
- "@angular/common": "~19.2.3",
27
- "@angular/core": "~19.2.3",
24
+ "@angular/common": ">=19 <20",
25
+ "@angular/core": ">=19 <20",
28
26
  "rxjs": "~7.8.2"
29
27
  },
30
28
  "sideEffects": false,
@@ -1,3 +0,0 @@
1
- export * from './mutation-resource';
2
- export * from './query-resource';
3
- export * from './util/public_api';