@mmstack/resource 19.2.0 → 20.0.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/README.md +1 -1
- package/fesm2022/mmstack-resource.mjs +13 -11
- package/fesm2022/mmstack-resource.mjs.map +1 -1
- package/index.d.ts +520 -1
- package/package.json +5 -5
- package/lib/mutation-resource.d.ts +0 -92
- package/lib/public_api.d.ts +0 -3
- package/lib/query-resource.d.ts +0 -92
- package/lib/util/cache/cache.d.ts +0 -177
- package/lib/util/cache/cache.interceptor.d.ts +0 -39
- package/lib/util/cache/index.d.ts +0 -2
- package/lib/util/cache/public_api.d.ts +0 -2
- package/lib/util/circuit-breaker.d.ts +0 -74
- package/lib/util/dedupe.interceptor.d.ts +0 -50
- package/lib/util/equality.d.ts +0 -3
- package/lib/util/has-slow-connection.d.ts +0 -1
- package/lib/util/index.d.ts +0 -9
- package/lib/util/persist.d.ts +0 -3
- package/lib/util/public_api.d.ts +0 -3
- package/lib/util/refresh.d.ts +0 -3
- package/lib/util/retry-on-error.d.ts +0 -6
- package/lib/util/url-with-params.d.ts +0 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, untracked, InjectionToken, inject, isDevMode, signal, effect, linkedSignal,
|
|
1
|
+
import { computed, untracked, InjectionToken, inject, isDevMode, signal, effect, linkedSignal, DestroyRef } from '@angular/core';
|
|
2
2
|
import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
|
|
3
3
|
import { of, tap, map, finalize, shareReplay, interval, firstValueFrom, combineLatestWith, filter } from 'rxjs';
|
|
4
4
|
import { HttpContextToken, HttpContext, HttpResponse, HttpParams, httpResource, HttpClient } from '@angular/common/http';
|
|
@@ -755,9 +755,9 @@ function retryOnError(res, opt) {
|
|
|
755
755
|
};
|
|
756
756
|
const ref = effect(() => {
|
|
757
757
|
switch (res.status()) {
|
|
758
|
-
case
|
|
758
|
+
case 'error':
|
|
759
759
|
return onError();
|
|
760
|
-
case
|
|
760
|
+
case 'resolved':
|
|
761
761
|
return onSuccess();
|
|
762
762
|
}
|
|
763
763
|
});
|
|
@@ -805,7 +805,9 @@ function queryResource(request, options) {
|
|
|
805
805
|
return undefined;
|
|
806
806
|
return request() ?? undefined;
|
|
807
807
|
}, {
|
|
808
|
-
equal:
|
|
808
|
+
equal: options?.triggerOnSameRequest
|
|
809
|
+
? undefined
|
|
810
|
+
: createEqualRequest(options?.equal),
|
|
809
811
|
});
|
|
810
812
|
const hashFn = typeof options?.cache === 'object'
|
|
811
813
|
? (options.cache.hash ?? urlWithParams)
|
|
@@ -881,9 +883,9 @@ function queryResource(request, options) {
|
|
|
881
883
|
// iterate circuit breaker state, is effect as a computed would cause a circular dependency (resource -> cb -> resource)
|
|
882
884
|
const cbEffectRef = effect(() => {
|
|
883
885
|
const status = resource.status();
|
|
884
|
-
if (status ===
|
|
886
|
+
if (status === 'error')
|
|
885
887
|
cb.fail();
|
|
886
|
-
else if (status ===
|
|
888
|
+
else if (status === 'resolved')
|
|
887
889
|
cb.success();
|
|
888
890
|
});
|
|
889
891
|
const set = (value) => {
|
|
@@ -1007,22 +1009,22 @@ function mutationResource(request, options = {}) {
|
|
|
1007
1009
|
const value$ = toObservable(resource.value);
|
|
1008
1010
|
const statusSub = toObservable(resource.status)
|
|
1009
1011
|
.pipe(combineLatestWith(error$, value$), map(([status, error, value]) => {
|
|
1010
|
-
if (status ===
|
|
1012
|
+
if (status === 'error' && error) {
|
|
1011
1013
|
return {
|
|
1012
|
-
status:
|
|
1014
|
+
status: 'error',
|
|
1013
1015
|
error,
|
|
1014
1016
|
};
|
|
1015
1017
|
}
|
|
1016
|
-
if (status ===
|
|
1018
|
+
if (status === 'resolved' && value !== null) {
|
|
1017
1019
|
return {
|
|
1018
|
-
status:
|
|
1020
|
+
status: 'resolved',
|
|
1019
1021
|
value,
|
|
1020
1022
|
};
|
|
1021
1023
|
}
|
|
1022
1024
|
return null;
|
|
1023
1025
|
}), filter((v) => v !== null), takeUntilDestroyed(destroyRef))
|
|
1024
1026
|
.subscribe((result) => {
|
|
1025
|
-
if (result.status ===
|
|
1027
|
+
if (result.status === 'error')
|
|
1026
1028
|
onError?.(result.error, ctx);
|
|
1027
1029
|
else
|
|
1028
1030
|
onSuccess?.(result.value, ctx);
|