@ethlete/query 2.2.0 → 2.3.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/lib/directives/infinity-query-trigger.directive.mjs +3 -3
- package/esm2020/lib/directives/infinity-query.directive.mjs +15 -2
- package/esm2020/lib/infinite-query/infinity-query.mjs +4 -1
- package/esm2020/lib/infinite-query/infinity-query.types.mjs +1 -1
- package/esm2020/lib/query/query.utils.mjs +14 -1
- package/esm2020/lib/query-client/query-client.types.mjs +1 -1
- package/esm2020/lib/query-store/query-store.mjs +31 -17
- package/fesm2015/ethlete-query.mjs +65 -21
- package/fesm2015/ethlete-query.mjs.map +1 -1
- package/fesm2020/ethlete-query.mjs +63 -20
- package/fesm2020/ethlete-query.mjs.map +1 -1
- package/lib/auth/auth-provider.types.d.ts +5 -0
- package/lib/directives/infinity-query.directive.d.ts +11 -5
- package/lib/infinite-query/infinity-query.d.ts +5 -3
- package/lib/infinite-query/infinity-query.types.d.ts +6 -2
- package/lib/query/query.d.ts +8 -0
- package/lib/query/query.types.d.ts +9 -0
- package/lib/query/query.utils.d.ts +8 -1
- package/lib/query-client/query-client.types.d.ts +5 -1
- package/lib/query-store/query-store.d.ts +2 -0
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BehaviorSubjectWithSubscriberCount, getCookie, setCookie, deleteCookie, DestroyService, equal, clone } from '@ethlete/core';
|
|
2
|
-
import { Observable, filter, takeWhile, switchMap, of, BehaviorSubject, Subject, takeUntil, interval, startWith, tap, timer, fromEvent,
|
|
2
|
+
import { Observable, filter, takeWhile, switchMap, of, BehaviorSubject, Subject, takeUntil, interval, startWith, tap, timer, fromEvent, take, concat, debounceTime, combineLatest, map, distinctUntilChanged } from 'rxjs';
|
|
3
3
|
import * as i0 from '@angular/core';
|
|
4
4
|
import { Directive, Input, InjectionToken, inject, ChangeDetectorRef, ViewContainerRef, TemplateRef, ErrorHandler, ElementRef } from '@angular/core';
|
|
5
5
|
import { FormGroup } from '@angular/forms';
|
|
@@ -494,6 +494,11 @@ function filterSuccess() {
|
|
|
494
494
|
return source.pipe(filter((value) => isQueryStateSuccess(value)));
|
|
495
495
|
};
|
|
496
496
|
}
|
|
497
|
+
function ignoreAutoRefresh() {
|
|
498
|
+
return function (source) {
|
|
499
|
+
return source.pipe(filter((value) => !isAutoRefresh(value)));
|
|
500
|
+
};
|
|
501
|
+
}
|
|
497
502
|
function filterFailure() {
|
|
498
503
|
return function (source) {
|
|
499
504
|
return source.pipe(filter((value) => isQueryStateFailure(value)));
|
|
@@ -534,6 +539,7 @@ const isQueryStateSuccess = (state) => state?.type === "SUCCESS" /* QueryStateTy
|
|
|
534
539
|
const isQueryStateFailure = (state) => state?.type === "FAILURE" /* QueryStateType.Failure */;
|
|
535
540
|
const isQueryStateCancelled = (state) => state?.type === "CANCELLED" /* QueryStateType.Cancelled */;
|
|
536
541
|
const isQueryStatePrepared = (state) => state?.type === "PREPARED" /* QueryStateType.Prepared */;
|
|
542
|
+
const isAutoRefresh = (state) => state?.meta.triggeredVia === 'auto';
|
|
537
543
|
const mergeHeaders = (...headers) => {
|
|
538
544
|
return headers.reduce((acc, headers) => {
|
|
539
545
|
if (!headers) {
|
|
@@ -576,6 +582,13 @@ const getDefaultHeaders = (headers, method) => {
|
|
|
576
582
|
}
|
|
577
583
|
return headers;
|
|
578
584
|
};
|
|
585
|
+
const castQueryCreatorTypes = (config) => {
|
|
586
|
+
if (config.args?.pathParams) {
|
|
587
|
+
console.error(config);
|
|
588
|
+
throw new Error('Path params cannot be overridden in castQueryCreatorTypes. Create a new query creator instead.');
|
|
589
|
+
}
|
|
590
|
+
return config.creator;
|
|
591
|
+
};
|
|
579
592
|
|
|
580
593
|
class Query {
|
|
581
594
|
get _nextId() {
|
|
@@ -1155,6 +1168,9 @@ class InfinityQuery {
|
|
|
1155
1168
|
this._data$.next([]);
|
|
1156
1169
|
this.nextPage();
|
|
1157
1170
|
}
|
|
1171
|
+
/**
|
|
1172
|
+
* @internal
|
|
1173
|
+
*/
|
|
1158
1174
|
_clearSubscriptions() {
|
|
1159
1175
|
this._subscriptions.forEach((sub) => sub.unsubscribe());
|
|
1160
1176
|
this._subscriptions = [];
|
|
@@ -1285,7 +1301,7 @@ class InfinityQueryDirective {
|
|
|
1285
1301
|
this._cleanup();
|
|
1286
1302
|
this._infinityQuery = v;
|
|
1287
1303
|
this._infinityQueryInstance = this._setupInfinityQuery(v);
|
|
1288
|
-
this.
|
|
1304
|
+
this.loadNextPage();
|
|
1289
1305
|
}
|
|
1290
1306
|
get context() {
|
|
1291
1307
|
return this._viewContext;
|
|
@@ -1358,12 +1374,25 @@ class InfinityQueryDirective {
|
|
|
1358
1374
|
.subscribe();
|
|
1359
1375
|
return instance;
|
|
1360
1376
|
}
|
|
1377
|
+
/**
|
|
1378
|
+
* @deprecated Use `loadNextPage` instead
|
|
1379
|
+
* @breaking 3.0.0
|
|
1380
|
+
*/
|
|
1361
1381
|
_loadNextPage() {
|
|
1382
|
+
this.loadNextPage();
|
|
1383
|
+
}
|
|
1384
|
+
loadNextPage() {
|
|
1362
1385
|
if (!this._infinityQueryInstance) {
|
|
1363
1386
|
return;
|
|
1364
1387
|
}
|
|
1365
1388
|
this._infinityQueryInstance.nextPage();
|
|
1366
1389
|
}
|
|
1390
|
+
reset(newConfig) {
|
|
1391
|
+
if (!this._infinityQueryInstance) {
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
this._infinityQueryInstance.reset(newConfig);
|
|
1395
|
+
}
|
|
1367
1396
|
_renderMainView() {
|
|
1368
1397
|
if (!this._isMainViewCreated) {
|
|
1369
1398
|
this._isMainViewCreated = true;
|
|
@@ -1412,7 +1441,7 @@ class InfinityQueryTriggerDirective {
|
|
|
1412
1441
|
ngOnInit() {
|
|
1413
1442
|
const isInteractive = this._elementRef.nativeElement.hasAttribute('infinityQueryTrigger');
|
|
1414
1443
|
if (isInteractive) {
|
|
1415
|
-
this.click$.pipe(takeUntil(this._destroy)).subscribe(() => this._infinityQuery.
|
|
1444
|
+
this.click$.pipe(takeUntil(this._destroy)).subscribe(() => this._infinityQuery.loadNextPage());
|
|
1416
1445
|
}
|
|
1417
1446
|
else {
|
|
1418
1447
|
this._setupIntersectionObserver();
|
|
@@ -1427,7 +1456,7 @@ class InfinityQueryTriggerDirective {
|
|
|
1427
1456
|
this._observer = new IntersectionObserver((entries) => {
|
|
1428
1457
|
const entry = entries[0];
|
|
1429
1458
|
if (entry.isIntersecting && !this._infinityQuery.context.loading) {
|
|
1430
|
-
this._infinityQuery.
|
|
1459
|
+
this._infinityQuery.loadNextPage();
|
|
1431
1460
|
}
|
|
1432
1461
|
}, {
|
|
1433
1462
|
root: this.scrollContainerSelector ? document.querySelector(this.scrollContainerSelector) : null,
|
|
@@ -1455,6 +1484,8 @@ class QueryStore {
|
|
|
1455
1484
|
this._config = _config;
|
|
1456
1485
|
this._store = new Map();
|
|
1457
1486
|
this._garbageCollector = null;
|
|
1487
|
+
this._isInLowResourceMode = false;
|
|
1488
|
+
this._lastBlurTimestamp = Date.now();
|
|
1458
1489
|
this._initSmartQueryHandling();
|
|
1459
1490
|
}
|
|
1460
1491
|
add(id, query) {
|
|
@@ -1491,27 +1522,39 @@ class QueryStore {
|
|
|
1491
1522
|
const windowBlur$ = fromEvent(window, 'blur');
|
|
1492
1523
|
const windowFocus$ = fromEvent(window, 'focus');
|
|
1493
1524
|
windowBlur$.subscribe(() => {
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1525
|
+
timer(5000)
|
|
1526
|
+
.pipe(takeUntil(windowFocus$), take(1))
|
|
1527
|
+
.subscribe(() => {
|
|
1528
|
+
this._lastBlurTimestamp = Date.now();
|
|
1529
|
+
this._isInLowResourceMode = true;
|
|
1530
|
+
this._stopGarbageCollector();
|
|
1531
|
+
if (this._config?.enableSmartPolling) {
|
|
1532
|
+
this.forEach((query) => {
|
|
1533
|
+
if (!query.isPolling || !query._enableSmartPolling) {
|
|
1534
|
+
return;
|
|
1535
|
+
}
|
|
1536
|
+
query.pausePolling();
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
});
|
|
1503
1540
|
});
|
|
1504
1541
|
windowFocus$.subscribe(() => {
|
|
1542
|
+
if (!this._isInLowResourceMode) {
|
|
1543
|
+
return;
|
|
1544
|
+
}
|
|
1545
|
+
this._isInLowResourceMode = false;
|
|
1505
1546
|
if (this._config?.enableSmartPolling || this._config?.autoRefreshQueriesOnWindowFocus) {
|
|
1506
1547
|
this.forEach((query) => {
|
|
1507
1548
|
if (this._config?.enableSmartPolling && query._isPollingPaused) {
|
|
1508
1549
|
query.resumePolling();
|
|
1509
1550
|
}
|
|
1510
|
-
if (this.
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1551
|
+
if (Date.now() - this._lastBlurTimestamp > 15000) {
|
|
1552
|
+
if (this._config?.autoRefreshQueriesOnWindowFocus &&
|
|
1553
|
+
query.isExpired &&
|
|
1554
|
+
query.isInUse &&
|
|
1555
|
+
query.autoRefreshOnConfig.windowFocus) {
|
|
1556
|
+
query.execute({ skipCache: true, _triggeredVia: 'auto' });
|
|
1557
|
+
}
|
|
1515
1558
|
}
|
|
1516
1559
|
});
|
|
1517
1560
|
}
|
|
@@ -1542,6 +1585,7 @@ class QueryStore {
|
|
|
1542
1585
|
if (this._garbageCollector !== null) {
|
|
1543
1586
|
window.clearInterval(this._garbageCollector);
|
|
1544
1587
|
this._garbageCollector = null;
|
|
1588
|
+
this._logGarbageCollector('Stop');
|
|
1545
1589
|
}
|
|
1546
1590
|
}
|
|
1547
1591
|
_runGarbageCollector() {
|
|
@@ -1554,7 +1598,6 @@ class QueryStore {
|
|
|
1554
1598
|
this._logGarbageCollector('Collection done');
|
|
1555
1599
|
if (!this._store.size) {
|
|
1556
1600
|
this._stopGarbageCollector();
|
|
1557
|
-
this._logGarbageCollector('Stop');
|
|
1558
1601
|
}
|
|
1559
1602
|
}
|
|
1560
1603
|
_logGarbageCollector(action) {
|
|
@@ -1926,5 +1969,5 @@ const def = () => null;
|
|
|
1926
1969
|
* Generated bundle index. Do not edit.
|
|
1927
1970
|
*/
|
|
1928
1971
|
|
|
1929
|
-
export { BasicAuthProvider, BearerAuthProvider, CustomHeaderAuthProvider, INFINITY_QUERY_TOKEN, InfinityQuery, InfinityQueryDirective, InfinityQueryTriggerDirective, Query, QueryClient, QueryDirective, QueryError, QueryField, QueryForm, QueryStore, buildErrorMessage, buildGqlCacheKey, buildQueryArrayString, buildQueryString, buildRoute, buildTimestampFromSeconds, createInfinityQueryConfig, createQueryCollection, decryptBearer, deepFreeze, def, detectContentTypeHeader, extractExpiresInSeconds, extractQuery, filterFailure, filterInvalidParams, filterNull, filterQueryStates, filterSuccess, forEachHeader, getDefaultHeaders, getResponseUrl, gql, hasHeader, invalidBaseRouteError, invalidBodyError, invalidRouteError, isBasicAuthProvider, isBearerAuthProvider, isCustomHeaderAuthProvider, isFetchResponse, isGqlQueryConfig, isParamValid, isQuery, isQueryStateCancelled, isQueryStateFailure, isQueryStateLoading, isQueryStatePrepared, isQueryStateSuccess, isRequestError, mergeHeaders, 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 };
|
|
1972
|
+
export { BasicAuthProvider, BearerAuthProvider, CustomHeaderAuthProvider, INFINITY_QUERY_TOKEN, InfinityQuery, InfinityQueryDirective, InfinityQueryTriggerDirective, Query, QueryClient, QueryDirective, QueryError, QueryField, QueryForm, QueryStore, buildErrorMessage, buildGqlCacheKey, buildQueryArrayString, buildQueryString, buildRoute, buildTimestampFromSeconds, castQueryCreatorTypes, 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, isFetchResponse, isGqlQueryConfig, isParamValid, isQuery, isQueryStateCancelled, isQueryStateFailure, isQueryStateLoading, isQueryStatePrepared, isQueryStateSuccess, isRequestError, mergeHeaders, 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 };
|
|
1930
1973
|
//# sourceMappingURL=ethlete-query.mjs.map
|