@ethlete/query 2.2.0 → 2.4.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 +6 -6
- package/esm2020/lib/directives/infinity-query.directive.mjs +18 -5
- package/esm2020/lib/directives/query.directive.mjs +3 -3
- 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.mjs +10 -30
- package/esm2020/lib/query/query.types.mjs +1 -1
- package/esm2020/lib/query/query.utils.mjs +76 -1
- package/esm2020/lib/query-client/query-client.mjs +3 -3
- package/esm2020/lib/query-client/query-client.types.mjs +1 -1
- package/esm2020/lib/query-store/query-store.mjs +31 -17
- package/esm2020/lib/request/request.util.mjs +17 -8
- package/fesm2015/ethlete-query.mjs +187 -89
- package/fesm2015/ethlete-query.mjs.map +1 -1
- package/fesm2020/ethlete-query.mjs +178 -85
- 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 +18 -0
- package/lib/query/query.utils.d.ts +30 -2
- package/lib/query-client/query-client.types.d.ts +5 -1
- package/lib/query-store/query-store.d.ts +2 -0
- package/lib/request/request.util.d.ts +4 -1
- package/package.json +5 -5
|
@@ -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, finalize, 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';
|
|
@@ -32,29 +32,6 @@ class BasicAuthProvider {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
const getOpName = /(query|mutation) ?([\w\d-_]+)? ?\(.*?\)? \{/;
|
|
36
|
-
const transformGql = (str) => {
|
|
37
|
-
str = Array.isArray(str) ? str.join('') : str;
|
|
38
|
-
const name = getOpName.exec(str);
|
|
39
|
-
return function (variables) {
|
|
40
|
-
const data = { query: str };
|
|
41
|
-
if (variables)
|
|
42
|
-
data['variables'] = JSON.stringify(variables);
|
|
43
|
-
if (name && name.length) {
|
|
44
|
-
const operationName = name[2];
|
|
45
|
-
if (operationName)
|
|
46
|
-
data['operationName'] = name[2];
|
|
47
|
-
}
|
|
48
|
-
return data;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
const gql = (strings, ...values) => {
|
|
52
|
-
const str = strings.reduce((acc, cur, i) => {
|
|
53
|
-
return acc + cur + (values[i] || '');
|
|
54
|
-
}, '');
|
|
55
|
-
return str;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
35
|
const buildErrorMessage = (code, message) => `[@ethlete\\query:${code}] ${message}`;
|
|
59
36
|
class QueryError extends Error {
|
|
60
37
|
constructor(code, message, data) {
|
|
@@ -100,9 +77,15 @@ const buildRoute = (options) => {
|
|
|
100
77
|
const buildQueryString = (params) => {
|
|
101
78
|
const validParams = filterInvalidParams(params);
|
|
102
79
|
const queryString = Object.keys(validParams)
|
|
103
|
-
.map((key) =>
|
|
104
|
-
|
|
105
|
-
|
|
80
|
+
.map((key) => {
|
|
81
|
+
if (Array.isArray(validParams[key])) {
|
|
82
|
+
return buildQueryArrayString(key, validParams[key]);
|
|
83
|
+
}
|
|
84
|
+
if (typeof validParams[key] === 'object' && validParams[key] !== null) {
|
|
85
|
+
return buildQueryString(validParams[key]);
|
|
86
|
+
}
|
|
87
|
+
return `${key}=${encodeURIComponent(validParams[key])}`;
|
|
88
|
+
})
|
|
106
89
|
.join('&');
|
|
107
90
|
return queryString || null;
|
|
108
91
|
};
|
|
@@ -204,11 +187,14 @@ const serializeBody = (body) => {
|
|
|
204
187
|
}
|
|
205
188
|
return body.toString();
|
|
206
189
|
};
|
|
207
|
-
const transformMethod = (
|
|
208
|
-
if (method === 'GQL_QUERY' || method === 'GQL_MUTATE') {
|
|
209
|
-
|
|
190
|
+
const transformMethod = (config) => {
|
|
191
|
+
if (config.method === 'GQL_QUERY' || config.method === 'GQL_MUTATE') {
|
|
192
|
+
if (!config.transferVia) {
|
|
193
|
+
return 'POST';
|
|
194
|
+
}
|
|
195
|
+
return config.transferVia;
|
|
210
196
|
}
|
|
211
|
-
return method;
|
|
197
|
+
return config.method;
|
|
212
198
|
};
|
|
213
199
|
const detectContentTypeHeader = (body) => {
|
|
214
200
|
// An empty body has no content type.
|
|
@@ -489,11 +475,39 @@ const request = (config) => {
|
|
|
489
475
|
});
|
|
490
476
|
};
|
|
491
477
|
|
|
478
|
+
const getOpName = /(query|mutation) ?([\w\d-_]+)? ?\(.*?\)? \{/;
|
|
479
|
+
const transformGql = (str) => {
|
|
480
|
+
str = Array.isArray(str) ? str.join('') : str;
|
|
481
|
+
const name = getOpName.exec(str);
|
|
482
|
+
return function (variables) {
|
|
483
|
+
const data = { query: str };
|
|
484
|
+
if (variables)
|
|
485
|
+
data['variables'] = JSON.stringify(variables);
|
|
486
|
+
if (name && name.length) {
|
|
487
|
+
const operationName = name[2];
|
|
488
|
+
if (operationName)
|
|
489
|
+
data['operationName'] = name[2];
|
|
490
|
+
}
|
|
491
|
+
return data;
|
|
492
|
+
};
|
|
493
|
+
};
|
|
494
|
+
const gql = (strings, ...values) => {
|
|
495
|
+
const str = strings.reduce((acc, cur, i) => {
|
|
496
|
+
return acc + cur + (values[i] || '');
|
|
497
|
+
}, '');
|
|
498
|
+
return str;
|
|
499
|
+
};
|
|
500
|
+
|
|
492
501
|
function filterSuccess() {
|
|
493
502
|
return function (source) {
|
|
494
503
|
return source.pipe(filter((value) => isQueryStateSuccess(value)));
|
|
495
504
|
};
|
|
496
505
|
}
|
|
506
|
+
function ignoreAutoRefresh() {
|
|
507
|
+
return function (source) {
|
|
508
|
+
return source.pipe(filter((value) => !isAutoRefresh(value)));
|
|
509
|
+
};
|
|
510
|
+
}
|
|
497
511
|
function filterFailure() {
|
|
498
512
|
return function (source) {
|
|
499
513
|
return source.pipe(filter((value) => isQueryStateFailure(value)));
|
|
@@ -534,6 +548,7 @@ const isQueryStateSuccess = (state) => state?.type === "SUCCESS" /* QueryStateTy
|
|
|
534
548
|
const isQueryStateFailure = (state) => state?.type === "FAILURE" /* QueryStateType.Failure */;
|
|
535
549
|
const isQueryStateCancelled = (state) => state?.type === "CANCELLED" /* QueryStateType.Cancelled */;
|
|
536
550
|
const isQueryStatePrepared = (state) => state?.type === "PREPARED" /* QueryStateType.Prepared */;
|
|
551
|
+
const isAutoRefresh = (state) => state?.meta.triggeredVia === 'auto';
|
|
537
552
|
const mergeHeaders = (...headers) => {
|
|
538
553
|
return headers.reduce((acc, headers) => {
|
|
539
554
|
if (!headers) {
|
|
@@ -576,6 +591,73 @@ const getDefaultHeaders = (headers, method) => {
|
|
|
576
591
|
}
|
|
577
592
|
return headers;
|
|
578
593
|
};
|
|
594
|
+
const castQueryCreatorTypes = (config) => {
|
|
595
|
+
if (config.args?.pathParams) {
|
|
596
|
+
console.error(config);
|
|
597
|
+
throw new Error('Path params cannot be overridden in castQueryCreatorTypes. Create a new query creator instead.');
|
|
598
|
+
}
|
|
599
|
+
return config.creator;
|
|
600
|
+
};
|
|
601
|
+
const computeQueryMethod = (config) => {
|
|
602
|
+
let method;
|
|
603
|
+
if (isGqlQueryConfig(config.config)) {
|
|
604
|
+
method = transformMethod({ method: config.config.method, transferVia: config.config.transferVia });
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
method = transformMethod({ method: config.config.method });
|
|
608
|
+
}
|
|
609
|
+
return method;
|
|
610
|
+
};
|
|
611
|
+
const computeQueryBody = (config) => {
|
|
612
|
+
let body;
|
|
613
|
+
if (config.method === 'GET' ||
|
|
614
|
+
config.method === 'HEAD' ||
|
|
615
|
+
config.method === 'OPTIONS' ||
|
|
616
|
+
(isGqlQueryConfig(config.config) && config.config.transferVia === 'GET')) {
|
|
617
|
+
return undefined;
|
|
618
|
+
}
|
|
619
|
+
if (isGqlQueryConfig(config.config)) {
|
|
620
|
+
const queryTemplate = config.config.query;
|
|
621
|
+
const query = transformGql(queryTemplate);
|
|
622
|
+
body = query(config.args?.variables);
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
body = config.args?.body;
|
|
626
|
+
}
|
|
627
|
+
return body;
|
|
628
|
+
};
|
|
629
|
+
const computeQueryAuthHeader = (config) => {
|
|
630
|
+
let authHeader = null;
|
|
631
|
+
if (config.config.secure) {
|
|
632
|
+
const header = config.client.authProvider?.header;
|
|
633
|
+
if (header) {
|
|
634
|
+
authHeader = header;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
else if (config.client.authProvider?.header) {
|
|
638
|
+
if (config.config.secure === undefined || config.config.secure) {
|
|
639
|
+
authHeader = config.client.authProvider.header;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return authHeader;
|
|
643
|
+
};
|
|
644
|
+
const computeQueryHeaders = (config) => {
|
|
645
|
+
const authHeader = computeQueryAuthHeader(config);
|
|
646
|
+
const mergedHeaders = mergeHeaders(getDefaultHeaders(config.client.config.request?.headers, config.config.method), authHeader, config.args?.headers) || undefined;
|
|
647
|
+
return mergedHeaders;
|
|
648
|
+
};
|
|
649
|
+
const computeQueryQueryParams = (config) => {
|
|
650
|
+
if (isGqlQueryConfig(config.config) && config.config.transferVia === 'GET') {
|
|
651
|
+
const queryTemplate = config.config.query;
|
|
652
|
+
const query = transformGql(queryTemplate);
|
|
653
|
+
let params = query(config.args?.variables);
|
|
654
|
+
if (config.args?.queryParams) {
|
|
655
|
+
params = { ...params, ...config.args?.queryParams };
|
|
656
|
+
}
|
|
657
|
+
return params;
|
|
658
|
+
}
|
|
659
|
+
return config.args?.queryParams;
|
|
660
|
+
};
|
|
579
661
|
|
|
580
662
|
class Query {
|
|
581
663
|
get _nextId() {
|
|
@@ -656,33 +738,14 @@ class Query {
|
|
|
656
738
|
meta,
|
|
657
739
|
});
|
|
658
740
|
this._updateUseResultInDependencies();
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
const query = transformGql(queryTemplate);
|
|
663
|
-
body = query(this._args?.variables);
|
|
664
|
-
}
|
|
665
|
-
else {
|
|
666
|
-
body = this._args?.body;
|
|
667
|
-
}
|
|
668
|
-
let authHeader = null;
|
|
669
|
-
if (this._queryConfig.secure) {
|
|
670
|
-
const header = this._client.authProvider?.header;
|
|
671
|
-
if (header) {
|
|
672
|
-
authHeader = header;
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
else if (this._client.authProvider?.header) {
|
|
676
|
-
if (this._queryConfig.secure === undefined || this._queryConfig.secure) {
|
|
677
|
-
authHeader = this._client.authProvider.header;
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
const mergedHeaders = mergeHeaders(getDefaultHeaders(this._client.config.request?.headers, this._queryConfig.method), authHeader, this._args?.headers) || undefined;
|
|
741
|
+
const method = computeQueryMethod({ config: this._queryConfig });
|
|
742
|
+
const body = computeQueryBody({ config: this._queryConfig, args: this._args, method });
|
|
743
|
+
const headers = computeQueryHeaders({ client: this._client, config: this._queryConfig, args: this._args });
|
|
681
744
|
request({
|
|
682
745
|
urlWithParams: this._routeWithParams,
|
|
683
|
-
method
|
|
746
|
+
method,
|
|
684
747
|
body,
|
|
685
|
-
headers
|
|
748
|
+
headers,
|
|
686
749
|
reportProgress: this._queryConfig.reportProgress,
|
|
687
750
|
responseType: this._queryConfig.responseType,
|
|
688
751
|
withCredentials: this._queryConfig.withCredentials,
|
|
@@ -773,7 +836,7 @@ class Query {
|
|
|
773
836
|
? interval(config.interval).pipe(startWith(-1))
|
|
774
837
|
: interval(config.interval);
|
|
775
838
|
this._pollingSubscription = _interval
|
|
776
|
-
.pipe(takeUntil(config.takeUntil))
|
|
839
|
+
.pipe(takeUntil(config.takeUntil), finalize(() => this.stopPolling()))
|
|
777
840
|
.subscribe(() => this.execute({ skipCache: true, _triggeredVia: 'poll' }));
|
|
778
841
|
return this;
|
|
779
842
|
}
|
|
@@ -1061,9 +1124,9 @@ class QueryDirective {
|
|
|
1061
1124
|
}
|
|
1062
1125
|
}
|
|
1063
1126
|
}
|
|
1064
|
-
QueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1065
|
-
QueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1066
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
1127
|
+
QueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: QueryDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }, { token: i0.ErrorHandler }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
1128
|
+
QueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.2", type: QueryDirective, isStandalone: true, selector: "[query]", inputs: { query: "query", cache: ["queryCache", "cache"] }, ngImport: i0 });
|
|
1129
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: QueryDirective, decorators: [{
|
|
1067
1130
|
type: Directive,
|
|
1068
1131
|
args: [{
|
|
1069
1132
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1155,6 +1218,9 @@ class InfinityQuery {
|
|
|
1155
1218
|
this._data$.next([]);
|
|
1156
1219
|
this.nextPage();
|
|
1157
1220
|
}
|
|
1221
|
+
/**
|
|
1222
|
+
* @internal
|
|
1223
|
+
*/
|
|
1158
1224
|
_clearSubscriptions() {
|
|
1159
1225
|
this._subscriptions.forEach((sub) => sub.unsubscribe());
|
|
1160
1226
|
this._subscriptions = [];
|
|
@@ -1285,7 +1351,7 @@ class InfinityQueryDirective {
|
|
|
1285
1351
|
this._cleanup();
|
|
1286
1352
|
this._infinityQuery = v;
|
|
1287
1353
|
this._infinityQueryInstance = this._setupInfinityQuery(v);
|
|
1288
|
-
this.
|
|
1354
|
+
this.loadNextPage();
|
|
1289
1355
|
}
|
|
1290
1356
|
get context() {
|
|
1291
1357
|
return this._viewContext;
|
|
@@ -1358,12 +1424,25 @@ class InfinityQueryDirective {
|
|
|
1358
1424
|
.subscribe();
|
|
1359
1425
|
return instance;
|
|
1360
1426
|
}
|
|
1427
|
+
/**
|
|
1428
|
+
* @deprecated Use `loadNextPage` instead
|
|
1429
|
+
* @breaking 3.0.0
|
|
1430
|
+
*/
|
|
1361
1431
|
_loadNextPage() {
|
|
1432
|
+
this.loadNextPage();
|
|
1433
|
+
}
|
|
1434
|
+
loadNextPage() {
|
|
1362
1435
|
if (!this._infinityQueryInstance) {
|
|
1363
1436
|
return;
|
|
1364
1437
|
}
|
|
1365
1438
|
this._infinityQueryInstance.nextPage();
|
|
1366
1439
|
}
|
|
1440
|
+
reset(newConfig) {
|
|
1441
|
+
if (!this._infinityQueryInstance) {
|
|
1442
|
+
return;
|
|
1443
|
+
}
|
|
1444
|
+
this._infinityQueryInstance.reset(newConfig);
|
|
1445
|
+
}
|
|
1367
1446
|
_renderMainView() {
|
|
1368
1447
|
if (!this._isMainViewCreated) {
|
|
1369
1448
|
this._isMainViewCreated = true;
|
|
@@ -1385,9 +1464,9 @@ class InfinityQueryDirective {
|
|
|
1385
1464
|
this._data$.next([]);
|
|
1386
1465
|
}
|
|
1387
1466
|
}
|
|
1388
|
-
InfinityQueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1389
|
-
InfinityQueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1390
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
1467
|
+
InfinityQueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: InfinityQueryDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1468
|
+
InfinityQueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.2", type: InfinityQueryDirective, isStandalone: true, selector: "[infinityQuery]", inputs: { infinityQuery: "infinityQuery" }, providers: [{ provide: INFINITY_QUERY_TOKEN, useExisting: InfinityQueryDirective }, DestroyService], exportAs: ["infinityQuery"], ngImport: i0 });
|
|
1469
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: InfinityQueryDirective, decorators: [{
|
|
1391
1470
|
type: Directive,
|
|
1392
1471
|
args: [{
|
|
1393
1472
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1412,7 +1491,7 @@ class InfinityQueryTriggerDirective {
|
|
|
1412
1491
|
ngOnInit() {
|
|
1413
1492
|
const isInteractive = this._elementRef.nativeElement.hasAttribute('infinityQueryTrigger');
|
|
1414
1493
|
if (isInteractive) {
|
|
1415
|
-
this.click$.pipe(takeUntil(this._destroy)).subscribe(() => this._infinityQuery.
|
|
1494
|
+
this.click$.pipe(takeUntil(this._destroy)).subscribe(() => this._infinityQuery.loadNextPage());
|
|
1416
1495
|
}
|
|
1417
1496
|
else {
|
|
1418
1497
|
this._setupIntersectionObserver();
|
|
@@ -1427,7 +1506,7 @@ class InfinityQueryTriggerDirective {
|
|
|
1427
1506
|
this._observer = new IntersectionObserver((entries) => {
|
|
1428
1507
|
const entry = entries[0];
|
|
1429
1508
|
if (entry.isIntersecting && !this._infinityQuery.context.loading) {
|
|
1430
|
-
this._infinityQuery.
|
|
1509
|
+
this._infinityQuery.loadNextPage();
|
|
1431
1510
|
}
|
|
1432
1511
|
}, {
|
|
1433
1512
|
root: this.scrollContainerSelector ? document.querySelector(this.scrollContainerSelector) : null,
|
|
@@ -1437,9 +1516,9 @@ class InfinityQueryTriggerDirective {
|
|
|
1437
1516
|
this._observer.observe(this._elementRef.nativeElement);
|
|
1438
1517
|
}
|
|
1439
1518
|
}
|
|
1440
|
-
InfinityQueryTriggerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1441
|
-
InfinityQueryTriggerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1442
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
1519
|
+
InfinityQueryTriggerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: InfinityQueryTriggerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1520
|
+
InfinityQueryTriggerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.2", type: InfinityQueryTriggerDirective, isStandalone: true, selector: "[infinityQueryTrigger], infinity-query-trigger", inputs: { scrollContainerSelector: "scrollContainerSelector" }, ngImport: i0 });
|
|
1521
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: InfinityQueryTriggerDirective, decorators: [{
|
|
1443
1522
|
type: Directive,
|
|
1444
1523
|
args: [{
|
|
1445
1524
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1455,6 +1534,8 @@ class QueryStore {
|
|
|
1455
1534
|
this._config = _config;
|
|
1456
1535
|
this._store = new Map();
|
|
1457
1536
|
this._garbageCollector = null;
|
|
1537
|
+
this._isInLowResourceMode = false;
|
|
1538
|
+
this._lastBlurTimestamp = Date.now();
|
|
1458
1539
|
this._initSmartQueryHandling();
|
|
1459
1540
|
}
|
|
1460
1541
|
add(id, query) {
|
|
@@ -1491,27 +1572,39 @@ class QueryStore {
|
|
|
1491
1572
|
const windowBlur$ = fromEvent(window, 'blur');
|
|
1492
1573
|
const windowFocus$ = fromEvent(window, 'focus');
|
|
1493
1574
|
windowBlur$.subscribe(() => {
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1575
|
+
timer(5000)
|
|
1576
|
+
.pipe(takeUntil(windowFocus$), take(1))
|
|
1577
|
+
.subscribe(() => {
|
|
1578
|
+
this._lastBlurTimestamp = Date.now();
|
|
1579
|
+
this._isInLowResourceMode = true;
|
|
1580
|
+
this._stopGarbageCollector();
|
|
1581
|
+
if (this._config?.enableSmartPolling) {
|
|
1582
|
+
this.forEach((query) => {
|
|
1583
|
+
if (!query.isPolling || !query._enableSmartPolling) {
|
|
1584
|
+
return;
|
|
1585
|
+
}
|
|
1586
|
+
query.pausePolling();
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
});
|
|
1503
1590
|
});
|
|
1504
1591
|
windowFocus$.subscribe(() => {
|
|
1592
|
+
if (!this._isInLowResourceMode) {
|
|
1593
|
+
return;
|
|
1594
|
+
}
|
|
1595
|
+
this._isInLowResourceMode = false;
|
|
1505
1596
|
if (this._config?.enableSmartPolling || this._config?.autoRefreshQueriesOnWindowFocus) {
|
|
1506
1597
|
this.forEach((query) => {
|
|
1507
1598
|
if (this._config?.enableSmartPolling && query._isPollingPaused) {
|
|
1508
1599
|
query.resumePolling();
|
|
1509
1600
|
}
|
|
1510
|
-
if (this.
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1601
|
+
if (Date.now() - this._lastBlurTimestamp > 15000) {
|
|
1602
|
+
if (this._config?.autoRefreshQueriesOnWindowFocus &&
|
|
1603
|
+
query.isExpired &&
|
|
1604
|
+
query.isInUse &&
|
|
1605
|
+
query.autoRefreshOnConfig.windowFocus) {
|
|
1606
|
+
query.execute({ skipCache: true, _triggeredVia: 'auto' });
|
|
1607
|
+
}
|
|
1515
1608
|
}
|
|
1516
1609
|
});
|
|
1517
1610
|
}
|
|
@@ -1542,6 +1635,7 @@ class QueryStore {
|
|
|
1542
1635
|
if (this._garbageCollector !== null) {
|
|
1543
1636
|
window.clearInterval(this._garbageCollector);
|
|
1544
1637
|
this._garbageCollector = null;
|
|
1638
|
+
this._logGarbageCollector('Stop');
|
|
1545
1639
|
}
|
|
1546
1640
|
}
|
|
1547
1641
|
_runGarbageCollector() {
|
|
@@ -1554,7 +1648,6 @@ class QueryStore {
|
|
|
1554
1648
|
this._logGarbageCollector('Collection done');
|
|
1555
1649
|
if (!this._store.size) {
|
|
1556
1650
|
this._stopGarbageCollector();
|
|
1557
|
-
this._logGarbageCollector('Stop');
|
|
1558
1651
|
}
|
|
1559
1652
|
}
|
|
1560
1653
|
_logGarbageCollector(action) {
|
|
@@ -1627,7 +1720,7 @@ class QueryClient {
|
|
|
1627
1720
|
base: this._clientConfig.baseRoute,
|
|
1628
1721
|
route: queryConfig.route,
|
|
1629
1722
|
pathParams: args?.pathParams,
|
|
1630
|
-
queryParams: args
|
|
1723
|
+
queryParams: computeQueryQueryParams({ config: queryConfig, args }),
|
|
1631
1724
|
});
|
|
1632
1725
|
const cacheKey = isGqlQueryConfig(queryConfig) ? buildGqlCacheKey(queryConfig, args) : route;
|
|
1633
1726
|
if (shouldCacheQuery(queryConfig.method)) {
|
|
@@ -1926,5 +2019,5 @@ const def = () => null;
|
|
|
1926
2019
|
* Generated bundle index. Do not edit.
|
|
1927
2020
|
*/
|
|
1928
2021
|
|
|
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 };
|
|
2022
|
+
export { BasicAuthProvider, BearerAuthProvider, CustomHeaderAuthProvider, INFINITY_QUERY_TOKEN, InfinityQuery, InfinityQueryDirective, InfinityQueryTriggerDirective, Query, QueryClient, QueryDirective, QueryError, QueryField, QueryForm, QueryStore, buildErrorMessage, buildGqlCacheKey, buildQueryArrayString, 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, 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
2023
|
//# sourceMappingURL=ethlete-query.mjs.map
|