Files
ditto/src/utils/PleromaConfigDB.ts
2024-11-04 10:12:58 -06:00

30 lines
771 B
TypeScript

import type { PleromaConfig } from '@/schemas/pleroma-api.ts';
export class PleromaConfigDB {
constructor(private configs: PleromaConfig[]) {
}
get(group: string, key: string): PleromaConfig | undefined {
return this.configs.find((c) => c.group === group && c.key === key);
}
set(group: string, key: string, value: PleromaConfig): void {
const index = this.configs.findIndex((c) => c.group === group && c.key === key);
if (index === -1) {
this.configs.push(value);
} else {
this.configs[index] = value;
}
}
merge(configs: PleromaConfig[]): void {
for (const { group, key, value } of configs) {
this.set(group, key, { group, key, value });
}
}
toJSON(): PleromaConfig[] {
return this.configs;
}
}