PowerKeys Scripting API
    Preparing search index...

    Interface StorageAPI

    interface StorageAPI {
        SetString(key: string, value: string): Promise<void>;
        GetString(key: string): string | null;
        SetObject(key: string, value: unknown): Promise<void>;
        GetObject<T = unknown>(key: string): T | null;
    }
    Index
    • Persists a string value under the given key. Data is scoped to the current script. Values are stored locally for fast access and synced to the server in the background.

      Parameters

      • key: string

        Storage key.

      • value: string

        String value to store.

      Returns Promise<void>

      Resolves after the updated script state is durably written.

      await Storage.SetString("count", "42");
      await Storage.SetString("lastRun", new Date().toISOString());
    • Retrieves a previously stored string value.

      Parameters

      • key: string

        Storage key.

      Returns string | null

      The stored string, or null if storage is unavailable, the key is absent, or its value is not a string.

      ALWAYS check for null. The return value is null when the key is absent, storage is unavailable, or the stored JSON value is not a string. Use GetObject when the key may contain another JSON type.

      const count = Storage.GetString("count");
      if (count !== null) {
      Console.Log("count: " + count);
      }
    • Persists a JSON-serializable value under the given key.

      Parameters

      • key: string

        Storage key.

      • value: unknown

        Any JSON-serializable value (object, array, number, etc.).

      Returns Promise<void>

      Resolves after the updated script state is durably written.

      await Storage.SetObject("prefs", { delay: 100, enabled: true });
      
    • Retrieves a previously stored JSON value.

      Type Parameters

      • T = unknown

      Parameters

      • key: string

        Storage key.

      Returns T | null

      The deserialized JSON value, or null when storage is unavailable, the key is absent, or JSON null was stored.

      ALWAYS check for null. The return value is null when storage is unavailable, the key is absent, or JSON null was explicitly stored, so those cases are intentionally indistinguishable. Despite the historical name, this method returns any stored JSON value, not only objects. The value is deserialized and prototype methods are not preserved.

      const prefs = Storage.GetObject<{ delay: number; enabled: boolean }>("prefs");
      if (prefs !== null) {
      Console.Log("delay: " + prefs.delay);
      }