CollectionAdapter class is used to adapt a collection of entities. It provides various methods for manipulating and accessing the collection.

T - The type of entity in the collection

Type Parameters

Implements

Constructors

Properties

clear: () => Promise<void>

Clears the collection.

Type declaration

    • (): Promise<void>
    • Returns Promise<void>

filter: (
    fn: (value: CollectionEntityAdapter<T>, idx: number) => boolean,
) => CollectionEntityAdapter<T>[]

Filters the items in the collection based on the provided function.

Type declaration

    • (
          fn: (value: CollectionEntityAdapter<T>, idx: number) => boolean,
      ): CollectionEntityAdapter<T>[]
    • Parameters

      • fn: (value: CollectionEntityAdapter<T>, idx: number) => boolean

        A function used to filter the collection items. The function should accept two parameters: value and idx.

        • value: The current item being processed in the collection.
        • idx: The index of the current item being processed in the collection.

      Returns CollectionEntityAdapter<T>[]

      • An array containing the filtered items from the collection.
find: (
    fn: (value: CollectionEntityAdapter<T>, idx: number) => boolean,
) => undefined | CollectionEntityAdapter<T>

Finds the first element in the collection that satisfies the given condition.

Type declaration

findById: (id: string | number) => CollectionEntityAdapter<T>

Finds an entity by its ID in the current collection.

Type declaration

forEach: (fn: (value: CollectionEntityAdapter<T>, idx: number) => void) => void

Performs a given function on each element of the collection.

Type declaration

    • (fn: (value: CollectionEntityAdapter<T>, idx: number) => void): void
    • Parameters

      • fn: (value: CollectionEntityAdapter<T>, idx: number) => void

        The function to be executed on each element. The function should take two parameters: the current value in the collection and the index of the current value.

      Returns void

map: <V extends unknown = any>(
    fn: (value: CollectionEntityAdapter<T>, idx: number) => V,
) => V[]

Maps over the items in the collection and returns an array of values.

Type declaration

    • <V extends unknown = any>(
          fn: (value: CollectionEntityAdapter<T>, idx: number) => V,
      ): V[]
    • Type Parameters

      • V extends unknown = any

        The type of the mapped values.

      Parameters

      Returns V[]

      • An array of values obtained by applying the mapping function to each item.
push: (...items: T[] | T[][]) => Promise<void>

Asynchronously pushes item(s) to the collection.

Type declaration

    • (...items: T[] | T[][]): Promise<void>
    • Parameters

      • ...items: T[] | T[][]

        The item(s) to push.

      Returns Promise<void>

      A Promise that resolves once the item(s) are pushed to the collection.

refresh: () => Promise<void>

Refreshes the current collection after waiting for listeners.

Type declaration

    • (): Promise<void>
    • Returns Promise<void>

      A promise that resolves after the collection is refreshed.

remove: (entity: IEntity) => Promise<void>

Removes an entity from the collection.

Type declaration

    • (entity: IEntity): Promise<void>
    • Parameters

      • entity: IEntity

        The entity to be removed from the collection.

      Returns Promise<void>

      • A Promise that resolves when the entity is successfully removed.
removeAll: () => Promise<void>

Removes all items from the collection.

Type declaration

    • (): Promise<void>
    • Returns Promise<void>

      A promise that resolves once all items are removed.

removeAll

removeById: (id: string | number) => Promise<void>

Removes an item from the collection by its ID.

Type declaration

    • (id: string | number): Promise<void>
    • Parameters

      • id: string | number

        The ID of the item to remove.

      Returns Promise<void>

      A promise that resolves with no value.

setData: (items: T[]) => Promise<void>

Sets new data for the collection.

Type declaration

    • (items: T[]): Promise<void>
    • Parameters

      • items: T[]

        The new collection data.

      Returns Promise<void>

      • A promise that resolves when the new data is set.
some: (
    fn: (value: CollectionEntityAdapter<T>, idx: number) => boolean,
) => boolean

Checks if any element of the collection satisfies the provided testing function.

Type declaration

    • (fn: (value: CollectionEntityAdapter<T>, idx: number) => boolean): boolean
    • Parameters

      • fn: (value: CollectionEntityAdapter<T>, idx: number) => boolean

        The testing function to apply to each element of the collection. It should take two arguments: the current element of the collection and its index. Returns a boolean value indicating whether the element satisfies the testing condition.

      Returns boolean

      • A boolean value indicating whether any element of the collection satisfies the testing function.
toArray: () => T[]

Retrieves an array representation of the current collection.

Type declaration

    • (): T[]
    • Returns T[]

      • An array representation of the current collection.
toCollection: () => Collection<T>

Retrieve the current value of the collection.

Type declaration

upsert: (...items: T[] | T[][]) => Promise<void>

Upserts one or more items into the current collection.

Type declaration

    • (...items: T[] | T[][]): Promise<void>
    • Parameters

      • ...items: T[] | T[][]

        One or more items to upsert into the collection.

      Returns Promise<void>

      • A Promise that resolves when the upsert operation is complete.

Accessors

  • get ids(): (string | number)[]

    Retrieves the IDs from the current collection.

    Returns (string | number)[]

    The IDs from the current collection.

  • get isEmpty(): boolean

    Checks if the collection is empty.

    Returns boolean

    • True if the collection is empty, otherwise false.