@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) {
|
|
@@ -101,9 +78,15 @@ const buildRoute = (options) => {
|
|
|
101
78
|
const buildQueryString = (params) => {
|
|
102
79
|
const validParams = filterInvalidParams(params);
|
|
103
80
|
const queryString = Object.keys(validParams)
|
|
104
|
-
.map((key) =>
|
|
105
|
-
|
|
106
|
-
|
|
81
|
+
.map((key) => {
|
|
82
|
+
if (Array.isArray(validParams[key])) {
|
|
83
|
+
return buildQueryArrayString(key, validParams[key]);
|
|
84
|
+
}
|
|
85
|
+
if (typeof validParams[key] === 'object' && validParams[key] !== null) {
|
|
86
|
+
return buildQueryString(validParams[key]);
|
|
87
|
+
}
|
|
88
|
+
return `${key}=${encodeURIComponent(validParams[key])}`;
|
|
89
|
+
})
|
|
107
90
|
.join('&');
|
|
108
91
|
return queryString || null;
|
|
109
92
|
};
|
|
@@ -205,11 +188,14 @@ const serializeBody = (body) => {
|
|
|
205
188
|
}
|
|
206
189
|
return body.toString();
|
|
207
190
|
};
|
|
208
|
-
const transformMethod = (
|
|
209
|
-
if (method === 'GQL_QUERY' || method === 'GQL_MUTATE') {
|
|
210
|
-
|
|
191
|
+
const transformMethod = (config) => {
|
|
192
|
+
if (config.method === 'GQL_QUERY' || config.method === 'GQL_MUTATE') {
|
|
193
|
+
if (!config.transferVia) {
|
|
194
|
+
return 'POST';
|
|
195
|
+
}
|
|
196
|
+
return config.transferVia;
|
|
211
197
|
}
|
|
212
|
-
return method;
|
|
198
|
+
return config.method;
|
|
213
199
|
};
|
|
214
200
|
const detectContentTypeHeader = (body) => {
|
|
215
201
|
// An empty body has no content type.
|
|
@@ -491,11 +477,39 @@ const request = (config) => {
|
|
|
491
477
|
});
|
|
492
478
|
};
|
|
493
479
|
|
|
480
|
+
const getOpName = /(query|mutation) ?([\w\d-_]+)? ?\(.*?\)? \{/;
|
|
481
|
+
const transformGql = (str) => {
|
|
482
|
+
str = Array.isArray(str) ? str.join('') : str;
|
|
483
|
+
const name = getOpName.exec(str);
|
|
484
|
+
return function (variables) {
|
|
485
|
+
const data = { query: str };
|
|
486
|
+
if (variables)
|
|
487
|
+
data['variables'] = JSON.stringify(variables);
|
|
488
|
+
if (name && name.length) {
|
|
489
|
+
const operationName = name[2];
|
|
490
|
+
if (operationName)
|
|
491
|
+
data['operationName'] = name[2];
|
|
492
|
+
}
|
|
493
|
+
return data;
|
|
494
|
+
};
|
|
495
|
+
};
|
|
496
|
+
const gql = (strings, ...values) => {
|
|
497
|
+
const str = strings.reduce((acc, cur, i) => {
|
|
498
|
+
return acc + cur + (values[i] || '');
|
|
499
|
+
}, '');
|
|
500
|
+
return str;
|
|
501
|
+
};
|
|
502
|
+
|
|
494
503
|
function filterSuccess() {
|
|
495
504
|
return function (source) {
|
|
496
505
|
return source.pipe(filter((value) => isQueryStateSuccess(value)));
|
|
497
506
|
};
|
|
498
507
|
}
|
|
508
|
+
function ignoreAutoRefresh() {
|
|
509
|
+
return function (source) {
|
|
510
|
+
return source.pipe(filter((value) => !isAutoRefresh(value)));
|
|
511
|
+
};
|
|
512
|
+
}
|
|
499
513
|
function filterFailure() {
|
|
500
514
|
return function (source) {
|
|
501
515
|
return source.pipe(filter((value) => isQueryStateFailure(value)));
|
|
@@ -536,6 +550,7 @@ const isQueryStateSuccess = (state) => (state === null || state === void 0 ? voi
|
|
|
536
550
|
const isQueryStateFailure = (state) => (state === null || state === void 0 ? void 0 : state.type) === "FAILURE" /* QueryStateType.Failure */;
|
|
537
551
|
const isQueryStateCancelled = (state) => (state === null || state === void 0 ? void 0 : state.type) === "CANCELLED" /* QueryStateType.Cancelled */;
|
|
538
552
|
const isQueryStatePrepared = (state) => (state === null || state === void 0 ? void 0 : state.type) === "PREPARED" /* QueryStateType.Prepared */;
|
|
553
|
+
const isAutoRefresh = (state) => (state === null || state === void 0 ? void 0 : state.meta.triggeredVia) === 'auto';
|
|
539
554
|
const mergeHeaders = (...headers) => {
|
|
540
555
|
return headers.reduce((acc, headers) => {
|
|
541
556
|
if (!headers) {
|
|
@@ -576,6 +591,78 @@ const getDefaultHeaders = (headers, method) => {
|
|
|
576
591
|
}
|
|
577
592
|
return headers;
|
|
578
593
|
};
|
|
594
|
+
const castQueryCreatorTypes = (config) => {
|
|
595
|
+
var _a;
|
|
596
|
+
if ((_a = config.args) === null || _a === void 0 ? void 0 : _a.pathParams) {
|
|
597
|
+
console.error(config);
|
|
598
|
+
throw new Error('Path params cannot be overridden in castQueryCreatorTypes. Create a new query creator instead.');
|
|
599
|
+
}
|
|
600
|
+
return config.creator;
|
|
601
|
+
};
|
|
602
|
+
const computeQueryMethod = (config) => {
|
|
603
|
+
let method;
|
|
604
|
+
if (isGqlQueryConfig(config.config)) {
|
|
605
|
+
method = transformMethod({ method: config.config.method, transferVia: config.config.transferVia });
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
method = transformMethod({ method: config.config.method });
|
|
609
|
+
}
|
|
610
|
+
return method;
|
|
611
|
+
};
|
|
612
|
+
const computeQueryBody = (config) => {
|
|
613
|
+
var _a, _b;
|
|
614
|
+
let body;
|
|
615
|
+
if (config.method === 'GET' ||
|
|
616
|
+
config.method === 'HEAD' ||
|
|
617
|
+
config.method === 'OPTIONS' ||
|
|
618
|
+
(isGqlQueryConfig(config.config) && config.config.transferVia === 'GET')) {
|
|
619
|
+
return undefined;
|
|
620
|
+
}
|
|
621
|
+
if (isGqlQueryConfig(config.config)) {
|
|
622
|
+
const queryTemplate = config.config.query;
|
|
623
|
+
const query = transformGql(queryTemplate);
|
|
624
|
+
body = query((_a = config.args) === null || _a === void 0 ? void 0 : _a.variables);
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
body = (_b = config.args) === null || _b === void 0 ? void 0 : _b.body;
|
|
628
|
+
}
|
|
629
|
+
return body;
|
|
630
|
+
};
|
|
631
|
+
const computeQueryAuthHeader = (config) => {
|
|
632
|
+
var _a, _b;
|
|
633
|
+
let authHeader = null;
|
|
634
|
+
if (config.config.secure) {
|
|
635
|
+
const header = (_a = config.client.authProvider) === null || _a === void 0 ? void 0 : _a.header;
|
|
636
|
+
if (header) {
|
|
637
|
+
authHeader = header;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
else if ((_b = config.client.authProvider) === null || _b === void 0 ? void 0 : _b.header) {
|
|
641
|
+
if (config.config.secure === undefined || config.config.secure) {
|
|
642
|
+
authHeader = config.client.authProvider.header;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return authHeader;
|
|
646
|
+
};
|
|
647
|
+
const computeQueryHeaders = (config) => {
|
|
648
|
+
var _a, _b;
|
|
649
|
+
const authHeader = computeQueryAuthHeader(config);
|
|
650
|
+
const mergedHeaders = mergeHeaders(getDefaultHeaders((_a = config.client.config.request) === null || _a === void 0 ? void 0 : _a.headers, config.config.method), authHeader, (_b = config.args) === null || _b === void 0 ? void 0 : _b.headers) || undefined;
|
|
651
|
+
return mergedHeaders;
|
|
652
|
+
};
|
|
653
|
+
const computeQueryQueryParams = (config) => {
|
|
654
|
+
var _a, _b, _c, _d;
|
|
655
|
+
if (isGqlQueryConfig(config.config) && config.config.transferVia === 'GET') {
|
|
656
|
+
const queryTemplate = config.config.query;
|
|
657
|
+
const query = transformGql(queryTemplate);
|
|
658
|
+
let params = query((_a = config.args) === null || _a === void 0 ? void 0 : _a.variables);
|
|
659
|
+
if ((_b = config.args) === null || _b === void 0 ? void 0 : _b.queryParams) {
|
|
660
|
+
params = Object.assign(Object.assign({}, params), (_c = config.args) === null || _c === void 0 ? void 0 : _c.queryParams);
|
|
661
|
+
}
|
|
662
|
+
return params;
|
|
663
|
+
}
|
|
664
|
+
return (_d = config.args) === null || _d === void 0 ? void 0 : _d.queryParams;
|
|
665
|
+
};
|
|
579
666
|
|
|
580
667
|
class Query {
|
|
581
668
|
get _nextId() {
|
|
@@ -641,7 +728,7 @@ class Query {
|
|
|
641
728
|
return this._client.fetch(this._queryConfig);
|
|
642
729
|
}
|
|
643
730
|
execute(options) {
|
|
644
|
-
var _a, _b, _c
|
|
731
|
+
var _a, _b, _c;
|
|
645
732
|
const triggeredVia = (_a = options === null || options === void 0 ? void 0 : options._triggeredVia) !== null && _a !== void 0 ? _a : 'program';
|
|
646
733
|
if (!this.isExpired && !(options === null || options === void 0 ? void 0 : options.skipCache) && isQueryStateSuccess(this.state)) {
|
|
647
734
|
return this;
|
|
@@ -659,38 +746,19 @@ class Query {
|
|
|
659
746
|
meta,
|
|
660
747
|
});
|
|
661
748
|
this._updateUseResultInDependencies();
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
const query = transformGql(queryTemplate);
|
|
666
|
-
body = query((_b = this._args) === null || _b === void 0 ? void 0 : _b.variables);
|
|
667
|
-
}
|
|
668
|
-
else {
|
|
669
|
-
body = (_c = this._args) === null || _c === void 0 ? void 0 : _c.body;
|
|
670
|
-
}
|
|
671
|
-
let authHeader = null;
|
|
672
|
-
if (this._queryConfig.secure) {
|
|
673
|
-
const header = (_d = this._client.authProvider) === null || _d === void 0 ? void 0 : _d.header;
|
|
674
|
-
if (header) {
|
|
675
|
-
authHeader = header;
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
else if ((_e = this._client.authProvider) === null || _e === void 0 ? void 0 : _e.header) {
|
|
679
|
-
if (this._queryConfig.secure === undefined || this._queryConfig.secure) {
|
|
680
|
-
authHeader = this._client.authProvider.header;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
const mergedHeaders = mergeHeaders(getDefaultHeaders((_f = this._client.config.request) === null || _f === void 0 ? void 0 : _f.headers, this._queryConfig.method), authHeader, (_g = this._args) === null || _g === void 0 ? void 0 : _g.headers) || undefined;
|
|
749
|
+
const method = computeQueryMethod({ config: this._queryConfig });
|
|
750
|
+
const body = computeQueryBody({ config: this._queryConfig, args: this._args, method });
|
|
751
|
+
const headers = computeQueryHeaders({ client: this._client, config: this._queryConfig, args: this._args });
|
|
684
752
|
request({
|
|
685
753
|
urlWithParams: this._routeWithParams,
|
|
686
|
-
method
|
|
754
|
+
method,
|
|
687
755
|
body,
|
|
688
|
-
headers
|
|
756
|
+
headers,
|
|
689
757
|
reportProgress: this._queryConfig.reportProgress,
|
|
690
758
|
responseType: this._queryConfig.responseType,
|
|
691
759
|
withCredentials: this._queryConfig.withCredentials,
|
|
692
|
-
cacheAdapter: (
|
|
693
|
-
retryFn: (
|
|
760
|
+
cacheAdapter: (_b = this._client.config.request) === null || _b === void 0 ? void 0 : _b.cacheAdapter,
|
|
761
|
+
retryFn: (_c = this._client.config.request) === null || _c === void 0 ? void 0 : _c.retryFn,
|
|
694
762
|
})
|
|
695
763
|
.pipe(takeUntil(this._onAbort$))
|
|
696
764
|
.subscribe({
|
|
@@ -771,7 +839,7 @@ class Query {
|
|
|
771
839
|
? interval(config.interval).pipe(startWith(-1))
|
|
772
840
|
: interval(config.interval);
|
|
773
841
|
this._pollingSubscription = _interval
|
|
774
|
-
.pipe(takeUntil(config.takeUntil))
|
|
842
|
+
.pipe(takeUntil(config.takeUntil), finalize(() => this.stopPolling()))
|
|
775
843
|
.subscribe(() => this.execute({ skipCache: true, _triggeredVia: 'poll' }));
|
|
776
844
|
return this;
|
|
777
845
|
}
|
|
@@ -1073,9 +1141,9 @@ class QueryDirective {
|
|
|
1073
1141
|
}
|
|
1074
1142
|
}
|
|
1075
1143
|
}
|
|
1076
|
-
QueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1077
|
-
QueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1078
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
1144
|
+
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 });
|
|
1145
|
+
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 });
|
|
1146
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: QueryDirective, decorators: [{
|
|
1079
1147
|
type: Directive,
|
|
1080
1148
|
args: [{
|
|
1081
1149
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1170,6 +1238,9 @@ class InfinityQuery {
|
|
|
1170
1238
|
this._data$.next([]);
|
|
1171
1239
|
this.nextPage();
|
|
1172
1240
|
}
|
|
1241
|
+
/**
|
|
1242
|
+
* @internal
|
|
1243
|
+
*/
|
|
1173
1244
|
_clearSubscriptions() {
|
|
1174
1245
|
this._subscriptions.forEach((sub) => sub.unsubscribe());
|
|
1175
1246
|
this._subscriptions = [];
|
|
@@ -1282,7 +1353,7 @@ class InfinityQueryDirective {
|
|
|
1282
1353
|
this._cleanup();
|
|
1283
1354
|
this._infinityQuery = v;
|
|
1284
1355
|
this._infinityQueryInstance = this._setupInfinityQuery(v);
|
|
1285
|
-
this.
|
|
1356
|
+
this.loadNextPage();
|
|
1286
1357
|
}
|
|
1287
1358
|
get context() {
|
|
1288
1359
|
return this._viewContext;
|
|
@@ -1356,12 +1427,25 @@ class InfinityQueryDirective {
|
|
|
1356
1427
|
.subscribe();
|
|
1357
1428
|
return instance;
|
|
1358
1429
|
}
|
|
1430
|
+
/**
|
|
1431
|
+
* @deprecated Use `loadNextPage` instead
|
|
1432
|
+
* @breaking 3.0.0
|
|
1433
|
+
*/
|
|
1359
1434
|
_loadNextPage() {
|
|
1435
|
+
this.loadNextPage();
|
|
1436
|
+
}
|
|
1437
|
+
loadNextPage() {
|
|
1360
1438
|
if (!this._infinityQueryInstance) {
|
|
1361
1439
|
return;
|
|
1362
1440
|
}
|
|
1363
1441
|
this._infinityQueryInstance.nextPage();
|
|
1364
1442
|
}
|
|
1443
|
+
reset(newConfig) {
|
|
1444
|
+
if (!this._infinityQueryInstance) {
|
|
1445
|
+
return;
|
|
1446
|
+
}
|
|
1447
|
+
this._infinityQueryInstance.reset(newConfig);
|
|
1448
|
+
}
|
|
1365
1449
|
_renderMainView() {
|
|
1366
1450
|
if (!this._isMainViewCreated) {
|
|
1367
1451
|
this._isMainViewCreated = true;
|
|
@@ -1384,9 +1468,9 @@ class InfinityQueryDirective {
|
|
|
1384
1468
|
this._data$.next([]);
|
|
1385
1469
|
}
|
|
1386
1470
|
}
|
|
1387
|
-
InfinityQueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1388
|
-
InfinityQueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1389
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
1471
|
+
InfinityQueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: InfinityQueryDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1472
|
+
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 });
|
|
1473
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: InfinityQueryDirective, decorators: [{
|
|
1390
1474
|
type: Directive,
|
|
1391
1475
|
args: [{
|
|
1392
1476
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1411,7 +1495,7 @@ class InfinityQueryTriggerDirective {
|
|
|
1411
1495
|
ngOnInit() {
|
|
1412
1496
|
const isInteractive = this._elementRef.nativeElement.hasAttribute('infinityQueryTrigger');
|
|
1413
1497
|
if (isInteractive) {
|
|
1414
|
-
this.click$.pipe(takeUntil(this._destroy)).subscribe(() => this._infinityQuery.
|
|
1498
|
+
this.click$.pipe(takeUntil(this._destroy)).subscribe(() => this._infinityQuery.loadNextPage());
|
|
1415
1499
|
}
|
|
1416
1500
|
else {
|
|
1417
1501
|
this._setupIntersectionObserver();
|
|
@@ -1427,7 +1511,7 @@ class InfinityQueryTriggerDirective {
|
|
|
1427
1511
|
this._observer = new IntersectionObserver((entries) => {
|
|
1428
1512
|
const entry = entries[0];
|
|
1429
1513
|
if (entry.isIntersecting && !this._infinityQuery.context.loading) {
|
|
1430
|
-
this._infinityQuery.
|
|
1514
|
+
this._infinityQuery.loadNextPage();
|
|
1431
1515
|
}
|
|
1432
1516
|
}, {
|
|
1433
1517
|
root: this.scrollContainerSelector ? document.querySelector(this.scrollContainerSelector) : null,
|
|
@@ -1437,9 +1521,9 @@ class InfinityQueryTriggerDirective {
|
|
|
1437
1521
|
this._observer.observe(this._elementRef.nativeElement);
|
|
1438
1522
|
}
|
|
1439
1523
|
}
|
|
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.
|
|
1524
|
+
InfinityQueryTriggerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: InfinityQueryTriggerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1525
|
+
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 });
|
|
1526
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: InfinityQueryTriggerDirective, decorators: [{
|
|
1443
1527
|
type: Directive,
|
|
1444
1528
|
args: [{
|
|
1445
1529
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1455,6 +1539,8 @@ class QueryStore {
|
|
|
1455
1539
|
this._config = _config;
|
|
1456
1540
|
this._store = new Map();
|
|
1457
1541
|
this._garbageCollector = null;
|
|
1542
|
+
this._isInLowResourceMode = false;
|
|
1543
|
+
this._lastBlurTimestamp = Date.now();
|
|
1458
1544
|
this._initSmartQueryHandling();
|
|
1459
1545
|
}
|
|
1460
1546
|
add(id, query) {
|
|
@@ -1492,30 +1578,42 @@ class QueryStore {
|
|
|
1492
1578
|
const windowBlur$ = fromEvent(window, 'blur');
|
|
1493
1579
|
const windowFocus$ = fromEvent(window, 'focus');
|
|
1494
1580
|
windowBlur$.subscribe(() => {
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1581
|
+
timer(5000)
|
|
1582
|
+
.pipe(takeUntil(windowFocus$), take(1))
|
|
1583
|
+
.subscribe(() => {
|
|
1584
|
+
var _a;
|
|
1585
|
+
this._lastBlurTimestamp = Date.now();
|
|
1586
|
+
this._isInLowResourceMode = true;
|
|
1587
|
+
this._stopGarbageCollector();
|
|
1588
|
+
if ((_a = this._config) === null || _a === void 0 ? void 0 : _a.enableSmartPolling) {
|
|
1589
|
+
this.forEach((query) => {
|
|
1590
|
+
if (!query.isPolling || !query._enableSmartPolling) {
|
|
1591
|
+
return;
|
|
1592
|
+
}
|
|
1593
|
+
query.pausePolling();
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
});
|
|
1505
1597
|
});
|
|
1506
1598
|
windowFocus$.subscribe(() => {
|
|
1507
1599
|
var _a, _b;
|
|
1600
|
+
if (!this._isInLowResourceMode) {
|
|
1601
|
+
return;
|
|
1602
|
+
}
|
|
1603
|
+
this._isInLowResourceMode = false;
|
|
1508
1604
|
if (((_a = this._config) === null || _a === void 0 ? void 0 : _a.enableSmartPolling) || ((_b = this._config) === null || _b === void 0 ? void 0 : _b.autoRefreshQueriesOnWindowFocus)) {
|
|
1509
1605
|
this.forEach((query) => {
|
|
1510
1606
|
var _a, _b;
|
|
1511
1607
|
if (((_a = this._config) === null || _a === void 0 ? void 0 : _a.enableSmartPolling) && query._isPollingPaused) {
|
|
1512
1608
|
query.resumePolling();
|
|
1513
1609
|
}
|
|
1514
|
-
if ((
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1610
|
+
if (Date.now() - this._lastBlurTimestamp > 15000) {
|
|
1611
|
+
if (((_b = this._config) === null || _b === void 0 ? void 0 : _b.autoRefreshQueriesOnWindowFocus) &&
|
|
1612
|
+
query.isExpired &&
|
|
1613
|
+
query.isInUse &&
|
|
1614
|
+
query.autoRefreshOnConfig.windowFocus) {
|
|
1615
|
+
query.execute({ skipCache: true, _triggeredVia: 'auto' });
|
|
1616
|
+
}
|
|
1519
1617
|
}
|
|
1520
1618
|
});
|
|
1521
1619
|
}
|
|
@@ -1547,6 +1645,7 @@ class QueryStore {
|
|
|
1547
1645
|
if (this._garbageCollector !== null) {
|
|
1548
1646
|
window.clearInterval(this._garbageCollector);
|
|
1549
1647
|
this._garbageCollector = null;
|
|
1648
|
+
this._logGarbageCollector('Stop');
|
|
1550
1649
|
}
|
|
1551
1650
|
}
|
|
1552
1651
|
_runGarbageCollector() {
|
|
@@ -1559,7 +1658,6 @@ class QueryStore {
|
|
|
1559
1658
|
this._logGarbageCollector('Collection done');
|
|
1560
1659
|
if (!this._store.size) {
|
|
1561
1660
|
this._stopGarbageCollector();
|
|
1562
|
-
this._logGarbageCollector('Stop');
|
|
1563
1661
|
}
|
|
1564
1662
|
}
|
|
1565
1663
|
_logGarbageCollector(action) {
|
|
@@ -1615,7 +1713,7 @@ class QueryClient {
|
|
|
1615
1713
|
base: this._clientConfig.baseRoute,
|
|
1616
1714
|
route: queryConfig.route,
|
|
1617
1715
|
pathParams: args === null || args === void 0 ? void 0 : args.pathParams,
|
|
1618
|
-
queryParams:
|
|
1716
|
+
queryParams: computeQueryQueryParams({ config: queryConfig, args }),
|
|
1619
1717
|
});
|
|
1620
1718
|
const cacheKey = isGqlQueryConfig(queryConfig) ? buildGqlCacheKey(queryConfig, args) : route;
|
|
1621
1719
|
if (shouldCacheQuery(queryConfig.method)) {
|
|
@@ -1919,5 +2017,5 @@ const def = () => null;
|
|
|
1919
2017
|
* Generated bundle index. Do not edit.
|
|
1920
2018
|
*/
|
|
1921
2019
|
|
|
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 };
|
|
2020
|
+
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 };
|
|
1923
2021
|
//# sourceMappingURL=ethlete-query.mjs.map
|