Kfg Documentation
    Preparing search index...

    Class KfgPool<D, S>

    A set of Kfg instances keyed by scope id, exposing the exact same API as a single instance.

    Every read/write is routed to the instance for the currently active scope, resolved in this order: an enclosing run(), then options.resolve(), then options.defaultScope. for(id) addresses an instance explicitly and is a first-class entry point — background jobs and dashboards have no ambient scope to rely on.

    Pools are synchronous-only: a scope is materialized on demand, and a sync driver is what makes that transparent to callers.

    Type Parameters

    Implements

    Index
    missingScopeCount: number = 0

    How many operations have fallen back to defaultScope.

    • get size(): number

      Number of instances currently held by the pool.

      Returns number

    • Drops every instance, emptying the pool.

      Returns void

    • The scope that would be used right now, or null if there is none.

      Returns string | null

    • Drops the instance for id from the pool, releasing its cache. Persisted state is untouched; the next access builds a fresh instance.

      Parameters

      • id: string

      Returns boolean

    • Runs fn for every instance the pool currently holds.

      Parameters

      • fn: (instance: Kfg<D, S>, id: string) => void

      Returns void

    • Returns (creating it if needed) the instance for id.

      The id is passed verbatim to options.driver, which typically interpolates it into a file path. Ids that reach the pool from outside the process must be validated by the host first: the pool does no sanitizing, so a value containing path separators or .. would escape the intended directory.

      Parameters

      • id: string

      Returns Kfg<D, S>

    • Type Parameters

      • P extends string

      Parameters

      • ...paths: P[]

      Returns boolean

    • Ids of the instances currently held by the pool.

      Returns string[]

    • Marks the instance for id as stale so the next access rereads it from disk, keeping the instance's identity — unlike dispose, references previously handed out by for(id) also see the fresh state. Call it after writing a scope's file behind the pool's back.

      Parameters

      • id: string

      Returns void

    • Invalidates every instance the pool holds.

      Returns void

    • Runs fn with id as the active scope. The scope follows the async call tree, so everything fn awaits sees it too — including code that never received the id as an argument. Returns whatever fn returns.

      Type Parameters

      • T

      Parameters

      • id: string
      • fn: () => T

      Returns T