@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';
|
|
@@ -496,6 +496,11 @@ function filterSuccess() {
|
|
|
496
496
|
return source.pipe(filter((value) => isQueryStateSuccess(value)));
|
|
497
497
|
};
|
|
498
498
|
}
|
|
499
|
+
function ignoreAutoRefresh() {
|
|
500
|
+
return function (source) {
|
|
501
|
+
return source.pipe(filter((value) => !isAutoRefresh(value)));
|
|
502
|
+
};
|
|
503
|
+
}
|
|
499
504
|
function filterFailure() {
|
|
500
505
|
return function (source) {
|
|
501
506
|
return source.pipe(filter((value) => isQueryStateFailure(value)));
|
|
@@ -536,6 +541,7 @@ const isQueryStateSuccess = (state) => (state === null || state === void 0 ? voi
|
|
|
536
541
|
const isQueryStateFailure = (state) => (state === null || state === void 0 ? void 0 : state.type) === "FAILURE" /* QueryStateType.Failure */;
|
|
537
542
|
const isQueryStateCancelled = (state) => (state === null || state === void 0 ? void 0 : state.type) === "CANCELLED" /* QueryStateType.Cancelled */;
|
|
538
543
|
const isQueryStatePrepared = (state) => (state === null || state === void 0 ? void 0 : state.type) === "PREPARED" /* QueryStateType.Prepared */;
|
|
544
|
+
const isAutoRefresh = (state) => (state === null || state === void 0 ? void 0 : state.meta.triggeredVia) === 'auto';
|
|
539
545
|
const mergeHeaders = (...headers) => {
|
|
540
546
|
return headers.reduce((acc, headers) => {
|
|
541
547
|
if (!headers) {
|
|
@@ -576,6 +582,14 @@ const getDefaultHeaders = (headers, method) => {
|
|
|
576
582
|
}
|
|
577
583
|
return headers;
|
|
578
584
|
};
|
|
585
|
+
const castQueryCreatorTypes = (config) => {
|
|
586
|
+
var _a;
|
|
587
|
+
if ((_a = config.args) === null || _a === void 0 ? void 0 : _a.pathParams) {
|
|
588
|
+
console.error(config);
|
|
589
|
+
throw new Error('Path params cannot be overridden in castQueryCreatorTypes. Create a new query creator instead.');
|
|
590
|
+
}
|
|
591
|
+
return config.creator;
|
|
592
|
+
};
|
|
579
593
|
|
|
580
594
|
class Query {
|
|
581
595
|
get _nextId() {
|
|
@@ -1170,6 +1184,9 @@ class InfinityQuery {
|
|
|
1170
1184
|
this._data$.next([]);
|
|
1171
1185
|
this.nextPage();
|
|
1172
1186
|
}
|
|
1187
|
+
/**
|
|
1188
|
+
* @internal
|
|
1189
|
+
*/
|
|
1173
1190
|
_clearSubscriptions() {
|
|
1174
1191
|
this._subscriptions.forEach((sub) => sub.unsubscribe());
|
|
1175
1192
|
this._subscriptions = [];
|
|
@@ -1282,7 +1299,7 @@ class InfinityQueryDirective {
|
|
|
1282
1299
|
this._cleanup();
|
|
1283
1300
|
this._infinityQuery = v;
|
|
1284
1301
|
this._infinityQueryInstance = this._setupInfinityQuery(v);
|
|
1285
|
-
this.
|
|
1302
|
+
this.loadNextPage();
|
|
1286
1303
|
}
|
|
1287
1304
|
get context() {
|
|
1288
1305
|
return this._viewContext;
|
|
@@ -1356,12 +1373,25 @@ class InfinityQueryDirective {
|
|
|
1356
1373
|
.subscribe();
|
|
1357
1374
|
return instance;
|
|
1358
1375
|
}
|
|
1376
|
+
/**
|
|
1377
|
+
* @deprecated Use `loadNextPage` instead
|
|
1378
|
+
* @breaking 3.0.0
|
|
1379
|
+
*/
|
|
1359
1380
|
_loadNextPage() {
|
|
1381
|
+
this.loadNextPage();
|
|
1382
|
+
}
|
|
1383
|
+
loadNextPage() {
|
|
1360
1384
|
if (!this._infinityQueryInstance) {
|
|
1361
1385
|
return;
|
|
1362
1386
|
}
|
|
1363
1387
|
this._infinityQueryInstance.nextPage();
|
|
1364
1388
|
}
|
|
1389
|
+
reset(newConfig) {
|
|
1390
|
+
if (!this._infinityQueryInstance) {
|
|
1391
|
+
return;
|
|
1392
|
+
}
|
|
1393
|
+
this._infinityQueryInstance.reset(newConfig);
|
|
1394
|
+
}
|
|
1365
1395
|
_renderMainView() {
|
|
1366
1396
|
if (!this._isMainViewCreated) {
|
|
1367
1397
|
this._isMainViewCreated = true;
|
|
@@ -1411,7 +1441,7 @@ class InfinityQueryTriggerDirective {
|
|
|
1411
1441
|
ngOnInit() {
|
|
1412
1442
|
const isInteractive = this._elementRef.nativeElement.hasAttribute('infinityQueryTrigger');
|
|
1413
1443
|
if (isInteractive) {
|
|
1414
|
-
this.click$.pipe(takeUntil(this._destroy)).subscribe(() => this._infinityQuery.
|
|
1444
|
+
this.click$.pipe(takeUntil(this._destroy)).subscribe(() => this._infinityQuery.loadNextPage());
|
|
1415
1445
|
}
|
|
1416
1446
|
else {
|
|
1417
1447
|
this._setupIntersectionObserver();
|
|
@@ -1427,7 +1457,7 @@ class InfinityQueryTriggerDirective {
|
|
|
1427
1457
|
this._observer = new IntersectionObserver((entries) => {
|
|
1428
1458
|
const entry = entries[0];
|
|
1429
1459
|
if (entry.isIntersecting && !this._infinityQuery.context.loading) {
|
|
1430
|
-
this._infinityQuery.
|
|
1460
|
+
this._infinityQuery.loadNextPage();
|
|
1431
1461
|
}
|
|
1432
1462
|
}, {
|
|
1433
1463
|
root: this.scrollContainerSelector ? document.querySelector(this.scrollContainerSelector) : null,
|
|
@@ -1455,6 +1485,8 @@ class QueryStore {
|
|
|
1455
1485
|
this._config = _config;
|
|
1456
1486
|
this._store = new Map();
|
|
1457
1487
|
this._garbageCollector = null;
|
|
1488
|
+
this._isInLowResourceMode = false;
|
|
1489
|
+
this._lastBlurTimestamp = Date.now();
|
|
1458
1490
|
this._initSmartQueryHandling();
|
|
1459
1491
|
}
|
|
1460
1492
|
add(id, query) {
|
|
@@ -1492,30 +1524,42 @@ class QueryStore {
|
|
|
1492
1524
|
const windowBlur$ = fromEvent(window, 'blur');
|
|
1493
1525
|
const windowFocus$ = fromEvent(window, 'focus');
|
|
1494
1526
|
windowBlur$.subscribe(() => {
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1527
|
+
timer(5000)
|
|
1528
|
+
.pipe(takeUntil(windowFocus$), take(1))
|
|
1529
|
+
.subscribe(() => {
|
|
1530
|
+
var _a;
|
|
1531
|
+
this._lastBlurTimestamp = Date.now();
|
|
1532
|
+
this._isInLowResourceMode = true;
|
|
1533
|
+
this._stopGarbageCollector();
|
|
1534
|
+
if ((_a = this._config) === null || _a === void 0 ? void 0 : _a.enableSmartPolling) {
|
|
1535
|
+
this.forEach((query) => {
|
|
1536
|
+
if (!query.isPolling || !query._enableSmartPolling) {
|
|
1537
|
+
return;
|
|
1538
|
+
}
|
|
1539
|
+
query.pausePolling();
|
|
1540
|
+
});
|
|
1541
|
+
}
|
|
1542
|
+
});
|
|
1505
1543
|
});
|
|
1506
1544
|
windowFocus$.subscribe(() => {
|
|
1507
1545
|
var _a, _b;
|
|
1546
|
+
if (!this._isInLowResourceMode) {
|
|
1547
|
+
return;
|
|
1548
|
+
}
|
|
1549
|
+
this._isInLowResourceMode = false;
|
|
1508
1550
|
if (((_a = this._config) === null || _a === void 0 ? void 0 : _a.enableSmartPolling) || ((_b = this._config) === null || _b === void 0 ? void 0 : _b.autoRefreshQueriesOnWindowFocus)) {
|
|
1509
1551
|
this.forEach((query) => {
|
|
1510
1552
|
var _a, _b;
|
|
1511
1553
|
if (((_a = this._config) === null || _a === void 0 ? void 0 : _a.enableSmartPolling) && query._isPollingPaused) {
|
|
1512
1554
|
query.resumePolling();
|
|
1513
1555
|
}
|
|
1514
|
-
if ((
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1556
|
+
if (Date.now() - this._lastBlurTimestamp > 15000) {
|
|
1557
|
+
if (((_b = this._config) === null || _b === void 0 ? void 0 : _b.autoRefreshQueriesOnWindowFocus) &&
|
|
1558
|
+
query.isExpired &&
|
|
1559
|
+
query.isInUse &&
|
|
1560
|
+
query.autoRefreshOnConfig.windowFocus) {
|
|
1561
|
+
query.execute({ skipCache: true, _triggeredVia: 'auto' });
|
|
1562
|
+
}
|
|
1519
1563
|
}
|
|
1520
1564
|
});
|
|
1521
1565
|
}
|
|
@@ -1547,6 +1591,7 @@ class QueryStore {
|
|
|
1547
1591
|
if (this._garbageCollector !== null) {
|
|
1548
1592
|
window.clearInterval(this._garbageCollector);
|
|
1549
1593
|
this._garbageCollector = null;
|
|
1594
|
+
this._logGarbageCollector('Stop');
|
|
1550
1595
|
}
|
|
1551
1596
|
}
|
|
1552
1597
|
_runGarbageCollector() {
|
|
@@ -1559,7 +1604,6 @@ class QueryStore {
|
|
|
1559
1604
|
this._logGarbageCollector('Collection done');
|
|
1560
1605
|
if (!this._store.size) {
|
|
1561
1606
|
this._stopGarbageCollector();
|
|
1562
|
-
this._logGarbageCollector('Stop');
|
|
1563
1607
|
}
|
|
1564
1608
|
}
|
|
1565
1609
|
_logGarbageCollector(action) {
|
|
@@ -1919,5 +1963,5 @@ const def = () => null;
|
|
|
1919
1963
|
* Generated bundle index. Do not edit.
|
|
1920
1964
|
*/
|
|
1921
1965
|
|
|
1922
|
-
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 };
|
|
1966
|
+
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 };
|
|
1923
1967
|
//# sourceMappingURL=ethlete-query.mjs.map
|