2016-02-18 19:59:34 +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.
|
|
|
|
|
//
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2016-01-29 08:46:25 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2016-02-09 00:41:37 +00:00
|
|
|
|
* A Realm instance represents a Realm database.
|
2016-01-29 08:46:25 +00:00
|
|
|
|
* ```js
|
|
|
|
|
* const Realm = require('realm');
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
|
|
|
|
class Realm {
|
2017-07-12 11:02:21 +00:00
|
|
|
|
/**
|
|
|
|
|
* Indicates if this Realm contains any objects.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
* @readonly
|
|
|
|
|
* @since 1.10.0
|
|
|
|
|
*/
|
|
|
|
|
get empty() {}
|
|
|
|
|
|
2016-04-28 00:56:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* The path to the file where this Realm is stored.
|
|
|
|
|
* @type {string}
|
|
|
|
|
* @readonly
|
|
|
|
|
* @since 0.12.0
|
|
|
|
|
*/
|
|
|
|
|
get path() {}
|
|
|
|
|
|
2016-05-02 20:21:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Indicates if this Realm was opened as read-only.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
* @readonly
|
|
|
|
|
* @since 0.12.0
|
|
|
|
|
*/
|
|
|
|
|
get readOnly() {}
|
|
|
|
|
|
2016-05-03 01:28:54 +00:00
|
|
|
|
/**
|
|
|
|
|
* A normalized representation of the schema provided in the
|
|
|
|
|
* {@link Realm~Configuration Configuration} when this Realm was constructed.
|
|
|
|
|
* @type {Realm~ObjectSchema[]}
|
|
|
|
|
* @readonly
|
|
|
|
|
* @since 0.12.0
|
|
|
|
|
*/
|
|
|
|
|
get schema() {}
|
|
|
|
|
|
2016-04-28 00:56:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* The current schema version of this Realm.
|
|
|
|
|
* @type {number}
|
|
|
|
|
* @readonly
|
|
|
|
|
* @since 0.12.0
|
|
|
|
|
*/
|
|
|
|
|
get schemaVersion() {}
|
|
|
|
|
|
2017-08-21 15:48:53 +00:00
|
|
|
|
/**
|
|
|
|
|
* Indicates if this Realm is in a write transaction.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
* @readonly
|
|
|
|
|
* @since 1.10.3
|
|
|
|
|
*/
|
|
|
|
|
get isInTransaction() {}
|
|
|
|
|
|
2017-02-01 20:45:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* Gets the sync session if this is a synced Realm
|
|
|
|
|
* @type {Session}
|
|
|
|
|
*/
|
|
|
|
|
get syncSession() {}
|
|
|
|
|
|
2016-01-29 08:46:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Create a new `Realm` instance using the provided `config`. If a Realm does not yet exist
|
|
|
|
|
* at `config.path` (or {@link Realm.defaultPath} if not provided), then this constructor
|
|
|
|
|
* will create it with the provided `config.schema` (which is _required_ in this case).
|
2016-03-07 20:23:04 +00:00
|
|
|
|
* Otherwise, the instance will access the existing Realm from the file at that path.
|
2016-01-29 08:46:25 +00:00
|
|
|
|
* In this case, `config.schema` is _optional_ or not have changed, unless
|
2016-03-07 20:23:04 +00:00
|
|
|
|
* `config.schemaVersion` is incremented, in which case the Realm will be automatically
|
2016-01-29 08:46:25 +00:00
|
|
|
|
* migrated to use the new schema.
|
|
|
|
|
* @param {Realm~Configuration} [config] - **Required** when first creating the Realm.
|
2016-03-17 22:07:15 +00:00
|
|
|
|
* @throws {Error} If anything in the provided `config` is invalid.
|
2016-01-29 08:46:25 +00:00
|
|
|
|
*/
|
|
|
|
|
constructor(config) {}
|
|
|
|
|
|
2017-05-18 10:40:26 +00:00
|
|
|
|
/**
|
2017-09-22 17:39:00 +00:00
|
|
|
|
* Open a Realm asynchronously with a promise. If the Realm is synced, it will be fully
|
2017-05-18 10:40:26 +00:00
|
|
|
|
* synchronized before it is available.
|
2017-09-22 09:17:59 +00:00
|
|
|
|
* @param {Realm~Configuration} config
|
2017-09-28 00:57:41 +00:00
|
|
|
|
* @returns {ProgressPromise} - a promise that will be resolved with the Realm instance when it's available.
|
2017-05-18 10:40:26 +00:00
|
|
|
|
*/
|
|
|
|
|
static open(config) {}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-09-22 17:39:00 +00:00
|
|
|
|
* Open a Realm asynchronously with a callback. If the Realm is synced, it will be fully
|
2017-05-18 10:40:26 +00:00
|
|
|
|
* synchronized before it is available.
|
2017-09-22 09:17:59 +00:00
|
|
|
|
* @param {Realm~Configuration} config
|
2017-09-28 00:57:41 +00:00
|
|
|
|
* @param {callback(error, realm)} - will be called when the Realm is ready.
|
2017-09-13 09:37:44 +00:00
|
|
|
|
* @param {callback(transferred, transferable)} [progressCallback] - an optional callback for download progress notifications
|
2017-05-18 10:40:26 +00:00
|
|
|
|
* @throws {Error} If anything in the provided `config` is invalid.
|
|
|
|
|
*/
|
2017-09-13 09:37:44 +00:00
|
|
|
|
static openAsync(config, callback, progressCallback) {}
|
2017-05-18 10:40:26 +00:00
|
|
|
|
|
2016-05-04 09:39:06 +00:00
|
|
|
|
/**
|
|
|
|
|
* Closes this Realm so it may be re-opened with a newer schema version.
|
2016-05-04 18:40:06 +00:00
|
|
|
|
* All objects and collections from this Realm are no longer valid after calling this method.
|
2016-05-04 09:39:06 +00:00
|
|
|
|
*/
|
|
|
|
|
close() {}
|
|
|
|
|
|
2016-01-29 08:46:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Create a new Realm object of the given type and with the specified properties.
|
2016-03-04 22:13:28 +00:00
|
|
|
|
* @param {Realm~ObjectType} type - The type of Realm object to create.
|
2016-01-29 08:46:25 +00:00
|
|
|
|
* @param {Object} properties - Property values for all required properties without a
|
|
|
|
|
* default value.
|
|
|
|
|
* @param {boolean} [update=false] - Signals that an existing object with matching primary key
|
|
|
|
|
* should be updated. Only the primary key property and properties which should be updated
|
|
|
|
|
* need to be specified. All missing property values will remain unchanged.
|
|
|
|
|
* @returns {Realm.Object}
|
|
|
|
|
*/
|
|
|
|
|
create(type, properties, update) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Deletes the provided Realm object, or each one inside the provided collection.
|
|
|
|
|
* @param {Realm.Object|Realm.Object[]|Realm.List|Realm.Results} object
|
|
|
|
|
*/
|
|
|
|
|
delete(object) {}
|
|
|
|
|
|
2017-09-11 05:45:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* Deletes a Realm model, including all of its objects.
|
|
|
|
|
* @param {string} name - the model name
|
|
|
|
|
*/
|
|
|
|
|
deleteModel(name) {}
|
|
|
|
|
|
2016-01-29 08:46:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* **WARNING:** This will delete **all** objects in the Realm!
|
|
|
|
|
*/
|
|
|
|
|
deleteAll() {}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-02-19 09:44:52 +00:00
|
|
|
|
* Returns all objects of the given `type` in the Realm.
|
2016-03-04 22:13:28 +00:00
|
|
|
|
* @param {Realm~ObjectType} type - The type of Realm objects to retrieve.
|
2016-02-19 09:44:52 +00:00
|
|
|
|
* @throws {Error} If type passed into this method is invalid.
|
|
|
|
|
* @returns {Realm.Results} that will live-update as objects are created and destroyed.
|
2016-01-29 08:46:25 +00:00
|
|
|
|
*/
|
2016-03-04 22:13:28 +00:00
|
|
|
|
objects(type) {}
|
2016-01-29 08:46:25 +00:00
|
|
|
|
|
2016-06-03 23:59:50 +00:00
|
|
|
|
/**
|
|
|
|
|
* Searches for a Realm object by its primary key.
|
|
|
|
|
* @param {Realm~ObjectType} type - The type of Realm object to search for.
|
|
|
|
|
* @param {number|string} key - The primary key value of the object to search for.
|
|
|
|
|
* @throws {Error} If type passed into this method is invalid or if the object type did
|
|
|
|
|
* not have a `primaryKey` specified in its {@link Realm~ObjectSchema ObjectSchema}.
|
|
|
|
|
* @returns {Realm.Object|undefined} if no object is found.
|
2016-06-17 09:38:09 +00:00
|
|
|
|
* @since 0.14.0
|
2016-06-03 23:59:50 +00:00
|
|
|
|
*/
|
|
|
|
|
objectForPrimaryKey(type, key) {}
|
|
|
|
|
|
2016-01-29 08:46:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Add a listener `callback` for the specified event `name`.
|
|
|
|
|
* @param {string} name - The name of event that should cause the callback to be called.
|
|
|
|
|
* _Currently, only the "change" event supported_.
|
2017-05-31 11:22:53 +00:00
|
|
|
|
* @param {callback(Realm, string)} callback - Function to be called when the event occurs.
|
2016-01-29 08:46:25 +00:00
|
|
|
|
* Each callback will only be called once per event, regardless of the number of times
|
|
|
|
|
* it was added.
|
|
|
|
|
* @throws {Error} If an invalid event `name` is supplied, or if `callback` is not a function.
|
|
|
|
|
*/
|
|
|
|
|
addListener(name, callback) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the listener `callback` for the specfied event `name`.
|
|
|
|
|
* @param {string} name - The event name.
|
|
|
|
|
* _Currently, only the "change" event supported_.
|
2017-05-31 11:22:53 +00:00
|
|
|
|
* @param {callback(Realm, string)} callback - Function that was previously added as a
|
2016-01-29 08:46:25 +00:00
|
|
|
|
* listener for this event through the {@link Realm#addListener addListener} method.
|
|
|
|
|
* @throws {Error} If an invalid event `name` is supplied, or if `callback` is not a function.
|
|
|
|
|
*/
|
|
|
|
|
removeListener(name, callback) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove all event listeners (restricted to the event `name`, if provided).
|
|
|
|
|
* @param {string} [name] - The name of the event whose listeners should be removed.
|
|
|
|
|
* _Currently, only the "change" event supported_.
|
|
|
|
|
* @throws {Error} When invalid event `name` is supplied
|
|
|
|
|
*/
|
|
|
|
|
removeAllListeners(name) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Synchronously call the provided `callback` inside a write transaction.
|
|
|
|
|
* @param {function()} callback
|
|
|
|
|
*/
|
|
|
|
|
write(callback) {}
|
2017-08-18 12:22:29 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2017-08-21 15:48:53 +00:00
|
|
|
|
* Initiate a write transaction.
|
|
|
|
|
* @throws {Error} When already in write transaction
|
|
|
|
|
*/
|
|
|
|
|
beginTransaction() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Commit a write transaction.
|
|
|
|
|
*/
|
|
|
|
|
commitTransaction() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cancel a write transaction.
|
|
|
|
|
*/
|
|
|
|
|
cancelTransaction() {}
|
|
|
|
|
|
|
|
|
|
/*
|
2017-08-18 12:22:29 +00:00
|
|
|
|
* Replaces all string columns in this Realm with a string enumeration column and compacts the
|
|
|
|
|
* database file.
|
2017-09-22 09:17:59 +00:00
|
|
|
|
*
|
2017-08-18 12:22:29 +00:00
|
|
|
|
* Cannot be called from a write transaction.
|
|
|
|
|
*
|
|
|
|
|
* Compaction will not occur if other `Realm` instances exist.
|
|
|
|
|
*
|
|
|
|
|
* While compaction is in progress, attempts by other threads or processes to open the database will
|
|
|
|
|
* wait.
|
|
|
|
|
*
|
|
|
|
|
* Be warned that resource requirements for compaction is proportional to the amount of live data in
|
|
|
|
|
* the database. Compaction works by writing the database contents to a temporary database file and
|
|
|
|
|
* then replacing the database with the temporary one.
|
|
|
|
|
* @returns {true} if compaction succeeds.
|
|
|
|
|
*/
|
|
|
|
|
compact() {}
|
2016-01-29 08:46:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-17 23:05:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get the current schema version of the Realm at the given path.
|
|
|
|
|
* @param {string} path - The path to the file where the
|
|
|
|
|
* Realm database is stored.
|
2016-03-21 20:31:28 +00:00
|
|
|
|
* @param {ArrayBuffer|ArrayBufferView} [encryptionKey] - Required only when
|
|
|
|
|
* accessing encrypted Realms.
|
2016-03-21 18:28:46 +00:00
|
|
|
|
* @throws {Error} When passing an invalid or non-matching encryption key.
|
2016-03-17 23:05:49 +00:00
|
|
|
|
* @returns {number} version of the schema, or `-1` if no Realm exists at `path`.
|
|
|
|
|
*/
|
2016-03-21 18:28:46 +00:00
|
|
|
|
Realm.schemaVersion = function(path, encryptionKey) {};
|
2016-03-17 23:05:49 +00:00
|
|
|
|
|
2017-08-30 04:55:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* Delete the Realm file for the given configuration.
|
|
|
|
|
* @param {Realm~Configuration} config
|
|
|
|
|
* @throws {Error} If anything in the provided `config` is invalid.
|
|
|
|
|
*/
|
|
|
|
|
Realm.deleteFile = function(config) {};
|
|
|
|
|
|
2016-01-29 08:46:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* The default path where to create and access the Realm file.
|
|
|
|
|
* @type {string}
|
|
|
|
|
*/
|
|
|
|
|
Realm.defaultPath;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This describes the different options used to create a {@link Realm} instance.
|
|
|
|
|
* @typedef Realm~Configuration
|
|
|
|
|
* @type {Object}
|
2016-03-17 22:07:15 +00:00
|
|
|
|
* @property {ArrayBuffer|ArrayBufferView} [encryptionKey] - The 512-bit (64-byte) encryption
|
|
|
|
|
* key used to encrypt and decrypt all data in the Realm.
|
2017-05-31 11:22:53 +00:00
|
|
|
|
* @property {callback(Realm, Realm)} [migration] - The function to run if a migration is needed.
|
2016-05-02 20:49:40 +00:00
|
|
|
|
* This function should provide all the logic for converting data models from previous schemas
|
|
|
|
|
* to the new schema.
|
|
|
|
|
* This function takes two arguments:
|
|
|
|
|
* - `oldRealm` - The Realm before migration is performed.
|
|
|
|
|
* - `newRealm` - The Realm that uses the latest `schema`, which should be modified as necessary.
|
2017-09-22 09:17:59 +00:00
|
|
|
|
* @property {callback(number, number)} [shouldCompactOnLaunch] - The function called when opening
|
|
|
|
|
* a Realm for the first time during the life of a process to determine if it should be compacted
|
2017-08-18 12:22:29 +00:00
|
|
|
|
* before being returned to the user. The function takes two arguments:
|
2017-09-22 09:17:59 +00:00
|
|
|
|
* - `totalSize` - The total file size (data + free space)
|
2017-08-18 12:22:29 +00:00
|
|
|
|
* - `unusedSize` - The total bytes used by data in the file.
|
2017-09-22 09:17:59 +00:00
|
|
|
|
* It returns `true` to indicate that an attempt to compact the file should be made. The compaction
|
2017-08-18 12:22:29 +00:00
|
|
|
|
* will be skipped if another process is accessing it.
|
2016-01-29 08:46:25 +00:00
|
|
|
|
* @property {string} [path={@link Realm.defaultPath}] - The path to the file where the
|
|
|
|
|
* Realm database should be stored.
|
2017-09-13 18:42:23 +00:00
|
|
|
|
* @property {boolean} [inMemory=false] - Specifies if this Realm should be opened in-memory. This
|
|
|
|
|
* still requires a path (can be the default path) to identify the Realm so other processes can
|
|
|
|
|
* open the same Realm. The file will also be used as swap space if the Realm becomes bigger than
|
|
|
|
|
* what fits in memory, but it is not persistent and will be removed when the last instance
|
|
|
|
|
* is closed.
|
2016-05-02 20:21:02 +00:00
|
|
|
|
* @property {boolean} [readOnly=false] - Specifies if this Realm should be opened as read-only.
|
2016-03-04 22:13:28 +00:00
|
|
|
|
* @property {Array<Realm~ObjectClass|Realm~ObjectSchema>} [schema] - Specifies all the
|
2016-03-07 20:23:04 +00:00
|
|
|
|
* object types in this Realm. **Required** when first creating a Realm at this `path`.
|
2017-09-28 00:57:41 +00:00
|
|
|
|
* If omitted, the schema will be read from the existing Realm file.
|
2016-01-29 08:46:25 +00:00
|
|
|
|
* @property {number} [schemaVersion] - **Required** (and must be incremented) after
|
|
|
|
|
* changing the `schema`.
|
2017-09-22 09:17:59 +00:00
|
|
|
|
* @property {Object} [sync] - Sync configuration parameters with the following
|
2016-10-04 22:02:51 +00:00
|
|
|
|
* child properties:
|
|
|
|
|
* - `user` - A `User` object obtained by calling `Realm.Sync.User.login`
|
2017-09-15 13:22:44 +00:00
|
|
|
|
* - `url` - A `string` which contains a valid Realm Sync url
|
2017-09-25 09:05:16 +00:00
|
|
|
|
* - `error` - A callback function which is called in error situations.
|
|
|
|
|
* The `error` callback can take up to four optional arguments: `message`, `isFatal`,
|
|
|
|
|
* `category`, and `code`.
|
2017-09-15 13:22:44 +00:00
|
|
|
|
* - `validate_ssl` - Indicating if SSL certificates must be validated
|
|
|
|
|
* - `ssl_trust_certificate_path` - A path where to find trusted SSL certificates
|
2017-09-25 09:05:16 +00:00
|
|
|
|
* - `open_ssl_verify_callback` - A callback function used to accept or reject the server's
|
|
|
|
|
* SSL certificate. open_ssl_verify_callback is called with an object of type
|
|
|
|
|
* <code>
|
|
|
|
|
* {
|
|
|
|
|
* serverAddress: String,
|
|
|
|
|
* serverPort: Number,
|
|
|
|
|
* pemCertificate: String,
|
|
|
|
|
* acceptedByOpenSSL: Boolean,
|
|
|
|
|
* depth: Number
|
|
|
|
|
* }
|
|
|
|
|
* </code>
|
|
|
|
|
* The return value of open_ssl_verify_callback decides whether the certificate is accepted (true)
|
|
|
|
|
* or rejected (false). The open_ssl_verify_callback function is only respected on platforms where
|
|
|
|
|
* OpenSSL is used for the sync client, e.g. Linux. The open_ssl_verify_callback function is not
|
2017-09-25 09:57:18 +00:00
|
|
|
|
* 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.
|
2017-09-22 09:17:59 +00:00
|
|
|
|
*
|
2017-09-25 09:05:16 +00:00
|
|
|
|
* When the sync client has received the server's certificate chain, it presents every certificate in
|
|
|
|
|
* the chain to the open_ssl_verify_callback function. The depth argument 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.
|
2017-09-22 09:17:59 +00:00
|
|
|
|
*
|
2017-09-25 09:05:16 +00:00
|
|
|
|
* acceptedByOpenSSL is 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.
|
2017-09-22 09:17:59 +00:00
|
|
|
|
*
|
2017-09-25 09:05:16 +00:00
|
|
|
|
* One possible way of using the open_ssl_verify_callback function is to embed the known server certificate
|
|
|
|
|
* in the client and accept the presented certificate if and only if it is equal to the known certificate.
|
2017-09-22 09:17:59 +00:00
|
|
|
|
*
|
2017-09-25 09:05:16 +00:00
|
|
|
|
* The purpose of open_ssl_verify_callback is to enable custom certificate handling and to solve cases where
|
|
|
|
|
* OpenSSL erroneously rejects valid certificates possibly because OpenSSL doesn't have access to the
|
|
|
|
|
* proper trust certificates.
|
2017-09-22 09:17:59 +00:00
|
|
|
|
*
|
2016-01-29 08:46:25 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2016-03-04 22:13:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* Realm objects will inherit methods, getters, and setters from the `prototype` of this
|
2016-04-28 16:06:51 +00:00
|
|
|
|
* constructor. It is **highly recommended** that this constructor inherit from
|
|
|
|
|
* {@link Realm.Object}.
|
2016-03-04 22:13:28 +00:00
|
|
|
|
* @typedef Realm~ObjectClass
|
|
|
|
|
* @type {Class}
|
|
|
|
|
* @property {Realm~ObjectSchema} schema - Static property specifying object schema information.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-01-29 08:46:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* @typedef Realm~ObjectSchema
|
|
|
|
|
* @type {Object}
|
|
|
|
|
* @property {string} name - Represents the object type.
|
|
|
|
|
* @property {string} [primaryKey] - The name of a `"string"` or `"int"` property
|
|
|
|
|
* that must be unique across all objects of this type within the same Realm.
|
|
|
|
|
* @property {Object<string, (Realm~PropertyType|Realm~ObjectSchemaProperty)>} properties -
|
|
|
|
|
* An object where the keys are property names and the values represent the property type.
|
2017-09-28 00:57:41 +00:00
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* let MyClassSchema = {
|
|
|
|
|
* name: 'MyClass',
|
|
|
|
|
* primaryKey: 'pk',
|
|
|
|
|
* properties: {
|
|
|
|
|
* pk: 'int',
|
|
|
|
|
* optionalFloatValue: 'float?' // or {type: 'float', optional: true}
|
|
|
|
|
* listOfStrings: 'string[]',
|
|
|
|
|
* listOfOptionalDates: 'date?[]',
|
|
|
|
|
* indexedInt: {type: 'int', indexed: true}
|
|
|
|
|
*
|
|
|
|
|
* linkToObject: 'MyClass',
|
|
|
|
|
* listOfObjects: 'MyClass[]', // or {type: 'list', objectType: 'MyClass'}
|
|
|
|
|
* objectsLinkingToThisObject: {type: 'linkingObjects', objectType: 'MyClass', property: 'linkToObject'}
|
|
|
|
|
* }
|
|
|
|
|
* };
|
2016-01-29 08:46:25 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @typedef Realm~ObjectSchemaProperty
|
|
|
|
|
* @type {Object}
|
|
|
|
|
* @property {Realm~PropertyType} type - The type of this property.
|
2017-09-28 00:57:41 +00:00
|
|
|
|
* @property {Realm~PropertyType} [objectType] - **Required** when `type` is `"list"` or `"linkingObjects"`,
|
|
|
|
|
* and must match the type of an object in the same schema, or, for `"list"`
|
|
|
|
|
* only, any other type which may be stored as a Realm property.
|
2017-06-29 09:59:10 +00:00
|
|
|
|
* @property {string} [property] - **Required** when `type` is `"linkingObjects"`, and must match
|
|
|
|
|
* the name of a property on the type specified in `objectType` that links to the type this property belongs to.
|
2016-01-29 08:46:25 +00:00
|
|
|
|
* @property {any} [default] - The default value for this property on creation when not
|
|
|
|
|
* otherwise specified.
|
|
|
|
|
* @property {boolean} [optional] - Signals if this property may be assigned `null` or `undefined`.
|
2017-09-28 00:57:41 +00:00
|
|
|
|
* For `"list"` properties of non-object types, this instead signals whether the values inside the list may be assigned `null` or `undefined`.
|
|
|
|
|
* This is not supported for `"list"` properties of object types and `"linkingObjects"` properties.
|
2016-03-21 18:49:16 +00:00
|
|
|
|
* @property {boolean} [indexed] - Signals if this property should be indexed. Only supported for
|
2017-09-22 09:17:59 +00:00
|
|
|
|
* `"string"`, `"int"`, and `"bool"` properties.
|
2016-01-29 08:46:25 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2016-03-04 22:13:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* The type of an object may either be specified as a string equal to the `name` in a
|
|
|
|
|
* {@link Realm~ObjectSchema ObjectSchema} definition, **or** a constructor that was specified
|
|
|
|
|
* in the {@link Realm~Configuration configuration} `schema`.
|
|
|
|
|
* @typedef Realm~ObjectType
|
|
|
|
|
* @type {string|Realm~ObjectClass}
|
|
|
|
|
*/
|
|
|
|
|
|
2016-01-29 08:46:25 +00:00
|
|
|
|
/**
|
2017-09-28 00:57:41 +00:00
|
|
|
|
* A property type may be specified as one of the standard builtin types, or as
|
|
|
|
|
* an object type inside the same schema.
|
|
|
|
|
*
|
|
|
|
|
* When specifying property types in an {@linkplain Realm~ObjectSchema object schema}, you
|
|
|
|
|
* may append `?` to any of the property types to indicate that it is optional
|
|
|
|
|
* (i.e. it can be `null` in addition to the normal values) and `[]` to
|
|
|
|
|
* indicate that it is instead a list of that type. For example,
|
|
|
|
|
* `optionalIntList: 'int?[]'` would declare a property which is a list of
|
|
|
|
|
* nullable integers. The property types reported by {@linkplain Realm.Collection
|
|
|
|
|
* collections} and in a Realm's schema will never
|
|
|
|
|
* use these forms.
|
|
|
|
|
*
|
2016-01-29 08:46:25 +00:00
|
|
|
|
* @typedef Realm~PropertyType
|
2017-06-29 09:59:10 +00:00
|
|
|
|
* @type {("bool"|"int"|"float"|"double"|"string"|"date"|"data"|"list"|"linkingObjects"|"<ObjectType>")}
|
2017-09-28 00:57:41 +00:00
|
|
|
|
*
|
2016-01-29 08:46:25 +00:00
|
|
|
|
* @property {boolean} "bool" - Property value may either be `true` or `false`.
|
|
|
|
|
* @property {number} "int" - Property may be assigned any number, but will be stored as a
|
|
|
|
|
* round integer, meaning anything after the decimal will be truncated.
|
|
|
|
|
* @property {number} "float" - Property may be assigned any number, but will be stored as a
|
|
|
|
|
* `float`, which may result in a loss of precision.
|
|
|
|
|
* @property {number} "double" - Property may be assigned any number, and will have no loss
|
|
|
|
|
* of precision.
|
|
|
|
|
* @property {string} "string" - Property value may be any arbitrary string.
|
2016-05-19 20:33:00 +00:00
|
|
|
|
* @property {Date} "date" - Property may be assigned any `Date` instance.
|
2016-01-29 08:46:25 +00:00
|
|
|
|
* @property {ArrayBuffer} "data" - Property may either be assigned an `ArrayBuffer`
|
|
|
|
|
* or `ArrayBufferView` (e.g. `DataView`, `Int8Array`, `Float32Array`, etc.) instance,
|
|
|
|
|
* but will always be returned as an `ArrayBuffer`.
|
|
|
|
|
* @property {Realm.List} "list" - Property may be assigned any ordered collection
|
|
|
|
|
* (e.g. `Array`, {@link Realm.List}, {@link Realm.Results}) of objects all matching the
|
|
|
|
|
* `objectType` specified in the {@link Realm~ObjectSchemaProperty ObjectSchemaProperty}.
|
2017-06-29 09:59:10 +00:00
|
|
|
|
* @property {Realm.Results} "linkingObjects" - Property is read-only and always returns a {@link Realm.Results}
|
|
|
|
|
* of all the objects matching the `objectType` that are linking to the current object
|
|
|
|
|
* through the `property` relationship specified in {@link Realm~ObjectSchemaProperty ObjectSchemaProperty}.
|
2016-01-29 08:46:25 +00:00
|
|
|
|
* @property {Realm.Object} "<ObjectType>" - A string that matches the `name` of an object in the
|
|
|
|
|
* same schema (see {@link Realm~ObjectSchema ObjectSchema}) – this property may be assigned
|
|
|
|
|
* any object of this type from inside the same Realm, and will always be _optional_
|
|
|
|
|
* (meaning it may also be assigned `null` or `undefined`).
|
|
|
|
|
*/
|