Realm.Sync.Adapter

Class for creating custom Data Connectors. Only available in the Enterprise Edition.

new Realm.Sync.Adapter(local_path, server_url, admin_user, regex, change_callback)

Create a new Adapter to moitor and process changes made across multiple Realms

Parameters:
  • local_path
    • Type: string
    • the local path where realm files are stored

  • server_url
    • Type: string
    • the sync server to listen to

  • admin_user
    • Type: SyncUser
    • an admin user obtained by calling new Realm.Sync.User.adminUser

  • regex
    • Type: string
    • a regular expression used to determine which changed Realms should be monitored - use .* to match all all Realms

  • change_callback
    • Type: function
    • called when a new transaction is available to process for the given realm_path

advance(path)

Advance the to the next transaction indicating that you are done processing the current instructions for the given Realm.

Parameters:
  • path
    • Type: string
    • the path for the Realm to advance

close()

Close the adapter and all opened Realms.

current(path)Array(instructions)

Get the Array of current instructions for the given Realm.

Parameters:
  • path
    • Type: string
    • the path for the Realm being monitored

Returns: Array(instructions) or {undefined} if all transactions have been processed
realmAtPath(path, optional)Realm

Open the Realm used by the Adapter for the given path. This is useful for writing two way adapters as transactions written to this realm will be ignored when calling current and advance

Parameters:
  • path
    • Type: string
    • the path for the Realm to open

  • optional optional
    • Type: [ObjectSchema, ...]
    • schema - schema to apply when opening the Realm

Returns: Realm
Instruction

The following Instructions can be returned by Adapter.current(path). Each instruction object has a type property which is one of the following types. For each type below we list the other properties that will exist in the instruction object.

Type:
INSERT or SET or DELETE or CLEAR or CHANGE_IDENTITY or LIST_SET or LIST_INSERT or LIST_ERASE or LIST_CLEAR or ADD_TYPE or ADD_PROPERTY
Properties:
  • INSERT
    • insert a new object

      • object_type - type of the object being inserted
      • identity - primary key value or row index for the object
      • values - map of property names and property values for the object to insert
  • SET
    • set property values for an existing object

      • object_type - type of the object
      • identity - primary key value or row index for the object
      • values - map of property names and property values to update for the object
  • DELETE
    • delete an exising object

      • object_type - type of the object
      • identity - primary key value or row index for the object
  • CLEAR
    • delete all objects of a given type

      • object_type - type of the object
  • LIST_SET
    • set the object at a given list index to an object

      • object_type - type of the object
      • identity - primary key for the object
      • property - property name for the list property to mutate
      • list_index - list index to set
      • object_identity - primary key or row number of the object being set
  • LIST_INSERT
    • insert an object in the list at the given index

      • object_type - type of the object
      • identity - primary key for the object
      • property - property name for the list property to mutate
      • list_index - list index at which to insert
      • object_identity - primary key or row number of the object to insert
  • LIST_ERASE
    • erase an object in the list at the given index - this removes the object from the list but the object will still exist in the Realm

      • object_type - type of the object
      • identity - primary key for the object
      • property - property name for the list property to mutate
      • list_index - list index which should be erased
  • LIST_CLEAR
    • clear a list removing all objects - objects are not deleted from the Realm

      • object_type - type of the object
      • identity - primary key for the object
      • property - property name for the list property to clear
  • ADD_TYPE
    • add a new type

      • object_type - name of the type
      • primary_key - name of primary key property for this type
      • properties - Property map as described in Realm~ObjectSchema
  • ADD_PROPERTIES
    • add properties to an existing type

      • object_type - name of the type
      • properties - Property map as described in Realm~ObjectSchema
  • CHANGE_IDENTITY
    • change the row index for an existing object - not called for objects with primary keys

      • object_type - type fo the object
      • identity - old row value for the object
      • new_identity - new row value for the object