@ethlete/query 3.0.4 → 4.0.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/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/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 +85 -4
- package/fesm2015/ethlete-query.mjs.map +1 -1
- package/fesm2020/ethlete-query.mjs +84 -4
- 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
|
|
|
@@ -506,6 +506,26 @@ const gql = (strings, ...values) => {
|
|
|
506
506
|
return str;
|
|
507
507
|
};
|
|
508
508
|
|
|
509
|
+
const isSymfonyError = (error) => {
|
|
510
|
+
if (!error || typeof error !== 'object') {
|
|
511
|
+
return false;
|
|
512
|
+
}
|
|
513
|
+
const symfonyError = error;
|
|
514
|
+
return (symfonyError.class !== undefined &&
|
|
515
|
+
symfonyError.detail !== undefined &&
|
|
516
|
+
symfonyError.status !== undefined &&
|
|
517
|
+
symfonyError.title !== undefined &&
|
|
518
|
+
symfonyError.trace !== undefined &&
|
|
519
|
+
symfonyError.type !== undefined);
|
|
520
|
+
};
|
|
521
|
+
const isSymfonyPagerfantaOutOfRangeError = (error) => {
|
|
522
|
+
if (!isSymfonyError(error)) {
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
return error.class.startsWith('Pagerfanta') && error.class.endsWith('OutOfRangeCurrentPageException');
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
509
529
|
function filterSuccess() {
|
|
510
530
|
return function (source) {
|
|
511
531
|
return source.pipe(filter((value) => isQueryStateSuccess(value)));
|
|
@@ -551,6 +571,34 @@ function switchQueryCollectionState() {
|
|
|
551
571
|
return source.pipe(switchMap((value) => value?.query.state$ ?? of(null)));
|
|
552
572
|
};
|
|
553
573
|
}
|
|
574
|
+
const resetPageOnError = (config) => (source) => {
|
|
575
|
+
const { queryForm, pageControlKey = 'page' } = config;
|
|
576
|
+
if (isDevMode() && !queryForm.form.controls[pageControlKey]) {
|
|
577
|
+
console.warn(`resetPageOnError: queryForm.form.controls["${pageControlKey}"] is undefined`);
|
|
578
|
+
}
|
|
579
|
+
return source.pipe(switchMap((q) => {
|
|
580
|
+
if (!q) {
|
|
581
|
+
return of(q);
|
|
582
|
+
}
|
|
583
|
+
return q.state$.pipe(tap((state) => {
|
|
584
|
+
if (!isQueryStateFailure(state)) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
switch (state.error.status) {
|
|
588
|
+
// The page is invalid (in prod mode, code is 416)
|
|
589
|
+
case 416 /* HttpStatusCode.RangeNotSatisfiable */:
|
|
590
|
+
queryForm.form.controls[pageControlKey]?.patchValue(1);
|
|
591
|
+
break;
|
|
592
|
+
// The page might be invalid (in dev mode, code is 500)
|
|
593
|
+
case 500 /* HttpStatusCode.InternalServerError */:
|
|
594
|
+
if (isSymfonyPagerfantaOutOfRangeError(state.error.detail)) {
|
|
595
|
+
queryForm.form.controls[pageControlKey].patchValue(1);
|
|
596
|
+
}
|
|
597
|
+
break;
|
|
598
|
+
}
|
|
599
|
+
}), takeUntilResponse());
|
|
600
|
+
}));
|
|
601
|
+
};
|
|
554
602
|
const isQueryStateLoading = (state) => state?.type === "LOADING" /* QueryStateType.Loading */;
|
|
555
603
|
const isQueryStateSuccess = (state) => state?.type === "SUCCESS" /* QueryStateType.Success */;
|
|
556
604
|
const isQueryStateFailure = (state) => state?.type === "FAILURE" /* QueryStateType.Failure */;
|
|
@@ -1971,7 +2019,39 @@ class QueryForm {
|
|
|
1971
2019
|
if (options?.syncViaUrlQueryParams !== false) {
|
|
1972
2020
|
this._syncViaUrlQueryParams(values);
|
|
1973
2021
|
}
|
|
1974
|
-
}))
|
|
2022
|
+
}), pairwise(), startWith([null, this.form.getRawValue()]), map(([previousValue, currentValue]) => ({ previousValue, currentValue })), map(({ previousValue, currentValue }) => {
|
|
2023
|
+
let didResetValues = false;
|
|
2024
|
+
for (const formFieldKey in this._fields) {
|
|
2025
|
+
const resets = this._fields[formFieldKey].data.isResetBy;
|
|
2026
|
+
if (!resets)
|
|
2027
|
+
continue;
|
|
2028
|
+
const resetConditionKeys = Array.isArray(resets) ? resets : [resets];
|
|
2029
|
+
for (const resetConditionKey of resetConditionKeys) {
|
|
2030
|
+
if (!(resetConditionKey in this._fields)) {
|
|
2031
|
+
if (isDevMode()) {
|
|
2032
|
+
console.warn(`The field "${resetConditionKey}" is not defined in the QueryForm. Is it a typo?`, this);
|
|
2033
|
+
}
|
|
2034
|
+
continue;
|
|
2035
|
+
}
|
|
2036
|
+
if (previousValue &&
|
|
2037
|
+
currentValue &&
|
|
2038
|
+
!equal(previousValue[resetConditionKey], currentValue[resetConditionKey])) {
|
|
2039
|
+
const defaultValueForKeyToReset = this._defaultValues[formFieldKey];
|
|
2040
|
+
const currentValueForKeyToReset = currentValue[formFieldKey];
|
|
2041
|
+
if (equal(defaultValueForKeyToReset, currentValueForKeyToReset)) {
|
|
2042
|
+
continue;
|
|
2043
|
+
}
|
|
2044
|
+
this.form.controls[formFieldKey].setValue(defaultValueForKeyToReset);
|
|
2045
|
+
didResetValues = true;
|
|
2046
|
+
break;
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
return (didResetValues || {
|
|
2051
|
+
previousValue,
|
|
2052
|
+
currentValue,
|
|
2053
|
+
});
|
|
2054
|
+
}), filter((value) => value !== true));
|
|
1975
2055
|
}
|
|
1976
2056
|
setFormValueFromUrlQueryParams(options) {
|
|
1977
2057
|
if (!this._activatedRoute) {
|
|
@@ -2168,5 +2248,5 @@ const def = () => null;
|
|
|
2168
2248
|
* Generated bundle index. Do not edit.
|
|
2169
2249
|
*/
|
|
2170
2250
|
|
|
2171
|
-
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 };
|
|
2251
|
+
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 };
|
|
2172
2252
|
//# sourceMappingURL=ethlete-query.mjs.map
|