@ethlete/query 2.5.4 → 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/index.mjs +2 -1
- 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/entity/entity-store.mjs +141 -0
- package/esm2020/lib/entity/entity.types.mjs +2 -0
- package/esm2020/lib/entity/index.mjs +3 -0
- package/esm2020/lib/infinite-query/infinity-query.mjs +17 -3
- package/esm2020/lib/query/query.mjs +63 -1
- package/esm2020/lib/query/query.types.mjs +1 -1
- package/esm2020/lib/query/query.utils.mjs +24 -1
- package/esm2020/lib/query-client/query-client.mjs +2 -2
- package/esm2020/lib/query-client/query-client.types.mjs +1 -1
- package/esm2020/lib/query-client/query-client.utils.mjs +2 -4
- package/esm2020/lib/query-store/query-store.mjs +2 -1
- package/esm2020/lib/request/request.types.mjs +1 -1
- package/esm2020/lib/request/request.util.mjs +24 -5
- package/fesm2015/ethlete-query.mjs +273 -23
- package/fesm2015/ethlete-query.mjs.map +1 -1
- package/fesm2020/ethlete-query.mjs +277 -20
- package/fesm2020/ethlete-query.mjs.map +1 -1
- package/index.d.ts +1 -0
- package/lib/entity/entity-store.d.ts +33 -0
- package/lib/entity/entity.types.d.ts +10 -0
- package/lib/entity/index.d.ts +2 -0
- package/lib/infinite-query/infinity-query.d.ts +8 -6
- package/lib/query/query.d.ts +11 -5
- package/lib/query/query.types.d.ts +28 -9
- package/lib/query/query.utils.d.ts +21 -7
- package/lib/query-client/query-client.d.ts +8 -8
- package/lib/query-client/query-client.types.d.ts +12 -10
- package/lib/query-client/query-client.utils.d.ts +2 -2
- package/lib/request/request.types.d.ts +3 -1
- package/lib/request/request.util.d.ts +1 -0
- 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, finalize, tap, timer, fromEvent, take, concat,
|
|
2
|
+
import { Observable, filter, takeWhile, switchMap, of, BehaviorSubject, Subject, takeUntil, interval, startWith, finalize, tap, timer, map, fromEvent, debounceTime, take, concat, combineLatest, 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';
|
|
@@ -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))];
|
|
110
126
|
}
|
|
111
|
-
|
|
127
|
+
else if (typeof value === 'object' && value !== null) {
|
|
128
|
+
return [key, filterInvalidParams(value)];
|
|
129
|
+
}
|
|
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() {
|
|
@@ -704,6 +746,9 @@ class Query {
|
|
|
704
746
|
get _enableSmartPolling() {
|
|
705
747
|
return this._queryConfig.enableSmartPolling ?? true;
|
|
706
748
|
}
|
|
749
|
+
get store() {
|
|
750
|
+
return this._queryConfig.entity?.store ?? null;
|
|
751
|
+
}
|
|
707
752
|
constructor(_client, _queryConfig, _routeWithParams, _args) {
|
|
708
753
|
this._client = _client;
|
|
709
754
|
this._queryConfig = _queryConfig;
|
|
@@ -711,6 +756,7 @@ class Query {
|
|
|
711
756
|
this._args = _args;
|
|
712
757
|
this._currentId = 0;
|
|
713
758
|
this._pollingSubscription = null;
|
|
759
|
+
this._entitySubscription = null;
|
|
714
760
|
this._onAbort$ = new Subject();
|
|
715
761
|
this._currentPollConfig = null;
|
|
716
762
|
/**
|
|
@@ -721,6 +767,49 @@ class Query {
|
|
|
721
767
|
type: "PREPARED" /* QueryStateType.Prepared */,
|
|
722
768
|
meta: { id: this._currentId, triggeredVia: 'program' },
|
|
723
769
|
});
|
|
770
|
+
if (this._queryConfig.entity?.store) {
|
|
771
|
+
this._entitySubscription = this._queryConfig.entity.store.events$.subscribe((event) => {
|
|
772
|
+
if (event.type !== 'update' && event.type !== 'set') {
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
if (!isQueryStateSuccess(this.state)) {
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
const response = this.state.response;
|
|
779
|
+
const rawResponse = this.state.rawResponse;
|
|
780
|
+
const key = this._queryConfig.entity?.store.config.idKey;
|
|
781
|
+
if (!key) {
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
const newData = this._queryConfig.entity?.store.getOne(event.key);
|
|
785
|
+
if (!newData) {
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
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
|
+
: {
|
|
796
|
+
response: newData,
|
|
797
|
+
rawResponse: newData,
|
|
798
|
+
};
|
|
799
|
+
if (!newResponse) {
|
|
800
|
+
return;
|
|
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
|
+
});
|
|
811
|
+
});
|
|
812
|
+
}
|
|
724
813
|
}
|
|
725
814
|
clone() {
|
|
726
815
|
return this._client.fetch(this._queryConfig);
|
|
@@ -809,6 +898,12 @@ class Query {
|
|
|
809
898
|
const transformedResponse = this._queryConfig.responseTransformer
|
|
810
899
|
? this._queryConfig.responseTransformer(responseData)
|
|
811
900
|
: responseData;
|
|
901
|
+
this._queryConfig.entity?.successAction?.({
|
|
902
|
+
args: this._args,
|
|
903
|
+
rawResponse: state.response,
|
|
904
|
+
response: transformedResponse,
|
|
905
|
+
store: this._queryConfig.entity.store,
|
|
906
|
+
});
|
|
812
907
|
this._state$.next({
|
|
813
908
|
type: "SUCCESS" /* QueryStateType.Success */,
|
|
814
909
|
rawResponse: state.response,
|
|
@@ -894,6 +989,15 @@ class Query {
|
|
|
894
989
|
}))
|
|
895
990
|
.subscribe();
|
|
896
991
|
}
|
|
992
|
+
/**
|
|
993
|
+
* @internal
|
|
994
|
+
*/
|
|
995
|
+
_destroy() {
|
|
996
|
+
this._state$.complete();
|
|
997
|
+
this._onAbort$.complete();
|
|
998
|
+
this._pollingSubscription?.unsubscribe();
|
|
999
|
+
this._entitySubscription?.unsubscribe();
|
|
1000
|
+
}
|
|
897
1001
|
}
|
|
898
1002
|
|
|
899
1003
|
const isBasicAuthProvider = (authProvider) => authProvider instanceof BasicAuthProvider;
|
|
@@ -1139,9 +1243,9 @@ class QueryDirective {
|
|
|
1139
1243
|
}
|
|
1140
1244
|
}
|
|
1141
1245
|
}
|
|
1142
|
-
QueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1143
|
-
QueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1144
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
1246
|
+
QueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", 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.4", type: QueryDirective, isStandalone: true, selector: "[query]", inputs: { query: "query", cache: ["queryCache", "cache"] }, ngImport: i0 });
|
|
1248
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: QueryDirective, decorators: [{
|
|
1145
1249
|
type: Directive,
|
|
1146
1250
|
args: [{
|
|
1147
1251
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1202,6 +1306,7 @@ class InfinityQuery {
|
|
|
1202
1306
|
this._currentQuery$ = new BehaviorSubject(null);
|
|
1203
1307
|
this._data$ = new BehaviorSubject([]);
|
|
1204
1308
|
this._subscriptions = [];
|
|
1309
|
+
this._responsiveDataSubscription = null;
|
|
1205
1310
|
}
|
|
1206
1311
|
nextPage() {
|
|
1207
1312
|
const newPage = (this._currentPage$.value ?? 0) + 1;
|
|
@@ -1239,6 +1344,7 @@ class InfinityQuery {
|
|
|
1239
1344
|
_clearSubscriptions() {
|
|
1240
1345
|
this._subscriptions.forEach((sub) => sub.unsubscribe());
|
|
1241
1346
|
this._subscriptions = [];
|
|
1347
|
+
this._responsiveDataSubscription?.unsubscribe();
|
|
1242
1348
|
}
|
|
1243
1349
|
_handleNewQuery(query) {
|
|
1244
1350
|
const stateChangesSub = query.state$.pipe(takeUntilResponse(), filterSuccess()).subscribe({
|
|
@@ -1253,7 +1359,19 @@ class InfinityQuery {
|
|
|
1253
1359
|
else {
|
|
1254
1360
|
newData = [...this.data, ...newData];
|
|
1255
1361
|
}
|
|
1256
|
-
|
|
1362
|
+
if (query.store) {
|
|
1363
|
+
this._responsiveDataSubscription?.unsubscribe();
|
|
1364
|
+
const key = query.store.idKey;
|
|
1365
|
+
const responsiveData = query.store.entities$.pipe(map((entities) => newData.map((item) => {
|
|
1366
|
+
// TODO(TRB): This is kind of unsafe. The entity array keys might not be the same as the response keys
|
|
1367
|
+
const index = entities.values.findIndex((entity) => entity[key] === item[key]);
|
|
1368
|
+
return index > -1 ? entities.values[index] : item;
|
|
1369
|
+
})));
|
|
1370
|
+
this._responsiveDataSubscription = responsiveData.subscribe((data) => this._data$.next(data));
|
|
1371
|
+
}
|
|
1372
|
+
else {
|
|
1373
|
+
this._data$.next(newData);
|
|
1374
|
+
}
|
|
1257
1375
|
const totalPages = this._config.response.totalPagesExtractor?.({
|
|
1258
1376
|
response: state.response,
|
|
1259
1377
|
itemsPerPage: this.itemsPerPage,
|
|
@@ -1479,9 +1597,9 @@ class InfinityQueryDirective {
|
|
|
1479
1597
|
this._data$.next([]);
|
|
1480
1598
|
}
|
|
1481
1599
|
}
|
|
1482
|
-
InfinityQueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1483
|
-
InfinityQueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1484
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
1600
|
+
InfinityQueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InfinityQueryDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1601
|
+
InfinityQueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.4", type: InfinityQueryDirective, isStandalone: true, selector: "[infinityQuery]", inputs: { infinityQuery: "infinityQuery" }, providers: [{ provide: INFINITY_QUERY_TOKEN, useExisting: InfinityQueryDirective }, DestroyService], exportAs: ["infinityQuery"], ngImport: i0 });
|
|
1602
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InfinityQueryDirective, decorators: [{
|
|
1485
1603
|
type: Directive,
|
|
1486
1604
|
args: [{
|
|
1487
1605
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1531,9 +1649,9 @@ class InfinityQueryTriggerDirective {
|
|
|
1531
1649
|
this._observer.observe(this._elementRef.nativeElement);
|
|
1532
1650
|
}
|
|
1533
1651
|
}
|
|
1534
|
-
InfinityQueryTriggerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1535
|
-
InfinityQueryTriggerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1536
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
1652
|
+
InfinityQueryTriggerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InfinityQueryTriggerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1653
|
+
InfinityQueryTriggerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.4", type: InfinityQueryTriggerDirective, isStandalone: true, selector: "[infinityQueryTrigger], infinity-query-trigger", inputs: { scrollContainerSelector: "scrollContainerSelector" }, ngImport: i0 });
|
|
1654
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InfinityQueryTriggerDirective, decorators: [{
|
|
1537
1655
|
type: Directive,
|
|
1538
1656
|
args: [{
|
|
1539
1657
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1544,6 +1662,146 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.3", ngImpor
|
|
|
1544
1662
|
type: Input
|
|
1545
1663
|
}] } });
|
|
1546
1664
|
|
|
1665
|
+
class EntityStore {
|
|
1666
|
+
get events$() {
|
|
1667
|
+
return this._events$.asObservable();
|
|
1668
|
+
}
|
|
1669
|
+
get keys() {
|
|
1670
|
+
return [...this._keys];
|
|
1671
|
+
}
|
|
1672
|
+
get values() {
|
|
1673
|
+
return [...this._dictionary.values()];
|
|
1674
|
+
}
|
|
1675
|
+
get size() {
|
|
1676
|
+
return this._keys.size;
|
|
1677
|
+
}
|
|
1678
|
+
get isEmpty() {
|
|
1679
|
+
return this.size === 0;
|
|
1680
|
+
}
|
|
1681
|
+
get config() {
|
|
1682
|
+
return this._config;
|
|
1683
|
+
}
|
|
1684
|
+
get idKey() {
|
|
1685
|
+
return this._config.idKey || 'id';
|
|
1686
|
+
}
|
|
1687
|
+
constructor(_config) {
|
|
1688
|
+
this._config = _config;
|
|
1689
|
+
this._dictionary = new Map();
|
|
1690
|
+
this._keys = new Set();
|
|
1691
|
+
this._events$ = new Subject();
|
|
1692
|
+
this.entities$ = this.events$.pipe(startWith(null), debounceTime(0), map(() => ({
|
|
1693
|
+
keys: this.keys,
|
|
1694
|
+
values: this.values,
|
|
1695
|
+
})));
|
|
1696
|
+
}
|
|
1697
|
+
getOne(key) {
|
|
1698
|
+
const value = this._dictionary.get(key);
|
|
1699
|
+
if (!value) {
|
|
1700
|
+
console.error(`EntityStore: ${this._config.name || 'unknown'}: missing key "${key}" for get`);
|
|
1701
|
+
return null;
|
|
1702
|
+
}
|
|
1703
|
+
if (this._config.logActions) {
|
|
1704
|
+
console.log(`EntityStore: ${this._config.name || 'unknown'}: get "${key}"`);
|
|
1705
|
+
}
|
|
1706
|
+
return value;
|
|
1707
|
+
}
|
|
1708
|
+
getMany(keys) {
|
|
1709
|
+
return keys.map((key) => this.getOne(key));
|
|
1710
|
+
}
|
|
1711
|
+
addOne(value) {
|
|
1712
|
+
const key = this.getKey(value);
|
|
1713
|
+
if (this._dictionary.has(key)) {
|
|
1714
|
+
console.error(`EntityStore: ${this._config.name || 'unknown'}: duplicate key "${key}" for add`);
|
|
1715
|
+
return null;
|
|
1716
|
+
}
|
|
1717
|
+
this._dictionary.set(key, value);
|
|
1718
|
+
this._keys.add(key);
|
|
1719
|
+
const event = { type: 'add', key };
|
|
1720
|
+
this._events$.next(event);
|
|
1721
|
+
if (this._config.logActions) {
|
|
1722
|
+
console.log(`EntityStore: ${this._config.name || 'unknown'}: add "${key}"`);
|
|
1723
|
+
}
|
|
1724
|
+
return event;
|
|
1725
|
+
}
|
|
1726
|
+
addMany(values) {
|
|
1727
|
+
const events = values.map((value) => this.addOne(value));
|
|
1728
|
+
return events;
|
|
1729
|
+
}
|
|
1730
|
+
updateOne(value) {
|
|
1731
|
+
const key = this.getKey(value);
|
|
1732
|
+
const existing = this._dictionary.get(key);
|
|
1733
|
+
if (!existing) {
|
|
1734
|
+
console.error(`EntityStore: ${this._config.name || 'unknown'}: missing key "${key}" for update`);
|
|
1735
|
+
return null;
|
|
1736
|
+
}
|
|
1737
|
+
this._dictionary.set(key, value);
|
|
1738
|
+
const event = { type: 'update', key };
|
|
1739
|
+
this._events$.next(event);
|
|
1740
|
+
if (this._config.logActions) {
|
|
1741
|
+
console.log(`EntityStore: ${this._config.name || 'unknown'}: update "${key}"`);
|
|
1742
|
+
}
|
|
1743
|
+
return event;
|
|
1744
|
+
}
|
|
1745
|
+
updateMany(values) {
|
|
1746
|
+
const events = values.map((value) => this.updateOne(value));
|
|
1747
|
+
return events;
|
|
1748
|
+
}
|
|
1749
|
+
setOne(value) {
|
|
1750
|
+
const key = this.getKey(value);
|
|
1751
|
+
this._dictionary.set(key, value);
|
|
1752
|
+
this._keys.add(key);
|
|
1753
|
+
const event = { type: 'set', key };
|
|
1754
|
+
this._events$.next(event);
|
|
1755
|
+
if (this._config.logActions) {
|
|
1756
|
+
console.log(`EntityStore: ${this._config.name || 'unknown'}: set "${key}"`);
|
|
1757
|
+
}
|
|
1758
|
+
return event;
|
|
1759
|
+
}
|
|
1760
|
+
setMany(values) {
|
|
1761
|
+
const events = values.map((value) => this.setOne(value));
|
|
1762
|
+
return events;
|
|
1763
|
+
}
|
|
1764
|
+
removeOne(key) {
|
|
1765
|
+
if (!this._dictionary.has(key)) {
|
|
1766
|
+
console.error(`EntityStore: ${this._config.name || 'unknown'}: missing key "${key}" for remove`);
|
|
1767
|
+
return null;
|
|
1768
|
+
}
|
|
1769
|
+
this._dictionary.delete(key);
|
|
1770
|
+
this._keys.delete(key);
|
|
1771
|
+
const event = { type: 'remove', key };
|
|
1772
|
+
this._events$.next(event);
|
|
1773
|
+
if (this._config.logActions) {
|
|
1774
|
+
console.log(`EntityStore: ${this._config.name || 'unknown'}: remove "${key}"`);
|
|
1775
|
+
}
|
|
1776
|
+
return event;
|
|
1777
|
+
}
|
|
1778
|
+
removeMany(keys) {
|
|
1779
|
+
const events = keys.map((key) => this.removeOne(key));
|
|
1780
|
+
return events;
|
|
1781
|
+
}
|
|
1782
|
+
has(key) {
|
|
1783
|
+
return this._dictionary.has(key);
|
|
1784
|
+
}
|
|
1785
|
+
clear() {
|
|
1786
|
+
this._dictionary.clear();
|
|
1787
|
+
this._keys.clear();
|
|
1788
|
+
}
|
|
1789
|
+
getKey(value) {
|
|
1790
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1791
|
+
const key = value[this._config.idKey || 'id'];
|
|
1792
|
+
if (key === undefined) {
|
|
1793
|
+
throw new Error(`EntityStore: ${this._config.name || 'unknown'}: missing key`);
|
|
1794
|
+
}
|
|
1795
|
+
return key;
|
|
1796
|
+
}
|
|
1797
|
+
logState() {
|
|
1798
|
+
console.log('EntityStore:', this._config.name, {
|
|
1799
|
+
dictionary: this._dictionary,
|
|
1800
|
+
keys: this._keys,
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1547
1805
|
class QueryStore {
|
|
1548
1806
|
constructor(_config) {
|
|
1549
1807
|
this._config = _config;
|
|
@@ -1562,6 +1820,7 @@ class QueryStore {
|
|
|
1562
1820
|
return this._store.get(id) ?? null;
|
|
1563
1821
|
}
|
|
1564
1822
|
remove(id) {
|
|
1823
|
+
this.get(id)?._destroy();
|
|
1565
1824
|
this._store.delete(id);
|
|
1566
1825
|
this._logState(id, null, 'REMOVE');
|
|
1567
1826
|
}
|
|
@@ -1675,9 +1934,7 @@ class QueryStore {
|
|
|
1675
1934
|
const shouldCacheQuery = (method) => {
|
|
1676
1935
|
return method === 'GET' || method === 'OPTIONS' || method === 'HEAD' || method === 'GQL_QUERY';
|
|
1677
1936
|
};
|
|
1678
|
-
const buildGqlCacheKey = (
|
|
1679
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1680
|
-
config, args) => {
|
|
1937
|
+
const buildGqlCacheKey = (config, args) => {
|
|
1681
1938
|
const { query } = config;
|
|
1682
1939
|
const variables = args?.variables || {};
|
|
1683
1940
|
const queryWithoutNewLinesAndWhitespace = query.replace(/\s/g, '');
|
|
@@ -1744,7 +2001,7 @@ class QueryClient {
|
|
|
1744
2001
|
return existingQuery;
|
|
1745
2002
|
}
|
|
1746
2003
|
}
|
|
1747
|
-
const query = new Query(this, queryConfig, route, args);
|
|
2004
|
+
const query = new Query(this, queryConfig, route, args ?? {});
|
|
1748
2005
|
if (shouldCacheQuery(queryConfig.method)) {
|
|
1749
2006
|
this._store.add(cacheKey, query);
|
|
1750
2007
|
}
|
|
@@ -2031,5 +2288,5 @@ const def = () => null;
|
|
|
2031
2288
|
* Generated bundle index. Do not edit.
|
|
2032
2289
|
*/
|
|
2033
2290
|
|
|
2034
|
-
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 };
|
|
2291
|
+
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 };
|
|
2035
2292
|
//# sourceMappingURL=ethlete-query.mjs.map
|