@ethlete/query 2.6.0 → 2.7.1
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/infinite-query/infinity-query.mjs +2 -9
- package/esm2020/lib/query/query.mjs +24 -37
- package/esm2020/lib/query/query.types.mjs +1 -1
- package/esm2020/lib/query/query.utils.mjs +24 -1
- package/esm2020/lib/request/request.types.mjs +1 -1
- package/esm2020/lib/request/request.util.mjs +24 -5
- package/fesm2015/ethlete-query.mjs +69 -47
- package/fesm2015/ethlete-query.mjs.map +1 -1
- package/fesm2020/ethlete-query.mjs +80 -58
- package/fesm2020/ethlete-query.mjs.map +1 -1
- package/lib/query/query.types.d.ts +6 -2
- package/lib/query/query.utils.d.ts +14 -0
- package/lib/request/request.types.d.ts +3 -1
- package/lib/request/request.util.d.ts +1 -0
- package/package.json +1 -1
|
@@ -82,7 +82,7 @@ const buildQueryString = (params) => {
|
|
|
82
82
|
return buildQueryArrayString(key, validParams[key]);
|
|
83
83
|
}
|
|
84
84
|
if (typeof validParams[key] === 'object' && validParams[key] !== null) {
|
|
85
|
-
return
|
|
85
|
+
return buildQueryObjectString(key, validParams[key]);
|
|
86
86
|
}
|
|
87
87
|
return `${key}=${encodeURIComponent(validParams[key])}`;
|
|
88
88
|
})
|
|
@@ -96,6 +96,22 @@ const buildQueryArrayString = (key, array) => {
|
|
|
96
96
|
.map((item) => `${key}${uriBrackets}=${encodeURIComponent(item)}`)
|
|
97
97
|
.join('&');
|
|
98
98
|
};
|
|
99
|
+
const buildQueryObjectString = (key, object) => {
|
|
100
|
+
const uriBracketStart = encodeURIComponent(`${key}[`);
|
|
101
|
+
const uriBracketEnd = encodeURIComponent(`]`);
|
|
102
|
+
return Object.keys(object)
|
|
103
|
+
.map((k) => {
|
|
104
|
+
const key = `${uriBracketStart}${k}${uriBracketEnd}`;
|
|
105
|
+
if (Array.isArray(object[k])) {
|
|
106
|
+
return buildQueryArrayString(key, object[k]);
|
|
107
|
+
}
|
|
108
|
+
if (typeof object[k] === 'object' && object[k] !== null) {
|
|
109
|
+
return buildQueryObjectString(key, object[k]);
|
|
110
|
+
}
|
|
111
|
+
return `${key}=${encodeURIComponent(object[k])}`;
|
|
112
|
+
})
|
|
113
|
+
.join('&');
|
|
114
|
+
};
|
|
99
115
|
const isFetchResponse = (response) => typeof response === 'object' &&
|
|
100
116
|
response !== null &&
|
|
101
117
|
'status' in response &&
|
|
@@ -105,10 +121,13 @@ const isFetchResponse = (response) => typeof response === 'object' &&
|
|
|
105
121
|
const filterInvalidParams = (params) => {
|
|
106
122
|
const filteredParams = Object.entries(params)
|
|
107
123
|
.map(([key, value]) => {
|
|
108
|
-
if (
|
|
109
|
-
return [key, value];
|
|
124
|
+
if (Array.isArray(value)) {
|
|
125
|
+
return [key, value.filter((v) => isParamValid(v))];
|
|
126
|
+
}
|
|
127
|
+
else if (typeof value === 'object' && value !== null) {
|
|
128
|
+
return [key, filterInvalidParams(value)];
|
|
110
129
|
}
|
|
111
|
-
return [key, value
|
|
130
|
+
return [key, value];
|
|
112
131
|
})
|
|
113
132
|
.filter(([, value]) => isParamValid(value))
|
|
114
133
|
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
|
|
@@ -663,6 +682,29 @@ const computeQueryQueryParams = (config) => {
|
|
|
663
682
|
}
|
|
664
683
|
return config.args?.queryParams;
|
|
665
684
|
};
|
|
685
|
+
const paginatedEntityValueUpdater = (findFn) => ({ response, rawResponse, entity }) => {
|
|
686
|
+
const indexOfEntityRaw = rawResponse.items.findIndex((item) => findFn(item, entity));
|
|
687
|
+
const indexOfEntity = response.items.findIndex((item) => findFn(item, entity));
|
|
688
|
+
if (indexOfEntity === -1 || indexOfEntityRaw === -1) {
|
|
689
|
+
return null;
|
|
690
|
+
}
|
|
691
|
+
const newRawResponse = {
|
|
692
|
+
...rawResponse,
|
|
693
|
+
items: [
|
|
694
|
+
...rawResponse.items.slice(0, indexOfEntityRaw),
|
|
695
|
+
entity,
|
|
696
|
+
...rawResponse.items.slice(indexOfEntityRaw + 1),
|
|
697
|
+
],
|
|
698
|
+
};
|
|
699
|
+
const newResponse = {
|
|
700
|
+
...response,
|
|
701
|
+
items: [...response.items.slice(0, indexOfEntity), entity, ...response.items.slice(indexOfEntity + 1)],
|
|
702
|
+
};
|
|
703
|
+
return {
|
|
704
|
+
response: newResponse,
|
|
705
|
+
rawResponse: newRawResponse,
|
|
706
|
+
};
|
|
707
|
+
};
|
|
666
708
|
|
|
667
709
|
class Query {
|
|
668
710
|
get _nextId() {
|
|
@@ -739,46 +781,33 @@ class Query {
|
|
|
739
781
|
if (!key) {
|
|
740
782
|
return;
|
|
741
783
|
}
|
|
742
|
-
const currentValue = this._queryConfig.entity?.valueSelector({
|
|
743
|
-
args: this._args,
|
|
744
|
-
response,
|
|
745
|
-
rawResponse,
|
|
746
|
-
});
|
|
747
784
|
const newData = this._queryConfig.entity?.store.getOne(event.key);
|
|
748
|
-
if (
|
|
749
|
-
|
|
750
|
-
if (index === -1) {
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
|
-
const newValue = [...currentValue];
|
|
754
|
-
if (newData) {
|
|
755
|
-
newValue[index] = newData;
|
|
756
|
-
}
|
|
757
|
-
else {
|
|
758
|
-
newValue.splice(index, 1);
|
|
759
|
-
}
|
|
760
|
-
this._state$.next({
|
|
761
|
-
...this.state,
|
|
762
|
-
response: newValue,
|
|
763
|
-
meta: {
|
|
764
|
-
...this.state.meta,
|
|
765
|
-
triggeredVia: 'auto',
|
|
766
|
-
},
|
|
767
|
-
});
|
|
785
|
+
if (!newData) {
|
|
786
|
+
return;
|
|
768
787
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
788
|
+
const newResponse = this._queryConfig.entity?.valueUpdater
|
|
789
|
+
? this._queryConfig.entity?.valueUpdater({
|
|
790
|
+
args: this._args,
|
|
791
|
+
entity: newData,
|
|
792
|
+
rawResponse,
|
|
793
|
+
response,
|
|
794
|
+
})
|
|
795
|
+
: {
|
|
775
796
|
response: newData,
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
});
|
|
797
|
+
rawResponse: newData,
|
|
798
|
+
};
|
|
799
|
+
if (!newResponse) {
|
|
800
|
+
return;
|
|
781
801
|
}
|
|
802
|
+
this._state$.next({
|
|
803
|
+
...this.state,
|
|
804
|
+
response: newResponse.response,
|
|
805
|
+
rawResponse: newResponse.rawResponse,
|
|
806
|
+
meta: {
|
|
807
|
+
...this.state.meta,
|
|
808
|
+
triggeredVia: 'auto',
|
|
809
|
+
},
|
|
810
|
+
});
|
|
782
811
|
});
|
|
783
812
|
}
|
|
784
813
|
}
|
|
@@ -1214,9 +1243,9 @@ class QueryDirective {
|
|
|
1214
1243
|
}
|
|
1215
1244
|
}
|
|
1216
1245
|
}
|
|
1217
|
-
QueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1218
|
-
QueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1219
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
1246
|
+
QueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: QueryDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }, { token: i0.ErrorHandler }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
1247
|
+
QueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.5", type: QueryDirective, isStandalone: true, selector: "[query]", inputs: { query: "query", cache: ["queryCache", "cache"] }, ngImport: i0 });
|
|
1248
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: QueryDirective, decorators: [{
|
|
1220
1249
|
type: Directive,
|
|
1221
1250
|
args: [{
|
|
1222
1251
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1355,14 +1384,7 @@ class InfinityQuery {
|
|
|
1355
1384
|
this._subscriptions = this._subscriptions.filter((sub) => sub !== stateChangesSub);
|
|
1356
1385
|
},
|
|
1357
1386
|
});
|
|
1358
|
-
|
|
1359
|
-
next: (state) => {
|
|
1360
|
-
if (state.meta.triggeredVia === 'auto') {
|
|
1361
|
-
this.reset();
|
|
1362
|
-
}
|
|
1363
|
-
},
|
|
1364
|
-
});
|
|
1365
|
-
this._subscriptions.push(stateChangesSub, queryAutoRefreshSub);
|
|
1387
|
+
this._subscriptions.push(stateChangesSub);
|
|
1366
1388
|
}
|
|
1367
1389
|
_prepareArgs(config, page) {
|
|
1368
1390
|
const pageParamLocation = this._getPageParamLocation(config?.pageParam?.location);
|
|
@@ -1568,9 +1590,9 @@ class InfinityQueryDirective {
|
|
|
1568
1590
|
this._data$.next([]);
|
|
1569
1591
|
}
|
|
1570
1592
|
}
|
|
1571
|
-
InfinityQueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1572
|
-
InfinityQueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1573
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
1593
|
+
InfinityQueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: InfinityQueryDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1594
|
+
InfinityQueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.5", type: InfinityQueryDirective, isStandalone: true, selector: "[infinityQuery]", inputs: { infinityQuery: "infinityQuery" }, providers: [{ provide: INFINITY_QUERY_TOKEN, useExisting: InfinityQueryDirective }, DestroyService], exportAs: ["infinityQuery"], ngImport: i0 });
|
|
1595
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: InfinityQueryDirective, decorators: [{
|
|
1574
1596
|
type: Directive,
|
|
1575
1597
|
args: [{
|
|
1576
1598
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1620,9 +1642,9 @@ class InfinityQueryTriggerDirective {
|
|
|
1620
1642
|
this._observer.observe(this._elementRef.nativeElement);
|
|
1621
1643
|
}
|
|
1622
1644
|
}
|
|
1623
|
-
InfinityQueryTriggerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1624
|
-
InfinityQueryTriggerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1625
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
1645
|
+
InfinityQueryTriggerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: InfinityQueryTriggerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1646
|
+
InfinityQueryTriggerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.5", type: InfinityQueryTriggerDirective, isStandalone: true, selector: "[infinityQueryTrigger], infinity-query-trigger", inputs: { scrollContainerSelector: "scrollContainerSelector" }, ngImport: i0 });
|
|
1647
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: InfinityQueryTriggerDirective, decorators: [{
|
|
1626
1648
|
type: Directive,
|
|
1627
1649
|
args: [{
|
|
1628
1650
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -2259,5 +2281,5 @@ const def = () => null;
|
|
|
2259
2281
|
* Generated bundle index. Do not edit.
|
|
2260
2282
|
*/
|
|
2261
2283
|
|
|
2262
|
-
export { BasicAuthProvider, BearerAuthProvider, CustomHeaderAuthProvider, EntityStore, 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 };
|
|
2284
|
+
export { BasicAuthProvider, BearerAuthProvider, CustomHeaderAuthProvider, EntityStore, INFINITY_QUERY_TOKEN, InfinityQuery, InfinityQueryDirective, InfinityQueryTriggerDirective, Query, QueryClient, QueryDirective, QueryError, QueryField, QueryForm, QueryStore, buildErrorMessage, buildGqlCacheKey, buildQueryArrayString, buildQueryObjectString, 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, paginatedEntityValueUpdater, 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 };
|
|
2263
2285
|
//# sourceMappingURL=ethlete-query.mjs.map
|