@mantlebee/ts-data
    Preparing search index...

    Interface IProjectionExtension<TItem>

    Extension that adds the list of Projection to the payload. Every mutation raises its own event at once and schedules the debounced projectionsChange event (see ProjectionExtensionEvents).

    interface IProjectionExtension<TItem = Any> {
        hasProjections: boolean;
        projections: List<Projection<TItem>>;
        addProjection(projection: Projection<TItem>): void;
        buildPayload?(
            payload: DataSourcePayload<TItem>,
            signal?: AbortSignal,
        ): Promise<DataSourcePayload<TItem>>;
        clearProjections(): void;
        dispose(): Promise<void>;
        on<TKey extends string>(
            event: TKey,
            handler: EventHandler<ProjectionExtensionEvents<TItem>, TKey>,
        ): IDisposable;
        readItems?(
            payload: DataSourcePayload<TItem>,
            next: DataSourceReadNext<TItem>,
            signal?: AbortSignal,
        ): Promise<List<TItem>>;
        removeProjection(field: KeyOf<TItem>): void;
        setProjections(projections: List<Projection<TItem>>): void;
    }

    Type Parameters

    • TItem = Any

      Type of the items.

    Hierarchy (View Summary)

    Implemented by

    Index
    hasProjections: boolean

    true when at least one projection is set.

    projections: List<Projection<TItem>>

    Current projections, in insertion order; empty means "every field".

    • Releases the held resource. Implementations should be safe to call more than once.

      Returns Promise<void>

      a promise that settles once the resource has been released.

    • Registers a handler for an event.

      Type Parameters

      • TKey extends string

        Name of the event to listen to.

      Parameters

      Returns IDisposable

      a subscription; dispose it to remove this single handler.

    • Wraps the reading of the items. Read phase: the extension is a layer of the onion around the reader, next the layers inside it (the inner extensions, then the reader of the data source). The payload is the whole query, whatever the position of the extension.

      next may be called zero times (e.g. a cache hit: the reader is never invoked), once, with this or another payload, or several times (e.g. a payload split into several reads whose results are merged); every call runs the inner layers and the reader again, so the hooks and the events of the inner extensions may fire as many times. The result may be transformed before being returned, and flows outward: the outermost extension transforms last.

      Parameters

      • payload: DataSourcePayload<TItem>

        The whole query, built by the build phase.

      • next: DataSourceReadNext<TItem>

        Reads the items through the inner layers and the reader; the signal of the read is bound already.

      • Optionalsignal: AbortSignal

        Signal of the read, aborted when the read is superseded, for the reads of the extension itself.

      Returns Promise<List<TItem>>

      the items for the outer extension, or the data source.