A Time To Live configuration file where each entry is timestamped and removed once the TTL has expired.

Example

import { Duration } from '@salesforce/kit';
const config = await TTLConfig.create({
isGlobal: false,
ttl: Duration.days(1)
});

Hierarchy

Methods

  • Asynchronously invokes actionFn once for each key-value pair present in the config object.

    Returns

    Parameters

    • actionFn: ((key: string, value: AnyJson) => Promise<void>)

      The function (key: string, value: ConfigValue) => Promise<void> to be called for each element.

        • (key: string, value: AnyJson): Promise<void>
        • Parameters

          • key: string
          • value: AnyJson

          Returns Promise<void>

    Returns Promise<void>

  • Check to see if the config file exists. Returns true if the config file exists and has access, false otherwise.

    Returns Promise<boolean>

  • Invokes actionFn once for each key-value pair present in the config object.

    Parameters

    • actionFn: ((key: string, value: AnyJson) => void)

      The function (key: string, value: ConfigValue) => void to be called for each element.

        • (key: string, value: AnyJson): void
        • Parameters

          • key: string
          • value: AnyJson

          Returns void

    Returns void

  • Returns the value associated to the key, or undefined if there is none.

    Type Parameters

    • K extends string

    Parameters

    • key: K

      The key. Supports query key like a.b[0].

    • Optional decrypt: boolean

      If it is an encrypted key, decrypt the value. If the value is an object, a clone will be returned.

    Returns Entry<CachedOptions>

  • Type Parameters

    • V = AnyJson

    Parameters

    • key: string
    • Optional decrypt: boolean

    Returns V

  • Returns the absolute path to the config file.

    The first time getPath is called, the path is resolved and becomes immutable. This allows implementers to override options properties, like filePath, on the init method for async creation. If that is required for creation, the config files can not be synchronously created.

    Returns string

  • Returns a boolean asserting whether a value has been associated to the key in the config object or not.

    Parameters

    • key: string

      The key. Supports query key like a.b[0].

    Returns boolean

  • Read the config file and set the config contents. Returns the config contents of the config file. As an optimization, files are only read once per process and updated in memory and via write(). To force a read from the filesystem pass force=true. Throws SfError{ name: 'UnexpectedJsonFileFormat' } There was a problem reading or parsing the file.

    Parameters

    • Optional throwOnNotFound: boolean = false
    • Optional force: boolean = false

    Returns Promise<Contents<CachedOptions>>

  • Read the config file and set the config contents. Returns the config contents of the config file. As an optimization, files are only read once per process and updated in memory and via write(). To force a read from the filesystem pass force=true. Throws SfError{ name: 'UnexpectedJsonFileFormat' } There was a problem reading or parsing the file.

    Parameters

    • Optional throwOnNotFound: boolean = false
    • Optional force: boolean = false

    Returns Contents<CachedOptions>

  • Sets the value for the key in the config object. This will override the existing value. To do a partial update, use BaseConfigStore.update.

    Parameters

    • key: string

      The key. Supports query key like a.b[0].

    • value: Partial<Entry<CachedOptions>>

      The value.

    Returns void

  • Delete the config file if it exists.

    Throws Error{ name: 'TargetFileNotFound' } If the ConfigFile.getFilename file is not found. fs.unlink

    Returns Promise<void>

  • Delete the config file if it exists.

    Throws Error{ name: 'TargetFileNotFound' } If the ConfigFile.getFilename file is not found. fs.unlink

    Returns void

  • Returns true if an element in the config object existed and has been removed, or false if the element does not exist. BaseConfigStore.has will return false afterwards.

    Parameters

    • key: string

      The key. Supports query key like a.b[0].

    Returns boolean

  • Returns true if all elements in the config object existed and have been removed, or false if all the elements do not exist (some may have been removed). BaseConfigStore.has(key) will return false afterwards.

    Parameters

    • keys: string[]

      The keys. Supports query keys like a.b[0].

    Returns boolean

  • Helper used to determine what the local and global folder point to. Returns the file path of the root folder.

    Parameters

    • isGlobal: boolean

      True if the config should be global. False for local.

    Returns Promise<string>

  • Helper used to determine what the local and global folder point to. Returns the file path of the root folder.

    Parameters

    • isGlobal: boolean

      True if the config should be global. False for local.

    Returns string