Kfg Documentation
    Preparing search index...

    Class JsonDriver

    Persists the configuration to a JSON file, synchronously.

    Every write goes through the safeguard layer: lock file, temp-write + verification + atomic rename, and a backup mirror used to recover a corrupted main file on load. See JsonAsyncDriver for the non-blocking counterpart.

    Hierarchy (View Summary)

    Index
    async: false
    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 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 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: reads the current persisted config, passes it to fn, and atomically writes the result — all under one lock, so concurrent processes cannot lose updates.

      Parameters

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

      Returns 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 void

    • Safe-write options derived from the driver config.

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