http-request-manager 18.13.35 → 18.13.37

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.
@@ -5141,12 +5141,12 @@ class LocalStorageManagerService extends ComponentStore {
5141
5141
  this.storeExists$ = (store) => this.select(this.data$, (data) => data.settings.find(item => item.name === store) ? true : false);
5142
5142
  this.store$ = (store) => this.select(this.data$, (data) => {
5143
5143
  store = store.toLowerCase();
5144
- const foundStore = data.settings.find(item => item.name === store);
5144
+ const foundStore = [...data.settings].reverse().find(item => item.name === store);
5145
5145
  if (foundStore) {
5146
5146
  const options = SettingOptions.adapt(foundStore.options);
5147
5147
  const found = foundStore.options?.storage === StorageType.GLOBAL
5148
- ? data.localStores.find(item => item.id === foundStore.id)
5149
- : data.sessionStores.find(item => item.id === foundStore.id);
5148
+ ? [...data.localStores].reverse().find(item => item.id === foundStore.id)
5149
+ : [...data.sessionStores].reverse().find(item => item.id === foundStore.id);
5150
5150
  if (!found) {
5151
5151
  console.warn('[CacheDebug] store$: settings entry found but no data entry in localStores/sessionStores', { store, foundStoreId: foundStore.id, storageType: foundStore.options?.storage });
5152
5152
  this.deleteStore({ name: store });
@@ -5181,7 +5181,7 @@ class LocalStorageManagerService extends ComponentStore {
5181
5181
  });
5182
5182
  this.settings$ = this.select(state => (state) ? state.settings : storage.settings);
5183
5183
  this.setting$ = (store) => this.select(this.data$, (state) => {
5184
- const foundSetting = state.settings.find(item => item.name === store);
5184
+ const foundSetting = [...state.settings].reverse().find(item => item.name === store);
5185
5185
  return (foundSetting) ? foundSetting : null;
5186
5186
  });
5187
5187
  this.persistence$ = this.data$
@@ -5208,11 +5208,14 @@ class LocalStorageManagerService extends ComponentStore {
5208
5208
  const dataStr = (this.isObjectOrArray(str)) ? (store.options.encrypted) ? this.encryption.encrypt(str, this.app.appID) : store.data : store.data;
5209
5209
  const localData = (dataStr && settings.options?.storage === StorageType.GLOBAL) ? [{ data: dataStr, id: settings.id }] : [];
5210
5210
  const sessionData = (dataStr && settings.options?.storage === StorageType.SESSION) ? [{ data: dataStr, id: settings.id }] : [];
5211
+ const localStores = state.localStores.filter(item => item.id !== settings.id);
5212
+ const sessionStores = state.sessionStores.filter(item => item.id !== settings.id);
5213
+ const stateSettings = state.settings.filter(item => item.id !== settings.id);
5211
5214
  return {
5212
5215
  ...state,
5213
- localStores: [...state.localStores, ...localData],
5214
- sessionStores: [...state.sessionStores, ...sessionData],
5215
- settings: [...state.settings, ...[settings]],
5216
+ localStores: [...localStores, ...localData],
5217
+ sessionStores: [...sessionStores, ...sessionData],
5218
+ settings: [...stateSettings, ...[settings]],
5216
5219
  };
5217
5220
  }
5218
5221
  });
@@ -5249,7 +5252,7 @@ class LocalStorageManagerService extends ComponentStore {
5249
5252
  this.updateStore = this.updater((state, store) => {
5250
5253
  store.name = store.name.toLowerCase();
5251
5254
  store.name = this.validStoreName(store.name);
5252
- const settings = state.settings.find(item => item.name === store.name);
5255
+ const settings = [...state.settings].reverse().find(item => item.name === store.name);
5253
5256
  if (settings) {
5254
5257
  const type = settings.options?.storage;
5255
5258
  const hasStore = this.hasGlobalStorage(type, settings.id || '');
@@ -6099,7 +6102,7 @@ class DatabaseManagerService extends DbService {
6099
6102
  console.error(`createTableRecords: DB not open. Cannot write to '${tableName}'.`);
6100
6103
  return EMPTY;
6101
6104
  }
6102
- const tableInstance = this.tables.find(t => t.name === tableName);
6105
+ const tableInstance = this.getTable(tableName);
6103
6106
  if (!tableInstance) {
6104
6107
  console.error(`createTableRecords: Table '${tableName}' does not exist in DB version ${this.verno}. Available:`, this.tables.map(t => t.name));
6105
6108
  return EMPTY;
@@ -6107,17 +6110,49 @@ class DatabaseManagerService extends DbService {
6107
6110
  console.log(`createTableRecords: Bulk putting ${insertRecords.length} records into ${tableName}`);
6108
6111
  return from(tableInstance.bulkPut(insertRecords)).pipe(map(() => insertRecords));
6109
6112
  }));
6113
+ const recreateMissingTableAndRetry = () => {
6114
+ const inferredSchema = this.inferSchemaFromRecords(insertRecords);
6115
+ if (!inferredSchema) {
6116
+ console.warn(`createTableRecords: Could not infer schema for '${tableName}'. Retrying after DB reopen.`);
6117
+ return from(this.createNewDatabase()).pipe(switchMap(() => writeRecords()));
6118
+ }
6119
+ const tableDef = TableSchemaDef.adapt({ table: tableName, schema: inferredSchema });
6120
+ return this.createDatabaseTable(tableDef).pipe(switchMap((created) => {
6121
+ if (!created) {
6122
+ console.warn(`createTableRecords: Failed to recreate table '${tableName}' from inferred schema. Retrying after DB reopen.`);
6123
+ return from(this.createNewDatabase()).pipe(switchMap(() => writeRecords()));
6124
+ }
6125
+ return writeRecords();
6126
+ }));
6127
+ };
6110
6128
  return writeRecords().pipe(catchError((error) => {
6111
6129
  if (!this.isMissingObjectStoreError(error)) {
6112
6130
  throw error;
6113
6131
  }
6114
- console.warn(`createTableRecords: Missing object store for '${tableName}'. Waiting for DB readiness and retrying once...`, error);
6115
- return from(this.createNewDatabase()).pipe(switchMap(() => writeRecords()), catchError((retryError) => {
6132
+ console.warn(`createTableRecords: Missing object store for '${tableName}'. Recreating table and retrying once...`, error);
6133
+ return recreateMissingTableAndRetry().pipe(catchError((retryError) => {
6116
6134
  console.error(`createTableRecords: Retry failed for '${tableName}'`, retryError);
6117
6135
  throw retryError;
6118
6136
  }));
6119
6137
  }));
6120
6138
  }
6139
+ inferSchemaFromRecords(records) {
6140
+ if (!Array.isArray(records) || records.length === 0) {
6141
+ return null;
6142
+ }
6143
+ const sample = records.find((record) => record && typeof record === 'object');
6144
+ if (!sample) {
6145
+ return null;
6146
+ }
6147
+ const fields = Object.keys(sample)
6148
+ .filter((key) => key !== 'id')
6149
+ .filter((key) => {
6150
+ const value = sample[key];
6151
+ return value === null || ['string', 'number', 'boolean'].includes(typeof value);
6152
+ })
6153
+ .sort();
6154
+ return ['++id', ...fields].join(', ');
6155
+ }
6121
6156
  isMissingObjectStoreError(error) {
6122
6157
  const name = String(error?.name || '').toLowerCase();
6123
6158
  const innerName = String(error?.inner?.name || '').toLowerCase();