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 ModelServiceEvents for the events that may be emitted on this model.

### Hierarchy

- ConvergenceEventEmitter<IConvergenceEvent>
  - ModelService

## Index

### Properties

- Events

### Methods

- addListener
- create
- events
- getOfflineModelMetaData
- getOfflineSubscriptions
- history
- isOpen
- isOpening
- isResyncing
- off
- on
- once
- open
- openAutoCreate
- permissions
- query
- remove
- removeAllListeners
- removeListener
- removeListeners
- session
- setOfflineSubscription
- subscribeOffline
- unsubscribeOffline

## Properties

### StaticEvents

Events: ModelServiceEvents = 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.MODEL_DELETED, function listener(e) {
      // ...
    })

## Methods

### addListener

- addListener(event: string, listener: ConvergenceEventListener<IConvergenceEvent>): ConvergenceEventEmitter<IConvergenceEvent>

- Inherited from ConvergenceEventEmitter.addListener

  Adds a new event listener for the specified event. The class will ignore duplicate registrations of the same listener to the same event.

  #### Parameters

  - ##### event: string

    The name of the event to add the listener for.

  - ##### listener: ConvergenceEventListener<IConvergenceEvent>

    The listener callback to register.

  #### Returns ConvergenceEventEmitter<IConvergenceEvent>

  This object, in support of a fluent API.

### create

- create(options: ICreateModelOptions): Promise<string>

- 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

  - ##### options: ICreateModelOptions

    A options object specifying how the model is to be created.

  #### Returns Promise<string>

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

### events

- events(): Observable<IConvergenceEvent>

- Inherited from ConvergenceEventEmitter.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

- getOfflineModelMetaData(): Promise<IModelMetaData[]>

- 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

- history(id: string): Promise<HistoricalModel>

- Opens an existing model, by id, in history mode.

  #### Parameters

  - ##### id: string

    The id of the model to open in history mode.

  #### Returns Promise<HistoricalModel>

  A Promise resolved with the HistoricalModel when opened.

### 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

- off(event: string, listener: ConvergenceEventListener<IConvergenceEvent>): ConvergenceEventEmitter<IConvergenceEvent>

- Inherited from ConvergenceEventEmitter.off

  Removes a single event listener for a specific event.

  #### Parameters

  - ##### event: string

    The name of the event to remove the listener for.

  - ##### listener: ConvergenceEventListener<IConvergenceEvent>

    The listener callback to unregister.

  #### Returns ConvergenceEventEmitter<IConvergenceEvent>

  This object, in support of a fluent API.

### on

- on(event: string, listener: ConvergenceEventListener<IConvergenceEvent>): ConvergenceEventEmitter<IConvergenceEvent>

- Inherited from ConvergenceEventEmitter.on

  Adds a new event listener for the specified event. The class will ignore duplicate registrations of the same listener to the same event.

  #### Parameters

  - ##### event: string

    The name of the event to add the listener for.

  - ##### listener: ConvergenceEventListener<IConvergenceEvent>

    The listener callback to register.

  #### Returns ConvergenceEventEmitter<IConvergenceEvent>

  This object, in support of a fluent API.

### once

- once(event: string, listener: ConvergenceEventListener<IConvergenceEvent>): ConvergenceEventEmitter<IConvergenceEvent>

- Inherited from ConvergenceEventEmitter.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

  - ##### event: string

    The name of the event to add the listener for.

  - ##### listener: ConvergenceEventListener<IConvergenceEvent>

    The listener callback to register.

  #### Returns ConvergenceEventEmitter<IConvergenceEvent>

  This object, in support of a fluent API.

### open

- open(id: string): Promise<RealTimeModel>

- 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

- openAutoCreate(options: IAutoCreateModelOptions): Promise<RealTimeModel>

- 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

  - ##### options: IAutoCreateModelOptions

    The options that define how to open and / or create the model.

  #### Returns Promise<RealTimeModel>

  A Promise resolved with the RealTimeModel, once opened.

### permissions

- permissions(id: string): ModelPermissionManager

- 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

- query(query: string): Promise<PagedData<ModelResult>>

- Searches for models using the model query syntax. Only `SELECT`s 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

- removeAllListeners(): ConvergenceEventEmitter<IConvergenceEvent>

- Inherited from ConvergenceEventEmitter.removeAllListeners

  Removes all listeners for all events. This is useful for cleanup before disposing of this particular event emitter.

  #### Returns ConvergenceEventEmitter<IConvergenceEvent>

  This object, in support of a fluent API.

### removeListener

- removeListener(event: string, listener: ConvergenceEventListener<IConvergenceEvent>): ConvergenceEventEmitter<IConvergenceEvent>

- Inherited from ConvergenceEventEmitter.removeListener

  Removes a single event listener for a specific event.

  #### Parameters

  - ##### event: string

    The name of the event to remove the listener for.

  - ##### listener: ConvergenceEventListener<IConvergenceEvent>

    The listener callback to unregister.

  #### Returns ConvergenceEventEmitter<IConvergenceEvent>

  This object, in support of a fluent API.

### removeListeners

- removeListeners(event: string): ConvergenceEventEmitter<IConvergenceEvent>

- Inherited from ConvergenceEventEmitter.removeListeners

  Removes all listeners bound on the given event.

  #### Parameters

  - ##### event: string

    the name of the event to remove listeners for

  #### Returns ConvergenceEventEmitter<IConvergenceEvent>

  This object, in support of a fluent API.

### session

- session(): ConvergenceSession

- #### Returns ConvergenceSession

  The ConvergenceSession attached to this domain.

### 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.