@mmstack/resource 20.4.0 → 20.5.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/LICENSE +21 -21
- package/README.md +120 -120
- package/fesm2022/mmstack-resource.mjs +128 -48
- package/fesm2022/mmstack-resource.mjs.map +1 -1
- package/index.d.ts +54 -7
- package/package.json +4 -4
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HttpResponse, HttpInterceptorFn, HttpContext,
|
|
1
|
+
import { HttpResponse, HttpInterceptorFn, HttpContext, HttpResourceRef, HttpHeaders, HttpResourceRequest, HttpResourceOptions } from '@angular/common/http';
|
|
2
2
|
import { Signal, Injector, Provider, WritableSignal, ValueEqualityFn } from '@angular/core';
|
|
3
3
|
|
|
4
4
|
type StoredEntry<T> = Omit<CacheEntry<T>, 'timeout'>;
|
|
@@ -516,16 +516,27 @@ type QueryResourceRef<TResult> = Omit<HttpResourceRef<TResult>, 'headers' | 'sta
|
|
|
516
516
|
* @param req - Optional partial request parameters to use for the prefetch. This allows you
|
|
517
517
|
* to prefetch data with different parameters than the main resource request.
|
|
518
518
|
*/
|
|
519
|
-
prefetch: (req?: Partial<HttpResourceRequest>) => Promise<void>;
|
|
519
|
+
prefetch: (req?: Partial<HttpResourceRequest> | string) => Promise<void>;
|
|
520
520
|
};
|
|
521
|
-
|
|
521
|
+
/**
|
|
522
|
+
* 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`.
|
|
523
|
+
* This overload is for when a `defaultValue` is provided, ensuring that the resource's value is always defined.
|
|
524
|
+
* @param request A function that returns the `HttpResourceRequest` or a URL string to be made. This function
|
|
525
|
+
* is called reactively, so the request can change over time. If the function
|
|
526
|
+
* returns `undefined`, the resource is considered "disabled" and no request will be made.
|
|
527
|
+
* @param options Configuration options for the resource. These options extend the basic
|
|
528
|
+
* `HttpResourceOptions` and add features like `keepPrevious`, `refresh`, `retry`,
|
|
529
|
+
* `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.
|
|
530
|
+
* @returns An `QueryResourceRef` instance, which extends the basic `HttpResourceRef` with additional features.
|
|
531
|
+
*/
|
|
532
|
+
declare function queryResource<TResult, TRaw = TResult>(request: () => HttpResourceRequest | string | undefined | void, options: QueryResourceOptions<TResult, TRaw> & {
|
|
522
533
|
defaultValue: NoInfer<TResult>;
|
|
523
534
|
}): QueryResourceRef<TResult>;
|
|
524
535
|
/**
|
|
525
536
|
* Creates an extended HTTP resource with features like caching, retries, refresh intervals,
|
|
526
537
|
* circuit breaker, and optimistic updates. Without additional options it is equivalent to simply calling `httpResource`.
|
|
527
538
|
*
|
|
528
|
-
* @param request A function that returns the `HttpResourceRequest` to be made. This function
|
|
539
|
+
* @param request A function that returns the `HttpResourceRequest` or a URL string to be made. This function
|
|
529
540
|
* is called reactively, so the request can change over time. If the function
|
|
530
541
|
* returns `undefined`, the resource is considered "disabled" and no request will be made.
|
|
531
542
|
* @param options Configuration options for the resource. These options extend the basic
|
|
@@ -533,7 +544,43 @@ declare function queryResource<TResult, TRaw = TResult>(request: () => HttpResou
|
|
|
533
544
|
* `onError`, `circuitBreaker`, and `cache`.
|
|
534
545
|
* @returns An `QueryResourceRef` instance, which extends the basic `HttpResourceRef` with additional features.
|
|
535
546
|
*/
|
|
536
|
-
declare function queryResource<TResult, TRaw = TResult>(request: () => HttpResourceRequest | undefined | void, options?: QueryResourceOptions<TResult, TRaw>): QueryResourceRef<TResult | undefined>;
|
|
547
|
+
declare function queryResource<TResult, TRaw = TResult>(request: () => HttpResourceRequest | string | undefined | void, options?: QueryResourceOptions<TResult, TRaw>): QueryResourceRef<TResult | undefined>;
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* A reference to a manually triggered query resource. This type extends the standard `QueryResourceRef`
|
|
551
|
+
* with an additional `trigger` method that allows you to manually trigger the resource request.
|
|
552
|
+
* @see QueryResourceRef
|
|
553
|
+
*/
|
|
554
|
+
type ManualQueryResourceRef<TResult> = QueryResourceRef<TResult> & {
|
|
555
|
+
trigger: (req?: HttpResourceRequest | string, injector?: Injector) => Promise<TResult>;
|
|
556
|
+
};
|
|
557
|
+
/**
|
|
558
|
+
* Creates a manually triggered HTTP resource with features like caching, retries, refresh intervals, circuit breaker, and optimistic updates. Without additional options it is equivalent to simply calling `httpResource`.
|
|
559
|
+
* This overload is for when a `defaultValue` is provided, ensuring that the resource's value is always defined.
|
|
560
|
+
* @param request A function that returns the `HttpResourceRequest` or a URL string to be made. This function
|
|
561
|
+
* is called reactively, so the request can change over time. If the function
|
|
562
|
+
* returns `undefined`, the resource is considered "disabled" and no request will be made.
|
|
563
|
+
* @param options Configuration options for the resource. These options extend the basic
|
|
564
|
+
* `HttpResourceOptions` and add features like `keepPrevious`, `refresh`, `retry`,
|
|
565
|
+
* `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.
|
|
566
|
+
* @returns An `ManualQueryResourceRef` instance, which extends the basic `QueryResourceRef` with additional features.
|
|
567
|
+
*/
|
|
568
|
+
declare function manualQueryResource<TResult, TRaw = TResult>(request: () => HttpResourceRequest | string | undefined | void, options: QueryResourceOptions<TResult, TRaw> & {
|
|
569
|
+
defaultValue: NoInfer<TResult>;
|
|
570
|
+
}): ManualQueryResourceRef<TResult>;
|
|
571
|
+
/**
|
|
572
|
+
* Creates a manually triggered extended HTTP resource with features like caching, retries, refresh intervals,
|
|
573
|
+
* circuit breaker, and optimistic updates. Without additional options it is equivalent to simply calling `httpResource`.
|
|
574
|
+
*
|
|
575
|
+
* @param request A function that returns the `HttpResourceRequest` or a URL string to be made. This function
|
|
576
|
+
* is called reactively, so the request can change over time. If the function
|
|
577
|
+
* returns `undefined`, the resource is considered "disabled" and no request will be made.
|
|
578
|
+
* @param options Configuration options for the resource. These options extend the basic
|
|
579
|
+
* `HttpResourceOptions` and add features like `keepPrevious`, `refresh`, `retry`,
|
|
580
|
+
* `onError`, `circuitBreaker`, and `cache`.
|
|
581
|
+
* @returns An `ManualQueryResourceRef` instance, which extends the basic `QueryResourceRef` with additional features.
|
|
582
|
+
*/
|
|
583
|
+
declare function manualQueryResource<TResult, TRaw = TResult>(request: () => HttpResourceRequest | string | undefined | void, options?: QueryResourceOptions<TResult, TRaw>): ManualQueryResourceRef<TResult | undefined>;
|
|
537
584
|
|
|
538
585
|
/**
|
|
539
586
|
* @internal
|
|
@@ -625,5 +672,5 @@ type MutationResourceRef<TResult, TMutation = TResult, TICTX = void> = Omit<Quer
|
|
|
625
672
|
*/
|
|
626
673
|
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>;
|
|
627
674
|
|
|
628
|
-
export { Cache, createCacheInterceptor, createCircuitBreaker, createDedupeRequestsInterceptor, injectQueryCache, mutationResource, noDedupe, provideCircuitBreakerDefaultOptions, provideQueryCache, queryResource };
|
|
629
|
-
export type { MutationResourceOptions, MutationResourceRef, QueryResourceOptions, QueryResourceRef };
|
|
675
|
+
export { Cache, createCacheInterceptor, createCircuitBreaker, createDedupeRequestsInterceptor, injectQueryCache, manualQueryResource, mutationResource, noDedupe, provideCircuitBreakerDefaultOptions, provideQueryCache, queryResource };
|
|
676
|
+
export type { ManualQueryResourceRef, MutationResourceOptions, MutationResourceRef, QueryResourceOptions, QueryResourceRef };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mmstack/resource",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.5.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"angular",
|
|
6
6
|
"signals",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/mihajm/mmstack/blob/master/packages/resource",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@mmstack/primitives": "^20.
|
|
20
|
+
"@mmstack/primitives": "^20.5.0",
|
|
21
21
|
"tslib": "^2.3.0"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@angular/common": "
|
|
25
|
-
"@angular/core": "
|
|
24
|
+
"@angular/common": ">=20 <21",
|
|
25
|
+
"@angular/core": ">=20 <21",
|
|
26
26
|
"rxjs": "~7.8.2"
|
|
27
27
|
},
|
|
28
28
|
"sideEffects": false,
|