@ethlete/query 3.0.4 → 4.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/esm2020/index.mjs +2 -1
- package/esm2020/lib/query/query.types.mjs +1 -1
- package/esm2020/lib/query/query.utils.mjs +33 -2
- package/esm2020/lib/query-form/query-form.mjs +36 -4
- package/esm2020/lib/query-form/query-form.types.mjs +1 -1
- package/esm2020/lib/request/request.util.mjs +7 -2
- package/esm2020/lib/symfony/index.mjs +3 -0
- package/esm2020/lib/symfony/symfony.types.mjs +2 -0
- package/esm2020/lib/symfony/symfony.utils.mjs +19 -0
- package/fesm2015/ethlete-query.mjs +90 -5
- package/fesm2015/ethlete-query.mjs.map +1 -1
- package/fesm2020/ethlete-query.mjs +89 -5
- package/fesm2020/ethlete-query.mjs.map +1 -1
- package/index.d.ts +1 -0
- package/lib/query/query.types.d.ts +12 -0
- package/lib/query/query.utils.d.ts +3 -1
- package/lib/query-form/query-form.d.ts +5 -4
- package/lib/query-form/query-form.types.d.ts +14 -0
- package/lib/query-form/query-form.utils.d.ts +1 -1
- package/lib/symfony/index.d.ts +2 -0
- package/lib/symfony/symfony.types.d.ts +19 -0
- package/lib/symfony/symfony.utils.d.ts +3 -0
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as i1 from '@ethlete/core';
|
|
2
2
|
import { BehaviorSubjectWithSubscriberCount, getCookie, setCookie, deleteCookie, DestroyService, DelayableDirective, equal, clone } from '@ethlete/core';
|
|
3
|
-
import { Observable, filter, takeWhile, switchMap, of, BehaviorSubject, shareReplay, Subject, takeUntil,
|
|
3
|
+
import { Observable, filter, takeWhile, switchMap, of, tap, BehaviorSubject, shareReplay, Subject, takeUntil, interval, skip, map, timer, combineLatest, withLatestFrom, fromEvent, startWith, take, concat, debounceTime, distinctUntilChanged, pairwise } from 'rxjs';
|
|
4
4
|
import * as i0 from '@angular/core';
|
|
5
|
-
import { Directive, Input, InjectionToken, inject, ChangeDetectorRef, ViewContainerRef, TemplateRef, ErrorHandler, ElementRef } from '@angular/core';
|
|
5
|
+
import { isDevMode, Directive, Input, InjectionToken, inject, ChangeDetectorRef, ViewContainerRef, TemplateRef, ErrorHandler, ElementRef } from '@angular/core';
|
|
6
6
|
import { FormGroup } from '@angular/forms';
|
|
7
7
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
8
8
|
|
|
@@ -49,6 +49,25 @@ const queryStateDoesNotContainKeyError = (data) => new QueryError('005', 'The qu
|
|
|
49
49
|
const queryStateCannotTransformError = (data) => new QueryError('006', 'The query state cannot be transformed because it is not loading', data);
|
|
50
50
|
const invalidBodyError = (data) => new QueryError('007', 'The body is not valid or upsupported', data);
|
|
51
51
|
|
|
52
|
+
const isSymfonyError = (error) => {
|
|
53
|
+
if (!error || typeof error !== 'object') {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const symfonyError = error;
|
|
57
|
+
return (symfonyError.class !== undefined &&
|
|
58
|
+
symfonyError.detail !== undefined &&
|
|
59
|
+
symfonyError.status !== undefined &&
|
|
60
|
+
symfonyError.title !== undefined &&
|
|
61
|
+
symfonyError.trace !== undefined &&
|
|
62
|
+
symfonyError.type !== undefined);
|
|
63
|
+
};
|
|
64
|
+
const isSymfonyPagerfantaOutOfRangeError = (error) => {
|
|
65
|
+
if (!isSymfonyError(error)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return error.class.startsWith('Pagerfanta') && error.class.endsWith('OutOfRangeCurrentPageException');
|
|
69
|
+
};
|
|
70
|
+
|
|
52
71
|
const isRequestError = (error) => error instanceof Object && 'status' in error && 'statusText' in error && 'url' in error;
|
|
53
72
|
const buildRoute = (options) => {
|
|
54
73
|
var _a;
|
|
@@ -280,9 +299,13 @@ const shouldRetryRequest = (config) => {
|
|
|
280
299
|
if (!isRequestError(config.error)) {
|
|
281
300
|
return { retry: false };
|
|
282
301
|
}
|
|
283
|
-
const { status } = config.error;
|
|
302
|
+
const { status, detail } = config.error;
|
|
284
303
|
// Retry on 5xx errors
|
|
285
304
|
if (status >= 500) {
|
|
305
|
+
// Don't retry if a requested page is out of range
|
|
306
|
+
if (isSymfonyPagerfantaOutOfRangeError(detail)) {
|
|
307
|
+
return { retry: false };
|
|
308
|
+
}
|
|
286
309
|
return { retry: true, delay: defaultRetryDelay };
|
|
287
310
|
}
|
|
288
311
|
// Retry on 408 or 425 errors
|
|
@@ -508,6 +531,7 @@ const gql = (strings, ...values) => {
|
|
|
508
531
|
return str;
|
|
509
532
|
};
|
|
510
533
|
|
|
534
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
511
535
|
function filterSuccess() {
|
|
512
536
|
return function (source) {
|
|
513
537
|
return source.pipe(filter((value) => isQueryStateSuccess(value)));
|
|
@@ -553,6 +577,35 @@ function switchQueryCollectionState() {
|
|
|
553
577
|
return source.pipe(switchMap((value) => { var _a; return (_a = value === null || value === void 0 ? void 0 : value.query.state$) !== null && _a !== void 0 ? _a : of(null); }));
|
|
554
578
|
};
|
|
555
579
|
}
|
|
580
|
+
const resetPageOnError = (config) => (source) => {
|
|
581
|
+
const { queryForm, pageControlKey = 'page' } = config;
|
|
582
|
+
if (isDevMode() && !queryForm.form.controls[pageControlKey]) {
|
|
583
|
+
console.warn(`resetPageOnError: queryForm.form.controls["${pageControlKey}"] is undefined`);
|
|
584
|
+
}
|
|
585
|
+
return source.pipe(switchMap((q) => {
|
|
586
|
+
if (!q) {
|
|
587
|
+
return of(q);
|
|
588
|
+
}
|
|
589
|
+
return q.state$.pipe(tap((state) => {
|
|
590
|
+
var _a;
|
|
591
|
+
if (!isQueryStateFailure(state)) {
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
switch (state.error.status) {
|
|
595
|
+
// The page is invalid (in prod mode, code is 416)
|
|
596
|
+
case 416 /* HttpStatusCode.RangeNotSatisfiable */:
|
|
597
|
+
(_a = queryForm.form.controls[pageControlKey]) === null || _a === void 0 ? void 0 : _a.patchValue(1);
|
|
598
|
+
break;
|
|
599
|
+
// The page might be invalid (in dev mode, code is 500)
|
|
600
|
+
case 500 /* HttpStatusCode.InternalServerError */:
|
|
601
|
+
if (isSymfonyPagerfantaOutOfRangeError(state.error.detail)) {
|
|
602
|
+
queryForm.form.controls[pageControlKey].patchValue(1);
|
|
603
|
+
}
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
606
|
+
}), takeUntilResponse());
|
|
607
|
+
}));
|
|
608
|
+
};
|
|
556
609
|
const isQueryStateLoading = (state) => (state === null || state === void 0 ? void 0 : state.type) === "LOADING" /* QueryStateType.Loading */;
|
|
557
610
|
const isQueryStateSuccess = (state) => (state === null || state === void 0 ? void 0 : state.type) === "SUCCESS" /* QueryStateType.Success */;
|
|
558
611
|
const isQueryStateFailure = (state) => (state === null || state === void 0 ? void 0 : state.type) === "FAILURE" /* QueryStateType.Failure */;
|
|
@@ -1969,7 +2022,39 @@ class QueryForm {
|
|
|
1969
2022
|
if ((options === null || options === void 0 ? void 0 : options.syncViaUrlQueryParams) !== false) {
|
|
1970
2023
|
this._syncViaUrlQueryParams(values);
|
|
1971
2024
|
}
|
|
1972
|
-
}))
|
|
2025
|
+
}), pairwise(), startWith([null, this.form.getRawValue()]), map(([previousValue, currentValue]) => ({ previousValue, currentValue })), map(({ previousValue, currentValue }) => {
|
|
2026
|
+
let didResetValues = false;
|
|
2027
|
+
for (const formFieldKey in this._fields) {
|
|
2028
|
+
const resets = this._fields[formFieldKey].data.isResetBy;
|
|
2029
|
+
if (!resets)
|
|
2030
|
+
continue;
|
|
2031
|
+
const resetConditionKeys = Array.isArray(resets) ? resets : [resets];
|
|
2032
|
+
for (const resetConditionKey of resetConditionKeys) {
|
|
2033
|
+
if (!(resetConditionKey in this._fields)) {
|
|
2034
|
+
if (isDevMode()) {
|
|
2035
|
+
console.warn(`The field "${resetConditionKey}" is not defined in the QueryForm. Is it a typo?`, this);
|
|
2036
|
+
}
|
|
2037
|
+
continue;
|
|
2038
|
+
}
|
|
2039
|
+
if (previousValue &&
|
|
2040
|
+
currentValue &&
|
|
2041
|
+
!equal(previousValue[resetConditionKey], currentValue[resetConditionKey])) {
|
|
2042
|
+
const defaultValueForKeyToReset = this._defaultValues[formFieldKey];
|
|
2043
|
+
const currentValueForKeyToReset = currentValue[formFieldKey];
|
|
2044
|
+
if (equal(defaultValueForKeyToReset, currentValueForKeyToReset)) {
|
|
2045
|
+
continue;
|
|
2046
|
+
}
|
|
2047
|
+
this.form.controls[formFieldKey].setValue(defaultValueForKeyToReset);
|
|
2048
|
+
didResetValues = true;
|
|
2049
|
+
break;
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
return (didResetValues || {
|
|
2054
|
+
previousValue,
|
|
2055
|
+
currentValue,
|
|
2056
|
+
});
|
|
2057
|
+
}), filter((value) => value !== true));
|
|
1973
2058
|
}
|
|
1974
2059
|
setFormValueFromUrlQueryParams(options) {
|
|
1975
2060
|
var _a, _b, _c, _d;
|
|
@@ -2169,5 +2254,5 @@ const def = () => null;
|
|
|
2169
2254
|
* Generated bundle index. Do not edit.
|
|
2170
2255
|
*/
|
|
2171
2256
|
|
|
2172
|
-
export { BasicAuthProvider, BearerAuthProvider, CustomHeaderAuthProvider, EntityStore, INFINITY_QUERY_TOKEN, InfinityQuery, InfinityQueryDirective, InfinityQueryTriggerDirective, Query, QueryClient, QueryCreator, QueryDirective, QueryError, QueryField, QueryForm, QueryStore, buildErrorMessage, buildGqlCacheKey, buildQueryArrayString, buildQueryObjectString, buildQueryString, buildRoute, buildTimestampFromSeconds, castQueryCreatorTypes, computeQueryAuthHeader, computeQueryBody, computeQueryHeaders, computeQueryMethod, computeQueryQueryParams, createInfinityQueryConfig, createQueryCollection, decryptBearer, deepFreeze, def, detectContentTypeHeader, extractExpiresInSeconds, extractQuery, filterFailure, filterInvalidParams, filterNull, filterQueryStates, filterSuccess, forEachHeader, getDefaultHeaders, getResponseUrl, gql, hasHeader, ignoreAutoRefresh, invalidBaseRouteError, invalidBodyError, invalidRouteError, isAutoRefresh, isBasicAuthProvider, isBearerAuthProvider, isCustomHeaderAuthProvider, isGqlQueryConfig, isParamValid, isQuery, isQueryStateCancelled, isQueryStateFailure, isQueryStateLoading, isQueryStatePrepared, isQueryStateSuccess, isRequestError, mapToPaginated, mergeHeaders, paginatedEntityValueUpdater, parseAllXhrResponseHeaders, pathParamsMissingInRouteFunctionError, queryStateAlreadyHasKeyError, queryStateCannotTransformError, queryStateDoesNotContainKeyError, request, serializeBody, shouldCacheQuery, shouldRetryRequest, skipPaginationPageParamCalculator, switchQueryCollectionState, switchQueryState, takeUntilResponse, transformGql, transformMethod, transformToBoolean, transformToBooleanArray, transformToDate, transformToDateArray, transformToNumber, transformToNumberArray, transformToSort, transformToSortQueryParam, transformToString, transformToStringArray };
|
|
2257
|
+
export { BasicAuthProvider, BearerAuthProvider, CustomHeaderAuthProvider, EntityStore, INFINITY_QUERY_TOKEN, InfinityQuery, InfinityQueryDirective, InfinityQueryTriggerDirective, Query, QueryClient, QueryCreator, QueryDirective, QueryError, QueryField, QueryForm, QueryStore, buildErrorMessage, buildGqlCacheKey, buildQueryArrayString, buildQueryObjectString, buildQueryString, buildRoute, buildTimestampFromSeconds, castQueryCreatorTypes, computeQueryAuthHeader, computeQueryBody, computeQueryHeaders, computeQueryMethod, computeQueryQueryParams, createInfinityQueryConfig, createQueryCollection, decryptBearer, deepFreeze, def, detectContentTypeHeader, extractExpiresInSeconds, extractQuery, filterFailure, filterInvalidParams, filterNull, filterQueryStates, filterSuccess, forEachHeader, getDefaultHeaders, getResponseUrl, gql, hasHeader, ignoreAutoRefresh, invalidBaseRouteError, invalidBodyError, invalidRouteError, isAutoRefresh, isBasicAuthProvider, isBearerAuthProvider, isCustomHeaderAuthProvider, isGqlQueryConfig, isParamValid, isQuery, isQueryStateCancelled, isQueryStateFailure, isQueryStateLoading, isQueryStatePrepared, isQueryStateSuccess, isRequestError, isSymfonyError, isSymfonyPagerfantaOutOfRangeError, mapToPaginated, mergeHeaders, paginatedEntityValueUpdater, parseAllXhrResponseHeaders, pathParamsMissingInRouteFunctionError, queryStateAlreadyHasKeyError, queryStateCannotTransformError, queryStateDoesNotContainKeyError, request, resetPageOnError, serializeBody, shouldCacheQuery, shouldRetryRequest, skipPaginationPageParamCalculator, switchQueryCollectionState, switchQueryState, takeUntilResponse, transformGql, transformMethod, transformToBoolean, transformToBooleanArray, transformToDate, transformToDateArray, transformToNumber, transformToNumberArray, transformToSort, transformToSortQueryParam, transformToString, transformToStringArray };
|
|
2173
2258
|
//# sourceMappingURL=ethlete-query.mjs.map
|