http-request-manager 18.15.17 → 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.
|
@@ -6127,13 +6127,18 @@ class DbService extends Dexie {
|
|
|
6127
6127
|
return schema;
|
|
6128
6128
|
}
|
|
6129
6129
|
deleteAndReinitialize() {
|
|
6130
|
-
return from(
|
|
6131
|
-
|
|
6132
|
-
|
|
6130
|
+
return from(this.delete({ disableAutoOpen: false }).then(async () => {
|
|
6131
|
+
console.log('[DB] Database deleted. Reopening...');
|
|
6132
|
+
try {
|
|
6133
|
+
await this.open();
|
|
6134
|
+
this.dbReady = Promise.resolve();
|
|
6135
|
+
console.log(`[DB] Reopened database. Version: ${this.verno}, Tables: ${this.getTables.join(', ')}`);
|
|
6136
|
+
return this.isOpen();
|
|
6137
|
+
}
|
|
6138
|
+
catch (openErr) {
|
|
6139
|
+
console.error('[DB] Failed to reopen after delete:', openErr);
|
|
6140
|
+
return false;
|
|
6133
6141
|
}
|
|
6134
|
-
this.dbReady = this.init();
|
|
6135
|
-
await this.dbReady;
|
|
6136
|
-
return this.isOpen();
|
|
6137
6142
|
})).pipe(catchError((err) => {
|
|
6138
6143
|
console.error('[DB] deleteAndReinitialize failed:', err);
|
|
6139
6144
|
return of(false);
|
|
@@ -6466,34 +6471,33 @@ class QueryParamsTrackerService {
|
|
|
6466
6471
|
}
|
|
6467
6472
|
checkRequestOptions(requestOptions = [], options = {}) {
|
|
6468
6473
|
this.ensureStateRestored();
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
pathState.consumedValuesByKey['__path_seen__'] = ['true'];
|
|
6483
|
-
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;
|
|
6484
6487
|
}
|
|
6485
|
-
|
|
6486
|
-
|
|
6487
|
-
|
|
6488
|
-
return this.
|
|
6489
|
-
}
|
|
6490
|
-
return this.checkVariation(normalized, options);
|
|
6488
|
+
if (options.mode === 'exact') {
|
|
6489
|
+
return this.checkExact(normalized, options);
|
|
6490
|
+
}
|
|
6491
|
+
return this.checkVariation(normalized, options);
|
|
6492
|
+
}));
|
|
6491
6493
|
}
|
|
6492
6494
|
matchesPath(requestOptions = [], expectedPathOptions = []) {
|
|
6493
6495
|
this.ensureStateRestored();
|
|
6494
|
-
|
|
6495
|
-
|
|
6496
|
-
|
|
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
|
+
}));
|
|
6497
6501
|
}
|
|
6498
6502
|
checkExact(normalized, options) {
|
|
6499
6503
|
const pathState = this.ensurePathState(normalized.pathKey);
|
|
@@ -7339,56 +7343,57 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7339
7343
|
const tableDef = TableSchemaDef.adapt({ table: this.databaseOptions.table, schema: expectedSchema });
|
|
7340
7344
|
return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(switchMap(() => this.dbManagerService.createDatabaseTable(tableDef)), switchMap(() => fetchFromAPI()));
|
|
7341
7345
|
}
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
7347
|
-
|
|
7348
|
-
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
|
|
7352
|
-
|
|
7353
|
-
|
|
7354
|
-
|
|
7355
|
-
|
|
7356
|
-
|
|
7357
|
-
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
|
|
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);
|
|
7363
7395
|
return fetchFromAPI();
|
|
7364
7396
|
}));
|
|
7365
|
-
}
|
|
7366
|
-
return fetchFromAPI();
|
|
7367
|
-
}
|
|
7368
|
-
return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
|
|
7369
|
-
if (Array.isArray(dbData) && dbData.length > 0) {
|
|
7370
|
-
this.setData$(dbData);
|
|
7371
|
-
this.saveRequestCacheMetadata(this.databaseOptions.table, 'GET', requestSignature, storedSchemaSignature ?? expectedSchemaSignature ?? undefined, options);
|
|
7372
|
-
return of(dbData);
|
|
7373
|
-
}
|
|
7374
|
-
const currentStateData = this.get()?.data;
|
|
7375
|
-
if (Array.isArray(currentStateData) && currentStateData.length > 0) {
|
|
7376
|
-
return of(currentStateData);
|
|
7377
|
-
}
|
|
7378
|
-
if (currentStateData &&
|
|
7379
|
-
!Array.isArray(currentStateData) &&
|
|
7380
|
-
Object.keys(currentStateData).length > 0) {
|
|
7381
|
-
return of(currentStateData);
|
|
7382
|
-
}
|
|
7383
|
-
return of(this.dataType === DataType.ARRAY ? [] : {});
|
|
7384
|
-
}), catchError((error) => {
|
|
7385
|
-
const tableName = this.databaseOptions.table;
|
|
7386
|
-
console.warn('[DB STORAGE] getTableRecords failed, recreating table and falling back to API:', { table: tableName, error });
|
|
7387
|
-
const schema = this.buildSchemaFromAdapter();
|
|
7388
|
-
const tableDef = TableSchemaDef.adapt({ table: tableName, schema });
|
|
7389
|
-
return this.dbManagerService.createDatabaseTable(tableDef).pipe(switchMap(() => fetchFromAPI()), catchError((recreateError) => {
|
|
7390
|
-
console.error('[DB STORAGE] Failed to recreate table after read error, continuing with API only:', recreateError);
|
|
7391
|
-
return fetchFromAPI();
|
|
7392
7397
|
}));
|
|
7393
7398
|
}));
|
|
7394
7399
|
}));
|
|
@@ -7571,25 +7576,26 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7571
7576
|
const tableDef = TableSchemaDef.adapt({ table: this.databaseOptions.table, schema: expectedSchema });
|
|
7572
7577
|
return this.dbManagerService.clearTable(this.databaseOptions.table).pipe(switchMap(() => this.dbManagerService.createDatabaseTable(tableDef)), switchMap(() => fetchStreamFromAPI()));
|
|
7573
7578
|
}
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
|
|
7584
|
-
|
|
7585
|
-
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
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
|
+
}));
|
|
7593
7599
|
})).pipe(tap((packet) => {
|
|
7594
7600
|
const res = packet?.data;
|
|
7595
7601
|
// console.log('[DEBUG] Streaming response received:', res)
|
|
@@ -8501,7 +8507,7 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
8501
8507
|
if (!Array.isArray(ignoreQueryParams))
|
|
8502
8508
|
return { ...query };
|
|
8503
8509
|
if (ignoreQueryParams.length === 0)
|
|
8504
|
-
return {};
|
|
8510
|
+
return { ...query };
|
|
8505
8511
|
const result = {};
|
|
8506
8512
|
ignoreQueryParams.forEach((param) => {
|
|
8507
8513
|
const key = this.trackerNormalizeParamKey(param);
|
|
@@ -8536,15 +8542,14 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
8536
8542
|
}
|
|
8537
8543
|
const normalized = this.trackerNormalizePath(path);
|
|
8538
8544
|
const ignoreQueryParams = Array.isArray(options?.ignoreQueryParams) ? options.ignoreQueryParams : [];
|
|
8539
|
-
if (!normalized.hasQuery
|
|
8545
|
+
if (!normalized.hasQuery) {
|
|
8540
8546
|
const meta = this.getRequestCacheMetadata(storeData, 'GET');
|
|
8541
|
-
|
|
8542
|
-
return !meta;
|
|
8547
|
+
return of(!meta);
|
|
8543
8548
|
}
|
|
8544
8549
|
const filtered = this.trackerFilterQuery(normalized.query, ignoreQueryParams);
|
|
8545
8550
|
const keys = Object.keys(filtered);
|
|
8546
8551
|
if (keys.length === 0) {
|
|
8547
|
-
return !this.getRequestCacheMetadata(storeData, 'GET');
|
|
8552
|
+
return of(!this.getRequestCacheMetadata(storeData, 'GET'));
|
|
8548
8553
|
}
|
|
8549
8554
|
const tracker = this.getTrackerState(storeData);
|
|
8550
8555
|
const now = Math.floor(Date.now() / 1000);
|
|
@@ -8568,7 +8573,7 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
8568
8573
|
}
|
|
8569
8574
|
this.saveTrackerState(tableName, tracker.consumedValuesByKey, tracker.trackingExpires);
|
|
8570
8575
|
}
|
|
8571
|
-
return accepted;
|
|
8576
|
+
return of(accepted);
|
|
8572
8577
|
}
|
|
8573
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 }); }
|
|
8574
8579
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: HTTPManagerStateService }); }
|