@vestra-player/sdk - v1.11.3
    Preparing search index...

    Interface JsonStore<T>

    A JSON file dataDirectory/<name>.json, loaded once and saved debounced.

    One JSON file, <dataDirectory>/<name>.json, made by Storage.json. value is read once when the store is made; save replaces it in memory at once and writes the file debounceMs later (300 by default) through a temporary file and a rename, so a crash never leaves half a file. Writes to one file run one at a time, newest last. Disposing the store, its scope or stopping the plugin writes a pending save first.

    The counter grows by one at every start and is kept in stats.json. The store reads the file when it is made (the defaults when there is none), and save writes the new count a moment later.

    const stats = plugin.storage.json("stats", { defaults: { starts: 0 } });
    stats.save({ starts: stats.value.starts + 1 }); // written 300 ms later

    1.0.0

    interface JsonStore<T> {
        dispose(): Promise<void>;
        value: T;
        save(next: T): void;
        flush(): Promise<void>;
    }

    Type Parameters

    • T

    Hierarchy (View Summary)

    Index
    • Release the resource. Resolves once the player confirmed the release (or immediately for purely local resources). Never rejects.

      Returns Promise<void>

      Never.

      A "Turn feature off" item removes the feature's own menu item at once, before the plugin stops. dispose takes the command out of the menu and the binding table and resolves once the player confirmed it; the id can be added again later.

      const extra = plugin.commands.add({ id: "extra", path: ["Tools", "Extra"], run() {} });
      plugin.commands.add({
      id: "extra-off",
      path: ["Tools", "Turn extra off"],
      run: () => extra.dispose(), // never rejects
      });

      1.0.0

    • Replace the value now and write it after debounceMs. Only save writes: mutating value in place is not saved.

      Parameters

      • next: T

      Returns void

      Dragging the plugin's volume slider updates the stored value at once but writes the file only once the user stops for 300 ms. Each save replaces the value and restarts the debounce timer.

      const store = plugin.storage.json("prefs", { defaults: { volume: 100 } });
      volumeWindow.on("volumeChanged", (volume: number) => store.save({ ...store.value, volume }));

      1.0.0

    • Write a pending save now.

      Returns Promise<void>

      Error (rejects) Node's file system error when the file cannot be written; its code is Node's (ENOSPC, EACCES and so on), not a player error code.

      Before exporting its settings, the plugin makes sure the file on disk has the latest value. flush writes a pending save at once (or waits for the write in progress) and resolves when the file is written.

      const store = plugin.storage.json("settings", { defaults: { step: 5 } });
      await store.flush(); // the file now has the newest value
      await copyFile(join(plugin.dataDirectory, "settings.json"), exportPath);

      1.0.0

    value: T

    The loaded value, or defaults when the file was missing or broken.