import { AbstractBackend } from "./abstract-backend"; import { GetValueFromKeyPath, KeyPath } from "../types"; export class StaticBackend extends AbstractBackend { #data: Partial; constructor(data: Partial) { super(); this.#data = data; } getSnapshot, T extends GetValueFromKeyPath>(keyPath: KP, defaultValue: T): T { if (keyPath.length === 0) { return defaultValue; } let result: any = this.#data; for (const key of keyPath as string[]) { result = result[key]; if (result === undefined) { return defaultValue; } } return result; } }