Options
Menu

Class ModelService

This is the main entry point in Convergence for working with real time data models. RealTimeModels can be created, opened, deleted, and managed from the ModelService.

See IModelServiceEvents for the events that may be emitted on this model.

Hierarchy

Index

Properties

Events

Events: IModelServiceEvents = ModelServiceEventConstants

A mapping of the events this model could emit to each event's unique name. Use this to refer an event name:

modelService.on(ModelService.Events.OFFLINE_MODEL_DELETED, (e) => {
  // ...
})

See IModelServiceEvents for information on each event.

Methods

addListener

create

  • Creates a new model according to the options provided. If a model with the given ID already exists, this will return a rejected Promise.

    Parameters

    Returns Promise<string>

    A Promise that is resolved with the id of the created model.

events

  • Provides the events emitted by this object as an Observable stream.

    example
    
    eventEmitter.events()
      .filter(e => e.name === "myevent")
      .subscribe(e => console.log(e));
    

    Returns Observable<IConvergenceEvent>

    An Observable stream of all events emitted by this object.

getOfflineModelMetaData

  • Gets the meta data for all models currently stored offline.

    experimental

    Returns Promise<IModelMetaData[]>

    The list of currently available offline models.

getOfflineSubscriptions

  • getOfflineSubscriptions(): Promise<string[]>
  • Gets the list of model ids that are are currently subscribed to, to be available offline.

    experimental

    Returns Promise<string[]>

    The list of currently subscribed models.

history

isOpen

  • isOpen(id: string): boolean
  • Determines if a model with the specified id is opened.

    Parameters

    • id: string

      The id of the model to check.

    Returns boolean

    True if the model is open, false otherwise.

isOpening

  • isOpening(id: string): boolean
  • Determines if a model with the specified ID is currently in the process of being opened.

    Parameters

    • id: string

      The id of the model to check.

    Returns boolean

    True if the model is opening, false otherwise.

isResyncing

  • isResyncing(): boolean
  • Returns boolean

off

on

once

  • Adds a single shot event listener for the specified event. The listener will be called the first time the specified event is fired after the event registration occurs, after which the registration will be removed and no further events will be passed to the listener.

    Parameters

    Returns ConvergenceEventEmitter<IConvergenceEvent>

    This object, in support of a fluent API.

open

  • Opens an existing model with a known model id. A model with the specified id must already exist in the system.

    Don't forget to RealTimeModel.close the model when you're done with it to avoid memory leaks!

    Parameters

    • id: string

      The id of the model to open.

    Returns Promise<RealTimeModel>

    A promise that is resolved with the specified model, once open.

openAutoCreate

  • Opens a model, creating it if needed. If the model already exists, it will be opened. If the model does not exist it will be created first, and then opened.

    See here for more context about race conditions this alleviates.

    Parameters

    Returns Promise<RealTimeModel>

    A Promise resolved with the RealTimeModel, once opened.

permissions

  • Gets the permissions manager for a specific model, by id. The permissions manager will allow the caller to set the model permissions for the specified model.

    Parameters

    • id: string

      The id of an existing model to get the permissions manager for.

    Returns ModelPermissionManager

    A permissions manager for the specified model.

query

  • Searches for models using the model query syntax. Only SELECTs are currently supported. The grammar is as follows:

    SELECT [ * ]
    [ FROM <Collection> ]
    [ WHERE <Condition>* ]
    [ ORDER BY (<Field> [ ASC|DESC ])* ]
    [ LIMIT <MaxRecords> ]
    [ OFFSET <SkipRecords> ]
    

    Parameters

    • query: string

      The query string to use to look up the model.

    Returns Promise<PagedData<ModelResult>>

    A promise that will be resolved with the query results.

remove

  • remove(id: string): Promise<void>
  • Removes an existing model by id.

    Parameters

    • id: string

      The id of the model to remove.

    Returns Promise<void>

    A Promise that is resolved when the model is successfully removed.

removeAllListeners

removeListener

removeListeners

session

setOfflineSubscription

  • setOfflineSubscription(modelIds: string[]): Promise<void>
  • Sets the total set of models that will be proactively downloaded and made available offline. Any models currently subscribed to that do not appear in the supplied list of ids will be unsubscribe and immediately removed from the offline store.

    experimental

    Parameters

    • modelIds: string[]

    Returns Promise<void>

    An empty Promise that will be resolved upon successful subscription.

subscribeOffline

  • subscribeOffline(modelId: string | string[]): Promise<void>
  • Adds a model or a list of models to the set of models that will be proactively downloaded and made available offline. Note that duplicates will simply be ignored.

    experimental

    Parameters

    • modelId: string | string[]

      A string or string array containing the unique ids of the models to be added to the current offline subscription list.

    Returns Promise<void>

    An empty Promise that will be resolved upon successful subscription.

unsubscribeOffline

  • unsubscribeOffline(modelId: string | string[]): Promise<void>
  • Removes a model or a list of models to the set of models that will be proactively downloaded and made available offline. If a model is currently stored offline, and it is unsubscribed it will be purged from the offline store.

    experimental

    Parameters

    • modelId: string | string[]

      A string or string array containing the unique ids of the models to be removed from the current offline subscription list.

    Returns Promise<void>

    An empty Promise that will be resolved upon successful unsubscription.