http-request-manager 18.13.23 → 18.13.25
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.
|
@@ -926,9 +926,13 @@ class QueryParamsTrackerService {
|
|
|
926
926
|
return false;
|
|
927
927
|
this.cleanupExpiredEntries();
|
|
928
928
|
if (!normalized.hasQuery) {
|
|
929
|
-
this.ensurePathState(normalized.pathKey);
|
|
930
|
-
|
|
931
|
-
|
|
929
|
+
const pathState = this.ensurePathState(normalized.pathKey);
|
|
930
|
+
const pathSeenBefore = !!pathState.baselineQuery;
|
|
931
|
+
if (!pathSeenBefore) {
|
|
932
|
+
pathState.baselineQuery = {};
|
|
933
|
+
this.persistState();
|
|
934
|
+
}
|
|
935
|
+
return !pathSeenBefore;
|
|
932
936
|
}
|
|
933
937
|
if (options.mode === 'exact') {
|
|
934
938
|
return this.checkExact(normalized, options);
|
|
@@ -943,7 +947,7 @@ class QueryParamsTrackerService {
|
|
|
943
947
|
}
|
|
944
948
|
checkExact(normalized, options) {
|
|
945
949
|
const pathState = this.ensurePathState(normalized.pathKey);
|
|
946
|
-
const filteredQuery = normalized.query;
|
|
950
|
+
const filteredQuery = this.filterQueryByWatchParams(normalized.query, options.watchParams);
|
|
947
951
|
if (Object.keys(filteredQuery).length === 0) {
|
|
948
952
|
return false;
|
|
949
953
|
}
|
|
@@ -952,11 +956,20 @@ class QueryParamsTrackerService {
|
|
|
952
956
|
this.persistState();
|
|
953
957
|
return true;
|
|
954
958
|
}
|
|
955
|
-
return this.stringifyQuery(pathState.baselineQuery)
|
|
959
|
+
return this.stringifyQuery(pathState.baselineQuery) !== this.stringifyQuery(filteredQuery);
|
|
956
960
|
}
|
|
957
961
|
checkVariation(normalized, options) {
|
|
958
962
|
const pathState = this.ensurePathState(normalized.pathKey);
|
|
959
|
-
|
|
963
|
+
if (Array.isArray(options.watchParams) && options.watchParams.length === 0) {
|
|
964
|
+
const pathSeenBefore = !!pathState.baselineQuery;
|
|
965
|
+
if (!pathSeenBefore) {
|
|
966
|
+
pathState.baselineQuery = {};
|
|
967
|
+
pathState.watchExpiresAt = this.buildExpiryEpoch(typeof options.watchExpiresAt !== 'undefined' ? options.watchExpiresAt : options.watchParamsExpire);
|
|
968
|
+
this.persistState();
|
|
969
|
+
}
|
|
970
|
+
return !pathSeenBefore;
|
|
971
|
+
}
|
|
972
|
+
const filteredQuery = this.filterQueryByWatchParams(normalized.query, options.watchParams);
|
|
960
973
|
const keys = Object.keys(filteredQuery);
|
|
961
974
|
if (keys.length === 0) {
|
|
962
975
|
return false;
|
|
@@ -980,6 +993,21 @@ class QueryParamsTrackerService {
|
|
|
980
993
|
}
|
|
981
994
|
return accepted;
|
|
982
995
|
}
|
|
996
|
+
filterQueryByWatchParams(query, watchParams) {
|
|
997
|
+
if (!Array.isArray(watchParams)) {
|
|
998
|
+
return query;
|
|
999
|
+
}
|
|
1000
|
+
if (watchParams.length === 0) {
|
|
1001
|
+
return {};
|
|
1002
|
+
}
|
|
1003
|
+
const normalizedWatchParams = watchParams.map((p) => this.normalizeParamKey(p));
|
|
1004
|
+
return Object.keys(query).reduce((acc, key) => {
|
|
1005
|
+
if (normalizedWatchParams.includes(key)) {
|
|
1006
|
+
acc[key] = query[key];
|
|
1007
|
+
}
|
|
1008
|
+
return acc;
|
|
1009
|
+
}, {});
|
|
1010
|
+
}
|
|
983
1011
|
normalizeRequestOptions(requestOptions) {
|
|
984
1012
|
const params = Array.isArray(requestOptions) ? requestOptions : [];
|
|
985
1013
|
const pathSegments = [];
|
|
@@ -1117,7 +1145,7 @@ class QueryParamsTrackerService {
|
|
|
1117
1145
|
pathState.consumedValuesByKey = {};
|
|
1118
1146
|
pathState.watchExpiresAt = undefined;
|
|
1119
1147
|
}
|
|
1120
|
-
const hasBaseline =
|
|
1148
|
+
const hasBaseline = pathState.baselineQuery !== undefined;
|
|
1121
1149
|
const hasTrackedValues = Object.keys(pathState.consumedValuesByKey).some((key) => (pathState.consumedValuesByKey[key] || []).length > 0);
|
|
1122
1150
|
if (!hasBaseline && !hasTrackedValues) {
|
|
1123
1151
|
delete this.state.paths[pathKey];
|
|
@@ -7011,7 +7039,6 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7011
7039
|
databaseOptions: this.databaseOptions
|
|
7012
7040
|
});
|
|
7013
7041
|
if (this.hasDatabase && this.databaseOptions?.table) {
|
|
7014
|
-
console.log('[DB STORAGE] Stage 1');
|
|
7015
7042
|
return this.dbManagerService.databaseExists().pipe(switchMap((dbExists) => {
|
|
7016
7043
|
if (!dbExists) {
|
|
7017
7044
|
const initObs = this.initDBStorageAsync();
|
|
@@ -7020,7 +7047,6 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7020
7047
|
return fetchFromAPI();
|
|
7021
7048
|
}));
|
|
7022
7049
|
}
|
|
7023
|
-
console.log('[DB STORAGE] Stage 2');
|
|
7024
7050
|
return this.dbManagerService.hasDatabaseTable(this.databaseOptions.table).pipe(switchMap((tableExists) => {
|
|
7025
7051
|
if (!tableExists) {
|
|
7026
7052
|
const initObs = this.initDBStorageAsync();
|
|
@@ -7029,14 +7055,10 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7029
7055
|
return fetchFromAPI();
|
|
7030
7056
|
}));
|
|
7031
7057
|
}
|
|
7032
|
-
console.log('[DB STORAGE] Stage 3');
|
|
7033
7058
|
return this.localStorageManagerService.store$(this.databaseOptions.table).pipe(take(1), switchMap((storeData) => {
|
|
7034
|
-
const forceRefresh = !!options?.forceRefresh;
|
|
7035
7059
|
const storedSchemaSignature = this.getStoredSchemaSignature(storeData);
|
|
7036
7060
|
const expires = storeData?.expires || 0;
|
|
7037
7061
|
const hasExpired = expires > 0 && this.utils.hasExpired(expires);
|
|
7038
|
-
if (forceRefresh)
|
|
7039
|
-
return fetchFromAPI();
|
|
7040
7062
|
if (hasExpired) {
|
|
7041
7063
|
return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(switchMap(() => fetchFromAPI()), tap(() => {
|
|
7042
7064
|
this.localStorageManagerService.updateStore({
|
|
@@ -7045,7 +7067,6 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7045
7067
|
});
|
|
7046
7068
|
}));
|
|
7047
7069
|
}
|
|
7048
|
-
console.log('[DB STORAGE] Stage 4');
|
|
7049
7070
|
const expectedSchema = this.buildSchemaFromAdapter();
|
|
7050
7071
|
const expectedSchemaSignature = this.buildSchemaSignature(expectedSchema);
|
|
7051
7072
|
if (storedSchemaSignature && storedSchemaSignature !== expectedSchemaSignature) {
|
|
@@ -7053,11 +7074,6 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7053
7074
|
return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(switchMap(() => this.dbManagerService.createDatabaseTable(tableDef)), switchMap(() => fetchFromAPI()));
|
|
7054
7075
|
}
|
|
7055
7076
|
const shouldMakeRequest = this.queryParamsTrackerService.checkRequestOptions(this.resolvePath(effectiveParams), this.buildQueryTrackerOptions(options));
|
|
7056
|
-
console.log('[DB CHECK] Request options check:', {
|
|
7057
|
-
shouldMakeRequest,
|
|
7058
|
-
effectiveParams,
|
|
7059
|
-
options
|
|
7060
|
-
});
|
|
7061
7077
|
if (shouldMakeRequest)
|
|
7062
7078
|
return fetchFromAPI();
|
|
7063
7079
|
return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
|
|
@@ -7065,15 +7081,8 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7065
7081
|
this.setData$(dbData);
|
|
7066
7082
|
return of(dbData);
|
|
7067
7083
|
}
|
|
7068
|
-
|
|
7069
|
-
|
|
7070
|
-
return of(currentStateData);
|
|
7071
|
-
if (currentStateData &&
|
|
7072
|
-
!Array.isArray(currentStateData) &&
|
|
7073
|
-
Object.keys(currentStateData).length > 0) {
|
|
7074
|
-
return of(currentStateData);
|
|
7075
|
-
}
|
|
7076
|
-
return of(this.dataType === DataType.ARRAY ? [] : {});
|
|
7084
|
+
// DB empty → fall back to API
|
|
7085
|
+
return fetchFromAPI();
|
|
7077
7086
|
}), catchError((error) => {
|
|
7078
7087
|
const tableName = this.databaseOptions.table;
|
|
7079
7088
|
console.warn('[DB STORAGE] getTableRecords failed, recreating table and falling back to API:', { table: tableName, error });
|
|
@@ -7231,13 +7240,8 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7231
7240
|
if (this.hasDatabase && this.databaseOptions?.table) {
|
|
7232
7241
|
const requestSignature = this.buildRequestSignature('STREAM', requestOptions, effectiveParams);
|
|
7233
7242
|
return this.localStorageManagerService.store$(this.databaseOptions.table).pipe(take(1), switchMap((storeData) => {
|
|
7234
|
-
const forceRefresh = !!options?.forceRefresh;
|
|
7235
7243
|
const expires = storeData?.expires || 0;
|
|
7236
7244
|
const hasExpired = expires > 0 && this.utils.hasExpired(expires);
|
|
7237
|
-
if (forceRefresh) {
|
|
7238
|
-
this.setCachedRequestSignature(this.databaseOptions.table, 'STREAM', requestSignature);
|
|
7239
|
-
return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })));
|
|
7240
|
-
}
|
|
7241
7245
|
if (hasExpired) {
|
|
7242
7246
|
return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(tap(() => this.setCachedRequestSignature(this.databaseOptions.table, 'STREAM', requestSignature)), switchMap(() => this.httpManagerService.getRequest(requestOptions, effectiveParams)), map((apiData) => ({ data: apiData, fromCache: false })));
|
|
7243
7247
|
}
|
|
@@ -7248,16 +7252,8 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7248
7252
|
if (Array.isArray(dbData) && dbData.length > 0) {
|
|
7249
7253
|
return of({ data: dbData, fromCache: true });
|
|
7250
7254
|
}
|
|
7251
|
-
|
|
7252
|
-
|
|
7253
|
-
return of({ data: currentStateData, fromCache: true });
|
|
7254
|
-
}
|
|
7255
|
-
if (currentStateData &&
|
|
7256
|
-
!Array.isArray(currentStateData) &&
|
|
7257
|
-
Object.keys(currentStateData).length > 0) {
|
|
7258
|
-
return of({ data: currentStateData, fromCache: true });
|
|
7259
|
-
}
|
|
7260
|
-
return of({ data: this.dataType === DataType.ARRAY ? [] : {}, fromCache: true });
|
|
7255
|
+
// DB empty → fall back to API
|
|
7256
|
+
return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })));
|
|
7261
7257
|
}));
|
|
7262
7258
|
}
|
|
7263
7259
|
this.setCachedRequestSignature(this.databaseOptions.table, 'STREAM', requestSignature);
|
|
@@ -7971,10 +7967,13 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7971
7967
|
return options;
|
|
7972
7968
|
}
|
|
7973
7969
|
buildQueryTrackerOptions(options) {
|
|
7974
|
-
|
|
7975
|
-
watchParams: Array.isArray(options?.watchParams) ? options.watchParams : [],
|
|
7970
|
+
const result = {
|
|
7976
7971
|
watchExpiresAt: options?.watchExpiresAt,
|
|
7977
7972
|
};
|
|
7973
|
+
if (Array.isArray(options?.watchParams)) {
|
|
7974
|
+
result.watchParams = options.watchParams;
|
|
7975
|
+
}
|
|
7976
|
+
return result;
|
|
7978
7977
|
}
|
|
7979
7978
|
normalizeObject(value) {
|
|
7980
7979
|
if (Array.isArray(value)) {
|