MCPcopy
hub / github.com/tinyplex/tinybase / getConfigStructures

Function getConfigStructures

src/persisters/common/database/config.ts:131–210  ·  view source on GitHub ↗
(
  configOrStoreTableName: DatabasePersisterConfig | string | undefined,
)

Source from the content-addressed store, hash-verified

129};
130
131export const getConfigStructures = (
132 configOrStoreTableName: DatabasePersisterConfig | string | undefined,
133): [
134 isJson: 0 | 1,
135 autoLoadIntervalSeconds: number,
136 defaultedConfig: DefaultedJsonConfig | DefaultedTabularConfig,
137 managedTableNamesSet: Set<string>,
138] => {
139 const config = getDefaultedConfig(configOrStoreTableName);
140 const autoLoadIntervalSeconds = config[AUTO_LOAD_INTERVAL_SECONDS] as number;
141
142 if (config.mode == JSON) {
143 const storeTableName = config[STORE_TABLE_NAME] ?? TINYBASE;
144 return [
145 1,
146 autoLoadIntervalSeconds,
147 [
148 storeTableName,
149 config[STORE_ID_COLUMN_NAME] ?? DEFAULT_ROW_ID_COLUMN_NAME,
150 config[STORE_COLUMN_NAME] ?? STORE,
151 ],
152 setNew(storeTableName),
153 ];
154 }
155
156 const {tables: {load = {}, save = {}} = {}, values = {}} = config;
157
158 const valuesConfigObj = objMerge(DEFAULT_TABULAR_VALUES_CONFIG, values);
159 const {load: valuesLoad, save: valuesSave} = valuesConfigObj;
160 const valuesConfig = [
161 hasValues(valuesLoad),
162 hasValues(valuesSave),
163 valuesConfigObj[TABLE_NAME],
164 getValuesIn(valuesLoad),
165 getValuesIn(valuesSave),
166 ] as DefaultedTabularConfig[2];
167 const valuesTable = valuesConfig[2];
168 const managedTableNames = setNew(valuesTable);
169 const excludedTableNames = setNew(valuesTable);
170
171 const tablesLoadConfig = getDefaultedTabularConfigMap(
172 load,
173 {
174 [TABLE_ID]: null,
175 [ROW_ID_COLUMN_NAME]: DEFAULT_ROW_ID_COLUMN_NAME,
176 [CONDITION]: TRUE,
177 },
178 TABLE_ID,
179 (tableName) => collHas(excludedTableNames, tableName),
180 (tableName) => setAdd(managedTableNames, tableName),
181 ) as DefaultedTabularConfig[0];
182
183 const tablesSaveConfig = getDefaultedTabularConfigMap(
184 save,
185 {
186 [TABLE_NAME]: null,
187 [ROW_ID_COLUMN_NAME]: DEFAULT_ROW_ID_COLUMN_NAME,
188 [DELETE_EMPTY_COLUMNS]: 0,

Callers 2

Calls 10

setNewFunction · 0.90
objMergeFunction · 0.90
collHasFunction · 0.90
setAddFunction · 0.90
mapForEachFunction · 0.90
mapGetFunction · 0.90
getDefaultedConfigFunction · 0.85
getValuesInFunction · 0.85
hasValuesFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…