@adviser/cement - v0.0.0
    Preparing search index...

    Class KeyedResolvSeq<VALUEType, KEYType, CTX>

    Keyed collection of ResolveSeq instances.

    Manages a map of ResolveSeq instances indexed by keys, with optional LRU caching. Each key gets its own ResolveSeq instance for sequential execution of operations.

    const sequences = new KeyedResolvSeq<number, string>();

    // Each key gets its own sequential executor
    sequences.get('user1').add(() => updateUser1());
    sequences.get('user2').add(() => updateUser2());

    Type Parameters

    • VALUEType extends NonNullable<unknown>

      The return type of the ResolveSeq instances

    • KEYType = string

      The key type

    • CTX extends NonNullable<object> = object

      Optional context type

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    opts: Required<Omit<KeyedNgOptions<K, V, CTX>, "lru">>

    The resolved options with defaults applied.

    Methods

    • Checks if a key exists in the collection.

      Does not create a new value if the key doesn't exist.

      Parameters

      • keyOfFnKey: KEYType | (() => KEYType)

        The key or function returning the key

      Returns boolean

      True if the key exists in the collection

      if (keyed.has('myKey')) {
      console.log('Key exists');
      }

      // With function
      if (keyed.has(() => computeKey())) {
      console.log('Computed key exists');
      }
    • Deletes an item from the collection.

      Triggers onDelete callbacks before removal. The item will need to be recreated if accessed again.

      Parameters

      Returns void

      keyed.delete('myKey');
      
    • Returns all keys currently in the collection.

      Returns the original keys (givenKey), not the normalized string versions.

      Returns KEYType[]

      Array of all keys

      const keys = keyed.keys();
      console.log(keys); // ['key1', 'key2', 'key3']
    • Gets or creates a value for the given key.

      This is the primary method for accessing values. If the key doesn't exist, the factory function is called to create the value. Subsequent calls with the same key return the cached value.

      Parameters

      • key: KEYType | (() => KEYType)

        The key or function returning the key

      • Optionalctx: CTX

        Optional context override for this get operation

      Returns ResolveSeq

      The value associated with the key

      // Simple key
      const value1 = keyed.get('myKey');

      // With function
      const value2 = keyed.get(() => computeKey());

      // With custom context
      const value3 = keyed.get('myKey', { custom: 'context' });