mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-09 13:55:49 +00:00
Merge branch '2.0.x' into kneth/v1_v2-upgrade
This commit is contained in:
commit
3bf61963e8
14
CHANGELOG.md
14
CHANGELOG.md
@ -1,4 +1,16 @@
|
||||
2.0.0 Release notes (2017-9-26)
|
||||
2.0.0 Release notes (2017-9-28)
|
||||
=============================================================
|
||||
### Breaking changes
|
||||
* None.
|
||||
|
||||
### Enhancements
|
||||
* None.
|
||||
|
||||
### Bug fixes
|
||||
* An issue where access tokens were not refreshed correctly has been addressed.
|
||||
|
||||
|
||||
2.0.0-rc11 Release notes (2017-9-26)
|
||||
=============================================================
|
||||
### Breaking changes
|
||||
* None
|
||||
|
@ -1,5 +1,5 @@
|
||||
PACKAGE_NAME=realm-js
|
||||
VERSION=2.0.0-rc11
|
||||
VERSION=2.0.0-rc13
|
||||
REALM_CORE_VERSION=3.2.1
|
||||
REALM_SYNC_VERSION=2.0.0-rc24
|
||||
REALM_OBJECT_SERVER_VERSION=2.0.0-alpha.32
|
||||
REALM_OBJECT_SERVER_VERSION=2.0.0-alpha.36
|
||||
|
@ -18,17 +18,39 @@
|
||||
|
||||
/**
|
||||
* Abstract base class containing methods shared by {@link Realm.List} and {@link Realm.Results}.
|
||||
*
|
||||
* A Realm Collection is a homogenous sequence of values of any of the types
|
||||
* that can be stored as properties of Realm objects. A collection can be
|
||||
* accessed in any of the ways that a normal Javascript Array can, including
|
||||
* subscripting, enumerating with `for-of` and so on.
|
||||
*
|
||||
* @memberof Realm
|
||||
* @since 0.11.0
|
||||
*/
|
||||
class Collection {
|
||||
/**
|
||||
* The number of objects in the collection.
|
||||
* The number of values in the collection.
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
get length() {}
|
||||
|
||||
/**
|
||||
* The {@linkplain Realm~PropertyType type} of values in the collection.
|
||||
* @type {string}
|
||||
* @readonly
|
||||
* @since 2.0.0
|
||||
*/
|
||||
get type() {}
|
||||
|
||||
/**
|
||||
* Whether `null` is a valid value for the collection.
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @since 2.0.0
|
||||
*/
|
||||
get optional() {}
|
||||
|
||||
/**
|
||||
* Checks if this collection has not been deleted and is part of a valid Realm.
|
||||
* @returns {boolean} indicating if the collection can be safely accessed.
|
||||
@ -38,11 +60,14 @@ class Collection {
|
||||
|
||||
/**
|
||||
* Returns new _Results_ that represent this collection being filtered by the provided query.
|
||||
*
|
||||
* @param {string} query - Query used to filter objects from the collection.
|
||||
* @param {...any} [arg] - Each subsequent argument is used by the placeholders
|
||||
* (e.g. `$0`, `$1`, `$2`, …) in the query.
|
||||
* @throws {Error} If the query or any other argument passed into this method is invalid.
|
||||
* @returns {Realm.Results} filtered according to the provided query.
|
||||
* @returns {Realm.Results<T>} filtered according to the provided query.
|
||||
*
|
||||
* This is currently only supported for collections of Realm Objects.
|
||||
*
|
||||
* See {@tutorial query-language} for details about the query language.
|
||||
* @example
|
||||
@ -51,43 +76,76 @@ class Collection {
|
||||
filtered(query, ...arg) {}
|
||||
|
||||
/**
|
||||
* Returns new _Results_ that represent this collection being sorted by the provided property
|
||||
* (or properties) of each object.
|
||||
* @param {string|Realm.Results~SortDescriptor[]} descriptor - The property name(s) to sort
|
||||
* the objects in the collection.
|
||||
* @param {boolean} [reverse=false] - May only be provided if `descriptor` is a string.
|
||||
* Returns new _Results_ that represent a sorted view of this collection.
|
||||
*
|
||||
* A collection of Realm Objects can be sorted on one or more properties of
|
||||
* those objects, or of properties of objects linked to by those objects.
|
||||
* To sort by a single property, simply pass the name of that property to
|
||||
* `sorted()`, optionally followed by a boolean indicating if the sort should be reversed.
|
||||
* For more than one property, you must pass an array of
|
||||
* {@linkplain Realm.Collection~SortDescriptor sort descriptors} which list
|
||||
* which properties to sort on.
|
||||
*
|
||||
* Collections of other types sort on the values themselves rather than
|
||||
* properties of the values, and so no property name or sort descriptors
|
||||
* should be supplied.
|
||||
*
|
||||
* @example
|
||||
* // Sort wines by age
|
||||
* wines.sorted('age')
|
||||
* @example
|
||||
* // Sort wines by price in descending order, then sort ties by age in
|
||||
* // ascending order
|
||||
* wines.sorted([['price', false], ['age'])
|
||||
* @example
|
||||
* // Sort a list of numbers in ascending order
|
||||
* let sortedPrices = wine.pricesSeen.sort()
|
||||
* @example
|
||||
* // Sort people by how expensive their favorite wine is
|
||||
* people.sort("favoriteWine.price")
|
||||
*
|
||||
* @param {string|Realm.Collection~SortDescriptor[]} [descriptor] - The property name(s) to sort the collection on.
|
||||
* @param {boolean} [reverse=false] - Sort in descending order rather than ascended.
|
||||
* May not be supplied if `descriptor` is an array of sort descriptors.
|
||||
* @throws {Error} If a specified property does not exist.
|
||||
* @returns {Realm.Results} sorted according to the arguments passed in
|
||||
* @returns {Realm.Results<T>} sorted according to the arguments passed in.
|
||||
*/
|
||||
sorted(descriptor, reverse) {}
|
||||
|
||||
/**
|
||||
* Create a frozen snapshot of the collection. This means objects added to and removed from the
|
||||
* original collection will not be reflected in the _Results_ returned by this method.
|
||||
* However, objects deleted from the Realm will become `null` at their respective indices.
|
||||
* This is **not** a _deep_ snapshot, meaning the objects contained in this snapshot will
|
||||
* continue to update as changes are made to them.
|
||||
* @returns {Realm.Results} which will **not** live update.
|
||||
* Create a frozen snapshot of the collection.
|
||||
*
|
||||
* Values added to and removed from the original collection will not be
|
||||
* reflected in the _Results_ returned by this method, including if the
|
||||
* values of properties are changed to make them match or not match any
|
||||
* filters applied.
|
||||
*
|
||||
* This is **not** a _deep_ snapshot. Realm objects contained in this
|
||||
* snapshot will continue to update as changes are made to them, and if
|
||||
* they are deleted from the Realm they will be replaced by `null` at the
|
||||
* respective indices.
|
||||
*
|
||||
* @returns {Realm.Results<T>} which will **not** live update.
|
||||
*/
|
||||
snapshot() {}
|
||||
|
||||
/**
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries Array.prototype.entries}
|
||||
* @returns {Realm.Collection~Iterator} of each `[index, object]` pair in the collection
|
||||
* @returns {Realm.Collection~Iterator<T>} of each `[index, object]` pair in the collection
|
||||
* @since 0.11.0
|
||||
*/
|
||||
entries() {}
|
||||
|
||||
/**
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys Array.prototype.keys}
|
||||
* @returns {Realm.Collection~Iterator} of each index in the collection
|
||||
* @returns {Realm.Collection~Iterator<T>} of each index in the collection
|
||||
* @since 0.11.0
|
||||
*/
|
||||
keys() {}
|
||||
|
||||
/**
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values Array.prototype.values}
|
||||
* @returns {Realm.Collection~Iterator} of each Realm object in the collection
|
||||
* @returns {Realm.Collection~Iterator<T>} of each Realm object in the collection
|
||||
* @since 0.11.0
|
||||
*/
|
||||
values() {}
|
||||
@ -101,7 +159,7 @@ class Collection {
|
||||
* spread operators, and more.
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator Symbol.iterator}
|
||||
* and the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterable iterable protocol}
|
||||
* @returns {Realm.Collection~Iterator} of each Realm object in the collection
|
||||
* @returns {Realm.Collection~Iterator<T>} of each Realm object in the collection
|
||||
* @since 0.11.0
|
||||
* @example
|
||||
* for (let object of collection) {
|
||||
@ -128,7 +186,7 @@ class Collection {
|
||||
* index will be include in the return value. If negative, then the end index will be
|
||||
* counted from the end of the collection. If omitted, then all objects from the start
|
||||
* index will be included in the return value.
|
||||
* @returns {Realm.Object[]} containing the objects from the start index up to, but not
|
||||
* @returns {T[]} containing the objects from the start index up to, but not
|
||||
* including, the end index.
|
||||
* @since 0.11.0
|
||||
*/
|
||||
@ -143,7 +201,7 @@ class Collection {
|
||||
* - `index` – The index of the object being processed in the collection.
|
||||
* - `collection` – The collection itself.
|
||||
* @param {object} [thisArg] - The value of `this` when `callback` is called.
|
||||
* @returns {Realm.Object|undefined} if the `callback` did not return `true` for any object
|
||||
* @returns {T|undefined} if the `callback` did not return `true` for any object
|
||||
* in the collection.
|
||||
* @since 0.11.0
|
||||
*/
|
||||
@ -166,10 +224,11 @@ class Collection {
|
||||
|
||||
/**
|
||||
Finds the index of the given object in the collection.
|
||||
* @param {Realm.Object} [object] - The object to search for in the collection.
|
||||
* @throws {Error} If the argument does not belong to the realm.
|
||||
* @returns {number} representing the index where the object was found, or `-1`
|
||||
* if not in collection.
|
||||
* @param {T} object - The value to search for in the collection.
|
||||
* @throws {Error} If the argument is a {@link Realm.Object} that does not
|
||||
* belong to the same Realm as the collection.
|
||||
* @returns {number} representing the index where the value was found, or
|
||||
* `-1` if not in collection.
|
||||
* @since 1.8.2
|
||||
*/
|
||||
indexOf(object) {}
|
||||
@ -324,8 +383,9 @@ class Collection {
|
||||
*/
|
||||
|
||||
/**
|
||||
* The sort descriptors may either just be a string representing the property name, **or** an
|
||||
* array with two items: `[propertyName, reverse]`
|
||||
* A sort descriptor is either a string containing one or more property names
|
||||
* separate by dots, **or** an array with two items: `[propertyName, reverse]`.
|
||||
*
|
||||
* @typedef Realm.Collection~SortDescriptor
|
||||
* @type {string|Array}
|
||||
*/
|
||||
|
61
docs/list.js
61
docs/list.js
@ -19,59 +19,70 @@
|
||||
/**
|
||||
* Instances of this class will be returned when accessing object properties whose type is `"list"`
|
||||
* (see {@linkplain Realm~ObjectSchemaProperty ObjectSchemaProperty}).
|
||||
* The objects contained in a list are accessible through its index properties and may only be
|
||||
* modified inside a {@linkplain Realm#write write} transaction.
|
||||
*
|
||||
* Lists mostly behave like normal Javascript Arrays, except for that they can
|
||||
* only store values of a single type (indicated by the `type` and `optional`
|
||||
* properties of the List), and can only be modified inside a {@linkplain
|
||||
* Realm#write write} transaction.
|
||||
*
|
||||
* @extends Realm.Collection
|
||||
* @memberof Realm
|
||||
*/
|
||||
class List extends Collection {
|
||||
/**
|
||||
* Remove the **last** object from the list and return it.
|
||||
* Remove the **last** value from the list and return it.
|
||||
* @throws {Error} If not inside a write transaction.
|
||||
* @returns {Realm.Object|undefined} if the list is empty.
|
||||
* @returns {T|undefined} if the list is empty.
|
||||
*/
|
||||
pop() {}
|
||||
|
||||
/**
|
||||
* Add one or more objects to the _end_ of the list.
|
||||
* @param {...Realm.Object} object - Each object’s type must match
|
||||
* {@linkcode Realm~ObjectSchemaProperty objectType} specified in the schema.
|
||||
* @throws {TypeError} If an `object` is of the wrong type.
|
||||
* Add one or more values to the _end_ of the list.
|
||||
*
|
||||
* @param {...T} value - Values to add to the list.
|
||||
* @throws {TypeError} If a `value` is not of a type which can be stored in
|
||||
* the list, or if an object being added to the list does not match the
|
||||
* {@linkcode Realm~ObjectSchema object schema} for the list.
|
||||
*
|
||||
* @throws {Error} If not inside a write transaction.
|
||||
* @returns {number} equal to the new {@link Realm.List#length length} of the list
|
||||
* after adding objects.
|
||||
* @returns {number} equal to the new {@link Realm.List#length length} of
|
||||
* the list after adding the values.
|
||||
*/
|
||||
push(...object) {}
|
||||
push(...value) {}
|
||||
|
||||
/**
|
||||
* Remove the **first** object from the list and return it.
|
||||
* Remove the **first** value from the list and return it.
|
||||
* @throws {Error} If not inside a write transaction.
|
||||
* @returns {Realm.Object|undefined} if the list is empty.
|
||||
* @returns {T|undefined} if the list is empty.
|
||||
*/
|
||||
shift() {}
|
||||
|
||||
/**
|
||||
* Changes the contents of the list by removing objects and/or inserting new objects.
|
||||
* Changes the contents of the list by removing value and/or inserting new value.
|
||||
*
|
||||
* @see {@linkcode https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice Array.prototype.splice}
|
||||
* @param {number} index - The start index. If greater than the length of the list,
|
||||
* the start index will be set to the length instead. If negative, then the start index
|
||||
* will be counted from the end of the list (e.g. `list.length - index`).
|
||||
* @param {number} [count] - The number of objects to remove from the list. If not provided,
|
||||
* then all objects from the start index through the end of the list will be removed.
|
||||
* @param {...Realm.Object} [object] - Objects to insert into the list starting at `index`.
|
||||
* @returns {Realm.Object[]} containing the objects that were removed from the list. The
|
||||
* array is empty if no objects were removed.
|
||||
* @param {number} [count] - The number of values to remove from the list.
|
||||
* If not provided, then all values from the start index through the end of
|
||||
* the list will be removed.
|
||||
* @param {...T} [value] - Values to insert into the list starting at `index`.
|
||||
* @returns {T[]} containing the value that were removed from the list. The
|
||||
* array is empty if no value were removed.
|
||||
*/
|
||||
splice(index, count, ...object) {}
|
||||
|
||||
/**
|
||||
* Add one or more objects to the _beginning_ of the list.
|
||||
* @param {...Realm.Object} object - Each object’s type must match
|
||||
* {@linkcode Realm~ObjectSchemaProperty objectType} specified in the schema.
|
||||
* @throws {TypeError} If an `object` is of the wrong type.
|
||||
* Add one or more values to the _beginning_ of the list.
|
||||
*
|
||||
* @param {...T} value - Values to add to the list.
|
||||
* @throws {TypeError} If a `value` is not of a type which can be stored in
|
||||
* the list, or if an object being added to the list does not match the
|
||||
* {@linkcode Realm~ObjectSchema object schema} for the list.
|
||||
* @throws {Error} If not inside a write transaction.
|
||||
* @returns {number} equal to the new {@link Realm.List#length length} of the list
|
||||
* after adding objects.
|
||||
* @returns {number} equal to the new {@link Realm.List#length length} of
|
||||
* the list after adding the values.
|
||||
*/
|
||||
unshift(...object) {}
|
||||
}
|
@ -96,7 +96,7 @@ class Realm {
|
||||
* Open a Realm asynchronously with a promise. If the Realm is synced, it will be fully
|
||||
* synchronized before it is available.
|
||||
* @param {Realm~Configuration} config
|
||||
* @returns {ProgressPromise} - a promise that will be resolved with the realm instance when it's available.
|
||||
* @returns {ProgressPromise} - a promise that will be resolved with the Realm instance when it's available.
|
||||
*/
|
||||
static open(config) {}
|
||||
|
||||
@ -104,7 +104,7 @@ class Realm {
|
||||
* Open a Realm asynchronously with a callback. If the Realm is synced, it will be fully
|
||||
* synchronized before it is available.
|
||||
* @param {Realm~Configuration} config
|
||||
* @param {callback(error, realm)} - will be called when the realm is ready.
|
||||
* @param {callback(error, realm)} - will be called when the Realm is ready.
|
||||
* @param {callback(transferred, transferable)} [progressCallback] - an optional callback for download progress notifications
|
||||
* @throws {Error} If anything in the provided `config` is invalid
|
||||
* @throws {IncompatibleSyncedRealmError} if migration from RMP version 1 to 2 is not possible
|
||||
@ -288,6 +288,7 @@ Realm.defaultPath;
|
||||
* @property {boolean} [readOnly=false] - Specifies if this Realm should be opened as read-only.
|
||||
* @property {Array<Realm~ObjectClass|Realm~ObjectSchema>} [schema] - Specifies all the
|
||||
* object types in this Realm. **Required** when first creating a Realm at this `path`.
|
||||
* If omitted, the schema will be read from the existing Realm file.
|
||||
* @property {number} [schemaVersion] - **Required** (and must be incremented) after
|
||||
* changing the `schema`.
|
||||
* @property {Object} [sync] - Sync configuration parameters with the following
|
||||
@ -352,19 +353,39 @@ Realm.defaultPath;
|
||||
* 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.
|
||||
*
|
||||
* @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'}
|
||||
* }
|
||||
* };
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef Realm~ObjectSchemaProperty
|
||||
* @type {Object}
|
||||
* @property {Realm~PropertyType} type - The type of this property.
|
||||
* @property {string} [objectType] - **Required** when `type` is `"list"` or `"linkingObjects"`,
|
||||
* and must match the type of an object in the same schema.
|
||||
* @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.
|
||||
* @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.
|
||||
* @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`.
|
||||
* 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.
|
||||
* @property {boolean} [indexed] - Signals if this property should be indexed. Only supported for
|
||||
* `"string"`, `"int"`, and `"bool"` properties.
|
||||
*/
|
||||
@ -378,10 +399,21 @@ Realm.defaultPath;
|
||||
*/
|
||||
|
||||
/**
|
||||
* A property type may be specified as one of the standard builtin types, or as an object type
|
||||
* inside the same schema.
|
||||
* 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.
|
||||
*
|
||||
* @typedef Realm~PropertyType
|
||||
* @type {("bool"|"int"|"float"|"double"|"string"|"date"|"data"|"list"|"linkingObjects"|"<ObjectType>")}
|
||||
*
|
||||
* @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.
|
||||
|
@ -23,6 +23,7 @@
|
||||
* {@link Realm.Results#snapshot snapshot()}, however, will **not** live update
|
||||
* (and listener callbacks added through {@link Realm.Results#addListener addListener()}
|
||||
* will thus never be called).
|
||||
*
|
||||
* @extends Realm.Collection
|
||||
* @memberof Realm
|
||||
*/
|
||||
|
@ -72,6 +72,12 @@ export function createUser(args) {
|
||||
return deserialize(undefined, result);
|
||||
}
|
||||
|
||||
export function _adminUser(args) {
|
||||
args = args.map((arg) => serialize(null, arg));
|
||||
const result = sendRequest('_adminUser', {arguments: args});
|
||||
return deserialize(undefined, result);
|
||||
}
|
||||
|
||||
export function callMethod(realmId, id, name, args) {
|
||||
if (args) {
|
||||
args = args.map((arg) => serialize(realmId, arg));
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import { createUser as createUserRPC, getAllUsers as getAllUsersRPC } from './rpc';
|
||||
import { createUser as createUserRPC, _adminUser as _adminUserRPC, getAllUsers as getAllUsersRPC } from './rpc';
|
||||
import { keys, objectTypes } from './constants';
|
||||
import { createMethods } from './util';
|
||||
|
||||
@ -28,6 +28,10 @@ export default class User {
|
||||
return createUserRPC(Array.from(arguments));
|
||||
}
|
||||
|
||||
static _adminUser(adminToken, server) {
|
||||
return _adminUserRPC(Array.from(arguments));
|
||||
}
|
||||
|
||||
static get all() {
|
||||
return getAllUsersRPC();
|
||||
}
|
||||
|
@ -76,7 +76,10 @@ function refreshAccessToken(user, localRealmPath, realmUrl) {
|
||||
provider: 'realm',
|
||||
app_id: ''
|
||||
}),
|
||||
headers: postHeaders
|
||||
headers: postHeaders,
|
||||
// FIXME: This timeout appears to be necessary in order for some requests to be sent at all.
|
||||
// See https://github.com/realm/realm-js-private/issues/338 for details.
|
||||
timeout: 1000.0
|
||||
};
|
||||
performFetch(url, options)
|
||||
.then((response) => response.json().then((json) => { return { response, json }; }))
|
||||
@ -276,7 +279,7 @@ const instanceMethods = {
|
||||
retrieveAccount(provider, provider_id) {
|
||||
checkTypes(arguments, ['string', 'string']);
|
||||
const url = url_parse(this.server);
|
||||
url.set('pathname', `/api/providers/${provider}/accounts/${provider_id}`);
|
||||
url.set('pathname', `/auth/users/${provider}/${provider_id}`);
|
||||
const headers = {
|
||||
Authorization: this.token
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "realm",
|
||||
"description": "Realm is a mobile database: an alternative to SQLite and key-value stores",
|
||||
"version": "2.0.0-rc11",
|
||||
"version": "2.0.0-rc13",
|
||||
"license": "Apache-2.0",
|
||||
"homepage": "https://realm.io",
|
||||
"keywords": [
|
||||
|
@ -1,7 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
exit 0
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
[ "$(uname -s)" != "Darwin" ] && exit
|
||||
|
21
src/rpc.cpp
21
src/rpc.cpp
@ -191,6 +191,27 @@ RPCServer::RPCServer() {
|
||||
JSObjectRef user_object = (JSObjectRef)jsc::Function::call(m_context, create_user_method, arg_count, arg_values);
|
||||
return (json){{"result", serialize_json_value(user_object)}};
|
||||
};
|
||||
m_requests["/_adminUser"] = [this](const json dict) {
|
||||
JSObjectRef realm_constructor = m_session_id ? JSObjectRef(m_objects[m_session_id]) : NULL;
|
||||
if (!realm_constructor) {
|
||||
throw std::runtime_error("Realm constructor not found!");
|
||||
}
|
||||
|
||||
JSObjectRef sync_constructor = (JSObjectRef)jsc::Object::get_property(m_context, realm_constructor, "Sync");
|
||||
JSObjectRef user_constructor = (JSObjectRef)jsc::Object::get_property(m_context, sync_constructor, "User");
|
||||
JSObjectRef create_user_method = (JSObjectRef)jsc::Object::get_property(m_context, user_constructor, "_adminUser");
|
||||
|
||||
json::array_t args = dict["arguments"];
|
||||
size_t arg_count = args.size();
|
||||
JSValueRef arg_values[arg_count];
|
||||
|
||||
for (size_t i = 0; i < arg_count; i++) {
|
||||
arg_values[i] = deserialize_json_value(args[i]);
|
||||
}
|
||||
|
||||
JSObjectRef user_object = (JSObjectRef)jsc::Function::call(m_context, create_user_method, arg_count, arg_values);
|
||||
return (json){{"result", serialize_json_value(user_object)}};
|
||||
};
|
||||
m_requests["/call_method"] = [this](const json dict) {
|
||||
JSObjectRef object = m_objects[dict["id"].get<RPCObjectID>()];
|
||||
std::string method_string = dict["name"].get<std::string>();
|
||||
|
@ -20,8 +20,7 @@
|
||||
|
||||
const Realm = require('realm');
|
||||
|
||||
// FIXME: sync testing needs to be updated for ROS 2.0
|
||||
global.enableSyncTests = Realm.Sync && false;
|
||||
global.enableSyncTests = Realm.Sync;
|
||||
|
||||
var TESTS = {
|
||||
ListTests: require('./list-tests'),
|
||||
@ -48,7 +47,7 @@ if (global.enableSyncTests) {
|
||||
if (typeof navigator === 'undefined' ||
|
||||
!/Chrome/.test(navigator.userAgent)) { // eslint-disable-line no-undef
|
||||
|
||||
TESTS.PermissionTests = require('./permission-tests');
|
||||
//TESTS.PermissionTests = require('./permission-tests');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ module.exports = {
|
||||
|
||||
Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, user) => {
|
||||
try {
|
||||
assertIsAuthError(error, 613, "The account cannot be registered as it exists already.");
|
||||
assertIsAuthError(error, 611, "The provided credentials are invalid or the user does not exist.");
|
||||
TestCase.assertUndefined(user);
|
||||
resolve();
|
||||
} catch(e) {
|
||||
@ -209,7 +209,7 @@ module.exports = {
|
||||
|
||||
testLoginNonExistingUser() {
|
||||
return callbackTest((callback) => Realm.Sync.User.login('http://localhost:9080', 'does_not', 'exist', callback), (error, user) => {
|
||||
assertIsAuthError(error, 611, "The provided credentials are invalid.");
|
||||
assertIsAuthError(error, 611, "The provided credentials are invalid or the user does not exist.");
|
||||
TestCase.assertUndefined(user);
|
||||
});
|
||||
},
|
||||
@ -322,20 +322,10 @@ module.exports = {
|
||||
|
||||
user.retrieveAccount('password', global.testAdminUserInfo.username)
|
||||
.then(account => {
|
||||
// {
|
||||
// "provider_id": "admin",
|
||||
// "provider": "password",
|
||||
// "user": {
|
||||
// "id": "07ac9a0a-a97a-4ee1-b53c-b05a6542035a",
|
||||
// "isAdmin": true,
|
||||
// }
|
||||
// }
|
||||
|
||||
TestCase.assertEqual(account.provider_id, global.testAdminUserInfo.username);
|
||||
TestCase.assertEqual(account.provider, 'password');
|
||||
TestCase.assertTrue(account.user);
|
||||
TestCase.assertTrue(account.user.isAdmin !== undefined);
|
||||
TestCase.assertTrue(account.user.id);
|
||||
TestCase.assertEqual(account.accounts[0].provider_id, global.testAdminUserInfo.username);
|
||||
TestCase.assertEqual(account.accounts[0].provider, 'password');
|
||||
TestCase.assertTrue(account.is_admin);
|
||||
TestCase.assertTrue(account.user_id);
|
||||
resolve();
|
||||
})
|
||||
.catch(e => reject(e));
|
||||
@ -367,7 +357,10 @@ module.exports = {
|
||||
})
|
||||
.catch(e => {
|
||||
try {
|
||||
TestCase.assertEqual(e.code, 404);
|
||||
TestCase.assertEqual(e.status, 404);
|
||||
TestCase.assertEqual(e.code, 612);
|
||||
TestCase.assertEqual(e.message, "The account does not exist.");
|
||||
TestCase.assertEqual(e.type, "https://realm.io/docs/object-server/problems/unknown-account");
|
||||
}
|
||||
catch (e) {
|
||||
reject(e);
|
||||
|
Loading…
x
Reference in New Issue
Block a user