Skip to content

Commit

Permalink
Enables config values to be backed by optional persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
Spoffy committed Jul 2, 2024
1 parent fe90bf6 commit 0a00bd0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions app/server/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ export function fileConfigAccessorFactory<FileContents>(
*/
export function createConfigValue<ValueType>(
defaultValue: ValueType,
persistence?: ConfigAccessors<ValueType | undefined>,
persistence?: ConfigAccessors<ValueType> | ConfigAccessors<ValueType | undefined>,
): IWritableConfigValue<ValueType> {
let inMemoryValue = (persistence && persistence.get()) ?? defaultValue;
let inMemoryValue = (persistence && persistence.get());
return {
get() {
return inMemoryValue;
get(): ValueType {
return inMemoryValue ?? defaultValue;
},
async set(value: ValueType) {
if (persistence && persistence.set) {
Expand Down
2 changes: 1 addition & 1 deletion app/server/lib/configCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export async function loadGristCoreConfigFile(configPath?: string): Promise<IGri
export function loadGristCoreConfig(fileConfig?: FileConfig<IGristCoreConfigFileLatest>): IGristCoreConfig {
const fileConfigValue = fileConfigAccessorFactory(fileConfig);
return {
edition: createConfigValue("core", fileConfigValue("edition"))
edition: createConfigValue<Edition>("core", fileConfigValue("edition"))
};
}
2 changes: 1 addition & 1 deletion app/server/lib/configCoreFileFormats-ti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const IGristCoreConfigFileLatest = t.name("IGristCoreConfigFileV1");

export const IGristCoreConfigFileV1 = t.iface([], {
"version": t.lit("1"),
"edition": t.union(t.lit("core"), t.lit("enterprise")),
"edition": t.opt(t.union(t.lit("core"), t.lit("enterprise"))),
});

export const IGristCoreConfigFileV0 = t.iface([], {
Expand Down

0 comments on commit 0a00bd0

Please sign in to comment.