Skip to content

Commit 4b6664c

Browse files
committed
[pagination] Default save conditions from the correct load conditions
1 parent b80bdf4 commit 4b6664c

1 file changed

Lines changed: 47 additions & 31 deletions

File tree

src/persisters/common/database/config.ts

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import type {Id} from '../../../@types/common/index.d.ts';
22
import type {DatabasePersisterConfig} from '../../../@types/persisters/index.d.ts';
33
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';
511
import {
612
IdObj,
713
objMap,
@@ -137,38 +143,48 @@ export const getConfigStructures = (
137143
objValues(objMerge(DEFAULT_TABULAR_VALUES_CONFIG, values)),
138144
0,
139145
objSize(DEFAULT_TABULAR_VALUES_CONFIG),
140-
);
141-
const valuesTable = valuesConfig[2] as string;
146+
) as DefaultedTabularConfig[2];
147+
const valuesTable = valuesConfig[2];
142148
const managedTableNames = setNew(valuesTable);
143149
const excludedTableNames = setNew(valuesTable);
144150

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];
172176

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+
];
174190
};

0 commit comments

Comments
 (0)