@ethlete/query 2.6.0 → 2.7.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/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 +59 -30
- package/fesm2015/ethlete-query.mjs.map +1 -1
- package/fesm2020/ethlete-query.mjs +70 -41
- 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
|
@@ -83,7 +83,7 @@ const buildQueryString = (params) => {
|
|
|
83
83
|
return buildQueryArrayString(key, validParams[key]);
|
|
84
84
|
}
|
|
85
85
|
if (typeof validParams[key] === 'object' && validParams[key] !== null) {
|
|
86
|
-
return
|
|
86
|
+
return buildQueryObjectString(key, validParams[key]);
|
|
87
87
|
}
|
|
88
88
|
return `${key}=${encodeURIComponent(validParams[key])}`;
|
|
89
89
|
})
|
|
@@ -97,6 +97,22 @@ const buildQueryArrayString = (key, array) => {
|
|
|
97
97
|
.map((item) => `${key}${uriBrackets}=${encodeURIComponent(item)}`)
|
|
98
98
|
.join('&');
|
|
99
99
|
};
|
|
100
|
+
const buildQueryObjectString = (key, object) => {
|
|
101
|
+
const uriBracketStart = encodeURIComponent(`${key}[`);
|
|
102
|
+
const uriBracketEnd = encodeURIComponent(`]`);
|
|
103
|
+
return Object.keys(object)
|
|
104
|
+
.map((k) => {
|
|
105
|
+
const key = `${uriBracketStart}${k}${uriBracketEnd}`;
|
|
106
|
+
if (Array.isArray(object[k])) {
|
|
107
|
+
return buildQueryArrayString(key, object[k]);
|
|
108
|
+
}
|
|
109
|
+
if (typeof object[k] === 'object' && object[k] !== null) {
|
|
110
|
+
return buildQueryObjectString(key, object[k]);
|
|
111
|
+
}
|
|
112
|
+
return `${key}=${encodeURIComponent(object[k])}`;
|
|
113
|
+
})
|
|
114
|
+
.join('&');
|
|
115
|
+
};
|
|
100
116
|
const isFetchResponse = (response) => typeof response === 'object' &&
|
|
101
117
|
response !== null &&
|
|
102
118
|
'status' in response &&
|
|
@@ -106,10 +122,13 @@ const isFetchResponse = (response) => typeof response === 'object' &&
|
|
|
106
122
|
const filterInvalidParams = (params) => {
|
|
107
123
|
const filteredParams = Object.entries(params)
|
|
108
124
|
.map(([key, value]) => {
|
|
109
|
-
if (
|
|
110
|
-
return [key, value];
|
|
125
|
+
if (Array.isArray(value)) {
|
|
126
|
+
return [key, value.filter((v) => isParamValid(v))];
|
|
111
127
|
}
|
|
112
|
-
|
|
128
|
+
else if (typeof value === 'object' && value !== null) {
|
|
129
|
+
return [key, filterInvalidParams(value)];
|
|
130
|
+
}
|
|
131
|
+
return [key, value];
|
|
113
132
|
})
|
|
114
133
|
.filter(([, value]) => isParamValid(value))
|
|
115
134
|
.reduce((acc, [key, value]) => (Object.assign(Object.assign({}, acc), { [key]: value })), {});
|
|
@@ -669,6 +688,23 @@ const computeQueryQueryParams = (config) => {
|
|
|
669
688
|
}
|
|
670
689
|
return (_f = config.args) === null || _f === void 0 ? void 0 : _f.queryParams;
|
|
671
690
|
};
|
|
691
|
+
const paginatedEntityValueUpdater = (findFn) => ({ response, rawResponse, entity }) => {
|
|
692
|
+
const indexOfEntityRaw = rawResponse.items.findIndex((item) => findFn(item, entity));
|
|
693
|
+
const indexOfEntity = response.items.findIndex((item) => findFn(item, entity));
|
|
694
|
+
if (indexOfEntity === -1 || indexOfEntityRaw === -1) {
|
|
695
|
+
return null;
|
|
696
|
+
}
|
|
697
|
+
const newRawResponse = Object.assign(Object.assign({}, rawResponse), { items: [
|
|
698
|
+
...rawResponse.items.slice(0, indexOfEntityRaw),
|
|
699
|
+
entity,
|
|
700
|
+
...rawResponse.items.slice(indexOfEntityRaw + 1),
|
|
701
|
+
] });
|
|
702
|
+
const newResponse = Object.assign(Object.assign({}, response), { items: [...response.items.slice(0, indexOfEntity), entity, ...response.items.slice(indexOfEntity + 1)] });
|
|
703
|
+
return {
|
|
704
|
+
response: newResponse,
|
|
705
|
+
rawResponse: newRawResponse,
|
|
706
|
+
};
|
|
707
|
+
};
|
|
672
708
|
|
|
673
709
|
class Query {
|
|
674
710
|
get _nextId() {
|
|
@@ -737,7 +773,7 @@ class Query {
|
|
|
737
773
|
});
|
|
738
774
|
if ((_a = this._queryConfig.entity) === null || _a === void 0 ? void 0 : _a.store) {
|
|
739
775
|
this._entitySubscription = this._queryConfig.entity.store.events$.subscribe((event) => {
|
|
740
|
-
var _a, _b, _c;
|
|
776
|
+
var _a, _b, _c, _d;
|
|
741
777
|
if (event.type !== 'update' && event.type !== 'set') {
|
|
742
778
|
return;
|
|
743
779
|
}
|
|
@@ -750,32 +786,25 @@ class Query {
|
|
|
750
786
|
if (!key) {
|
|
751
787
|
return;
|
|
752
788
|
}
|
|
753
|
-
const
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
rawResponse,
|
|
757
|
-
});
|
|
758
|
-
const newData = (_c = this._queryConfig.entity) === null || _c === void 0 ? void 0 : _c.store.getOne(event.key);
|
|
759
|
-
if (Array.isArray(currentValue)) {
|
|
760
|
-
const index = currentValue.findIndex((item) => item[key] === event.key);
|
|
761
|
-
if (index === -1) {
|
|
762
|
-
return;
|
|
763
|
-
}
|
|
764
|
-
const newValue = [...currentValue];
|
|
765
|
-
if (newData) {
|
|
766
|
-
newValue[index] = newData;
|
|
767
|
-
}
|
|
768
|
-
else {
|
|
769
|
-
newValue.splice(index, 1);
|
|
770
|
-
}
|
|
771
|
-
this._state$.next(Object.assign(Object.assign({}, this.state), { response: newValue, meta: Object.assign(Object.assign({}, this.state.meta), { triggeredVia: 'auto' }) }));
|
|
789
|
+
const newData = (_b = this._queryConfig.entity) === null || _b === void 0 ? void 0 : _b.store.getOne(event.key);
|
|
790
|
+
if (!newData) {
|
|
791
|
+
return;
|
|
772
792
|
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
793
|
+
const newResponse = ((_c = this._queryConfig.entity) === null || _c === void 0 ? void 0 : _c.valueUpdater)
|
|
794
|
+
? (_d = this._queryConfig.entity) === null || _d === void 0 ? void 0 : _d.valueUpdater({
|
|
795
|
+
args: this._args,
|
|
796
|
+
entity: newData,
|
|
797
|
+
rawResponse,
|
|
798
|
+
response,
|
|
799
|
+
})
|
|
800
|
+
: {
|
|
801
|
+
response: newData,
|
|
802
|
+
rawResponse: newData,
|
|
803
|
+
};
|
|
804
|
+
if (!newResponse) {
|
|
805
|
+
return;
|
|
778
806
|
}
|
|
807
|
+
this._state$.next(Object.assign(Object.assign({}, this.state), { response: newResponse.response, rawResponse: newResponse.rawResponse, meta: Object.assign(Object.assign({}, this.state.meta), { triggeredVia: 'auto' }) }));
|
|
779
808
|
});
|
|
780
809
|
}
|
|
781
810
|
}
|
|
@@ -2251,5 +2280,5 @@ const def = () => null;
|
|
|
2251
2280
|
* Generated bundle index. Do not edit.
|
|
2252
2281
|
*/
|
|
2253
2282
|
|
|
2254
|
-
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 };
|
|
2283
|
+
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 };
|
|
2255
2284
|
//# sourceMappingURL=ethlete-query.mjs.map
|