Class MaxKeyLengthStorage<T>

A KeyValueStorage that hashes keys in case they would be longer than the set limit. Hashed keys are prefixed with a certain value to prevent issues with incoming keys that are already hashed. The default max length is 150 and the default prefix is $hash$.

This class mostly exists to prevent issues when writing storage entries to disk. Keys that are too long would cause issues with the file name limit. For this reason, only the part after the last / in a key is hashed, to preserve the expected file structure.

Type Parameters

  • T


  • MaxKeyLengthStorage




hashPrefix: string
logger: Logger = ...
maxKeyLength: number
source: KeyValueStorage<string, Entry<T>>


  • Hashes the last part of the key if it is too long. Otherwise, just returns the key.


    • key: string
    • Optional parts: string[]

    Returns string

  • Similar to getKey but checks to make sure the key does not already contain the prefix. Only necessary for set calls.


    • key: string

    Returns string