Interface SyncWritableStore<ItemType, IDType>

A synchronous store that accepts changes to it's contents.

use WritableAsyncStore instead

interface SyncWritableStore<
    ItemType extends IndexableThing = IndexableThing,
    IDType extends AllowedIdTypes = AllowedIdTypes,
> {
    add(item: Partial<ItemType>, options?: CreateOptions<IDType>): ItemType;
    get(id: IDType, options?: GetOptions): undefined | ItemType;
    getIdentity(item: Partial<ItemType>): undefined | IDType;
    getMetadata(): Metadata;
    id: string;
    idProperty?: string;
    on<Name extends "changed">(
        eventName: Name,
        callback: EventCallback<StoreEvents<IDType>[Name]>,
    ): EventHandle;
    on(
        eventName: "*",
        callback: EventCallback<StoreChangedEvent<IDType>>,
    ): EventHandle;
    on(
        eventName: string | string[],
        callback: EventCallback<unknown>,
    ): EventHandle;
    put(item: Partial<ItemType>, options?: CreateOptions<IDType>): ItemType;
    query(
        query?: ComplexQueryExpression,
        options?: QueryOptions,
    ): ResultItems<ItemType>;
    remove(id: IDType): void;
}

Type Parameters

Hierarchy (View Summary)

Implemented by

Properties

id: string

ID of the store.

idProperty?: string

Name of the property used as ID. If not provided, the 'getIdentity' method must be declared.

Methods

  • Create a new item. Throws an error, if the item already exists. The 'overwrite' option is assumed to be false).

    Parameters

    Returns ItemType

  • Retrieves an item by its identifier.

    Parameters

    • id: IDType

      id of an item in the store.

    • Optionaloptions: GetOptions

      options to specify the result.

    Returns undefined | ItemType

  • Returns an items‘s identity. This must always execute synchronously.

    Parameters

    Returns undefined | IDType

    the ID

  • Returns any available metadata about the store. This may include attribution, available fields, cache directives, history or version information.

    Returns Metadata

  • Register event listener for specific events.

    Type Parameters

    • Name extends "changed"

    Parameters

    Returns EventHandle

    a handle to unregister from the event

  • Register event listener for any event.

    Parameters

    Returns EventHandle

    a handle to unregister from the events

  • Register event listener for the events listed in eventName. Comma separated event names are possible, for example "eventA,eventB".

    Parameters

    • eventName: string | string[]

      the event name or list of names

    • callback: EventCallback<unknown>

      the event handler callback

    Returns EventHandle

    a handle to unregister from the event(s)

  • Saves the given item. Depending on the specified options, a new item is created or a given item is updated.

    Parameters

    Returns ItemType

  • Delete an item by id.

    Parameters

    • id: IDType

      id of item to delete

    Returns void