http-request-manager 18.15.18 → 18.15.20

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.
@@ -6471,34 +6471,33 @@ class QueryParamsTrackerService {
6471
6471
  }
6472
6472
  checkRequestOptions(requestOptions = [], options = {}) {
6473
6473
  this.ensureStateRestored();
6474
- if (!this.ready$.value) {
6475
- return true;
6476
- }
6477
- const normalized = this.normalizeRequestOptions(requestOptions);
6478
- if (!normalized.pathKey)
6479
- return false;
6480
- this.cleanupExpiredEntries();
6481
- if (!normalized.hasQuery) {
6482
- const pathState = this.ensurePathState(normalized.pathKey);
6483
- // Check if we've seen this path before by checking for a special marker
6484
- const pathSeenBefore = pathState.consumedValuesByKey.hasOwnProperty('__path_seen__');
6485
- if (!pathSeenBefore) {
6486
- // Mark this path as seen
6487
- pathState.consumedValuesByKey['__path_seen__'] = ['true'];
6488
- this.persistState();
6474
+ return this.ready$.pipe(filter(ready => ready === true), take(1), map(() => {
6475
+ const normalized = this.normalizeRequestOptions(requestOptions);
6476
+ if (!normalized.pathKey)
6477
+ return false;
6478
+ this.cleanupExpiredEntries();
6479
+ if (!normalized.hasQuery) {
6480
+ const pathState = this.ensurePathState(normalized.pathKey);
6481
+ const pathSeenBefore = pathState.consumedValuesByKey.hasOwnProperty('__path_seen__');
6482
+ if (!pathSeenBefore) {
6483
+ pathState.consumedValuesByKey['__path_seen__'] = ['true'];
6484
+ this.persistState();
6485
+ }
6486
+ return !pathSeenBefore;
6489
6487
  }
6490
- return !pathSeenBefore;
6491
- }
6492
- if (options.mode === 'exact') {
6493
- return this.checkExact(normalized, options);
6494
- }
6495
- return this.checkVariation(normalized, options);
6488
+ if (options.mode === 'exact') {
6489
+ return this.checkExact(normalized, options);
6490
+ }
6491
+ return this.checkVariation(normalized, options);
6492
+ }));
6496
6493
  }
6497
6494
  matchesPath(requestOptions = [], expectedPathOptions = []) {
6498
6495
  this.ensureStateRestored();
6499
- const requestPath = this.normalizeRequestOptions(requestOptions).pathKey;
6500
- const expectedPath = this.normalizeRequestOptions(expectedPathOptions).pathKey;
6501
- return Boolean(requestPath) && requestPath === expectedPath;
6496
+ return this.ready$.pipe(filter(ready => ready === true), take(1), map(() => {
6497
+ const requestPath = this.normalizeRequestOptions(requestOptions).pathKey;
6498
+ const expectedPath = this.normalizeRequestOptions(expectedPathOptions).pathKey;
6499
+ return Boolean(requestPath) && requestPath === expectedPath;
6500
+ }));
6502
6501
  }
6503
6502
  checkExact(normalized, options) {
6504
6503
  const pathState = this.ensurePathState(normalized.pathKey);
@@ -7344,56 +7343,57 @@ class HTTPManagerStateService extends ComponentStore {
7344
7343
  const tableDef = TableSchemaDef.adapt({ table: this.databaseOptions.table, schema: expectedSchema });
7345
7344
  return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(switchMap(() => this.dbManagerService.createDatabaseTable(tableDef)), switchMap(() => fetchFromAPI()));
7346
7345
  }
7347
- const trackerAllowsRequest = this.checkTrackerAllowsRequest(this.databaseOptions.table, this.resolvePath(effectiveParams), options, storeData);
7348
- if (trackerAllowsRequest) {
7349
- const normalizedPath = this.trackerNormalizePath(this.resolvePath(effectiveParams));
7350
- if (!normalizedPath.hasQuery) {
7351
- return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
7352
- if (Array.isArray(dbData) && dbData.length > 0) {
7353
- this.setData$(dbData);
7354
- // Save cache metadata for both GET and STREAM request types so
7355
- // tracker/check logic can detect cached responses regardless
7356
- // of whether a subsequent call is a normal GET or a streaming GET.
7357
- const getSignature = requestSignature;
7358
- const streamRequestOptions = { ...(requestOptions || {}), stream: true };
7359
- const streamSignature = this.buildRequestSignature('STREAM', streamRequestOptions, effectiveParams);
7360
- this.saveRequestCacheMetadata(this.databaseOptions.table, 'GET', getSignature, storedSchemaSignature ?? expectedSchemaSignature ?? undefined, options);
7361
- this.saveRequestCacheMetadata(this.databaseOptions.table, 'STREAM', streamSignature, storedSchemaSignature ?? expectedSchemaSignature ?? undefined, options);
7362
- return of({ data: dbData, fromCache: true });
7363
- }
7364
- return fetchFromAPI();
7365
- }), catchError((error) => {
7366
- const tableName = this.databaseOptions.table;
7367
- console.warn('[DB STORAGE] fallback cache read failed, falling back to API:', { table: tableName, error });
7346
+ return this.checkTrackerAllowsRequest(this.databaseOptions.table, this.resolvePath(effectiveParams), options, storeData).pipe(switchMap((trackerAllowsRequest) => {
7347
+ if (trackerAllowsRequest) {
7348
+ const normalizedPath = this.trackerNormalizePath(this.resolvePath(effectiveParams));
7349
+ if (!normalizedPath.hasQuery) {
7350
+ return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
7351
+ if (Array.isArray(dbData) && dbData.length > 0) {
7352
+ this.setData$(dbData);
7353
+ // Save cache metadata for both GET and STREAM request types so
7354
+ // tracker/check logic can detect cached responses regardless
7355
+ // of whether a subsequent call is a normal GET or a streaming GET.
7356
+ const getSignature = requestSignature;
7357
+ const streamRequestOptions = { ...(requestOptions || {}), stream: true };
7358
+ const streamSignature = this.buildRequestSignature('STREAM', streamRequestOptions, effectiveParams);
7359
+ this.saveRequestCacheMetadata(this.databaseOptions.table, 'GET', getSignature, storedSchemaSignature ?? expectedSchemaSignature ?? undefined, options);
7360
+ this.saveRequestCacheMetadata(this.databaseOptions.table, 'STREAM', streamSignature, storedSchemaSignature ?? expectedSchemaSignature ?? undefined, options);
7361
+ return of({ data: dbData, fromCache: true });
7362
+ }
7363
+ return fetchFromAPI();
7364
+ }), catchError((error) => {
7365
+ const tableName = this.databaseOptions.table;
7366
+ console.warn('[DB STORAGE] fallback cache read failed, falling back to API:', { table: tableName, error });
7367
+ return fetchFromAPI();
7368
+ }));
7369
+ }
7370
+ return fetchFromAPI();
7371
+ }
7372
+ return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
7373
+ if (Array.isArray(dbData) && dbData.length > 0) {
7374
+ this.setData$(dbData);
7375
+ this.saveRequestCacheMetadata(this.databaseOptions.table, 'GET', requestSignature, storedSchemaSignature ?? expectedSchemaSignature ?? undefined, options);
7376
+ return of(dbData);
7377
+ }
7378
+ const currentStateData = this.get()?.data;
7379
+ if (Array.isArray(currentStateData) && currentStateData.length > 0) {
7380
+ return of(currentStateData);
7381
+ }
7382
+ if (currentStateData &&
7383
+ !Array.isArray(currentStateData) &&
7384
+ Object.keys(currentStateData).length > 0) {
7385
+ return of(currentStateData);
7386
+ }
7387
+ return of(this.dataType === DataType.ARRAY ? [] : {});
7388
+ }), catchError((error) => {
7389
+ const tableName = this.databaseOptions.table;
7390
+ console.warn('[DB STORAGE] getTableRecords failed, recreating table and falling back to API:', { table: tableName, error });
7391
+ const schema = this.buildSchemaFromAdapter();
7392
+ const tableDef = TableSchemaDef.adapt({ table: tableName, schema });
7393
+ return this.dbManagerService.createDatabaseTable(tableDef).pipe(switchMap(() => fetchFromAPI()), catchError((recreateError) => {
7394
+ console.error('[DB STORAGE] Failed to recreate table after read error, continuing with API only:', recreateError);
7368
7395
  return fetchFromAPI();
7369
7396
  }));
7370
- }
7371
- return fetchFromAPI();
7372
- }
7373
- return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
7374
- if (Array.isArray(dbData) && dbData.length > 0) {
7375
- this.setData$(dbData);
7376
- this.saveRequestCacheMetadata(this.databaseOptions.table, 'GET', requestSignature, storedSchemaSignature ?? expectedSchemaSignature ?? undefined, options);
7377
- return of(dbData);
7378
- }
7379
- const currentStateData = this.get()?.data;
7380
- if (Array.isArray(currentStateData) && currentStateData.length > 0) {
7381
- return of(currentStateData);
7382
- }
7383
- if (currentStateData &&
7384
- !Array.isArray(currentStateData) &&
7385
- Object.keys(currentStateData).length > 0) {
7386
- return of(currentStateData);
7387
- }
7388
- return of(this.dataType === DataType.ARRAY ? [] : {});
7389
- }), catchError((error) => {
7390
- const tableName = this.databaseOptions.table;
7391
- console.warn('[DB STORAGE] getTableRecords failed, recreating table and falling back to API:', { table: tableName, error });
7392
- const schema = this.buildSchemaFromAdapter();
7393
- const tableDef = TableSchemaDef.adapt({ table: tableName, schema });
7394
- return this.dbManagerService.createDatabaseTable(tableDef).pipe(switchMap(() => fetchFromAPI()), catchError((recreateError) => {
7395
- console.error('[DB STORAGE] Failed to recreate table after read error, continuing with API only:', recreateError);
7396
- return fetchFromAPI();
7397
7397
  }));
7398
7398
  }));
