Kfg Documentation
    Preparing search index...

    Class JsonAsyncDriver

    Persists the configuration to a JSON file without blocking the event loop.

    Same file format and same safeguards as JsonDriver — they share every bit of parsing, serialization and error formatting — but all I/O is promise-based, including waiting for the write lock. In a server, a set that has to queue behind another writer no longer stalls everything else.

    Because the driver is async, Kfg's methods return promises:

    const kfg = new Kfg(new JsonAsyncDriver({ path: "config.json" }), schema);
    await kfg.load();
    await kfg.set("server.port", 8080);
    kfg.get("server.port"); // reads stay synchronous — they hit the cache

    lazy and Kfg.pool are not available here: both materialize state on first access, which cannot be done behind a synchronous get().

    Hierarchy (View Summary)

    Index
    async: true
    comments: Record<string, string> = {}
    forceExit: boolean
    name: string
    • Optional hook for deletion. Use this ONLY if the driver handles atomic deletion. If implemented, Kfg.del() will call this INSTEAD of save().

      Parameters

      • key: string

        The key deleted.

      Returns Promise<void>

    • Optional hook to format validation errors.

      Parameters

      • errors: any[]

        The array of errors from TypeBox/Value.

      Returns string

      A formatted string or undefined to use default formatting.

    • Saves the configuration to the source.

      Parameters

      • data: Record<string, any>

        The full configuration object.

      • Optionaloptions: { description?: string; path?: string }

        Optional metadata for the save operation (e.g. description for a specific update).

      Returns Promise<void>

    • Serializes a config object to the on-disk JSON string (comments/keyroot).

      Parameters

      • data: Record<string, any>
      • Optionaloptions: { description?: string; path?: string }

      Returns string

    • Locked read-modify-write. The lock is held across the whole cycle, so concurrent writers queue instead of losing each other's updates — and waiting for it yields rather than blocking.

      Parameters

      • schema: SchemaDefinition
      • fn: (current: Record<string, any>) => Record<string, any>

      Returns Promise<void>

    • Optional hook for updates. Use this ONLY if the driver handles atomic updates and doesn't need the full object every time. If implemented, Kfg.set() will call this INSTEAD of save().

      Parameters

      • key: string

        The key updated (dot notation).

      • value: any

        The new value.

      • Optionaldescription: string

      Returns Promise<void>

    • Safe-write options derived from the driver config.

      Returns {
          backup: string | boolean;
          lockTimeout: number | undefined;
          verify: (content: string) => boolean;
      }