|
1 | 1 | import type {Id} from '../../../@types/common/index.d.ts'; |
2 | 2 | import type {DatabasePersisterConfig} from '../../../@types/persisters/index.d.ts'; |
3 | 3 | import {collHas} from '../../../common/coll.ts'; |
4 | | -import {IdMap, mapNew, mapSet} from '../../../common/map.ts'; |
| 4 | +import { |
| 5 | + IdMap, |
| 6 | + mapForEach, |
| 7 | + mapGet, |
| 8 | + mapNew, |
| 9 | + mapSet, |
| 10 | +} from '../../../common/map.ts'; |
5 | 11 | import { |
6 | 12 | IdObj, |
7 | 13 | objMap, |
@@ -137,38 +143,48 @@ export const getConfigStructures = ( |
137 | 143 | objValues(objMerge(DEFAULT_TABULAR_VALUES_CONFIG, values)), |
138 | 144 | 0, |
139 | 145 | objSize(DEFAULT_TABULAR_VALUES_CONFIG), |
140 | | - ); |
141 | | - const valuesTable = valuesConfig[2] as string; |
| 146 | + ) as DefaultedTabularConfig[2]; |
| 147 | + const valuesTable = valuesConfig[2]; |
142 | 148 | const managedTableNames = setNew(valuesTable); |
143 | 149 | const excludedTableNames = setNew(valuesTable); |
144 | 150 |
|
145 | | - const tabularConfig = [ |
146 | | - getDefaultedTabularConfigMap( |
147 | | - load, |
148 | | - { |
149 | | - [TABLE_ID]: null, |
150 | | - [ROW_ID_COLUMN_NAME]: DEFAULT_ROW_ID_COLUMN_NAME, |
151 | | - [CONDITION]: null, |
152 | | - }, |
153 | | - TABLE_ID, |
154 | | - (tableName) => collHas(excludedTableNames, tableName), |
155 | | - (tableName) => setAdd(managedTableNames, tableName), |
156 | | - ), |
157 | | - getDefaultedTabularConfigMap( |
158 | | - save, |
159 | | - { |
160 | | - [TABLE_NAME]: null, |
161 | | - [ROW_ID_COLUMN_NAME]: DEFAULT_ROW_ID_COLUMN_NAME, |
162 | | - [DELETE_EMPTY_COLUMNS]: 0, |
163 | | - [DELETE_EMPTY_TABLE]: 0, |
164 | | - [CONDITION]: load[CONDITION] ?? null, |
165 | | - }, |
166 | | - TABLE_NAME, |
167 | | - (_, tableName) => collHas(excludedTableNames, tableName), |
168 | | - (_, tableName) => setAdd(managedTableNames, tableName), |
169 | | - ), |
170 | | - valuesConfig, |
171 | | - ] as any; |
| 151 | + const tablesLoadConfig = getDefaultedTabularConfigMap( |
| 152 | + load, |
| 153 | + { |
| 154 | + [TABLE_ID]: null, |
| 155 | + [ROW_ID_COLUMN_NAME]: DEFAULT_ROW_ID_COLUMN_NAME, |
| 156 | + [CONDITION]: null, |
| 157 | + }, |
| 158 | + TABLE_ID, |
| 159 | + (tableName) => collHas(excludedTableNames, tableName), |
| 160 | + (tableName) => setAdd(managedTableNames, tableName), |
| 161 | + ) as DefaultedTabularConfig[0]; |
| 162 | + |
| 163 | + const tablesSaveConfig = getDefaultedTabularConfigMap( |
| 164 | + save, |
| 165 | + { |
| 166 | + [TABLE_NAME]: null, |
| 167 | + [ROW_ID_COLUMN_NAME]: DEFAULT_ROW_ID_COLUMN_NAME, |
| 168 | + [DELETE_EMPTY_COLUMNS]: 0, |
| 169 | + [DELETE_EMPTY_TABLE]: 0, |
| 170 | + [CONDITION]: null, |
| 171 | + }, |
| 172 | + TABLE_NAME, |
| 173 | + (_, tableName) => collHas(excludedTableNames, tableName), |
| 174 | + (_, tableName) => setAdd(managedTableNames, tableName), |
| 175 | + ) as DefaultedTabularConfig[1]; |
172 | 176 |
|
173 | | - return [0, autoLoadIntervalSeconds, tabularConfig, managedTableNames]; |
| 177 | + mapForEach( |
| 178 | + tablesSaveConfig, |
| 179 | + (_, tableSaveConfig) => |
| 180 | + (tableSaveConfig[4] ??= |
| 181 | + mapGet(tablesLoadConfig, tableSaveConfig[0])?.[2] ?? null), |
| 182 | + ); |
| 183 | + |
| 184 | + return [ |
| 185 | + 0, |
| 186 | + autoLoadIntervalSeconds, |
| 187 | + [tablesLoadConfig, tablesSaveConfig, valuesConfig], |
| 188 | + managedTableNames, |
| 189 | + ]; |
174 | 190 | }; |
0 commit comments