http-request-manager 18.15.4 → 18.15.7

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.
@@ -6441,8 +6441,11 @@ class QueryParamsTrackerService {
6441
6441
  this.cleanupExpiredEntries();
6442
6442
  if (!normalized.hasQuery) {
6443
6443
  const pathState = this.ensurePathState(normalized.pathKey);
6444
- const pathSeenBefore = Object.keys(pathState.consumedValuesByKey).length > 0;
6444
+ // Check if we've seen this path before by checking for a special marker
6445
+ const pathSeenBefore = pathState.consumedValuesByKey.hasOwnProperty('__path_seen__');
6445
6446
  if (!pathSeenBefore) {
6447
+ // Mark this path as seen
6448
+ pathState.consumedValuesByKey['__path_seen__'] = ['true'];
6446
6449
  this.persistState();
6447
6450
  }
6448
6451
  return !pathSeenBefore;
@@ -6811,6 +6814,7 @@ class HTTPManagerStateService extends ComponentStore {
6811
6814
  'if-none-match'
6812
6815
  ]);
6813
6816
  this.requestSignatureCache = {};
6817
+ this.inFlightRequestSignatures = new Set();
6814
6818
  this._requestCachePaths = new Map();
6815
6819
  this.wsRetryAttempts = new BehaviorSubject(0);
6816
6820
  this.wsRetryAttempts$ = this.wsRetryAttempts.asObservable();
@@ -7204,6 +7208,18 @@ class HTTPManagerStateService extends ComponentStore {
7204
7208
  const fetchFromAPI = () => {
7205
7209
  if (this.hasDatabase && this.databaseOptions?.table) {
7206
7210
  this.setCachedRequestSignature(this.databaseOptions.table, 'GET', requestSignature);
7211
+ if (!this.tryBeginInFlightRequest(requestSignature)) {
7212
+ const currentStateData = this.get()?.data;
7213
+ if (Array.isArray(currentStateData) && currentStateData.length > 0) {
7214
+ return of(currentStateData);
7215
+ }
7216
+ if (currentStateData &&
7217
+ !Array.isArray(currentStateData) &&
7218
+ Object.keys(currentStateData).length > 0) {
7219
+ return of(currentStateData);
7220
+ }
7221
+ return of(this.dataType === DataType.ARRAY ? [] : {});
7222
+ }
7207
7223
  }
7208
7224
  return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(tap((data) => {
7209
7225
  // Extract array from paginated response if needed
@@ -7242,6 +7258,10 @@ class HTTPManagerStateService extends ComponentStore {
7242
7258
  }));
7243
7259
  }
7244
7260
  return of(data);
7261
+ }), finalize(() => {
7262
+ if (this.hasDatabase && this.databaseOptions?.table) {
7263
+ this.endInFlightRequest(requestSignature);
7264
+ }
7245
7265
  }));
7246
7266
  };
7247
7267
  console.log('[DB STORAGE] Checking database storage:', {
@@ -7484,23 +7504,38 @@ class HTTPManagerStateService extends ComponentStore {
7484
7504
  // console.log('[DEBUG] Making streaming request:', requestOptions)
7485
7505
  if (this.hasDatabase && this.databaseOptions?.table) {
7486
7506
  const requestSignature = this.buildRequestSignature('STREAM', requestOptions, effectiveParams);
7507
+ const fetchStreamFromAPI = () => {
7508
+ if (!this.tryBeginInFlightRequest(requestSignature)) {
7509
+ const currentStateData = this.get()?.data;
7510
+ if (Array.isArray(currentStateData) && currentStateData.length > 0) {
7511
+ return of({ data: currentStateData, fromCache: true });
7512
+ }
7513
+ if (currentStateData &&
7514
+ !Array.isArray(currentStateData) &&
7515
+ Object.keys(currentStateData).length > 0) {
7516
+ return of({ data: currentStateData, fromCache: true });
7517
+ }
7518
+ return of({ data: this.dataType === DataType.ARRAY ? [] : {}, fromCache: true });
7519
+ }
7520
+ this.setCachedRequestSignature(this.databaseOptions.table, 'STREAM', requestSignature);
7521
+ return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })), finalize(() => this.endInFlightRequest(requestSignature)));
7522
+ };
7487
7523
  return this.localStorageManagerService.store$(this.databaseOptions.table).pipe(take(1), switchMap((storeData) => {
7488
7524
  const forceRefresh = !!options?.forceRefresh;
7489
7525
  const expires = storeData?.expires || 0;
7490
7526
  const hasExpired = expires > 0 && this.utils.hasExpired(expires);
7491
7527
  if (forceRefresh) {
7492
- this.setCachedRequestSignature(this.databaseOptions.table, 'STREAM', requestSignature);
7493
- return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })));
7528
+ return fetchStreamFromAPI();
7494
7529
  }
