http-request-manager 18.15.13 → 18.15.14
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.
|
@@ -6434,31 +6434,25 @@ class QueryParamsTrackerService {
|
|
|
6434
6434
|
}
|
|
6435
6435
|
checkRequestOptions(requestOptions = [], options = {}) {
|
|
6436
6436
|
this.ensureStateRestored();
|
|
6437
|
-
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6447
|
-
|
|
6448
|
-
|
|
6449
|
-
|
|
6450
|
-
const pathSeenBefore = pathState.consumedValuesByKey.hasOwnProperty('__path_seen__');
|
|
6451
|
-
if (!pathSeenBefore) {
|
|
6452
|
-
// Mark this path as seen
|
|
6453
|
-
pathState.consumedValuesByKey['__path_seen__'] = ['true'];
|
|
6454
|
-
this.persistState();
|
|
6437
|
+
return this.ready$.pipe(take(1), map(() => {
|
|
6438
|
+
const normalized = this.normalizeRequestOptions(requestOptions);
|
|
6439
|
+
if (!normalized.pathKey)
|
|
6440
|
+
return false;
|
|
6441
|
+
this.cleanupExpiredEntries();
|
|
6442
|
+
if (!normalized.hasQuery) {
|
|
6443
|
+
const pathState = this.ensurePathState(normalized.pathKey);
|
|
6444
|
+
const pathSeenBefore = pathState.consumedValuesByKey.hasOwnProperty('__path_seen__');
|
|
6445
|
+
if (!pathSeenBefore) {
|
|
6446
|
+
pathState.consumedValuesByKey['__path_seen__'] = ['true'];
|
|
6447
|
+
this.persistState();
|
|
6448
|
+
}
|
|
6449
|
+
return !pathSeenBefore;
|
|
6455
6450
|
}
|
|
6456
|
-
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
return this.
|
|
6460
|
-
}
|
|
6461
|
-
return this.checkVariation(normalized, options);
|
|
6451
|
+
if (options.mode === 'exact') {
|
|
6452
|
+
return this.checkExact(normalized, options);
|
|
6453
|
+
}
|
|
6454
|
+
return this.checkVariation(normalized, options);
|
|
6455
|
+
}));
|
|
6462
6456
|
}
|
|
6463
6457
|
matchesPath(requestOptions = [], expectedPathOptions = []) {
|
|
6464
6458
|
this.ensureStateRestored();
|
|
@@ -7760,66 +7754,67 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7760
7754
|
const tableDef = TableSchemaDef.adapt({ table: this.databaseOptions.table, schema: expectedSchema });
|
|
7761
7755
|
return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(switchMap(() => this.dbManagerService.createDatabaseTable(tableDef)), switchMap(() => fetchFromAPI()));
|
|
7762
7756
|
}
|
|
7763
|
-
// 4 & 5. tracker decision
|
|
7764
|
-
|
|
7765
|
-
|
|
7766
|
-
|
|
7767
|
-
|
|
7768
|
-
|
|
7769
|
-
|
|
7770
|
-
|
|
7771
|
-
|
|
7772
|
-
|
|
7773
|
-
|
|
7774
|
-
|
|
7775
|
-
|
|
7776
|
-
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
7757
|
+
// 4 & 5. tracker decision (async — awaits tracker readiness)
|
|
7758
|
+
return this.checkTrackerAllowsRequest(this.databaseOptions.table, this.resolvePath(effectiveParams), options, storeData).pipe(switchMap((trackerAllowsRequest) => {
|
|
7759
|
+
if (trackerAllowsRequest) {
|
|
7760
|
+
// For no-query paths, try DB first before API
|
|
7761
|
+
const normalizedPath = this.trackerNormalizePath(this.resolvePath(effectiveParams));
|
|
7762
|
+
if (!normalizedPath.hasQuery) {
|
|
7763
|
+
return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
|
|
7764
|
+
if (Array.isArray(dbData) && dbData.length > 0) {
|
|
7765
|
+
this.setData$(dbData);
|
|
7766
|
+
// Save cache metadata for both GET and STREAM request types so
|
|
7767
|
+
// tracker/check logic can detect cached responses regardless
|
|
7768
|
+
// of whether a subsequent call is a normal GET or a streaming GET.
|
|
7769
|
+
const getSignature = this.buildRequestSignature('GET', requestOptions, effectiveParams);
|
|
7770
|
+
const streamRequestOptions = { ...(requestOptions || {}), stream: true };
|
|
7771
|
+
const streamSignature = this.buildRequestSignature('STREAM', streamRequestOptions, effectiveParams);
|
|
7772
|
+
this.saveRequestCacheMetadata(this.databaseOptions.table, 'GET', getSignature, storedSchemaSignature ?? expectedSchemaSignature ?? undefined, options);
|
|
7773
|
+
this.saveRequestCacheMetadata(this.databaseOptions.table, 'STREAM', streamSignature, storedSchemaSignature ?? expectedSchemaSignature ?? undefined, options);
|
|
7774
|
+
return of({ data: dbData, fromCache: true });
|
|
7775
|
+
}
|
|
7776
|
+
return fetchFromAPI();
|
|
7777
|
+
}), catchError((error) => {
|
|
7778
|
+
const tableName = this.databaseOptions.table;
|
|
7779
|
+
console.warn('[DB STORAGE] fallback cache read failed, falling back to API:', { table: tableName, error });
|
|
7780
|
+
return fetchFromAPI();
|
|
7781
|
+
}));
|
|
7782
|
+
}
|
|
7783
|
+
return fetchFromAPI();
|
|
7784
|
+
}
|
|
7785
|
+
// tracker blocks request → DB/state fallback
|
|
7786
|
+
return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
|
|
7787
|
+
if (Array.isArray(dbData) && dbData.length > 0) {
|
|
7788
|
+
this.setData$(dbData);
|
|
7789
|
+
// Save cache metadata for both GET and STREAM request types so
|
|
7790
|
+
// tracker/check logic can detect cached responses regardless
|
|
7791
|
+
// of whether a subsequent call is a normal GET or a streaming GET.
|
|
7792
|
+
const getSignature = this.buildRequestSignature('GET', requestOptions, effectiveParams);
|
|
7793
|
+
const streamRequestOptions = { ...(requestOptions || {}), stream: true };
|
|
7794
|
+
const streamSignature = this.buildRequestSignature('STREAM', streamRequestOptions, effectiveParams);
|
|
7795
|
+
this.saveRequestCacheMetadata(this.databaseOptions.table, 'GET', getSignature, storedSchemaSignature ?? expectedSchemaSignature ?? undefined, options);
|
|
7796
|
+
this.saveRequestCacheMetadata(this.databaseOptions.table, 'STREAM', streamSignature, storedSchemaSignature ?? expectedSchemaSignature ?? undefined, options);
|
|
7797
|
+
return of(dbData);
|
|
7798
|
+
}
|
|
7799
|
+
const currentStateData = this.get()?.data;
|
|
7800
|
+
if (Array.isArray(currentStateData) && currentStateData.length > 0) {
|
|
7801
|
+
return of(currentStateData);
|
|
7802
|
+
}
|
|
7803
|
+
if (currentStateData &&
|
|
7804
|
+
!Array.isArray(currentStateData) &&
|
|
7805
|
+
Object.keys(currentStateData).length > 0) {
|
|
7806
|
+
return of(currentStateData);
|
|
7807
|
+
}
|
|
7808
|
+
return of(this.dataType === DataType.ARRAY ? [] : {});
|
|
7809
|
+
}), catchError((error) => {
|
|
7810
|
+
const tableName = this.databaseOptions.table;
|
|
7811
|
+
console.warn('[DB STORAGE] getTableRecords failed, recreating table and falling back to API:', { table: tableName, error });
|
|
7812
|
+
const schema = this.buildSchemaFromAdapter();
|
|
7813
|
+
const tableDef = TableSchemaDef.adapt({ table: tableName, schema });
|
|
7814
|
+
return this.dbManagerService.createDatabaseTable(tableDef).pipe(switchMap(() => fetchFromAPI()), catchError((recreateError) => {
|
|
7815
|
+
console.error('[DB STORAGE] Failed to recreate table after read error, continuing with API only:', recreateError);
|
|
7786
7816
|
return fetchFromAPI();
|
|
7787
7817
|
}));
|
|
7788
|
-
}
|
|
7789
|
-
return fetchFromAPI();
|
|
7790
|
-
}
|
|
7791
|
-
// tracker blocks request → DB/state fallback
|
|
7792
|
-
return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
|
|
7793
|
-
if (Array.isArray(dbData) && dbData.length > 0) {
|
|
7794
|
-
this.setData$(dbData);
|
|
7795
|
-
// Save cache metadata for both GET and STREAM request types so
|
|
7796
|
-
// tracker/check logic can detect cached responses regardless
|
|
7797
|
-
// of whether a subsequent call is a normal GET or a streaming GET.
|
|
7798
|
-
const getSignature = this.buildRequestSignature('GET', requestOptions, effectiveParams);
|
|
7799
|
-
const streamRequestOptions = { ...(requestOptions || {}), stream: true };
|
|
7800
|
-
const streamSignature = this.buildRequestSignature('STREAM', streamRequestOptions, effectiveParams);
|
|
7801
|
-
this.saveRequestCacheMetadata(this.databaseOptions.table, 'GET', getSignature, storedSchemaSignature ?? expectedSchemaSignature ?? undefined, options);
|
|
7802
|
-
this.saveRequestCacheMetadata(this.databaseOptions.table, 'STREAM', streamSignature, storedSchemaSignature ?? expectedSchemaSignature ?? undefined, options);
|
|
7803
|
-
return of(dbData);
|
|
7804
|
-
}
|
|
7805
|
-
const currentStateData = this.get()?.data;
|
|
7806
|
-
if (Array.isArray(currentStateData) && currentStateData.length > 0) {
|
|
7807
|
-
return of(currentStateData);
|
|
7808
|
-
}
|
|
7809
|
-
if (currentStateData &&
|
|
7810
|
-
!Array.isArray(currentStateData) &&
|
|
7811
|
-
Object.keys(currentStateData).length > 0) {
|
|
7812
|
-
return of(currentStateData);
|
|
7813
|
-
}
|
|
7814
|
-
return of(this.dataType === DataType.ARRAY ? [] : {});
|
|
7815
|
-
}), catchError((error) => {
|
|
7816
|
-
const tableName = this.databaseOptions.table;
|
|
7817
|
-
console.warn('[DB STORAGE] getTableRecords failed, recreating table and falling back to API:', { table: tableName, error });
|
|
7818
|
-
const schema = this.buildSchemaFromAdapter();
|
|
7819
|
-
const tableDef = TableSchemaDef.adapt({ table: tableName, schema });
|
|
7820
|
-
return this.dbManagerService.createDatabaseTable(tableDef).pipe(switchMap(() => fetchFromAPI()), catchError((recreateError) => {
|
|
7821
|
-
console.error('[DB STORAGE] Failed to recreate table after read error, continuing with API only:', recreateError);
|
|
7822
|
-
return fetchFromAPI();
|
|
7823
7818
|
}));
|
|
7824
7819
|
}));
|
|
7825
7820
|
}));
|
|
@@ -8508,12 +8503,12 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
8508
8503
|
if (!normalized.hasQuery || ignoreQueryParams.length === 0) {
|
|
8509
8504
|
const meta = this.getRequestCacheMetadata(storeData, 'GET');
|
|
8510
8505
|
console.log('[CacheDebug] checkTrackerAllowsRequest: no query params path', { tableName, requestCacheMeta: meta, allowsRequest: !meta });
|
|
8511
|
-
return !meta;
|
|
8506
|
+
return of(!meta);
|
|
8512
8507
|
}
|
|
8513
8508
|
const filtered = this.trackerFilterQuery(normalized.query, ignoreQueryParams);
|
|
8514
8509
|
const keys = Object.keys(filtered);
|
|
8515
8510
|
if (keys.length === 0) {
|
|
8516
|
-
return !this.getRequestCacheMetadata(storeData, 'GET');
|
|
8511
|
+
return of(!this.getRequestCacheMetadata(storeData, 'GET'));
|
|
8517
8512
|
}
|
|
8518
8513
|
const tracker = this.getTrackerState(storeData);
|
|
8519
8514
|
const now = Math.floor(Date.now() / 1000);
|
|
@@ -8537,7 +8532,7 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
8537
8532
|
}
|
|
8538
8533
|
this.saveTrackerState(tableName, tracker.consumedValuesByKey, tracker.trackingExpires);
|
|
8539
8534
|
}
|
|
8540
|
-
return accepted;
|
|
8535
|
+
return of(accepted);
|
|
8541
8536
|
}
|
|
8542
8537
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: HTTPManagerStateService, deps: [{ token: API_OPTS }, { token: "dataType" }, { token: DatabaseStorage }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
8543
8538
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: HTTPManagerStateService }); }
|