http-request-manager 18.16.13 → 18.16.16
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.
|
@@ -7013,14 +7013,18 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7013
7013
|
return this.httpManagerService.getRequest(requestOptions, effectiveParams).pipe(tap((data) => {
|
|
7014
7014
|
// Extract array from paginated response if needed
|
|
7015
7015
|
const arrayData = (data?.results && Array.isArray(data.results)) ? data.results : data;
|
|
7016
|
-
|
|
7017
|
-
this.
|
|
7016
|
+
// Apply adapter to response data
|
|
7017
|
+
let adaptedData = this.applyAdapter(arrayData);
|
|
7018
|
+
adaptedData = (!adaptedData) ? (this.dataType === DataType.ARRAY) ? [] : {} : adaptedData;
|
|
7019
|
+
this.setData$(adaptedData);
|
|
7018
7020
|
}), concatMap((data) => {
|
|
7019
7021
|
// Extract array from paginated response for database storage
|
|
7020
7022
|
const dbData = (data?.results && Array.isArray(data.results)) ? data.results : data;
|
|
7021
|
-
|
|
7023
|
+
// Apply adapter before database storage
|
|
7024
|
+
const adaptedDbData = this.applyAdapter(dbData);
|
|
7025
|
+
if (this.hasDatabase && this.databaseOptions?.table && Array.isArray(adaptedDbData) && adaptedDbData.length > 0) {
|
|
7022
7026
|
const tableName = this.databaseOptions.table;
|
|
7023
|
-
const schema = this.buildSchemaFromSample(
|
|
7027
|
+
const schema = this.buildSchemaFromSample(adaptedDbData[0]);
|
|
7024
7028
|
const tableDef = TableSchemaDef.adapt({ table: tableName, schema });
|
|
7025
7029
|
const schemaSignature = this.buildSchemaSignature(schema);
|
|
7026
7030
|
// Always ensure table exists immediately before writing to avoid stale schema/store races.
|
|
@@ -7035,7 +7039,7 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7035
7039
|
console.warn('[DB STORAGE] Table create/open not ready, skipping DB write for this payload:', { table: tableName });
|
|
7036
7040
|
return of(data);
|
|
7037
7041
|
}
|
|
7038
|
-
return this.dbManagerService.createTableRecords(tableName,
|
|
7042
|
+
return this.dbManagerService.createTableRecords(tableName, adaptedDbData).pipe(tap(() => this.saveRequestCacheMetadata(tableName, 'GET', requestSignature, schemaSignature, options)));
|
|
7039
7043
|
}));
|
|
7040
7044
|
}), catchError((error) => {
|
|
7041
7045
|
console.error('[DB STORAGE] Failed to ensure table and write records:', { table: tableName, schema, error });
|
|
@@ -7158,39 +7162,43 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7158
7162
|
// Restore original path after request completes
|
|
7159
7163
|
this.apiOptions.path = originalPath;
|
|
7160
7164
|
console.log('🔧 Restored apiOptions.path to:', originalPath);
|
|
7161
|
-
|
|
7165
|
+
// Apply adapter if provided
|
|
7166
|
+
let adaptedData = this.applyAdapter(data);
|
|
7167
|
+
adaptedData = (!adaptedData) ? (this.dataType === DataType.ARRAY) ? [] : {} : adaptedData;
|
|
7162
7168
|
const id = options.path?.length ? options.path[options.path.length - 1] : null;
|
|
7163
7169
|
if (method === 'DELETE') {
|
|
7164
7170
|
console.log('🗑️ Deleting record with id:', id);
|
|
7165
7171
|
this.deleteData$({ id });
|
|
7166
7172
|
}
|
|
7167
7173
|
if (method === 'UPDATE') {
|
|
7168
|
-
console.log('✏️ Updating record:',
|
|
7169
|
-
this.updateData$(
|
|
7174
|
+
console.log('✏️ Updating record:', adaptedData);
|
|
7175
|
+
this.updateData$(adaptedData);
|
|
7170
7176
|
}
|
|
7171
7177
|
if (method === 'CREATE') {
|
|
7172
|
-
console.log('➕ Adding record:',
|
|
7173
|
-
this.addData$(
|
|
7178
|
+
console.log('➕ Adding record:', adaptedData);
|
|
7179
|
+
this.addData$(adaptedData);
|
|
7174
7180
|
}
|
|
7175
7181
|
}), concatMap((data) => {
|
|
7182
|
+
// Apply adapter to data before database operations
|
|
7183
|
+
const adaptedData = this.applyAdapter(data);
|
|
7176
7184
|
if (this.hasDatabase && this.databaseOptions?.table) {
|
|
7177
7185
|
const id = options.path?.length ? options.path[options.path.length - 1] : null;
|
|
7178
7186
|
if (method === 'DELETE' && id)
|
|
7179
7187
|
return this.dbManagerService.deleteTableRecord(this.databaseOptions.table, id);
|
|
7180
|
-
if (method === 'UPDATE' &&
|
|
7181
|
-
return this.dbManagerService.updateTableRecord(this.databaseOptions.table,
|
|
7182
|
-
if (method === 'CREATE' &&
|
|
7188
|
+
if (method === 'UPDATE' && adaptedData)
|
|
7189
|
+
return this.dbManagerService.updateTableRecord(this.databaseOptions.table, adaptedData);
|
|
7190
|
+
if (method === 'CREATE' && adaptedData) {
|
|
7183
7191
|
// Validate that data has a valid id before saving to IndexedDB
|
|
7184
|
-
if (
|
|
7185
|
-
console.log('💾 Saving to IndexedDB:', { table: this.databaseOptions.table, id:
|
|
7186
|
-
return this.dbManagerService.createTableRecord(this.databaseOptions.table,
|
|
7192
|
+
if (adaptedData && (adaptedData.id !== undefined && adaptedData.id !== null && adaptedData.id !== '')) {
|
|
7193
|
+
console.log('💾 Saving to IndexedDB:', { table: this.databaseOptions.table, id: adaptedData.id, data: adaptedData });
|
|
7194
|
+
return this.dbManagerService.createTableRecord(this.databaseOptions.table, adaptedData);
|
|
7187
7195
|
}
|
|
7188
7196
|
else {
|
|
7189
|
-
console.warn('⚠️ Skipping IndexedDB save: data.id is invalid',
|
|
7197
|
+
console.warn('⚠️ Skipping IndexedDB save: data.id is invalid', adaptedData);
|
|
7190
7198
|
}
|
|
7191
7199
|
}
|
|
7192
7200
|
}
|
|
7193
|
-
return of(
|
|
7201
|
+
return of(adaptedData);
|
|
7194
7202
|
}));
|
|
7195
7203
|
})));
|
|
7196
7204
|
// CREATE RECORD
|
|
@@ -7200,16 +7208,20 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7200
7208
|
const effectiveParams = this.getEffectiveParams(options?.path);
|
|
7201
7209
|
return this.httpManagerService.postRequest(data, requestOptions, effectiveParams)
|
|
7202
7210
|
.pipe(tap((data) => {
|
|
7203
|
-
|
|
7204
|
-
this.
|
|
7211
|
+
// Apply adapter to response data
|
|
7212
|
+
let adaptedData = this.applyAdapter(data);
|
|
7213
|
+
adaptedData = (!adaptedData) ? (this.dataType === DataType.ARRAY) ? [] : {} : adaptedData;
|
|
7214
|
+
this.addData$(adaptedData);
|
|
7205
7215
|
this.operationSuccess.next(OperationResultModel.adapt({ success: true, operation: 'CREATE' }));
|
|
7206
7216
|
// Always call wsCommunication - it will queue if not connected
|
|
7207
|
-
this.wsCommunication('CREATE', [...options?.path || [],
|
|
7217
|
+
this.wsCommunication('CREATE', [...options?.path || [], adaptedData.id]);
|
|
7208
7218
|
}), concatMap((data) => {
|
|
7209
|
-
|
|
7210
|
-
|
|
7219
|
+
// Apply adapter before database operations
|
|
7220
|
+
const adaptedData = this.applyAdapter(data);
|
|
7221
|
+
if (this.hasDatabase && this.databaseOptions?.table && adaptedData?.id) {
|
|
7222
|
+
return this.dbManagerService.createTableRecord(this.databaseOptions.table, adaptedData);
|
|
7211
7223
|
}
|
|
7212
|
-
return of(
|
|
7224
|
+
return of(adaptedData);
|
|
7213
7225
|
}));
|
|
7214
7226
|
})));
|
|
7215
7227
|
// UPDATE RECORD
|
|
@@ -7219,16 +7231,20 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7219
7231
|
const effectiveParams = this.getEffectiveParams(options?.path);
|
|
7220
7232
|
return this.httpManagerService.putRequest(data, requestOptions, effectiveParams)
|
|
7221
7233
|
.pipe(tap((data) => {
|
|
7222
|
-
|
|
7223
|
-
this.
|
|
7234
|
+
// Apply adapter to response data
|
|
7235
|
+
let adaptedData = this.applyAdapter(data);
|
|
7236
|
+
adaptedData = (!adaptedData) ? (this.dataType === DataType.ARRAY) ? [] : {} : adaptedData;
|
|
7237
|
+
this.updateData$(adaptedData);
|
|
7224
7238
|
this.operationSuccess.next(OperationResultModel.adapt({ success: true, operation: 'UPDATE' }));
|
|
7225
7239
|
// Always call wsCommunication - it will queue if not connected
|
|
7226
7240
|
this.wsCommunication('UPDATE', [...options?.path || []]);
|
|
7227
7241
|
}), concatMap((data) => {
|
|
7228
|
-
|
|
7229
|
-
|
|
7242
|
+
// Apply adapter before database operations
|
|
7243
|
+
const adaptedData = this.applyAdapter(data);
|
|
7244
|
+
if (this.hasDatabase && this.databaseOptions?.table && adaptedData?.id) {
|
|
7245
|
+
return this.dbManagerService.updateTableRecord(this.databaseOptions.table, adaptedData);
|
|
7230
7246
|
}
|
|
7231
|
-
return of(
|
|
7247
|
+
return of(adaptedData);
|
|
7232
7248
|
}));
|
|
7233
7249
|
})));
|
|
7234
7250
|
// DELETE RECORD
|
|
@@ -7238,16 +7254,20 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7238
7254
|
const effectiveParams = this.getEffectiveParams(options?.path);
|
|
7239
7255
|
return this.httpManagerService.deleteRequest(requestOptions, effectiveParams)
|
|
7240
7256
|
.pipe(tap((data) => {
|
|
7241
|
-
|
|
7242
|
-
this.
|
|
7257
|
+
// Apply adapter to response data
|
|
7258
|
+
let adaptedData = this.applyAdapter(data);
|
|
7259
|
+
adaptedData = (!adaptedData) ? (this.dataType === DataType.ARRAY) ? [] : {} : adaptedData;
|
|
7260
|
+
this.deleteData$(adaptedData);
|
|
7243
7261
|
this.operationSuccess.next(OperationResultModel.adapt({ success: true, operation: 'DELETE' }));
|
|
7244
7262
|
// Always call wsCommunication - it will queue if not connected
|
|
7245
7263
|
this.wsCommunication('DELETE', [...options?.path || []]);
|
|
7246
7264
|
}), concatMap((data) => {
|
|
7247
|
-
|
|
7248
|
-
|
|
7265
|
+
// Apply adapter before database operations
|
|
7266
|
+
const adaptedData = this.applyAdapter(data);
|
|
7267
|
+
if (this.hasDatabase && this.databaseOptions?.table && adaptedData?.id) {
|
|
7268
|
+
return this.dbManagerService.deleteTableRecord(this.databaseOptions.table, adaptedData.id);
|
|
7249
7269
|
}
|
|
7250
|
-
return of(
|
|
7270
|
+
return of(adaptedData);
|
|
7251
7271
|
}));
|
|
7252
7272
|
})));
|
|
7253
7273
|
// --------------------------------------------------------------------------------------------------
|
|
@@ -7257,9 +7277,11 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7257
7277
|
const effectiveParams = this.getEffectiveParams(options?.path);
|
|
7258
7278
|
return this.httpManagerService.postRequest(data, requestOptions, effectiveParams)
|
|
7259
7279
|
.pipe(tap((res) => {
|
|
7260
|
-
|
|
7261
|
-
|
|
7262
|
-
|
|
7280
|
+
// Apply adapter to streaming response
|
|
7281
|
+
const adaptedRes = this.applyAdapter(res);
|
|
7282
|
+
if (adaptedRes.length > 0)
|
|
7283
|
+
this.setData$(adaptedRes);
|
|
7284
|
+
this.streamedResponse = adaptedRes;
|
|
7263
7285
|
}), concatMap((res) => this.persistStreamDataToDb(res, options)), scan((acc, res) => {
|
|
7264
7286
|
const previous = acc.current;
|
|
7265
7287
|
const current = res;
|
|
@@ -7340,11 +7362,13 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7340
7362
|
}));
|
|
7341
7363
|
})).pipe(tap((packet) => {
|
|
7342
7364
|
const res = packet?.data;
|
|
7343
|
-
//
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
7347
|
-
|
|
7365
|
+
// Apply adapter to streaming response
|
|
7366
|
+
const adaptedRes = this.applyAdapter(res);
|
|
7367
|
+
// console.log('[DEBUG] Streaming response received:', adaptedRes)
|
|
7368
|
+
if (adaptedRes && adaptedRes.length > 0) {
|
|
7369
|
+
// console.log('[DEBUG] Updating state with streaming data:', adaptedRes)
|
|
7370
|
+
this.setData$(adaptedRes);
|
|
7371
|
+
this.streamedResponse = [...this.streamedResponse, ...adaptedRes];
|
|
7348
7372
|
}
|
|
7349
7373
|
}), concatMap((packet) => {
|
|
7350
7374
|
if (packet?.fromCache) {
|
|
@@ -7362,15 +7386,17 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7362
7386
|
// If no database is configured, always call the API (do not check tracker)
|
|
7363
7387
|
return this.httpManagerService.getRequest(requestOptions, effectiveParams)
|
|
7364
7388
|
.pipe(tap((res) => {
|
|
7365
|
-
|
|
7389
|
+
// Apply adapter to streaming response
|
|
7390
|
+
const adaptedRes = this.applyAdapter(res);
|
|
7391
|
+
console.log('[DEBUG] Streaming response received:', adaptedRes);
|
|
7366
7392
|
// Always update state with streaming data
|
|
7367
|
-
if (
|
|
7368
|
-
// console.log('[DEBUG] Updating state with streaming data:',
|
|
7369
|
-
this.setData$(
|
|
7370
|
-
this.streamedResponse = [...this.streamedResponse, ...
|
|
7393
|
+
if (adaptedRes && adaptedRes.length > 0) {
|
|
7394
|
+
// console.log('[DEBUG] Updating state with streaming data:', adaptedRes)
|
|
7395
|
+
this.setData$(adaptedRes);
|
|
7396
|
+
this.streamedResponse = [...this.streamedResponse, ...adaptedRes];
|
|
7371
7397
|
}
|
|
7372
7398
|
else {
|
|
7373
|
-
// console.log('[DEBUG] No streaming data or empty array:',
|
|
7399
|
+
// console.log('[DEBUG] No streaming data or empty array:', adaptedRes)
|
|
7374
7400
|
}
|
|
7375
7401
|
}), concatMap((res) => this.persistStreamDataToDb(res, options)), map((res) => {
|
|
7376
7402
|
// console.log('[DEBUG] Returning data to subscribers:', res)
|
|
@@ -7664,15 +7690,17 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7664
7690
|
if (!this.hasDatabase || !this.databaseOptions?.table) {
|
|
7665
7691
|
return of(payload);
|
|
7666
7692
|
}
|
|
7667
|
-
|
|
7668
|
-
|
|
7669
|
-
|
|
7670
|
-
|
|
7671
|
-
|
|
7672
|
-
|
|
7693
|
+
// Apply adapter to payload before processing
|
|
7694
|
+
const adaptedPayload = this.applyAdapter(payload);
|
|
7695
|
+
const dbData = (adaptedPayload?.results && Array.isArray(adaptedPayload.results))
|
|
7696
|
+
? adaptedPayload.results
|
|
7697
|
+
: Array.isArray(adaptedPayload)
|
|
7698
|
+
? adaptedPayload
|
|
7699
|
+
: adaptedPayload
|
|
7700
|
+
? [adaptedPayload]
|
|
7673
7701
|
: [];
|
|
7674
7702
|
if (dbData.length === 0) {
|
|
7675
|
-
return of(
|
|
7703
|
+
return of(adaptedPayload);
|
|
7676
7704
|
}
|
|
7677
7705
|
const tableName = this.databaseOptions.table;
|
|
7678
7706
|
const requestOptions = this.updateRequestOptions(streamOptions?.headers);
|
|
@@ -7691,13 +7719,13 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
7691
7719
|
return ensureTable$.pipe(switchMap((created) => {
|
|
7692
7720
|
if (!created) {
|
|
7693
7721
|
console.warn('[DB STORAGE] Stream table create/open not ready, skipping DB write for this chunk:', { table: tableName });
|
|
7694
|
-
return of(
|
|
7722
|
+
return of(adaptedPayload);
|
|
7695
7723
|
}
|
|
7696
|
-
return this.dbManagerService.createTableRecords(tableName, dbData).pipe(tap(() => this.saveRequestCacheMetadata(tableName, 'STREAM', requestSignature, schemaSignature, streamOptions)), map(() =>
|
|
7724
|
+
return this.dbManagerService.createTableRecords(tableName, dbData).pipe(tap(() => this.saveRequestCacheMetadata(tableName, 'STREAM', requestSignature, schemaSignature, streamOptions)), map(() => adaptedPayload));
|
|
7697
7725
|
}));
|
|
7698
|
-
}), map(() =>
|
|
7726
|
+
}), map(() => adaptedPayload), catchError((error) => {
|
|
7699
7727
|
console.error('[DB STORAGE] Failed to persist streaming payload:', { table: tableName, schema, error });
|
|
7700
|
-
return of(
|
|
7728
|
+
return of(adaptedPayload);
|
|
7701
7729
|
}));
|
|
7702
7730
|
}
|
|
7703
7731
|
// WEBSOCKET COMMUNICATION (STATE MANAGER)
|
|
@@ -8017,6 +8045,20 @@ class HTTPManagerStateService extends ComponentStore {
|
|
|
8017
8045
|
isEmpty(obj) {
|
|
8018
8046
|
return Object.keys(obj).length === 0;
|
|
8019
8047
|
}
|
|
8048
|
+
/**
|
|
8049
|
+
* Apply adapter to data if adapter is provided
|
|
8050
|
+
* Handles both array and single object responses
|
|
8051
|
+
* Only applies adapter when it exists - returns data as-is otherwise
|
|
8052
|
+
*/
|
|
8053
|
+
applyAdapter(data) {
|
|
8054
|
+
if (!data || !this.apiOptions?.adapter) {
|
|
8055
|
+
return data;
|
|
8056
|
+
}
|
|
8057
|
+
if (Array.isArray(data)) {
|
|
8058
|
+
return data.map((item) => this.apiOptions.adapter(item));
|
|
8059
|
+
}
|
|
8060
|
+
return this.apiOptions.adapter(data);
|
|
8061
|
+
}
|
|
8020
8062
|
updateRequestOptions(headers) {
|
|
8021
8063
|
const options = ApiRequest.adapt({ ...this.apiOptions });
|
|
8022
8064
|
options.headers = (headers)
|