@ethlete/query 2.3.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 +3 -3
- package/esm2020/lib/directives/infinity-query.directive.mjs +3 -3
- package/esm2020/lib/directives/query.directive.mjs +3 -3
- package/esm2020/lib/query/query.mjs +10 -30
- package/esm2020/lib/query/query.types.mjs +1 -1
- package/esm2020/lib/query/query.utils.mjs +63 -1
- package/esm2020/lib/query-client/query-client.mjs +3 -3
- package/esm2020/lib/request/request.util.mjs +17 -8
- package/fesm2015/ethlete-query.mjs +124 -70
- package/fesm2015/ethlete-query.mjs.map +1 -1
- package/fesm2020/ethlete-query.mjs +117 -67
- package/fesm2020/ethlete-query.mjs.map +1 -1
- package/lib/query/query.types.d.ts +9 -0
- package/lib/query/query.utils.d.ts +23 -2
- package/lib/request/request.util.d.ts +4 -1
- package/package.json +2 -2
|
@@ -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, take, concat, debounceTime, combineLatest, map, distinctUntilChanged } from 'rxjs';
|
|
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,6 +475,29 @@ 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)));
|
|
@@ -589,6 +598,66 @@ const castQueryCreatorTypes = (config) => {
|
|
|
589
598
|
}
|
|
590
599
|
return config.creator;
|
|
591
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
|
+
};
|
|
592
661
|
|
|
593
662
|
class Query {
|
|
594
663
|
get _nextId() {
|
|
@@ -669,33 +738,14 @@ class Query {
|
|
|
669
738
|
meta,
|
|
670
739
|
});
|
|
671
740
|
this._updateUseResultInDependencies();
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
const query = transformGql(queryTemplate);
|
|
676
|
-
body = query(this._args?.variables);
|
|
677
|
-
}
|
|
678
|
-
else {
|
|
679
|
-
body = this._args?.body;
|
|
680
|
-
}
|
|
681
|
-
let authHeader = null;
|
|
682
|
-
if (this._queryConfig.secure) {
|
|
683
|
-
const header = this._client.authProvider?.header;
|
|
684
|
-
if (header) {
|
|
685
|
-
authHeader = header;
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
else if (this._client.authProvider?.header) {
|
|
689
|
-
if (this._queryConfig.secure === undefined || this._queryConfig.secure) {
|
|
690
|
-
authHeader = this._client.authProvider.header;
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
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 });
|
|
694
744
|
request({
|
|
695
745
|
urlWithParams: this._routeWithParams,
|
|
696
|
-
method
|
|
746
|
+
method,
|
|
697
747
|
body,
|
|
698
|
-
headers
|
|
748
|
+
headers,
|
|
699
749
|
reportProgress: this._queryConfig.reportProgress,
|
|
700
750
|
responseType: this._queryConfig.responseType,
|
|
701
751
|
withCredentials: this._queryConfig.withCredentials,
|
|
@@ -786,7 +836,7 @@ class Query {
|
|
|
786
836
|
? interval(config.interval).pipe(startWith(-1))
|
|
787
837
|
: interval(config.interval);
|
|
788
838
|
this._pollingSubscription = _interval
|
|
789
|
-
.pipe(takeUntil(config.takeUntil))
|
|
839
|
+
.pipe(takeUntil(config.takeUntil), finalize(() => this.stopPolling()))
|
|
790
840
|
.subscribe(() => this.execute({ skipCache: true, _triggeredVia: 'poll' }));
|
|
791
841
|
return this;
|
|
792
842
|
}
|
|
@@ -1074,9 +1124,9 @@ class QueryDirective {
|
|
|
1074
1124
|
}
|
|
1075
1125
|
}
|
|
1076
1126
|
}
|
|
1077
|
-
QueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1078
|
-
QueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1079
|
-
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: [{
|
|
1080
1130
|
type: Directive,
|
|
1081
1131
|
args: [{
|
|
1082
1132
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1414,9 +1464,9 @@ class InfinityQueryDirective {
|
|
|
1414
1464
|
this._data$.next([]);
|
|
1415
1465
|
}
|
|
1416
1466
|
}
|
|
1417
|
-
InfinityQueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1418
|
-
InfinityQueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1419
|
-
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: [{
|
|
1420
1470
|
type: Directive,
|
|
1421
1471
|
args: [{
|
|
1422
1472
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1466,9 +1516,9 @@ class InfinityQueryTriggerDirective {
|
|
|
1466
1516
|
this._observer.observe(this._elementRef.nativeElement);
|
|
1467
1517
|
}
|
|
1468
1518
|
}
|
|
1469
|
-
InfinityQueryTriggerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1470
|
-
InfinityQueryTriggerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1471
|
-
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: [{
|
|
1472
1522
|
type: Directive,
|
|
1473
1523
|
args: [{
|
|
1474
1524
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1670,7 +1720,7 @@ class QueryClient {
|
|
|
1670
1720
|
base: this._clientConfig.baseRoute,
|
|
1671
1721
|
route: queryConfig.route,
|
|
1672
1722
|
pathParams: args?.pathParams,
|
|
1673
|
-
queryParams: args
|
|
1723
|
+
queryParams: computeQueryQueryParams({ config: queryConfig, args }),
|
|
1674
1724
|
});
|
|
1675
1725
|
const cacheKey = isGqlQueryConfig(queryConfig) ? buildGqlCacheKey(queryConfig, args) : route;
|
|
1676
1726
|
if (shouldCacheQuery(queryConfig.method)) {
|
|
@@ -1969,5 +2019,5 @@ const def = () => null;
|
|
|
1969
2019
|
* Generated bundle index. Do not edit.
|
|
1970
2020
|
*/
|
|
1971
2021
|
|
|
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 };
|
|
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 };
|
|
1973
2023
|
//# sourceMappingURL=ethlete-query.mjs.map
|