http-request-manager 18.15.6 → 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.
@@ -6814,6 +6814,7 @@ class HTTPManagerStateService extends ComponentStore {
6814
6814
  'if-none-match'
6815
6815
  ]);
6816
6816
  this.requestSignatureCache = {};
6817
+ this.inFlightRequestSignatures = new Set();
6817
6818
  this._requestCachePaths = new Map();
6818
6819
  this.wsRetryAttempts = new BehaviorSubject(0);
6819
6820
  this.wsRetryAttempts$ = this.wsRetryAttempts.asObservable();
@@ -7207,6 +7208,18 @@ class HTTPManagerStateService extends ComponentStore {
7207
7208
  const fetchFromAPI = () => {
7208
7209
  if (this.hasDatabase && this.databaseOptions?.table) {
7209
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
+ }
7210
7223
  }
7211
7224
  return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(tap((data) => {
7212
7225
  // Extract array from paginated response if needed
@@ -7245,6 +7258,10 @@ class HTTPManagerStateService extends ComponentStore {
7245
7258
  }));
7246
7259
  }
7247
7260
  return of(data);
7261
+ }), finalize(() => {
7262
+ if (this.hasDatabase && this.databaseOptions?.table) {
7263
+ this.endInFlightRequest(requestSignature);
7264
+ }
7248
7265
  }));
7249
7266
  };
7250
7267
  console.log('[DB STORAGE] Checking database storage:', {
@@ -7487,23 +7504,38 @@ class HTTPManagerStateService extends ComponentStore {
7487
7504
  // console.log('[DEBUG] Making streaming request:', requestOptions)
7488
7505
  if (this.hasDatabase && this.databaseOptions?.table) {
7489
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
+ };
7490
7523
  return this.localStorageManagerService.store$(this.databaseOptions.table).pipe(take(1), switchMap((storeData) => {
7491
7524
  const forceRefresh = !!options?.forceRefresh;
7492
7525
  const expires = storeData?.expires || 0;
7493
7526
  const hasExpired = expires > 0 && this.utils.hasExpired(expires);
7494
7527
  if (forceRefresh) {
7495
- this.setCachedRequestSignature(this.databaseOptions.table, 'STREAM', requestSignature);
7496
- return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })));
7528
+ return fetchStreamFromAPI();
7497
7529
  }
7498
7530
  if (hasExpired) {
7499
- 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()));
7500
7532
  }
7501
7533
  const storedSchemaSignature = this.getStoredSchemaSignature(storeData);
7502
7534
  const expectedSchema = this.buildSchemaFromAdapter();
7503
7535
  const expectedSchemaSignature = this.buildSchemaSignature(expectedSchema);
7504
7536
  if (storedSchemaSignature && storedSchemaSignature !== expectedSchemaSignature) {
7505
7537
  const tableDef = TableSchemaDef.adapt({ table: this.databaseOptions.table, schema: expectedSchema });
7506
- 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()));
7507
7539
  }
7508
7540
  const trackerAllowsRequest = this.checkTrackerAllowsRequest(this.databaseOptions.table, this.resolvePath(effectiveParams), options, storeData);
7509
7541
  if (!trackerAllowsRequest) {
@@ -7523,8 +7555,7 @@ class HTTPManagerStateService extends ComponentStore {
7523
7555
  return of({ data: this.dataType === DataType.ARRAY ? [] : {}, fromCache: true });
7524
7556
  }));
7525
7557
  }
7526
- this.setCachedRequestSignature(this.databaseOptions.table, 'STREAM', requestSignature);
7527
- return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(map((apiData) => ({ data: apiData, fromCache: false })));
7558
+ return fetchStreamFromAPI();
7528
7559
  })).pipe(tap((packet) => {
7529
7560
  const res = packet?.data;
7530
7561
  // console.log('[DEBUG] Streaming response received:', res)
@@ -8285,6 +8316,16 @@ class HTTPManagerStateService extends ComponentStore {
8285
8316
  [type]: signature,
8286
8317
  };
8287
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
+ }
8288
8329
  getRequestCacheMetadata(storeData, type) {
8289
8330
  return storeData?.requestCache?.[type] || null;
8290
8331
  }