http-request-manager 18.13.36 → 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.
@@ -6102,7 +6102,7 @@ class DatabaseManagerService extends DbService {
6102
6102
  console.error(`createTableRecords: DB not open. Cannot write to '${tableName}'.`);
6103
6103
  return EMPTY;
6104
6104
  }
6105
- const tableInstance = this.tables.find(t => t.name === tableName);
6105
+ const tableInstance = this.getTable(tableName);
6106
6106
  if (!tableInstance) {
6107
6107
  console.error(`createTableRecords: Table '${tableName}' does not exist in DB version ${this.verno}. Available:`, this.tables.map(t => t.name));
6108
6108
  return EMPTY;
@@ -6110,17 +6110,49 @@ class DatabaseManagerService extends DbService {
6110
6110
  console.log(`createTableRecords: Bulk putting ${insertRecords.length} records into ${tableName}`);
6111
6111
  return from(tableInstance.bulkPut(insertRecords)).pipe(map(() => insertRecords));
6112
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
+ };
6113
6128
  return writeRecords().pipe(catchError((error) => {
6114
6129
  if (!this.isMissingObjectStoreError(error)) {
6115
6130
  throw error;
6116
6131
  }
6117
- console.warn(`createTableRecords: Missing object store for '${tableName}'. Waiting for DB readiness and retrying once...`, error);
6118
- 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) => {
6119
6134
  console.error(`createTableRecords: Retry failed for '${tableName}'`, retryError);
6120
6135
  throw retryError;
6121
6136
  }));
6122
6137
  }));
6123
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
+ }
6124
6156
  isMissingObjectStoreError(error) {
6125
6157
  const name = String(error?.name || '').toLowerCase();
6126
6158
  const innerName = String(error?.inner?.name || '').toLowerCase();