@ethlete/query 2.5.4 → 2.6.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 +76 -1
- package/esm2020/lib/query/query.types.mjs +1 -1
- package/esm2020/lib/query/query.utils.mjs +1 -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/fesm2015/ethlete-query.mjs +240 -19
- package/fesm2015/ethlete-query.mjs.map +1 -1
- package/fesm2020/ethlete-query.mjs +244 -16
- 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 +24 -9
- package/lib/query/query.utils.d.ts +7 -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/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';
|
|
@@ -712,13 +712,19 @@ class Query {
|
|
|
712
712
|
var _a;
|
|
713
713
|
return (_a = this._queryConfig.enableSmartPolling) !== null && _a !== void 0 ? _a : true;
|
|
714
714
|
}
|
|
715
|
+
get store() {
|
|
716
|
+
var _a, _b;
|
|
717
|
+
return (_b = (_a = this._queryConfig.entity) === null || _a === void 0 ? void 0 : _a.store) !== null && _b !== void 0 ? _b : null;
|
|
718
|
+
}
|
|
715
719
|
constructor(_client, _queryConfig, _routeWithParams, _args) {
|
|
720
|
+
var _a;
|
|
716
721
|
this._client = _client;
|
|
717
722
|
this._queryConfig = _queryConfig;
|
|
718
723
|
this._routeWithParams = _routeWithParams;
|
|
719
724
|
this._args = _args;
|
|
720
725
|
this._currentId = 0;
|
|
721
726
|
this._pollingSubscription = null;
|
|
727
|
+
this._entitySubscription = null;
|
|
722
728
|
this._onAbort$ = new Subject();
|
|
723
729
|
this._currentPollConfig = null;
|
|
724
730
|
/**
|
|
@@ -729,6 +735,49 @@ class Query {
|
|
|
729
735
|
type: "PREPARED" /* QueryStateType.Prepared */,
|
|
730
736
|
meta: { id: this._currentId, triggeredVia: 'program' },
|
|
731
737
|
});
|
|
738
|
+
if ((_a = this._queryConfig.entity) === null || _a === void 0 ? void 0 : _a.store) {
|
|
739
|
+
this._entitySubscription = this._queryConfig.entity.store.events$.subscribe((event) => {
|
|
740
|
+
var _a, _b, _c;
|
|
741
|
+
if (event.type !== 'update' && event.type !== 'set') {
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
if (!isQueryStateSuccess(this.state)) {
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
const response = this.state.response;
|
|
748
|
+
const rawResponse = this.state.rawResponse;
|
|
749
|
+
const key = (_a = this._queryConfig.entity) === null || _a === void 0 ? void 0 : _a.store.config.idKey;
|
|
750
|
+
if (!key) {
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
const currentValue = (_b = this._queryConfig.entity) === null || _b === void 0 ? void 0 : _b.valueSelector({
|
|
754
|
+
args: this._args,
|
|
755
|
+
response,
|
|
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' }) }));
|
|
772
|
+
}
|
|
773
|
+
else {
|
|
774
|
+
if ((currentValue === null || currentValue === void 0 ? void 0 : currentValue[key]) !== event.key) {
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
this._state$.next(Object.assign(Object.assign({}, this.state), { response: newData, meta: Object.assign(Object.assign({}, this.state.meta), { triggeredVia: 'auto' }) }));
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
}
|
|
732
781
|
}
|
|
733
782
|
clone() {
|
|
734
783
|
return this._client.fetch(this._queryConfig);
|
|
@@ -774,6 +823,7 @@ class Query {
|
|
|
774
823
|
.pipe(takeUntil(this._onAbort$))
|
|
775
824
|
.subscribe({
|
|
776
825
|
next: (state) => {
|
|
826
|
+
var _a, _b;
|
|
777
827
|
if (state.type === 'start' || state.type === 'delay-retry') {
|
|
778
828
|
const newMeta = Object.assign(Object.assign({}, meta), { isWaitingForRetry: state.type === 'delay-retry', retryDelay: state.retryDelay, retryNumber: state.retryNumber });
|
|
779
829
|
this._state$.next({
|
|
@@ -813,6 +863,12 @@ class Query {
|
|
|
813
863
|
const transformedResponse = this._queryConfig.responseTransformer
|
|
814
864
|
? this._queryConfig.responseTransformer(responseData)
|
|
815
865
|
: responseData;
|
|
866
|
+
(_b = (_a = this._queryConfig.entity) === null || _a === void 0 ? void 0 : _a.successAction) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
867
|
+
args: this._args,
|
|
868
|
+
rawResponse: state.response,
|
|
869
|
+
response: transformedResponse,
|
|
870
|
+
store: this._queryConfig.entity.store,
|
|
871
|
+
});
|
|
816
872
|
this._state$.next({
|
|
817
873
|
type: "SUCCESS" /* QueryStateType.Success */,
|
|
818
874
|
rawResponse: state.response,
|
|
@@ -902,6 +958,16 @@ class Query {
|
|
|
902
958
|
}))
|
|
903
959
|
.subscribe();
|
|
904
960
|
}
|
|
961
|
+
/**
|
|
962
|
+
* @internal
|
|
963
|
+
*/
|
|
964
|
+
_destroy() {
|
|
965
|
+
var _a, _b;
|
|
966
|
+
this._state$.complete();
|
|
967
|
+
this._onAbort$.complete();
|
|
968
|
+
(_a = this._pollingSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
969
|
+
(_b = this._entitySubscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
|
|
970
|
+
}
|
|
905
971
|
}
|
|
906
972
|
|
|
907
973
|
const isBasicAuthProvider = (authProvider) => authProvider instanceof BasicAuthProvider;
|
|
@@ -1157,9 +1223,9 @@ class QueryDirective {
|
|
|
1157
1223
|
}
|
|
1158
1224
|
}
|
|
1159
1225
|
}
|
|
1160
|
-
QueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1161
|
-
QueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1162
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
1226
|
+
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 });
|
|
1227
|
+
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 });
|
|
1228
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: QueryDirective, decorators: [{
|
|
1163
1229
|
type: Directive,
|
|
1164
1230
|
args: [{
|
|
1165
1231
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1221,6 +1287,7 @@ class InfinityQuery {
|
|
|
1221
1287
|
this._currentQuery$ = new BehaviorSubject(null);
|
|
1222
1288
|
this._data$ = new BehaviorSubject([]);
|
|
1223
1289
|
this._subscriptions = [];
|
|
1290
|
+
this._responsiveDataSubscription = null;
|
|
1224
1291
|
}
|
|
1225
1292
|
nextPage() {
|
|
1226
1293
|
var _a, _b, _c, _d, _e;
|
|
@@ -1258,13 +1325,15 @@ class InfinityQuery {
|
|
|
1258
1325
|
* @internal
|
|
1259
1326
|
*/
|
|
1260
1327
|
_clearSubscriptions() {
|
|
1328
|
+
var _a;
|
|
1261
1329
|
this._subscriptions.forEach((sub) => sub.unsubscribe());
|
|
1262
1330
|
this._subscriptions = [];
|
|
1331
|
+
(_a = this._responsiveDataSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
1263
1332
|
}
|
|
1264
1333
|
_handleNewQuery(query) {
|
|
1265
1334
|
const stateChangesSub = query.state$.pipe(takeUntilResponse(), filterSuccess()).subscribe({
|
|
1266
1335
|
next: (state) => {
|
|
1267
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1336
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1268
1337
|
let newData = (_a = this._config) === null || _a === void 0 ? void 0 : _a.response.valueExtractor(state.response);
|
|
1269
1338
|
if (this._config.response.reverse) {
|
|
1270
1339
|
newData = [...newData].reverse();
|
|
@@ -1275,11 +1344,23 @@ class InfinityQuery {
|
|
|
1275
1344
|
else {
|
|
1276
1345
|
newData = [...this.data, ...newData];
|
|
1277
1346
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1347
|
+
if (query.store) {
|
|
1348
|
+
(_b = this._responsiveDataSubscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
|
|
1349
|
+
const key = query.store.idKey;
|
|
1350
|
+
const responsiveData = query.store.entities$.pipe(map((entities) => newData.map((item) => {
|
|
1351
|
+
// TODO(TRB): This is kind of unsafe. The entity array keys might not be the same as the response keys
|
|
1352
|
+
const index = entities.values.findIndex((entity) => entity[key] === item[key]);
|
|
1353
|
+
return index > -1 ? entities.values[index] : item;
|
|
1354
|
+
})));
|
|
1355
|
+
this._responsiveDataSubscription = responsiveData.subscribe((data) => this._data$.next(data));
|
|
1356
|
+
}
|
|
1357
|
+
else {
|
|
1358
|
+
this._data$.next(newData);
|
|
1359
|
+
}
|
|
1360
|
+
const totalPages = (_g = (_e = (_d = (_c = this._config.response).totalPagesExtractor) === null || _d === void 0 ? void 0 : _d.call(_c, {
|
|
1280
1361
|
response: state.response,
|
|
1281
1362
|
itemsPerPage: this.itemsPerPage,
|
|
1282
|
-
})) !== null &&
|
|
1363
|
+
})) !== null && _e !== void 0 ? _e : (_f = state.response) === null || _f === void 0 ? void 0 : _f.totalPages) !== null && _g !== void 0 ? _g : null;
|
|
1283
1364
|
this._totalPages$.next(totalPages);
|
|
1284
1365
|
},
|
|
1285
1366
|
complete: () => {
|
|
@@ -1484,9 +1565,9 @@ class InfinityQueryDirective {
|
|
|
1484
1565
|
this._data$.next([]);
|
|
1485
1566
|
}
|
|
1486
1567
|
}
|
|
1487
|
-
InfinityQueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1488
|
-
InfinityQueryDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1489
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
1568
|
+
InfinityQueryDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InfinityQueryDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1569
|
+
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 });
|
|
1570
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InfinityQueryDirective, decorators: [{
|
|
1490
1571
|
type: Directive,
|
|
1491
1572
|
args: [{
|
|
1492
1573
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1537,9 +1618,9 @@ class InfinityQueryTriggerDirective {
|
|
|
1537
1618
|
this._observer.observe(this._elementRef.nativeElement);
|
|
1538
1619
|
}
|
|
1539
1620
|
}
|
|
1540
|
-
InfinityQueryTriggerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.
|
|
1541
|
-
InfinityQueryTriggerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.
|
|
1542
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.
|
|
1621
|
+
InfinityQueryTriggerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InfinityQueryTriggerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1622
|
+
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 });
|
|
1623
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InfinityQueryTriggerDirective, decorators: [{
|
|
1543
1624
|
type: Directive,
|
|
1544
1625
|
args: [{
|
|
1545
1626
|
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
@@ -1550,6 +1631,146 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.3", ngImpor
|
|
|
1550
1631
|
type: Input
|
|
1551
1632
|
}] } });
|
|
1552
1633
|
|
|
1634
|
+
class EntityStore {
|
|
1635
|
+
get events$() {
|
|
1636
|
+
return this._events$.asObservable();
|
|
1637
|
+
}
|
|
1638
|
+
get keys() {
|
|
1639
|
+
return [...this._keys];
|
|
1640
|
+
}
|
|
1641
|
+
get values() {
|
|
1642
|
+
return [...this._dictionary.values()];
|
|
1643
|
+
}
|
|
1644
|
+
get size() {
|
|
1645
|
+
return this._keys.size;
|
|
1646
|
+
}
|
|
1647
|
+
get isEmpty() {
|
|
1648
|
+
return this.size === 0;
|
|
1649
|
+
}
|
|
1650
|
+
get config() {
|
|
1651
|
+
return this._config;
|
|
1652
|
+
}
|
|
1653
|
+
get idKey() {
|
|
1654
|
+
return this._config.idKey || 'id';
|
|
1655
|
+
}
|
|
1656
|
+
constructor(_config) {
|
|
1657
|
+
this._config = _config;
|
|
1658
|
+
this._dictionary = new Map();
|
|
1659
|
+
this._keys = new Set();
|
|
1660
|
+
this._events$ = new Subject();
|
|
1661
|
+
this.entities$ = this.events$.pipe(startWith(null), debounceTime(0), map(() => ({
|
|
1662
|
+
keys: this.keys,
|
|
1663
|
+
values: this.values,
|
|
1664
|
+
})));
|
|
1665
|
+
}
|
|
1666
|
+
getOne(key) {
|
|
1667
|
+
const value = this._dictionary.get(key);
|
|
1668
|
+
if (!value) {
|
|
1669
|
+
console.error(`EntityStore: ${this._config.name || 'unknown'}: missing key "${key}" for get`);
|
|
1670
|
+
return null;
|
|
1671
|
+
}
|
|
1672
|
+
if (this._config.logActions) {
|
|
1673
|
+
console.log(`EntityStore: ${this._config.name || 'unknown'}: get "${key}"`);
|
|
1674
|
+
}
|
|
1675
|
+
return value;
|
|
1676
|
+
}
|
|
1677
|
+
getMany(keys) {
|
|
1678
|
+
return keys.map((key) => this.getOne(key));
|
|
1679
|
+
}
|
|
1680
|
+
addOne(value) {
|
|
1681
|
+
const key = this.getKey(value);
|
|
1682
|
+
if (this._dictionary.has(key)) {
|
|
1683
|
+
console.error(`EntityStore: ${this._config.name || 'unknown'}: duplicate key "${key}" for add`);
|
|
1684
|
+
return null;
|
|
1685
|
+
}
|
|
1686
|
+
this._dictionary.set(key, value);
|
|
1687
|
+
this._keys.add(key);
|
|
1688
|
+
const event = { type: 'add', key };
|
|
1689
|
+
this._events$.next(event);
|
|
1690
|
+
if (this._config.logActions) {
|
|
1691
|
+
console.log(`EntityStore: ${this._config.name || 'unknown'}: add "${key}"`);
|
|
1692
|
+
}
|
|
1693
|
+
return event;
|
|
1694
|
+
}
|
|
1695
|
+
addMany(values) {
|
|
1696
|
+
const events = values.map((value) => this.addOne(value));
|
|
1697
|
+
return events;
|
|
1698
|
+
}
|
|
1699
|
+
updateOne(value) {
|
|
1700
|
+
const key = this.getKey(value);
|
|
1701
|
+
const existing = this._dictionary.get(key);
|
|
1702
|
+
if (!existing) {
|
|
1703
|
+
console.error(`EntityStore: ${this._config.name || 'unknown'}: missing key "${key}" for update`);
|
|
1704
|
+
return null;
|
|
1705
|
+
}
|
|
1706
|
+
this._dictionary.set(key, value);
|
|
1707
|
+
const event = { type: 'update', key };
|
|
1708
|
+
this._events$.next(event);
|
|
1709
|
+
if (this._config.logActions) {
|
|
1710
|
+
console.log(`EntityStore: ${this._config.name || 'unknown'}: update "${key}"`);
|
|
1711
|
+
}
|
|
1712
|
+
return event;
|
|
1713
|
+
}
|
|
1714
|
+
updateMany(values) {
|
|
1715
|
+
const events = values.map((value) => this.updateOne(value));
|
|
1716
|
+
return events;
|
|
1717
|
+
}
|
|
1718
|
+
setOne(value) {
|
|
1719
|
+
const key = this.getKey(value);
|
|
1720
|
+
this._dictionary.set(key, value);
|
|
1721
|
+
this._keys.add(key);
|
|
1722
|
+
const event = { type: 'set', key };
|
|
1723
|
+
this._events$.next(event);
|
|
1724
|
+
if (this._config.logActions) {
|
|
1725
|
+
console.log(`EntityStore: ${this._config.name || 'unknown'}: set "${key}"`);
|
|
1726
|
+
}
|
|
1727
|
+
return event;
|
|
1728
|
+
}
|
|
1729
|
+
setMany(values) {
|
|
1730
|
+
const events = values.map((value) => this.setOne(value));
|
|
1731
|
+
return events;
|
|
1732
|
+
}
|
|
1733
|
+
removeOne(key) {
|
|
1734
|
+
if (!this._dictionary.has(key)) {
|
|
1735
|
+
console.error(`EntityStore: ${this._config.name || 'unknown'}: missing key "${key}" for remove`);
|
|
1736
|
+
return null;
|
|
1737
|
+
}
|
|
1738
|
+
this._dictionary.delete(key);
|
|
1739
|
+
this._keys.delete(key);
|
|
1740
|
+
const event = { type: 'remove', key };
|
|
1741
|
+
this._events$.next(event);
|
|
1742
|
+
if (this._config.logActions) {
|
|
1743
|
+
console.log(`EntityStore: ${this._config.name || 'unknown'}: remove "${key}"`);
|
|
1744
|
+
}
|
|
1745
|
+
return event;
|
|
1746
|
+
}
|
|
1747
|
+
removeMany(keys) {
|
|
1748
|
+
const events = keys.map((key) => this.removeOne(key));
|
|
1749
|
+
return events;
|
|
1750
|
+
}
|
|
1751
|
+
has(key) {
|
|
1752
|
+
return this._dictionary.has(key);
|
|
1753
|
+
}
|
|
1754
|
+
clear() {
|
|
1755
|
+
this._dictionary.clear();
|
|
1756
|
+
this._keys.clear();
|
|
1757
|
+
}
|
|
1758
|
+
getKey(value) {
|
|
1759
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1760
|
+
const key = value[this._config.idKey || 'id'];
|
|
1761
|
+
if (key === undefined) {
|
|
1762
|
+
throw new Error(`EntityStore: ${this._config.name || 'unknown'}: missing key`);
|
|
1763
|
+
}
|
|
1764
|
+
return key;
|
|
1765
|
+
}
|
|
1766
|
+
logState() {
|
|
1767
|
+
console.log('EntityStore:', this._config.name, {
|
|
1768
|
+
dictionary: this._dictionary,
|
|
1769
|
+
keys: this._keys,
|
|
1770
|
+
});
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1553
1774
|
class QueryStore {
|
|
1554
1775
|
constructor(_config) {
|
|
1555
1776
|
this._config = _config;
|
|
@@ -1569,6 +1790,8 @@ class QueryStore {
|
|
|
1569
1790
|
return (_a = this._store.get(id)) !== null && _a !== void 0 ? _a : null;
|
|
1570
1791
|
}
|
|
1571
1792
|
remove(id) {
|
|
1793
|
+
var _a;
|
|
1794
|
+
(_a = this.get(id)) === null || _a === void 0 ? void 0 : _a._destroy();
|
|
1572
1795
|
this._store.delete(id);
|
|
1573
1796
|
this._logState(id, null, 'REMOVE');
|
|
1574
1797
|
}
|
|
@@ -1687,9 +1910,7 @@ class QueryStore {
|
|
|
1687
1910
|
const shouldCacheQuery = (method) => {
|
|
1688
1911
|
return method === 'GET' || method === 'OPTIONS' || method === 'HEAD' || method === 'GQL_QUERY';
|
|
1689
1912
|
};
|
|
1690
|
-
const buildGqlCacheKey = (
|
|
1691
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1692
|
-
config, args) => {
|
|
1913
|
+
const buildGqlCacheKey = (config, args) => {
|
|
1693
1914
|
const { query } = config;
|
|
1694
1915
|
const variables = (args === null || args === void 0 ? void 0 : args.variables) || {};
|
|
1695
1916
|
const queryWithoutNewLinesAndWhitespace = query.replace(/\s/g, '');
|
|
@@ -1738,7 +1959,7 @@ class QueryClient {
|
|
|
1738
1959
|
return existingQuery;
|
|
1739
1960
|
}
|
|
1740
1961
|
}
|
|
1741
|
-
const query = new Query(this, queryConfig, route, args);
|
|
1962
|
+
const query = new Query(this, queryConfig, route, args !== null && args !== void 0 ? args : {});
|
|
1742
1963
|
if (shouldCacheQuery(queryConfig.method)) {
|
|
1743
1964
|
this._store.add(cacheKey, query);
|
|
1744
1965
|
}
|
|
@@ -2030,5 +2251,5 @@ const def = () => null;
|
|
|
2030
2251
|
* Generated bundle index. Do not edit.
|
|
2031
2252
|
*/
|
|
2032
2253
|
|
|
2033
|
-
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 };
|
|
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 };
|
|
2034
2255
|
//# sourceMappingURL=ethlete-query.mjs.map
|