7495
7530
  if (hasExpired) {
7496
- 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 })));
7531
+ return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(switchMap(() => fetchStreamFromAPI()));
7497
7532
  }
7498
7533
  const storedSchemaSignature = this.getStoredSchemaSignature(storeData);
7499
7534
  const expectedSchema = this.buildSchemaFromAdapter();
7500
7535
  const expectedSchemaSignature = this.buildSchemaSignature(expectedSchema);
7501
7536
  if (storedSchemaSignature && storedSchemaSignature !== expectedSchemaSignature) {
7502
7537
  const tableDef = TableSchemaDef.adapt({ table: this.databaseOptions.table, schema: expectedSchema });
7503
- return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(switchMap(() => this.dbManagerService.createDatabaseTable(tableDef)), tap(() => this.setCachedRequestSignature(this.databaseOptions.table, 'STREAM', requestSignature)), switchMap(() => this.httpManagerService.getRequest(requestOptions, effectiveParams)), map((apiData) => ({ data: apiData, fromCache: false })));
7538
+ return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(switchMap(() => this.dbManagerService.createDatabaseTable(tableDef)), switchMap(() => fetchStreamFromAPI()));
7504
7539
  }
7505
7540
  const trackerAllowsRequest = this.checkTrackerAllowsRequest(this.databaseOptions.table, this.resolvePath(effectiveParams), options, storeData);
7506
7541
  if (!trackerAllowsRequest) {
@@ -7520,8 +7555,7 @@ class HTTPManagerStateService extends ComponentStore {
7520
7555
  return of({ data: this.dataType === DataType.ARRAY ? [] : {}, fromCache: true });
7521
7556
  }));
7522
7557
  }
7523
- this.setCachedRequestSignature(this.databaseOptions.table, 'STREAM', requestSignature);
7524
- return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })));
7558
+ return fetchStreamFromAPI();
7525
7559
  })).pipe(tap((packet) => {
7526
7560
  const res = packet?.data;
7527
7561
  // console.log('[DEBUG] Streaming response received:', res)
@@ -7543,6 +7577,7 @@ class HTTPManagerStateService extends ComponentStore {
7543
7577
  return of([]);
7544
7578
  }), finalize(() => this.httpManagerService.isPending.next(false)));
7545
7579
  }
7580
+ // If no database is configured, always call the API (do not check tracker)
7546
7581
  return this.httpManagerService.getRequest(requestOptions, effectiveParams)
7547
7582
  .pipe(tap((res) => {
7548
7583
  console.log('[DEBUG] Streaming response received:', res);
@@ -8281,6 +8316,16 @@ class HTTPManagerStateService extends ComponentStore {
8281
8316
  [type]: signature,
8282
8317
  };
8283
8318
  }
8319
+ tryBeginInFlightRequest(signature) {
8320
+ if (this.inFlightRequestSignatures.has(signature)) {
8321
+ return false;
8322
+ }
8323
+ this.inFlightRequestSignatures.add(signature);
8324
+ return true;
8325
+ }
8326
+ endInFlightRequest(signature) {
8327
+ this.inFlightRequestSignatures.delete(signature);
8328
+ }
8284
8329
  getRequestCacheMetadata(storeData, type) {
8285
8330
  return storeData?.requestCache?.[type] || null;
8286
8331
  }