Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Repository<TEntity, TRawData>

A Repository is a service through which all of an Entity's data is fetched, cached and saved back to the backend.

This class handles entities that can be added, updated or removed. see ReadonlyRepository base class.

Type parameters

Hierarchy

Implements

Index

Constructors

constructor

Properties

entityConstructor

entityConstructor: DataEntityType<TEntity, TRawData>

error$

error$: Observable<EntityErrorEvent>

remove$

remove$: Observable<RemoveEntitiesEvent>

save$

save$: Observable<SaveEntityEvent>

Accessors

allItems$

  • get allItems$(): Observable<Array<TEntity>>
  • An Observable for all the items of this entity. If the Entity has already loaded all possible items (if loadAll is set to true, for example), those items are returned. Otherwise, a query with no DataQuery will be performed to the backend and the data will be fetched.

    Returns Observable<Array<TEntity>>

entity

modelConfig

values

  • get values(): Array<TEntity>

Methods

addCustomHeaders

  • addCustomHeaders(data: any): Record<string, string>

clearAllValues

  • clearAllValues(): void

clearCache

  • clearCache(): void

createItem

  • Creates a full model of this Repository's Entity. Any sub-models that need to be fetched from backend will be fetched (if options.availability === DataAvailability.deep). This method is used internally when modeling entities and value objects, but may be used externally as well, in case an item should be created programmatically from raw data.

    Parameters

    • rawData: TRawData

      The raw data for the entity, as it arrives from backend

    • Default value options: DataOptions = { allowCache: true, availability: DataAvailability.available }
    • Optional query: DataQuery

    Returns Observable<TEntity>

createNewItem

  • createNewItem(): TEntity

getEndpointName

getEndpointUrl

getItemById

getQueryHttpOptions

query

  • Gets multiple items from backend. The backend may add paging information, such as count, page, etc, so a DataSet object is returned rather than just an Array.

    example

    Get all Todo items

    repository.query()
            .subscribe((todoItems:DataSet<TodoItem>) => console.log('Current items: ', todoItems.items));
    
    example

    Get all Todo items, sorted by name

    repository.query({ sortBy: { field: 'name' }})
            .subscribe((todoItems:DataSet<TodoItem>) => console.log('Items by name: ', todoItems.items));
    

    Parameters

    Returns Observable<DataSet<TEntity>>

queryItem

  • Same as {@link ReadonlyRepository#query|query}, but returns a single item rather than a {DataSet}. Useful for when we require to fetch a single model from backend, but it's either a ValueObject (so we can't refer to it by ID) or it's fetched by a more complex data query.

    Parameters

    Returns Observable<TEntity>

remove

  • remove(items: Array<TEntity>, options?: HttpOptions): Observable<Array<TEntity>>

removeItem

  • removeItem(item: TEntity, options?: HttpOptions): Observable<TEntity>

save

  • save(item: Partial<TEntity>, options?: HttpOptions, serializationData?: any): Observable<TEntity>
  • Saves an entity to the server

    Parameters

    • item: Partial<TEntity>
    • Optional options: HttpOptions
    • Optional serializationData: any

      Any data to pass to serialize or serializeItem

    Returns Observable<TEntity>

saveItems

  • saveItems(items: Array<TEntity>, options?: HttpOptions): Observable<Array<TEntity>>

serializeItem

  • serializeItem(item: Partial<TEntity>, serializationData?: any): TRawData

Static validateItem

  • validateItem<TEntity, TRawData>(item: __type, entity: ModelConfig<TEntity, TRawData>): boolean

Generated using TypeDoc