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

    Interface Storage

    plugin.storage: JSON settings files.

    Two kinds of storage, both private to the plugin. Storage.json keeps settings in JSON files in the plugin's data directory: they last across player restarts and upgrades, and are written by the plugin's own process. Storage.session keeps values in the player's memory for one player run: they survive a restart of the plugin's process but not of the player. Secrets belong in Secrets, never in either.

    The plugin's step size survives a restart of the player; its work queue survives a reload of the plugin but starts empty with the next player run. The JSON store reads its file at once and writes it shortly after each save; session values live in the player process.

    const settings = plugin.storage.json("settings", { defaults: { step: 5 } });
    const queue = (await plugin.storage.session.get<string[]>("queue")) ?? [];
    void settings.value.step; // read synchronously, from the file or the defaults
    void queue;

    1.0.0

    interface Storage {
        json<T>(
            name: string,
            options: {
                defaults: T;
                validate?: (value: unknown) => value is T;
                debounceMs?: number;
            },
        ): JsonStore<T>;
        session: SessionStorage;
    }
    Index
    • Open <name>.json (name: 1–64 of a-z 0-9 -). A file that cannot be parsed or fails validate is renamed <name>.json.bad-<timestamp> and defaults is used. Writes go to a temporary file, then a rename. Disposal (and stopping the plugin) flushes first.

      The file is read synchronously on creation; debounceMs defaults to 300. Files are created with mode 0600. invalid for a bad name.

      Type Parameters

      • T

      Parameters

      • name: string
      • options: { defaults: T; validate?: (value: unknown) => value is T; debounceMs?: number }

      Returns JsonStore<T>

      The plugin remembers whether to resume and the last ten files across restarts. json reads settings.json from the data directory at once (or uses defaults when it is missing or fails validate); save replaces the value and writes the file 300 ms later, and stopping the plugin writes a pending save first.

      type Settings = { resume: boolean; recent: string[] };
      const store = plugin.storage.json<Settings>("settings", {
      defaults: { resume: true, recent: [] },
      validate: (v): v is Settings =>
      typeof v === "object" && v !== null && typeof (v as Settings).resume === "boolean",
      });
      // Only `save` writes: changing `store.value` in place is not saved.
      store.save({ ...store.value, recent: [path, ...store.value.recent].slice(0, 10) });

      invalid (throws) A bad name, or a debounceMs that is not a non-negative number.

      1.0.0

    Values the player keeps in its memory for this plugin until the player quits: they survive a restart of the plugin's process (reload, upgrade, crash, failed start) but not the player. See SessionStorage.

    1.5.25