7399
7399
  }));
@@ -7576,25 +7576,26 @@ class HTTPManagerStateService extends ComponentStore {
7576
7576
  const tableDef = TableSchemaDef.adapt({ table: this.databaseOptions.table, schema: expectedSchema });
7577
7577
  return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(switchMap(() => this.dbManagerService.createDatabaseTable(tableDef)), switchMap(() => fetchStreamFromAPI()));
7578
7578
  }
7579
- const trackerAllowsRequest = this.checkTrackerAllowsRequest(this.databaseOptions.table, this.resolvePath(effectiveParams), options, storeData);
7580
- if (!trackerAllowsRequest) {
7581
- return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
7582
- if (Array.isArray(dbData) && dbData.length > 0) {
7583
- return of({ data: dbData, fromCache: true });
7584
- }
7585
- const currentStateData = this.get()?.data;
7586
- if (Array.isArray(currentStateData) && currentStateData.length > 0) {
7587
- return of({ data: currentStateData, fromCache: true });
7588
- }
7589
- if (currentStateData &&
7590
- !Array.isArray(currentStateData) &&
7591
- Object.keys(currentStateData).length > 0) {
7592
- return of({ data: currentStateData, fromCache: true });
7593
- }
7594
- return of({ data: this.dataType === DataType.ARRAY ? [] : {}, fromCache: true });
7595
- }));
7596
- }
7597
- return fetchStreamFromAPI();
7579
+ return this.checkTrackerAllowsRequest(this.databaseOptions.table, this.resolvePath(effectiveParams), options, storeData).pipe(switchMap((trackerAllowsRequest) => {
7580
+ if (!trackerAllowsRequest) {
7581
+ return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
7582
+ if (Array.isArray(dbData) && dbData.length > 0) {
7583
+ return of({ data: dbData, fromCache: true });
7584
+ }
7585
+ const currentStateData = this.get()?.data;
7586
+ if (Array.isArray(currentStateData) && currentStateData.length > 0) {
7587
+ return of({ data: currentStateData, fromCache: true });
7588
+ }
7589
+ if (currentStateData &&
7590
+ !Array.isArray(currentStateData) &&
7591
+ Object.keys(currentStateData).length > 0) {
7592
+ return of({ data: currentStateData, fromCache: true });
7593
+ }
7594
+ return of({ data: this.dataType === DataType.ARRAY ? [] : {}, fromCache: true });
7595
+ }));
7596
+ }
7597
+ return fetchStreamFromAPI();
7598
+ }));
7598
7599
  })).pipe(tap((packet) => {
7599
7600
  const res = packet?.data;
7600
7601
  // console.log('[DEBUG] Streaming response received:', res)
@@ -8506,7 +8507,7 @@ class HTTPManagerStateService extends ComponentStore {
8506
8507
  if (!Array.isArray(ignoreQueryParams))
8507
8508
  return { ...query };
8508
8509
  if (ignoreQueryParams.length === 0)
8509
- return {};
8510
+ return { ...query };
8510
8511
  const result = {};
8511
8512
  ignoreQueryParams.forEach((param) => {
8512
8513
  const key = this.trackerNormalizeParamKey(param);
@@ -8541,15 +8542,14 @@ class HTTPManagerStateService extends ComponentStore {
8541
8542
  }
8542
8543
  const normalized = this.trackerNormalizePath(path);
8543
8544
  const ignoreQueryParams = Array.isArray(options?.ignoreQueryParams) ? options.ignoreQueryParams : [];
8544
- if (!normalized.hasQuery || ignoreQueryParams.length === 0) {
8545
+ if (!normalized.hasQuery) {
8545
8546
  const meta = this.getRequestCacheMetadata(storeData, 'GET');
8546
- console.log('[CacheDebug] checkTrackerAllowsRequest: no query params path', { tableName, requestCacheMeta: meta, allowsRequest: !meta });
8547
- return !meta;
8547
+ return of(!meta);
8548
8548
  }
8549
8549
  const filtered = this.trackerFilterQuery(normalized.query, ignoreQueryParams);
8550
8550
  const keys = Object.keys(filtered);
8551
8551
  if (keys.length === 0) {
8552
- return !this.getRequestCacheMetadata(storeData, 'GET');
8552
+ return of(!this.getRequestCacheMetadata(storeData, 'GET'));
8553
8553
  }
8554
8554
  const tracker = this.getTrackerState(storeData);
8555
8555
  const now = Math.floor(Date.now() / 1000);
@@ -8573,7 +8573,7 @@ class HTTPManagerStateService extends ComponentStore {
8573
8573
  }
8574
8574
  this.saveTrackerState(tableName, tracker.consumedValuesByKey, tracker.trackingExpires);
8575
8575
  }
8576
- return accepted;
8576
+ return of(accepted);
8577
8577
  }
8578
8578
  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 }); }
8579
8579
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: HTTPManagerStateService }); }