2016-10-04 22:02:51 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright 2016 Realm Inc.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
//
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2018-05-15 16:20:20 +00:00
|
|
|
|
|
2018-05-14 12:16:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* This describes the different options used to create a {@link Realm} instance with Realm Platform synchronization.
|
|
|
|
|
* @typedef {Object} Realm.Sync~SyncConfiguration
|
|
|
|
|
* @property {Realm.Sync.User} user - A {@link Realm.Sync.User} object obtained by calling `Realm.Sync.User.login`.
|
|
|
|
|
* @property {string} url - A `string` which contains a valid Realm Sync url.
|
|
|
|
|
* @property {function} [error] - A callback function which is called in error situations.
|
|
|
|
|
* The `error` callback can take up to five optional arguments: `name`, `message`, `isFatal`,
|
|
|
|
|
* `category`, and `code`.
|
|
|
|
|
*
|
|
|
|
|
* @deprecated
|
|
|
|
|
* @property {boolean} [validate_ssl] - Indicating if SSL certificates must be validated.
|
|
|
|
|
* @deprecated
|
|
|
|
|
* @property {string} [ssl_trust_certificate_path] - A path where to find trusted SSL certificates.
|
|
|
|
|
* @deprecated
|
|
|
|
|
* @property {Realm.Sync~sslValidateCallback} [open_ssl_verify_callback] - A callback function used to
|
|
|
|
|
* accept or reject the server's SSL certificate.
|
|
|
|
|
*
|
|
|
|
|
* @property {Realm.Sync~SSLConfiguration} [ssl] - SSL configuration.
|
2018-05-30 10:54:51 +00:00
|
|
|
|
* @deprecated
|
|
|
|
|
* @property {boolean} [partial] - Whether this Realm should be opened in 'query-based synchronization' mode.
|
|
|
|
|
* Query-based synchronisation only synchronizes those objects that match the query specified in contrast
|
2018-05-14 12:16:52 +00:00
|
|
|
|
* to the normal mode of operation that synchronises all objects in a remote Realm.
|
2018-05-30 10:54:51 +00:00
|
|
|
|
* @property {boolean} [fullSynchronization] - Whether this Realm should be opened in query-based or full
|
|
|
|
|
* synchronization mode. The default is query-based mode which only synchronizes objects that have been subscribed to.
|
|
|
|
|
* A fully synchronized Realm will synchronize the entire Realm in the background, irrespectively of the data being
|
|
|
|
|
* used or not.
|
2018-10-08 10:02:44 +00:00
|
|
|
|
* @property {Object} [custom_http_headers] - A map (string, string) of custom HTTP headers.
|
|
|
|
|
* @property {string} [customQueryBasedSyncIdentifier] - A custom identifier to append to the Realm url rather than the default
|
|
|
|
|
* identifier which is comprised of the user id and a random string. It allows you to reuse query based Realms across
|
|
|
|
|
* different devices.
|
2018-05-14 12:16:52 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This describes the different options used to create a {@link Realm} instance with Realm Platform synchronization.
|
|
|
|
|
* @typedef {Object} Realm.Sync~SSLConfiguration
|
|
|
|
|
* @property {boolean} validate - Indicating if SSL certificates must be validated. Default is `true`.
|
|
|
|
|
* @property {string} certificatePath - A path where to find trusted SSL certificates.
|
|
|
|
|
* @property {Realm.Sync~sslValidateCallback} validateCallback - A callback function used to
|
|
|
|
|
* accept or reject the server's SSL certificate.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* When the sync client has received the server's certificate chain, it presents every certificate in
|
|
|
|
|
* the chain to the {@link Realm.Sync~sslValidateCallback} callback.
|
|
|
|
|
*
|
|
|
|
|
* The return value of the callback decides whether the certificate is accepted (`true`)
|
|
|
|
|
* or rejected (`false`). {@link Realm.Sync~sslValidateCallback} is only respected on platforms where
|
|
|
|
|
* OpenSSL is used for the sync client, e.g. Linux. The callback is not
|
|
|
|
|
* allowed to throw exceptions. If the operations needed to verify the certificate lead to an exception,
|
|
|
|
|
* the exception must be caught explicitly before returning. The return value would typically be false
|
|
|
|
|
* in case of an exception.
|
|
|
|
|
* @callback Realm.Sync~sslValidateCallback
|
|
|
|
|
* @param {Realm.Sync~SSLCertificateValidationInfo} validationInfo
|
|
|
|
|
* @return {boolean}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @typedef {Object} Realm.Sync~SSLCertificateValidationInfo
|
|
|
|
|
* @property {string} serverAddress
|
|
|
|
|
* @property {number} serverPort
|
|
|
|
|
* @property {string} pemCertificate
|
|
|
|
|
* @property {boolean} acceptedByOpenSSL - `true` if OpenSSL has accepted the certificate,
|
|
|
|
|
* and `false` if OpenSSL has rejected it.
|
|
|
|
|
* It is generally safe to return true when `acceptedByOpenSSL` is `true`. If `acceptedByOpenSSL` is `false`,
|
|
|
|
|
* an independent verification should be made.
|
|
|
|
|
* @property {number} depth - Specifies the position of the certificate in the chain.
|
|
|
|
|
* `depth = 0` represents the actual server certificate. The root
|
|
|
|
|
* certificate has the highest depth. The certificate of highest depth will be presented first.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-10-04 22:02:51 +00:00
|
|
|
|
/**
|
2017-09-22 11:50:17 +00:00
|
|
|
|
* When opening a Realm created with Realm Mobile Platform v1.x, it is automatically
|
2017-10-03 07:10:18 +00:00
|
|
|
|
* migrated to the v2.x format. In case this migration
|
2017-09-22 11:50:17 +00:00
|
|
|
|
* is not possible, an exception is thrown. The exception´s `message` property will be equal
|
|
|
|
|
* to `IncompatibleSyncedRealmException`. The Realm is backed up, and the property `configuration`
|
2017-11-01 13:44:40 +00:00
|
|
|
|
* is a {Realm~Configuration} which refers to it. You can open it as a local, read-only Realm, and
|
2017-09-22 11:50:17 +00:00
|
|
|
|
* copy objects to a new synced Realm.
|
2017-11-01 13:44:40 +00:00
|
|
|
|
*
|
2016-10-04 22:02:51 +00:00
|
|
|
|
* @memberof Realm
|
|
|
|
|
*/
|
|
|
|
|
class Sync {
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
2018-01-11 09:08:18 +00:00
|
|
|
|
* Add a sync listener to listen to changes across multiple Realms.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} serverUrl - The sync server to listen to.
|
2018-09-13 06:45:06 +00:00
|
|
|
|
* @param {SyncUser} adminUser - an admin user obtained by calling {@linkcode Realm.Sync.User.login|User.login} with admin credentials.
|
2018-01-11 09:08:18 +00:00
|
|
|
|
* @param {string} filterRegex - A regular expression used to determine which changed Realms should trigger events. Use `.*` to match all Realms.
|
|
|
|
|
* @param {string} name - The name of the event.
|
|
|
|
|
* @param {function(changeEvent)} changeCallback - The callback to invoke with the events.
|
|
|
|
|
*
|
|
|
|
|
* Registers the `changeCallback` to be called each time the given event occurs on the specified server.
|
|
|
|
|
* Only events on Realms with a _virtual path_ that matches the filter regex are emitted.
|
|
|
|
|
*
|
|
|
|
|
* Currently supported events:
|
|
|
|
|
*
|
|
|
|
|
* * `'available'`: Emitted whenever there is a new Realm which has a virtual
|
|
|
|
|
* path matching the filter regex, either due to the Realm being newly created
|
|
|
|
|
* or the listener being added. The virtual path (i.e. the portion of the
|
|
|
|
|
* URL after the protocol and hostname) is passed as an argument.
|
|
|
|
|
* * `'change'`: Emitted whenever the data within a Realm matching the filter
|
|
|
|
|
* regex has changed. A [ChangeEvent]{@link Realm.Sync.ChangeEvent} argument
|
|
|
|
|
* is passed containing information about which Realm changed and what
|
|
|
|
|
* objects within the Realm changed.
|
2018-05-08 20:28:37 +00:00
|
|
|
|
* * `'delete'`: Emitted whenever a Realm matching the filter regex has been
|
|
|
|
|
* deleted from the server. The virtual path of the Realm being deleted is
|
|
|
|
|
* passed as an argument.
|
2018-01-11 09:08:18 +00:00
|
|
|
|
*
|
|
|
|
|
* Only available in the Enterprise Edition.
|
|
|
|
|
*/
|
|
|
|
|
static addListener(serverUrl, adminUser, filterRegex, name, changeCallback) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a sync listener to listen to changes across multiple Realms.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} serverUrl - The sync server to listen to.
|
2018-09-13 06:45:06 +00:00
|
|
|
|
* @param {SyncUser} adminUser - an admin user obtained by calling {@linkcode Realm.Sync.User.login|User.login} with admin credentials.
|
2018-01-11 09:08:18 +00:00
|
|
|
|
* @param {string} filterRegex - A regular expression used to determine which changed Realms should trigger events. Use `.*` to match all Realms.
|
|
|
|
|
* @param {Realm.Worker} worker - Worker to deliver events to.
|
|
|
|
|
*
|
|
|
|
|
* Only available in the Enterprise Edition.
|
|
|
|
|
*/
|
|
|
|
|
static addListener(serverUrl, adminUser, filterRegex, worker) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove a previously registered sync listener.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} filterRegex - The regular expression previously used to register the listener.
|
|
|
|
|
* @param {string} name - The event name.
|
|
|
|
|
* @param {function(changeEvent)} changeCallback - The previously registered callback to be removed.
|
|
|
|
|
*/
|
|
|
|
|
static removeListener(regex, name, changeCallback) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove a previously registered sync listener.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} filterRegex - The regular expression previously used to register the listener.
|
|
|
|
|
* @param {string} worker - The worker registered as a listener.
|
|
|
|
|
* @return {Promise<void>} A promise which is resolved when the worker has finished shutting down.
|
|
|
|
|
*/
|
|
|
|
|
static removeListener(regex, worker) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove all previously registered listeners.
|
|
|
|
|
* @return {Promise<void>} A promise which is resolved when all workers (if any) have finished shutting down.
|
2017-03-20 09:40:56 +00:00
|
|
|
|
*/
|
|
|
|
|
static removeAllListeners(name) {}
|
2016-10-04 22:02:51 +00:00
|
|
|
|
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* Set the sync log level.
|
2018-01-11 09:08:18 +00:00
|
|
|
|
* @param {Realm.Sync~LogLevel} log_level - The new log level.
|
2017-03-20 09:40:56 +00:00
|
|
|
|
*/
|
|
|
|
|
static setLogLevel(log_level) {}
|
2016-11-14 18:48:50 +00:00
|
|
|
|
|
2017-10-02 17:44:24 +00:00
|
|
|
|
/**
|
|
|
|
|
* Initiate a client reset. The Realm must be closed prior to the reset.
|
2018-01-11 09:08:18 +00:00
|
|
|
|
*
|
2017-10-03 07:10:18 +00:00
|
|
|
|
* @param {string} [path] - The path to the Realm to reset.
|
2017-10-02 17:44:24 +00:00
|
|
|
|
* Throws error if reset is not possible.
|
|
|
|
|
* @example
|
|
|
|
|
* {
|
|
|
|
|
* const config = { sync: { user, url: 'realm://localhost:9080/~/myrealm' } };
|
|
|
|
|
* config.sync.error = (sender, error) => {
|
2017-11-06 12:51:33 +00:00
|
|
|
|
* if (error.name === 'ClientReset') {
|
2017-10-02 17:44:24 +00:00
|
|
|
|
* Realm.Sync.initiateClientReset(original_path);
|
|
|
|
|
* // copy required objects from Realm at error.config.path
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
*/
|
|
|
|
|
static initiateClientReset(path) {}
|
2016-11-14 18:48:50 +00:00
|
|
|
|
}
|
2016-10-04 22:02:51 +00:00
|
|
|
|
|
2016-12-06 16:42:15 +00:00
|
|
|
|
/**
|
2018-01-11 09:08:18 +00:00
|
|
|
|
* Change information passed when receiving sync `'change'` events.
|
|
|
|
|
*
|
|
|
|
|
* A ChangeEvent object can only be used within the callback which it is
|
2018-01-18 11:20:17 +00:00
|
|
|
|
* supplied to, and cannot be stored for use later. If the callback returns a
|
|
|
|
|
* promise, the ChangeEvent will remain valid until that promise is resolved
|
|
|
|
|
* (and no further notifications for that same Realm will be made until it is
|
|
|
|
|
* resolved). The Realms supplied by the change event do not need to be
|
2018-01-11 09:08:18 +00:00
|
|
|
|
* explicitly closed.
|
|
|
|
|
*
|
2016-12-06 16:42:15 +00:00
|
|
|
|
* @memberof Realm.Sync
|
|
|
|
|
*/
|
2016-12-20 16:00:39 +00:00
|
|
|
|
class ChangeEvent {
|
2016-12-06 16:42:15 +00:00
|
|
|
|
/**
|
2018-01-11 09:08:18 +00:00
|
|
|
|
* The virtual path of the changed Realm. This is the portion of the URL of
|
|
|
|
|
* the synced Realm after the protocol and the host name.
|
2016-12-06 16:42:15 +00:00
|
|
|
|
* @type {string}
|
|
|
|
|
*/
|
|
|
|
|
get path() {}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-01-11 09:08:18 +00:00
|
|
|
|
* The changed realm, with the changes applied.
|
2016-12-06 16:42:15 +00:00
|
|
|
|
* @type {Realm}
|
|
|
|
|
*/
|
|
|
|
|
get realm() {}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-01-11 09:08:18 +00:00
|
|
|
|
* The modified Realm prior to any of the changes being applied. This can
|
|
|
|
|
* be used in combination with the change indices to read the old values of
|
|
|
|
|
* any objects which were modified.
|
|
|
|
|
*
|
2016-12-06 16:42:15 +00:00
|
|
|
|
* @type {Realm}
|
|
|
|
|
*/
|
|
|
|
|
get oldRealm() {}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-01-11 09:08:18 +00:00
|
|
|
|
* The change indexes for all added, removed, and modified objects in the
|
|
|
|
|
* changed Realm. This object is a hashmap of object types to arrays of
|
|
|
|
|
* indexes for all changed objects:
|
|
|
|
|
*
|
|
|
|
|
* Note that deleting an object in Realm can cause other objects in the
|
|
|
|
|
* Realm to move, which will be reported as an insertion/deletion pair. For
|
|
|
|
|
* example, if there are ten objects in a Realm and the fifth is deleted,
|
|
|
|
|
* the change indices will be `{insertions: [4], deletions: [4, 9]}`.
|
|
|
|
|
*
|
2016-12-06 16:42:15 +00:00
|
|
|
|
* @example
|
2017-05-05 11:50:45 +00:00
|
|
|
|
* {
|
2018-01-11 09:08:18 +00:00
|
|
|
|
* MyObject: {
|
2016-12-06 16:42:15 +00:00
|
|
|
|
* insertions: [indexes...],
|
|
|
|
|
* deletions: [indexes...],
|
|
|
|
|
* modifications: [indexes...]
|
|
|
|
|
* },
|
2018-01-11 09:08:18 +00:00
|
|
|
|
* MyOtherObject:
|
2016-12-06 16:42:15 +00:00
|
|
|
|
* ...
|
|
|
|
|
* }
|
2018-01-11 09:08:18 +00:00
|
|
|
|
*
|
2016-12-06 16:42:15 +00:00
|
|
|
|
* @type {object}
|
|
|
|
|
*/
|
|
|
|
|
get changes() {}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 22:02:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* @typedef Realm.Sync~LogLevel
|
|
|
|
|
* @type {("error"|"info"|"debug")}
|
|
|
|
|
*/
|
|
|
|
|
|
2016-10-24 22:12:12 +00:00
|
|
|
|
/**
|
|
|
|
|
* Class that describes authentication errors in the Realm Object Server
|
|
|
|
|
* @memberof Realm.Sync
|
|
|
|
|
*/
|
|
|
|
|
class AuthError extends Error {
|
|
|
|
|
/**
|
|
|
|
|
* The numerical code for this error.
|
|
|
|
|
* @type {number}
|
|
|
|
|
*/
|
|
|
|
|
get code() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The unique help URI that describes this error.
|
|
|
|
|
* @type {string}
|
|
|
|
|
*/
|
|
|
|
|
get type() {}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-22 22:05:33 +00:00
|
|
|
|
/**
|
2017-10-01 09:21:17 +00:00
|
|
|
|
* Describes an error when an incompatible synced Realm is opened. The old version of the Realm can be accessed in readonly mode using the configuration() member
|
2017-09-22 22:05:33 +00:00
|
|
|
|
* @memberof Realm.Sync
|
|
|
|
|
*/
|
2017-10-01 09:29:04 +00:00
|
|
|
|
class IncompatibleSyncedRealmError {
|
2017-10-01 09:21:17 +00:00
|
|
|
|
/**
|
|
|
|
|
* The name of the error is 'IncompatibleSyncedRealmError'
|
|
|
|
|
*/
|
|
|
|
|
get name() {}
|
2017-11-01 13:44:40 +00:00
|
|
|
|
|
2017-09-22 22:05:33 +00:00
|
|
|
|
/**
|
|
|
|
|
* The {Realm~Configuration} of the backed up Realm.
|
|
|
|
|
* @type {Realm~Configuration}
|
|
|
|
|
*/
|
|
|
|
|
get configuration() {}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 22:02:51 +00:00
|
|
|
|
/**
|
2018-09-13 06:45:06 +00:00
|
|
|
|
* Class for creating user credentials
|
2016-10-04 22:02:51 +00:00
|
|
|
|
* @memberof Realm.Sync
|
|
|
|
|
*/
|
2018-09-13 06:45:06 +00:00
|
|
|
|
class Credentials {
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
2018-09-13 06:45:06 +00:00
|
|
|
|
* Creates credentials based on a login with a username and a password.
|
|
|
|
|
* @param {string} username The username of the user.
|
|
|
|
|
* @param {string} password The user's password.
|
|
|
|
|
* @param {boolean} [createUser] optional - `true` if the user should be created, `false` otherwise. If
|
|
|
|
|
* `true` is provided and the user exists, or `false` is provided and the user doesn't exist,
|
|
|
|
|
* an error will be thrown. If not specified, if the user doesn't exist, they will be created,
|
|
|
|
|
* otherwise, they'll be logged in if the password matches.
|
|
|
|
|
* @return {Credentials} An instance of `Credentials` that can be used in {@linkcode Realm.Sync.User.login|User.login}.
|
2017-03-20 09:40:56 +00:00
|
|
|
|
*/
|
2018-09-13 06:45:06 +00:00
|
|
|
|
static usernamePassword(username, password, createUser) {};
|
2016-11-11 02:21:57 +00:00
|
|
|
|
|
2018-01-05 08:38:53 +00:00
|
|
|
|
/**
|
2018-09-13 06:45:06 +00:00
|
|
|
|
* Creates credentials based on a Facebook login.
|
|
|
|
|
* @param {string} token A Facebook authentication token, obtained by logging into Facebook..
|
|
|
|
|
* @return {Credentials} An instance of `Credentials` that can be used in {@linkcode Realm.Sync.User.login|User.login}.
|
2018-01-05 08:38:53 +00:00
|
|
|
|
*/
|
2018-09-13 06:45:06 +00:00
|
|
|
|
static facebook(token) {};
|
2018-01-11 13:47:54 +00:00
|
|
|
|
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
2018-09-13 06:45:06 +00:00
|
|
|
|
* Creates credentials based on a Google login.
|
|
|
|
|
* @param {string} token A Google authentication token, obtained by logging into Google..
|
|
|
|
|
* @return {Credentials} An instance of `Credentials` that can be used in {@linkcode Realm.Sync.User.login|User.login}.
|
2017-03-20 09:40:56 +00:00
|
|
|
|
*/
|
2018-09-13 06:45:06 +00:00
|
|
|
|
static google(token) {};
|
2016-11-11 02:21:57 +00:00
|
|
|
|
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
2018-09-13 06:45:06 +00:00
|
|
|
|
* Creates credentials for an anonymous user. These can only be used once - using them a second
|
|
|
|
|
* time will result in a different user being logged in. If you need to get a user that has already logged
|
|
|
|
|
* in with the Anonymous credentials, use {@linkcode Realm.Sync.User.current|User.current} or {@linkcode Realm.Sync.User.all|User.all}
|
|
|
|
|
* @return {Credentials} An instance of `Credentials` that can be used in {@linkcode Realm.Sync.User.login|User.login}.
|
|
|
|
|
*/
|
|
|
|
|
static anonymous() {};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates credentials based on a login with a nickname. If multiple users try to login
|
|
|
|
|
* with the same nickname, they'll get the same underlying sync user.
|
|
|
|
|
* @param {string} value The nickname of the user.
|
|
|
|
|
* @param {boolean} [isAdmin] An optional parameter controlling whether the user is admin. Default is `false`.
|
|
|
|
|
* @return {Credentials} An instance of `Credentials` that can be used in {@linkcode Realm.Sync.User.login|User.login}.
|
|
|
|
|
*/
|
|
|
|
|
static nickname(value, isAdmin) {};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates credentials based on an Active Directory login.
|
|
|
|
|
* @param {string} token An access token, obtained by logging into Azure Active Directory.
|
|
|
|
|
* @return {Credentials} An instance of `Credentials` that can be used in {@linkcode Realm.Sync.User.login|User.login}.
|
|
|
|
|
*/
|
|
|
|
|
static azureAD(token) {};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates credentials based on a JWT login.
|
|
|
|
|
* @param {string} token A JSON Web Token, that will be validated against the server's configured rules.
|
|
|
|
|
* @param {string} [providerName] The name of the provider as configured in the Realm Object. If not specified, the default
|
|
|
|
|
* name - `jwt` - will be used.
|
|
|
|
|
* @return {Credentials} An instance of `Credentials` that can be used in {@linkcode Realm.Sync.User.login|User.login}.
|
|
|
|
|
*/
|
|
|
|
|
static jwt(token, providerName) {};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates credentials based on an admin token. Using this credential will not contact the Realm Object Server.
|
|
|
|
|
* @param {string} token The admin token.
|
|
|
|
|
* @return {Credentials} An instance of `Credentials` that can be used in {@linkcode Realm.Sync.User.login|User.login}.
|
|
|
|
|
*/
|
|
|
|
|
static adminToken(token) {};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates credentials with a custom provider and user identifier.
|
|
|
|
|
* @param {string} providerName Provider used to verify the credentials.
|
|
|
|
|
* @param {string} token A string identifying the user. Usually an identity token or a username.
|
|
|
|
|
* @param {userInfo} token Data describing the user further or null if the user does not have any extra data.
|
|
|
|
|
* The data will be serialized to JSON, so all values must be mappable to a valid JSON data type.
|
|
|
|
|
* @return {Credentials} An instance of `Credentials` that can be used in {@linkcode Realm.Sync.User.login|User.login}.
|
|
|
|
|
*/
|
|
|
|
|
static custom(providerName, token, userInfo) {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the identity provider for the credentials.
|
|
|
|
|
* @returns {string} The identity provider, such as Google, Facebook, etc.
|
|
|
|
|
*/
|
|
|
|
|
get identityProvider() {};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the access token.
|
|
|
|
|
* @returns {string}
|
|
|
|
|
*/
|
|
|
|
|
get token() {};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets additional user information associated with the credentials.
|
|
|
|
|
* @returns {object} A dictionary, containing the additional information.
|
2017-03-20 09:40:56 +00:00
|
|
|
|
*/
|
2018-09-13 06:45:06 +00:00
|
|
|
|
get userInfo() {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class for managing Sync users.
|
|
|
|
|
* @memberof Realm.Sync
|
|
|
|
|
*/
|
|
|
|
|
class User {
|
|
|
|
|
/**
|
|
|
|
|
* Logs the user in to the Realm Object Server.
|
|
|
|
|
* @param {string} server The url of the server that the user is authenticated against.
|
|
|
|
|
* @param {Credentials} credentials The credentials to use for authentication. Obtain them by calling one of
|
|
|
|
|
* the {@linkcode Realm.Sync.Credentials|Credentials} static methods.
|
|
|
|
|
* @return {Promise<User> | User} A {@linkcode Realm.Sync.User|User} object if the credentials are
|
|
|
|
|
* {@linkcode Realm.Sync.Credentials.adminToken|adminToken}, {@link Realm.Sync.User|`Promise<User>`} otherwise.
|
|
|
|
|
*/
|
|
|
|
|
static login(server, credentials) {}
|
2016-11-11 02:21:57 +00:00
|
|
|
|
|
2018-04-25 09:23:47 +00:00
|
|
|
|
/**
|
|
|
|
|
* Request a password reset email to be sent to a user's email.
|
|
|
|
|
* This will not throw an exception, even if the email doesn't belong to a Realm Object Server user.
|
2018-08-28 13:01:32 +00:00
|
|
|
|
*
|
2018-04-25 09:23:47 +00:00
|
|
|
|
* This can only be used for users who authenticated with the 'password' provider, and passed a valid email address as a username.
|
2018-08-28 13:01:32 +00:00
|
|
|
|
*
|
2018-04-25 09:23:47 +00:00
|
|
|
|
* @param {string} server - authentication server
|
|
|
|
|
* @param {string} email - The email that corresponds to the user's username.
|
|
|
|
|
* @return {Promise<void>} A promise which is resolved when the request has been sent.
|
|
|
|
|
*/
|
|
|
|
|
static requestPasswordReset(server, email) {}
|
2018-08-28 13:01:32 +00:00
|
|
|
|
|
2018-04-25 09:23:47 +00:00
|
|
|
|
/**
|
|
|
|
|
* Complete the password reset flow by using the reset token sent to the user's email as a one-time authorization token to change the password.
|
2018-08-28 13:01:32 +00:00
|
|
|
|
*
|
2018-04-25 09:23:47 +00:00
|
|
|
|
* By default, Realm Object Server will send a link to the user's email that will redirect to a webpage where they can enter their new password.
|
|
|
|
|
* If you wish to provide a native UX, you may wish to modify the password authentication provider to use a custom URL with deep linking, so you can
|
|
|
|
|
* open the app, extract the token, and navigate to a view that allows to change the password within the app.
|
2018-08-28 13:01:32 +00:00
|
|
|
|
*
|
2018-04-25 09:23:47 +00:00
|
|
|
|
* @param {string} server - authentication server
|
2018-09-13 06:45:06 +00:00
|
|
|
|
* @param {string} resetToken - The token that was sent to the user's email address.
|
|
|
|
|
* @param {string} newPassword - The user's new password.
|
2018-04-25 09:23:47 +00:00
|
|
|
|
* @return {Promise<void>} A promise which is resolved when the request has been sent.
|
|
|
|
|
*/
|
2018-09-13 06:45:06 +00:00
|
|
|
|
static completePasswordReset(server, resetToken, newPassword) {}
|
2018-04-25 09:23:47 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Request an email confirmation email to be sent to a user's email.
|
|
|
|
|
* This will not throw an exception, even if the email doesn't belong to a Realm Object Server user.
|
2018-08-28 13:01:32 +00:00
|
|
|
|
*
|
2018-04-25 09:23:47 +00:00
|
|
|
|
* @param {string} server - authentication server
|
|
|
|
|
* @param {string} email - The email that corresponds to the user's username.
|
|
|
|
|
* @return {Promise<void>} A promise which is resolved when the request has been sent.
|
|
|
|
|
*/
|
|
|
|
|
static requestEmailConfirmation(server, email) {}
|
2018-08-28 13:01:32 +00:00
|
|
|
|
|
2018-04-25 09:23:47 +00:00
|
|
|
|
/**
|
|
|
|
|
* Complete the email confirmation flow by using the confirmation token sent to the user's email as a one-time authorization token to confirm their email.
|
2018-08-28 13:01:32 +00:00
|
|
|
|
*
|
2018-04-25 09:23:47 +00:00
|
|
|
|
* By default, Realm Object Server will send a link to the user's email that will redirect to a webpage where they can enter their new password.
|
|
|
|
|
* If you wish to provide a native UX, you may wish to modify the password authentication provider to use a custom URL with deep linking, so you can
|
|
|
|
|
* open the app, extract the token, and navigate to a view that allows to confirm the email within the app.
|
2018-08-28 13:01:32 +00:00
|
|
|
|
*
|
2018-04-25 09:23:47 +00:00
|
|
|
|
* @param {string} server - authentication server
|
2018-09-13 06:45:06 +00:00
|
|
|
|
* @param {string} confirmationToken - The token that was sent to the user's email address.
|
2018-04-25 09:23:47 +00:00
|
|
|
|
* @return {Promise<void>} A promise which is resolved when the request has been sent.
|
|
|
|
|
*/
|
2018-09-13 06:45:06 +00:00
|
|
|
|
static confirmEmail(server, confirmationToken) {}
|
2016-11-11 02:21:57 +00:00
|
|
|
|
|
2018-08-28 13:01:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Creates a new sync user instance from the serialized representation.
|
|
|
|
|
* @param {object} serialized - the serialized version of the user, obtained by calling {@link User#serialize}.
|
|
|
|
|
*/
|
|
|
|
|
static deserialize(serialized) {}
|
|
|
|
|
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* A dictionary containing users that are currently logged in.
|
|
|
|
|
* The keys in the dictionary are user identities, values are corresponding User objects.
|
|
|
|
|
* @type {object}
|
|
|
|
|
*/
|
|
|
|
|
static get all() {}
|
2016-11-11 02:21:57 +00:00
|
|
|
|
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get the currently logged in user.
|
|
|
|
|
* Throws error if > 1 user logged in, returns undefined if no users logged in.
|
|
|
|
|
* @type {User}
|
|
|
|
|
*/
|
|
|
|
|
static get current() {}
|
2017-05-05 11:50:45 +00:00
|
|
|
|
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* Gets the server URL that was used for authentication.
|
|
|
|
|
* @type {string}
|
|
|
|
|
*/
|
|
|
|
|
get server() {}
|
2017-02-01 20:45:55 +00:00
|
|
|
|
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
2017-05-05 11:50:45 +00:00
|
|
|
|
* Gets the identity of this user on the Realm Object Server.
|
2017-03-20 09:40:56 +00:00
|
|
|
|
* The identity is a guaranteed to be unique among all users on the Realm Object Server.
|
|
|
|
|
* @type {string}
|
|
|
|
|
*/
|
|
|
|
|
get identity() {}
|
2017-02-01 20:45:55 +00:00
|
|
|
|
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
2017-05-05 11:50:45 +00:00
|
|
|
|
* Gets this user's refresh token. This is the user's credential for accessing the Realm
|
2017-03-20 09:40:56 +00:00
|
|
|
|
* Object Server and should be treated as sensitive data.
|
|
|
|
|
* @type {string}
|
|
|
|
|
*/
|
|
|
|
|
get token() {}
|
2017-02-01 20:45:55 +00:00
|
|
|
|
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
2018-01-11 13:47:54 +00:00
|
|
|
|
* Returns true if this user is an administrator.
|
2017-03-20 09:40:56 +00:00
|
|
|
|
* @type {bool}
|
|
|
|
|
*/
|
|
|
|
|
get isAdmin() {}
|
2017-02-01 20:45:55 +00:00
|
|
|
|
|
2018-01-11 13:47:54 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns true if the token is an administrator token.
|
|
|
|
|
*/
|
|
|
|
|
get isAdminToken() {}
|
|
|
|
|
|
2018-05-30 10:54:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* Creates the configuration object required to open a synchronized Realm.
|
|
|
|
|
*
|
|
|
|
|
* @param {Realm.PartialConfiguration} config - optional parameters that should override any default settings.
|
|
|
|
|
* @returns {Realm.Configuration} the full Realm configuration
|
|
|
|
|
* @since 3.0.0
|
|
|
|
|
*/
|
|
|
|
|
createConfiguration(config) {}
|
|
|
|
|
|
2018-08-28 13:01:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Serializes a user to an object, that can be persisted or passed to another component to create a new instance
|
|
|
|
|
* by calling {@link User.deserialize}. The serialized user instance includes the user's refresh token and should
|
|
|
|
|
* be treated as sensitive data.
|
|
|
|
|
* @returns {object} an object, containing the user identity, server url, and refresh token.
|
|
|
|
|
*/
|
|
|
|
|
serialize() {}
|
|
|
|
|
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
2018-10-15 12:20:19 +00:00
|
|
|
|
* Logs out the user from the Realm Object Server. Once the Object Server has confirmed the logout the user
|
|
|
|
|
* credentials will be deleted from this device.
|
|
|
|
|
* @return {Promise<void>} A promise which is resolved when the user has logged out both locally and on the server.
|
2017-03-20 09:40:56 +00:00
|
|
|
|
*/
|
|
|
|
|
logout() {}
|
2017-02-01 20:45:55 +00:00
|
|
|
|
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get the management realm for this User.
|
|
|
|
|
* This Realm can be used to control access and permissions for Realms owned by the user.
|
|
|
|
|
* This includes giving others access to the Realms.
|
|
|
|
|
* @returns {Realm}
|
|
|
|
|
*/
|
|
|
|
|
openManagementRealm() {}
|
2017-07-08 17:30:25 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get account information for a user. (requires administrator privilidges)
|
|
|
|
|
* @param {string} provider - the provider to query for user account information (ex. 'password')
|
|
|
|
|
* @param {string} username - the target username which account information should be retrieved
|
2018-09-13 06:45:06 +00:00
|
|
|
|
* @returns {Promise} - a promise that will be resolved with the retrieved account information as JSON object
|
2017-07-08 17:30:25 +00:00
|
|
|
|
* @example
|
|
|
|
|
* {
|
|
|
|
|
* "provider_id": "user@email.co",
|
|
|
|
|
* "provider": "password",
|
|
|
|
|
* "user": {
|
|
|
|
|
* "id": "06ac9a0a-a96a-4ee1-b53c-b05a7542035a",
|
|
|
|
|
* "isAdmin": true,
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
*/
|
2017-07-10 09:34:50 +00:00
|
|
|
|
retrieveAccount(provider, username) {}
|
2017-08-29 13:23:22 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Asynchronously retrieves all permissions associated with the user calling this method.
|
|
|
|
|
* @param {string} recipient the optional recipient of the permission. Can be either
|
|
|
|
|
* 'any' which is the default, or 'currentUser' or 'otherUser' if you want only permissions
|
|
|
|
|
* belonging to the user or *not* belonging to the user.
|
2017-10-01 05:50:31 +00:00
|
|
|
|
* @returns {Promise} a Promise with a queryable collection of permission objects that provides detailed
|
2017-08-29 13:23:22 +00:00
|
|
|
|
* information regarding the granted access.
|
|
|
|
|
* The collection is a live query similar to what you would get by callig Realm.objects,
|
|
|
|
|
* so the same features apply - you can listen for notifications or filter it.
|
|
|
|
|
*/
|
|
|
|
|
getGrantedPermissions(recipient) { }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Changes the permissions of a Realm.
|
|
|
|
|
* @param {object} condition - A condition that will be used to match existing users against.
|
|
|
|
|
* This should be an object, containing either the key 'userId', or 'metadataKey' and 'metadataValue'.
|
|
|
|
|
* @param {string} realmUrl - The path to the Realm that you want to apply permissions to.
|
|
|
|
|
* @param {string} accessLevel - The access level you want to set: 'none', 'read', 'write' or 'admin'.
|
2017-09-27 15:53:09 +00:00
|
|
|
|
* @returns {Promise} a Promise that, upon completion, indicates that the permissions have been
|
|
|
|
|
* successfully applied by the server. It will be resolved with the
|
2017-08-29 13:23:22 +00:00
|
|
|
|
* {@link PermissionChange PermissionChange} object that refers to the applied permission.
|
|
|
|
|
*/
|
|
|
|
|
applyPermissions(condition, realmUrl, accessLevel) { }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generates a token that can be used for sharing a Realm.
|
2017-09-27 15:53:09 +00:00
|
|
|
|
* @param {string} realmUrl - The Realm URL whose permissions settings should be changed. Use * to change
|
2017-08-29 13:23:22 +00:00
|
|
|
|
* the permissions of all Realms managed by this user.
|
2017-09-27 15:53:09 +00:00
|
|
|
|
* @param {string} accessLevel - The access level to grant matching users. Note that the access level
|
|
|
|
|
* setting is additive, i.e. you cannot revoke permissions for users who previously had a higher access level.
|
2017-08-29 13:23:22 +00:00
|
|
|
|
* Can be 'read', 'write' or 'admin'.
|
|
|
|
|
* @param {Date} [expiresAt] - Optional expiration date of the offer. If set to null, the offer doesn't expire.
|
|
|
|
|
* @returns {string} - A token that can be shared with another user, e.g. via email or message and then consumed by
|
2017-09-27 15:53:09 +00:00
|
|
|
|
* User.acceptPermissionOffer to obtain permissions to a Realm.
|
2017-08-29 13:23:22 +00:00
|
|
|
|
*/
|
|
|
|
|
offerPermissions(realmUrl, accessLevel, expiresAt) { }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Consumes a token generated by {@link Realm#Sync#User#offerPermissions offerPermissions} to obtain permissions to a shared Realm.
|
|
|
|
|
* @param {string} token - The token, generated by User.offerPermissions
|
|
|
|
|
* @returns {string} The url of the Realm that the token has granted permissions to.
|
|
|
|
|
*/
|
|
|
|
|
acceptPermissionOffer(token) { }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Invalidates a permission offer.
|
|
|
|
|
* Invalidating an offer prevents new users from consuming its token. It doesn't revoke any permissions that have
|
|
|
|
|
* already been granted.
|
2017-09-27 15:53:09 +00:00
|
|
|
|
* @param {string|PermissionOffer} permissionOfferOrToken - Either the token or the entire
|
|
|
|
|
* {@link PermissionOffer PermissionOffer} object that was generated with
|
|
|
|
|
* {@link Realm#Sync#User#offerPermissions offerPermissions}.
|
2017-08-29 13:23:22 +00:00
|
|
|
|
*/
|
|
|
|
|
invalidatePermissionOffer(permissionOfferOrToken) { }
|
2018-09-13 06:45:06 +00:00
|
|
|
|
|
|
|
|
|
// Deprecated
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated to be removed in future versions. Use User.login(server, Credentials.usernamePassword) instead.
|
|
|
|
|
*/
|
|
|
|
|
static register(server, username, password) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated to be removed in future versions. Use User.login(server, Credentials.adminToken) instead.
|
|
|
|
|
*/
|
|
|
|
|
static adminUser(adminToken, server) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated to be removed in future versions. Use User.login(server, Credentials.SOME-PROVIDER) instead.
|
|
|
|
|
*/
|
|
|
|
|
static registerWithProvider(server, options) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated to be removed in future versions. Use User.login(server, Credentials.SOME-PROVIDER) instead.
|
|
|
|
|
*/
|
|
|
|
|
static authenticate(server, provider, options) {}
|
2017-02-01 20:45:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-05-05 11:50:45 +00:00
|
|
|
|
* An object encapsulating a Realm Object Server session. Sessions represent the communication between the
|
2017-02-01 20:45:55 +00:00
|
|
|
|
* client (and a local Realm file on disk), and the server (and a remote Realm at a given URL stored on a Realm Object Server).
|
2017-05-05 11:50:45 +00:00
|
|
|
|
* Sessions are always created by the SDK and vended out through various APIs. The lifespans of sessions
|
2017-02-01 20:45:55 +00:00
|
|
|
|
* associated with Realms are managed automatically.
|
|
|
|
|
* @memberof Realm.Sync
|
|
|
|
|
*/
|
|
|
|
|
class Session {
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* Gets the Sync-part of the configuration that the corresponding Realm was
|
|
|
|
|
* constructed with.
|
|
|
|
|
* @type {object}
|
|
|
|
|
*/
|
|
|
|
|
get config() {}
|
2017-02-01 20:45:55 +00:00
|
|
|
|
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* Gets the User that this session was created with.
|
|
|
|
|
* @type {User}
|
|
|
|
|
*/
|
|
|
|
|
get user() {}
|
2017-02-01 20:45:55 +00:00
|
|
|
|
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* Gets the URL of the Realm Object Server that this session is connected to.
|
|
|
|
|
* @type {string}
|
|
|
|
|
*/
|
|
|
|
|
get url() {}
|
2017-02-01 20:45:55 +00:00
|
|
|
|
|
2017-03-20 09:40:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* Gets the current state of the session.
|
|
|
|
|
* Can be either:
|
|
|
|
|
* - "active": The session is connected to the Realm Object Server and is actively transferring data.
|
|
|
|
|
* - "inactive": The session is not currently communicating with the Realm Object Server.
|
|
|
|
|
* - "invalid": A non-recoverable error has occurred, and this session is semantically invalid. A new session should be created.
|
|
|
|
|
* @type {string}
|
|
|
|
|
*/
|
|
|
|
|
get state() {}
|
2017-09-08 22:59:06 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Register a progress notification callback on a session object
|
|
|
|
|
* @param {string} direction - The progress direction to register for.
|
2017-09-27 15:53:09 +00:00
|
|
|
|
* Can be either:
|
2017-09-08 22:59:06 +00:00
|
|
|
|
* - `download` - report download progress
|
|
|
|
|
* - `upload` - report upload progress
|
|
|
|
|
* @param {string} mode - The progress notification mode to use for the registration.
|
|
|
|
|
* Can be either:
|
|
|
|
|
* - `reportIndefinitely` - the registration will stay active until the callback is unregistered
|
|
|
|
|
* - `forCurrentlyOutstandingWork` - the registration will be active until only the currently transferable bytes are synced
|
|
|
|
|
* @param {callback(transferred, transferable)} callback - called with the following arguments:
|
|
|
|
|
* - `transferred` - the current number of bytes already transferred
|
|
|
|
|
* - `transferable` - the total number of transferable bytes (the number of bytes already transferred plus the number of bytes pending transfer)
|
|
|
|
|
*/
|
|
|
|
|
addProgressNotification(direction, mode, progressCallback) {}
|
|
|
|
|
|
|
|
|
|
/** Unregister a progress notification callback that was previously registered with addProgressNotification.
|
|
|
|
|
* Calling the function multiple times with the same callback is ignored.
|
|
|
|
|
* @param {callback(transferred, transferable)} callback - a previously registered progress callback
|
|
|
|
|
*/
|
|
|
|
|
removeProgressNotification(progressCallback) {}
|
2018-08-10 08:39:03 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2018-08-15 13:52:37 +00:00
|
|
|
|
* Registers a connection notification on the session object. This will be notified about changes to the
|
|
|
|
|
* underlying connection to the Realm Object Server.
|
2018-08-10 08:39:03 +00:00
|
|
|
|
*
|
2018-08-15 13:52:37 +00:00
|
|
|
|
* @param {callback(newState, oldState)} callback - called with the following arguments:
|
|
|
|
|
* - `newState` - the new state of the connection
|
|
|
|
|
* - `oldState` - the state the connection transitioned from.
|
2018-08-10 08:39:03 +00:00
|
|
|
|
*/
|
|
|
|
|
addConnectionNotification(connectionCallback) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unregister a state notification callback that was previously registered with addStateNotification.
|
|
|
|
|
* Calling the function multiple times with the same callback is ignored.
|
|
|
|
|
*
|
|
|
|
|
* @param {callback(oldState, newState)} callback - a previously registered state callback.
|
|
|
|
|
*/
|
|
|
|
|
removeConnectionNotification(connectionCallback) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the current state of the connection to the server. Multiple sessions might share the same underlying
|
|
|
|
|
* connection. In that case, any connection change is sent to all sessions.
|
|
|
|
|
*
|
|
|
|
|
* Can be either:
|
|
|
|
|
* - Realm.Sync.ConnectionState.Disconnected: No connection to the server is available.
|
|
|
|
|
* - Realm.Sync.ConnectionState.Connecting: An attempt to connect to the server is in progress.
|
|
|
|
|
* - Realm.Sync.ConnectionState.Connected: The connection to the server is active and data can be synchronized.
|
|
|
|
|
*
|
|
|
|
|
* Data will only be synchronized with the Realm ObjectServer if this method returns `Connected` and `state()`
|
|
|
|
|
* returns `Active` or `Dying`.
|
|
|
|
|
*
|
|
|
|
|
* @type {string}
|
|
|
|
|
*/
|
|
|
|
|
connectionState() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns `true` if the session is currently active and connected to the server, `false` if not.
|
|
|
|
|
*
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
isConnected() {}
|
2018-09-12 14:04:22 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2018-09-14 09:38:40 +00:00
|
|
|
|
* Resumes a sync session that has been paused.
|
|
|
|
|
*
|
2018-09-12 14:04:22 +00:00
|
|
|
|
* This method is asynchronous so in order to know when the session has started you will need
|
|
|
|
|
* to add a connection notification with `addConnectionNotification`.
|
2018-09-14 09:38:40 +00:00
|
|
|
|
*
|
|
|
|
|
* This method is idempotent so it will be a no-op if the session is already started.
|
2018-09-12 14:04:22 +00:00
|
|
|
|
*/
|
2018-09-14 09:38:40 +00:00
|
|
|
|
resume() {}
|
2018-09-12 14:04:22 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2018-09-14 09:38:40 +00:00
|
|
|
|
* Pause a sync session.
|
|
|
|
|
*
|
2018-09-12 14:04:22 +00:00
|
|
|
|
* This method is asynchronous so in order to know when the session has started you will need
|
|
|
|
|
* to add a connection notification with `addConnectionNotification`.
|
2018-09-14 09:38:40 +00:00
|
|
|
|
*
|
|
|
|
|
* This method is idempotent so it will be a no-op if the session is already paused.
|
2018-09-12 14:04:22 +00:00
|
|
|
|
*/
|
2018-09-14 09:38:40 +00:00
|
|
|
|
pause() {}
|
2018-08-10 08:39:03 +00:00
|
|
|
|
|
2016-10-04 22:02:51 +00:00
|
|
|
|
}
|
2017-05-18 11:40:25 +00:00
|
|
|
|
|
2018-02-20 12:40:54 +00:00
|
|
|
|
/**
|
2018-09-14 09:38:40 +00:00
|
|
|
|
* An object encapsulating query-based sync subscriptions.
|
2018-02-20 12:40:54 +00:00
|
|
|
|
* @memberof Realm.Sync
|
|
|
|
|
*/
|
|
|
|
|
class Subscription {
|
|
|
|
|
/**
|
|
|
|
|
* Gets the current state of the subscription.
|
|
|
|
|
* Can be either:
|
2018-09-14 09:38:40 +00:00
|
|
|
|
* - Realm.Sync.SubscriptionState.Error: An error occurred while creating or processing the query-based sync subscription.
|
2018-02-20 12:40:54 +00:00
|
|
|
|
* - Realm.Sync.SubscriptionState.Creating: The subscription is being created.
|
|
|
|
|
* - Realm.Sync.SubscriptionState.Pending: The subscription was created, but has not yet been processed by the sync server.
|
|
|
|
|
* - Realm.Sync.SubscriptionState.Complete: The subscription has been processed by the sync server and data is being synced to the device.
|
|
|
|
|
* - Realm.Sync.SubscriptionState.Invalidated: The subscription has been removed.
|
|
|
|
|
* @type {number}
|
|
|
|
|
*/
|
|
|
|
|
get state() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the error message. `undefined` if no error.
|
|
|
|
|
* @type {string}
|
|
|
|
|
*/
|
|
|
|
|
get error() {}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-09-14 09:38:40 +00:00
|
|
|
|
* Unsubscribe a query-based synced `Realm.Results`. The state will change to `Realm.Sync.SubscriptionState.Invalidated`.
|
2018-02-20 12:40:54 +00:00
|
|
|
|
* The `Realm.Results` will not produce any meaningful values. Moreover, any objects matching the query will be
|
|
|
|
|
* removed if they are not matched by any other query. The object removal is done asynchronously.
|
|
|
|
|
*/
|
|
|
|
|
unsubscribe() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds a listener `callback` which will be called when the state of the subscription changes.
|
2018-03-13 11:45:23 +00:00
|
|
|
|
* @param {function(subscription, state)} callback - A function to be called when changes to the subscription occur.
|
2018-02-20 12:40:54 +00:00
|
|
|
|
* @throws {Error} If `callback` is not a function.
|
|
|
|
|
* @example
|
|
|
|
|
* let subscription = results.subscribe();
|
|
|
|
|
* subscription.addListener((subscription, state) => {
|
|
|
|
|
* switch (state) {
|
|
|
|
|
* case Realm.Sync.SubscriptionState.Complete:
|
|
|
|
|
* // results is ready to be consumed
|
|
|
|
|
* break;
|
|
|
|
|
* case Realm.Sync.SubscriptionState.Error:
|
|
|
|
|
* console.log('An error occurred: ', subscription.error);
|
|
|
|
|
* break;
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
*/
|
|
|
|
|
addListener(callback) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the listener `callback` from the subscription instance.
|
2018-03-13 11:45:23 +00:00
|
|
|
|
* @param {function(subscription, state)} callback - Callback function that was previously
|
2018-02-20 12:40:54 +00:00
|
|
|
|
* added as a listener through the {@link Subscription#addListener addListener} method.
|
|
|
|
|
* @throws {Error} If `callback` is not a function.
|
|
|
|
|
*/
|
|
|
|
|
removeListener(callback) {}
|
2018-03-21 17:18:37 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove all listeners from the subscription instance.
|
|
|
|
|
*/
|
|
|
|
|
removeAllListeners() {}
|
2018-02-20 12:40:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 09:08:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* A Realm Worker can be used to process Sync events in multiple automatically-managed child processes.
|
|
|
|
|
*
|
|
|
|
|
* Similar to Web Workers, a Worker is initialized by passing it the name of a module which should be loaded in the new process.
|
|
|
|
|
* The module should export a function for each even type it wishes to handle, which will be called when that event is emitted.
|
|
|
|
|
*
|
|
|
|
|
* Currently supported events:
|
|
|
|
|
*
|
|
|
|
|
* * `'available'`: Emitted whenever there is a new Realm which has a virtual
|
|
|
|
|
* path matching the filter regex, either due to the Realm being newly created
|
|
|
|
|
* or the listener being added. The virtual path (i.e. the portion of the
|
|
|
|
|
* URL after the protocol and hostname) is passed as an argument.
|
|
|
|
|
* * `'change'`: Emitted whenever the data within a Realm matching the filter
|
|
|
|
|
* regex has changed. A [ChangeEvent]{@link Realm.Sync.ChangeEvent} argument
|
|
|
|
|
* is passed containing information about which Realm changed and what
|
|
|
|
|
* objects within the Realm changed.
|
2018-05-08 20:28:37 +00:00
|
|
|
|
* * `'delete'`: Emitted whenever a Realm matching the filter regex has been
|
|
|
|
|
* deleted from the server. The virtual path of the Realm being deleted is
|
|
|
|
|
* passed as an argument.
|
2018-01-11 09:08:18 +00:00
|
|
|
|
*
|
|
|
|
|
* Worker automatically spawns child processes as needed to handle events in
|
|
|
|
|
* parallel (up to the limit specified in the `options` parameter). Events for
|
|
|
|
|
* each specific Realm will be processes in serial in the order in which the
|
|
|
|
|
* events occurred, but may not all be processed in the same child.
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* // my-worker.js
|
|
|
|
|
* function onchange(path) {
|
|
|
|
|
* console.log(`Realm created at ${path}`);
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* function onavailable(change) {
|
|
|
|
|
* console.log(`Realm at ${change.path} changed`);
|
|
|
|
|
* }
|
|
|
|
|
*
|
2018-05-08 20:28:37 +00:00
|
|
|
|
* function ondelete(path) {
|
|
|
|
|
* console.log(`Realm at ${path} deleted`);
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* module.exports = {onchange, oncavailable, ondelete};
|
2018-01-11 09:08:18 +00:00
|
|
|
|
*
|
|
|
|
|
* // server script
|
|
|
|
|
* Realm.Sync.addListener(realmServerURL, adminUser, '.*', new Realm.Worker('my-worker'));
|
|
|
|
|
*
|
|
|
|
|
* @memberof Realm
|
|
|
|
|
*/
|
|
|
|
|
class Worker {
|
|
|
|
|
/**
|
|
|
|
|
* Create a new Worker which executes the given module.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} moduleName - The module to load in the worker process.
|
|
|
|
|
* @param {object} [options] - An object containing option properties to configure the worker.
|
|
|
|
|
* Available properties are as follows:
|
|
|
|
|
*
|
|
|
|
|
* * `maxWorkers`: The maximum number of child processes to spawn. Defaults to `os.cpus().length`.
|
|
|
|
|
* * `env`: An object containing environment variables to set for the child process.
|
|
|
|
|
* * `execArgv`: Command-line arguments to pass to the `node` worker processes.
|
|
|
|
|
*/
|
|
|
|
|
constructor(moduleName, options = {}) {}
|
|
|
|
|
}
|
2017-05-18 11:40:25 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2018-05-16 08:46:32 +00:00
|
|
|
|
* Custom Data Connectors.
|
2017-05-18 11:40:25 +00:00
|
|
|
|
* @memberof Realm.Sync
|
|
|
|
|
*/
|
|
|
|
|
class Adapter {
|
|
|
|
|
/**
|
2018-05-01 08:26:59 +00:00
|
|
|
|
* Create a new Adapter to monitor and process changes made across multiple Realms
|
2018-01-11 09:08:18 +00:00
|
|
|
|
* @param {string} localPath - the local path where realm files are stored
|
|
|
|
|
* @param {string} serverUrl - the sync server to listen to
|
2018-09-13 06:45:06 +00:00
|
|
|
|
* @param {SyncUser} adminUser - an admin user obtained by calling {@linkcode Realm.Sync.User.login|User.login} with admin credentials.
|
2017-12-01 09:15:56 +00:00
|
|
|
|
* @param {string} regex - a regular expression used to determine which changed Realms should be monitored -
|
2017-05-18 11:40:25 +00:00
|
|
|
|
* use `.*` to match all all Realms
|
2018-01-11 09:08:18 +00:00
|
|
|
|
* @param {function(realmPath)} changeCallback - called when a new transaction is available
|
2017-05-18 11:40:25 +00:00
|
|
|
|
* to process for the given realm_path
|
2018-05-14 12:16:52 +00:00
|
|
|
|
* @param {Realm.Sync~SSLConfiguration} [ssl] - SSL configuration for the spawned sync sessions.
|
2017-05-18 11:40:25 +00:00
|
|
|
|
*/
|
2018-05-14 12:16:52 +00:00
|
|
|
|
constructor(localPath, serverUrl, adminUser, regex, changeCallback, ssl) {}
|
2017-05-18 11:40:25 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the Array of current instructions for the given Realm.
|
|
|
|
|
* @param {string} path - the path for the Realm being monitored
|
2018-05-16 08:46:32 +00:00
|
|
|
|
*
|
|
|
|
|
* The following Instructions can be returned. 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|SET|DELETE|CLEAR|CHANGE_IDENTITY|LIST_SET|LIST_INSERT|LIST_ERASE|LIST_CLEAR|ADD_TYPE|ADD_PROPERTY)}
|
|
|
|
|
* @property 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
|
|
|
|
|
* @property 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
|
|
|
|
|
* @property DELETE - delete an exising object
|
|
|
|
|
* - `object_type` - type of the object
|
|
|
|
|
* - `identity` - primary key value or row index for the object
|
|
|
|
|
* @property CLEAR - delete all objects of a given type
|
|
|
|
|
* - `object_type` - type of the object
|
|
|
|
|
* @property 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
|
|
|
|
|
* @property 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
|
|
|
|
|
* @property 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
|
|
|
|
|
* @property 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
|
|
|
|
|
* @property 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 {@link Realm~ObjectSchema}
|
|
|
|
|
* @property ADD_PROPERTIES - add properties to an existing type
|
|
|
|
|
* - `object_type` - name of the type
|
|
|
|
|
* - `properties` - Property map as described in {@link Realm~ObjectSchema}
|
|
|
|
|
* @property 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
|
|
|
|
|
*
|
2017-05-18 11:40:25 +00:00
|
|
|
|
* @returns {Array(instructions)} or {undefined} if all transactions have been processed
|
|
|
|
|
*/
|
|
|
|
|
current(path) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Advance the to the next transaction indicating that you are done processing the current
|
|
|
|
|
* instructions for the given Realm.
|
|
|
|
|
* @param {string} path - the path for the Realm to advance
|
|
|
|
|
*/
|
|
|
|
|
advance(path) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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`
|
|
|
|
|
* @param {string} path - the path for the Realm to open
|
2018-09-13 06:45:06 +00:00
|
|
|
|
* @param {Realm~ObjectSchema[]} [schema] - optional schema to apply when opening the Realm
|
2017-05-18 11:40:25 +00:00
|
|
|
|
* @returns {Realm}
|
|
|
|
|
*/
|
2017-11-01 13:44:40 +00:00
|
|
|
|
realmAtPath(path, schema) {}
|
2017-05-18 11:40:25 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Close the adapter and all opened Realms.
|
|
|
|
|
*/
|
|
|
|
|
close() {}
|
|
|
|
|
}
|
|
|
|
|
|