2016-10-10 14:17:05 +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.
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
'use strict';
|
2017-10-04 09:28:50 +00:00
|
|
|
|
2018-03-09 09:40:45 +00:00
|
|
|
const URL = require('url-parse');
|
|
|
|
|
2017-01-31 21:56:09 +00:00
|
|
|
let getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function(obj) {
|
|
|
|
return Object.getOwnPropertyNames(obj).reduce(function (descriptors, name) {
|
|
|
|
descriptors[name] = Object.getOwnPropertyDescriptor(obj, name);
|
|
|
|
return descriptors;
|
|
|
|
}, {});
|
|
|
|
};
|
|
|
|
|
2017-02-02 01:41:11 +00:00
|
|
|
function setConstructorOnPrototype(klass) {
|
|
|
|
if (klass.prototype.constructor !== klass) {
|
|
|
|
Object.defineProperty(klass.prototype, 'constructor', { value: klass, configurable: true, writable: true });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-04 08:09:31 +00:00
|
|
|
/**
|
|
|
|
* Finds the permissions associated with a given Role or create them as needed.
|
2018-10-10 10:00:04 +00:00
|
|
|
*
|
2018-10-04 08:09:31 +00:00
|
|
|
* @param {RealmObject} Container RealmObject holding the permission list.
|
|
|
|
* @param {List<Realm.Permissions.Permission>} list of permissions.
|
|
|
|
* @param {string} name of the role to find or create permissions for.
|
|
|
|
*/
|
|
|
|
function findOrCreatePermissionForRole(realmObject, permissions, roleName) {
|
|
|
|
let realm = realmObject._realm;
|
|
|
|
if (!realm.isInTransaction) {
|
|
|
|
throw Error("'findOrCreate' can only be called inside a write transaction.");
|
|
|
|
}
|
|
|
|
let permissionsObj = permissions.filtered(`role.name = '${roleName}'`)[0];
|
|
|
|
if (permissionsObj === undefined) {
|
|
|
|
let role = realm.objects("__Role").filtered(`name = '${roleName}'`)[0];
|
|
|
|
if (role === undefined) {
|
|
|
|
role = realm.create("__Role", {'name': roleName});
|
|
|
|
}
|
|
|
|
// Create new permissions object with all privileges disabled
|
|
|
|
permissionsObj = realm.create("__Permission", { 'role': role });
|
|
|
|
permissions.push(permissionsObj);
|
|
|
|
}
|
|
|
|
return permissionsObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the schema object if one isn't already defined
|
|
|
|
*/
|
|
|
|
function addSchemaIfNeeded(schemaList, schemaObj) {
|
|
|
|
for (var i = 0; i < schemaList.length; i++) {
|
|
|
|
const obj = schemaList[i];
|
|
|
|
if (obj === undefined) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (schemaObj.name === obj.name || (obj.schema !== undefined && (schemaObj.name === obj.schema.name))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
schemaList.push(schemaObj);
|
|
|
|
}
|
|
|
|
|
2016-10-10 14:17:05 +00:00
|
|
|
module.exports = function(realmConstructor) {
|
|
|
|
// Add the specified Array methods to the Collection prototype.
|
|
|
|
Object.defineProperties(realmConstructor.Collection.prototype, require('./collection-methods'));
|
|
|
|
|
2017-02-02 01:41:11 +00:00
|
|
|
setConstructorOnPrototype(realmConstructor.Collection);
|
|
|
|
setConstructorOnPrototype(realmConstructor.List);
|
|
|
|
setConstructorOnPrototype(realmConstructor.Results);
|
|
|
|
setConstructorOnPrototype(realmConstructor.Object);
|
|
|
|
|
2018-10-04 08:09:31 +00:00
|
|
|
//Add static methods to the Realm object
|
2017-05-06 23:26:14 +00:00
|
|
|
Object.defineProperties(realmConstructor, getOwnPropertyDescriptors({
|
2018-10-04 08:09:31 +00:00
|
|
|
|
2017-05-06 23:26:14 +00:00
|
|
|
open(config) {
|
2018-05-25 10:00:42 +00:00
|
|
|
// If no config is defined, we should just open the default realm
|
|
|
|
if (config === undefined) { config = {}; }
|
|
|
|
|
2017-12-18 22:46:26 +00:00
|
|
|
// For local Realms we open the Realm and return it in a resolved Promise.
|
|
|
|
if (!("sync" in config)) {
|
|
|
|
let promise = Promise.resolve(new realmConstructor(config));
|
|
|
|
promise.progress = (callback) => { };
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
|
2017-09-01 15:12:06 +00:00
|
|
|
let syncSession;
|
|
|
|
let promise = new Promise((resolve, reject) => {
|
2018-10-16 07:49:16 +00:00
|
|
|
syncSession = realmConstructor._asyncOpen(config, (realm, error) => {
|
|
|
|
if (error) {
|
|
|
|
setTimeout(() => { reject(error); }, 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
setTimeout(() => { resolve(realm); }, 1);
|
|
|
|
}
|
|
|
|
});
|
2017-05-06 23:26:14 +00:00
|
|
|
});
|
2017-09-01 15:12:06 +00:00
|
|
|
|
|
|
|
promise.progress = (callback) => {
|
|
|
|
if (syncSession) {
|
|
|
|
syncSession.addProgressNotification('download', 'forCurrentlyOutstandingWork', callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
};
|
|
|
|
return promise;
|
2017-05-06 23:26:14 +00:00
|
|
|
},
|
|
|
|
|
2017-09-13 09:37:44 +00:00
|
|
|
openAsync(config, callback, progressCallback) {
|
2017-08-24 18:01:12 +00:00
|
|
|
const message = "Realm.openAsync is now deprecated in favor of Realm.open. This function will be removed in future versions.";
|
|
|
|
(console.warn || console.log).call(console, message);
|
2017-10-02 17:44:24 +00:00
|
|
|
|
2017-10-10 22:41:27 +00:00
|
|
|
let promise = this.open(config)
|
|
|
|
if (progressCallback) {
|
|
|
|
promise.progress(progressCallback)
|
|
|
|
}
|
|
|
|
|
|
|
|
promise.then(realm => {
|
|
|
|
callback(null, realm)
|
|
|
|
}).catch(error => {
|
|
|
|
callback(error);
|
|
|
|
});
|
2017-05-11 20:54:29 +00:00
|
|
|
},
|
2018-06-18 20:55:01 +00:00
|
|
|
|
|
|
|
createTemplateObject(objectSchema) {
|
|
|
|
let obj = {};
|
|
|
|
for (let key in objectSchema.properties) {
|
|
|
|
|
|
|
|
let type;
|
|
|
|
if (typeof objectSchema.properties[key] === 'string' || objectSchema.properties[key] instanceof String) {
|
|
|
|
// Simple declaration of the type
|
|
|
|
type = objectSchema.properties[key];
|
|
|
|
} else {
|
|
|
|
// Advanced property setup
|
|
|
|
const property = objectSchema.properties[key];
|
|
|
|
|
|
|
|
// if optional is set, it wil take precedence over any `?` set on the type parameter
|
|
|
|
if (property.optional === true) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a default value is explicitly set, always set the property
|
|
|
|
if (property.default !== undefined) {
|
2018-06-18 22:19:49 +00:00
|
|
|
obj[key] = property.default;
|
2018-06-18 20:55:01 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
type = property.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the default value for all required primitive types.
|
|
|
|
// Lists are always treated as empty if not specified and references to objects are always optional
|
|
|
|
switch (type) {
|
|
|
|
case 'bool': obj[key] = false; break;
|
|
|
|
case 'int': obj[key] = 0; break;
|
|
|
|
case 'float': obj[key] = 0.0; break;
|
|
|
|
case 'double': obj[key] = 0.0; break;
|
|
|
|
case 'string': obj[key] = ""; break;
|
2018-06-18 22:19:49 +00:00
|
|
|
case 'data': obj[key] = new ArrayBuffer(0); break;
|
2018-06-18 20:55:01 +00:00
|
|
|
case 'date': obj[key] = new Date(0); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
2017-05-06 23:26:14 +00:00
|
|
|
}));
|
|
|
|
|
2016-10-10 14:17:05 +00:00
|
|
|
// Add sync methods
|
|
|
|
if (realmConstructor.Sync) {
|
2017-01-31 21:56:09 +00:00
|
|
|
let userMethods = require('./user-methods');
|
|
|
|
Object.defineProperties(realmConstructor.Sync.User, getOwnPropertyDescriptors(userMethods.static));
|
|
|
|
Object.defineProperties(realmConstructor.Sync.User.prototype, getOwnPropertyDescriptors(userMethods.instance));
|
2017-02-08 12:36:43 +00:00
|
|
|
Object.defineProperty(realmConstructor.Sync.User, '_realmConstructor', { value: realmConstructor });
|
2018-09-13 06:45:06 +00:00
|
|
|
realmConstructor.Sync.Credentials = {};
|
|
|
|
Object.defineProperties(realmConstructor.Sync.Credentials, getOwnPropertyDescriptors(userMethods.credentials));
|
2016-10-24 22:12:12 +00:00
|
|
|
realmConstructor.Sync.AuthError = require('./errors').AuthError;
|
2016-10-25 22:04:58 +00:00
|
|
|
|
2017-06-14 10:54:47 +00:00
|
|
|
if (realmConstructor.Sync.removeAllListeners) {
|
|
|
|
process.on('exit', realmConstructor.Sync.removeAllListeners);
|
2016-11-20 18:34:13 +00:00
|
|
|
process.on('SIGINT', function () {
|
2017-06-14 10:54:47 +00:00
|
|
|
realmConstructor.Sync.removeAllListeners();
|
2016-11-20 18:34:13 +00:00
|
|
|
process.exit(2);
|
|
|
|
});
|
|
|
|
process.on('uncaughtException', function(e) {
|
2017-06-14 10:54:47 +00:00
|
|
|
realmConstructor.Sync.removeAllListeners();
|
2016-11-21 23:33:37 +00:00
|
|
|
/* eslint-disable no-console */
|
2016-11-20 18:34:13 +00:00
|
|
|
console.log(e.stack);
|
|
|
|
process.exit(99);
|
|
|
|
});
|
2016-10-25 22:04:58 +00:00
|
|
|
}
|
2017-02-02 01:41:11 +00:00
|
|
|
|
|
|
|
setConstructorOnPrototype(realmConstructor.Sync.User);
|
|
|
|
setConstructorOnPrototype(realmConstructor.Sync.Session);
|
2017-08-14 13:05:52 +00:00
|
|
|
|
2018-03-09 09:40:45 +00:00
|
|
|
// A configuration for a default Realm
|
2018-03-13 13:27:31 +00:00
|
|
|
realmConstructor.automaticSyncConfiguration = function() {
|
2018-03-14 07:26:41 +00:00
|
|
|
let user;
|
|
|
|
|
|
|
|
if (arguments.length === 0) {
|
|
|
|
let users = this.Sync.User.all;
|
|
|
|
let identities = Object.keys(users);
|
|
|
|
if (identities.length === 1) {
|
|
|
|
user = users[identities[0]];
|
|
|
|
} else {
|
|
|
|
new Error(`One and only one user should be logged in but found ${users.length} users.`);
|
|
|
|
}
|
|
|
|
} else if (arguments.length === 1) {
|
|
|
|
user = arguments[0];
|
|
|
|
} else {
|
|
|
|
new Error(`Zero or one argument expected.`);
|
2018-03-09 09:40:45 +00:00
|
|
|
}
|
2018-03-14 07:26:41 +00:00
|
|
|
|
|
|
|
let url = new URL(user.server);
|
|
|
|
let secure = (url.protocol === 'https:')?'s':'';
|
|
|
|
let port = (url.port === undefined)?'9080':url.port
|
2018-03-21 17:18:37 +00:00
|
|
|
let realmUrl = `realm${secure}://${url.hostname}:${port}/default`;
|
2018-03-14 07:26:41 +00:00
|
|
|
|
|
|
|
let config = {
|
|
|
|
sync: {
|
2018-03-21 17:18:37 +00:00
|
|
|
user: user,
|
|
|
|
url: realmUrl,
|
2018-03-14 07:26:41 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
return config;
|
2018-10-04 08:09:31 +00:00
|
|
|
};
|
2018-03-09 09:40:45 +00:00
|
|
|
|
2017-08-14 13:05:52 +00:00
|
|
|
if (realmConstructor.Sync._setFeatureToken) {
|
|
|
|
realmConstructor.Sync.setFeatureToken = function(featureToken) {
|
2018-03-08 16:27:13 +00:00
|
|
|
console.log('Realm.Sync.setFeatureToken() is deprecated and you can remove any calls to it.');
|
2017-08-14 13:05:52 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-02 18:29:36 +00:00
|
|
|
|
2018-02-20 12:40:54 +00:00
|
|
|
// Keep these value in sync with subscription_state.hpp
|
|
|
|
realmConstructor.Sync.SubscriptionState = {
|
|
|
|
Error: -1, // An error occurred while creating or processing the partial sync subscription.
|
|
|
|
Creating: 2, // The subscription is being created.
|
|
|
|
Pending: 0, // The subscription was created, but has not yet been processed by the sync server.
|
|
|
|
Complete: 1, // The subscription has been processed by the sync server and data is being synced to the device.
|
|
|
|
Invalidated: 3, // The subscription has been removed.
|
2017-10-04 09:28:50 +00:00
|
|
|
};
|
2018-02-28 22:56:00 +00:00
|
|
|
|
2018-08-10 08:39:03 +00:00
|
|
|
realmConstructor.Sync.ConnectionState = {
|
|
|
|
Disconnected: "disconnected",
|
|
|
|
Connecting: "connecting",
|
|
|
|
Connected: "connected",
|
2018-10-04 08:09:31 +00:00
|
|
|
};
|
2018-08-10 08:39:03 +00:00
|
|
|
|
2018-02-28 22:56:00 +00:00
|
|
|
// Define the permission schemas as constructors so that they can be
|
|
|
|
// passed into directly to functions which want object type names
|
2018-10-04 08:09:31 +00:00
|
|
|
const Permission = function() {};
|
|
|
|
Permission.schema = Object.freeze({
|
2018-02-28 22:56:00 +00:00
|
|
|
name: '__Permission',
|
|
|
|
properties: {
|
|
|
|
role: '__Role',
|
|
|
|
canRead: {type: 'bool', default: false},
|
|
|
|
canUpdate: {type: 'bool', default: false},
|
|
|
|
canDelete: {type: 'bool', default: false},
|
|
|
|
canSetPermissions: {type: 'bool', default: false},
|
|
|
|
canQuery: {type: 'bool', default: false},
|
|
|
|
canCreate: {type: 'bool', default: false},
|
|
|
|
canModifySchema: {type: 'bool', default: false},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-10-04 08:09:31 +00:00
|
|
|
const User = function() {};
|
|
|
|
User.schema = Object.freeze({
|
2018-02-28 22:56:00 +00:00
|
|
|
name: '__User',
|
|
|
|
primaryKey: 'id',
|
|
|
|
properties: {
|
2018-03-13 13:27:31 +00:00
|
|
|
id: 'string',
|
|
|
|
role: '__Role'
|
2018-02-28 22:56:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-10-04 08:09:31 +00:00
|
|
|
const Role = function() {};
|
|
|
|
Role.schema = Object.freeze({
|
2018-02-28 22:56:00 +00:00
|
|
|
name: '__Role',
|
|
|
|
primaryKey: 'name',
|
|
|
|
properties: {
|
|
|
|
name: 'string',
|
|
|
|
members: '__User[]'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-10-04 08:09:31 +00:00
|
|
|
const Class = function() {};
|
|
|
|
Class.schema = Object.freeze({
|
2018-02-28 22:56:00 +00:00
|
|
|
name: '__Class',
|
2018-08-06 13:35:26 +00:00
|
|
|
primaryKey: 'name',
|
2018-02-28 22:56:00 +00:00
|
|
|
properties: {
|
2018-08-06 13:35:26 +00:00
|
|
|
name: 'string',
|
2018-02-28 22:56:00 +00:00
|
|
|
permissions: '__Permission[]'
|
|
|
|
}
|
|
|
|
});
|
2018-10-04 08:09:31 +00:00
|
|
|
Class.prototype.findOrCreate = function(roleName) {
|
|
|
|
return findOrCreatePermissionForRole(this, this.permissions, roleName);
|
|
|
|
};
|
2018-02-28 22:56:00 +00:00
|
|
|
|
2018-10-04 08:09:31 +00:00
|
|
|
const Realm = function() {};
|
|
|
|
Realm.schema = Object.freeze({
|
2018-02-28 22:56:00 +00:00
|
|
|
name: '__Realm',
|
|
|
|
primaryKey: 'id',
|
|
|
|
properties: {
|
|
|
|
id: 'int',
|
|
|
|
permissions: '__Permission[]'
|
|
|
|
}
|
|
|
|
});
|
2018-10-04 08:09:31 +00:00
|
|
|
Realm.prototype.findOrCreate = function(roleName) {
|
|
|
|
return findOrCreatePermissionForRole(this, this.permissions, roleName);
|
|
|
|
};
|
|
|
|
|
|
|
|
const permissionsSchema = {
|
|
|
|
'Class': Class,
|
|
|
|
'Permission': Permission,
|
|
|
|
'Realm': Realm,
|
|
|
|
'Role': Role,
|
|
|
|
'User': User,
|
|
|
|
};
|
|
|
|
|
2018-03-21 17:44:57 +00:00
|
|
|
if (!realmConstructor.Permissions) {
|
|
|
|
Object.defineProperty(realmConstructor, 'Permissions', {
|
|
|
|
value: permissionsSchema,
|
|
|
|
configurable: false
|
|
|
|
});
|
|
|
|
}
|
2018-10-04 08:09:31 +00:00
|
|
|
|
2018-10-10 10:00:04 +00:00
|
|
|
const ResultSets = function() {};
|
|
|
|
ResultSets.schema = Object.freeze({
|
|
|
|
name: '__ResultSets',
|
|
|
|
properties: {
|
|
|
|
name: { type: 'string', indexed: true },
|
|
|
|
query: 'string',
|
|
|
|
matches_property: 'string',
|
|
|
|
status: 'int',
|
|
|
|
error_message: 'string',
|
|
|
|
query_parse_counter: 'int'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const subscriptionSchema = {
|
|
|
|
'ResultSets': ResultSets
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!realmConstructor.Subscription) {
|
|
|
|
Object.defineProperty(realmConstructor, 'Subscription', {
|
|
|
|
value: subscriptionSchema,
|
|
|
|
configurable: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-04 08:09:31 +00:00
|
|
|
// Add instance methods to the Realm object that are only applied if Sync is
|
|
|
|
Object.defineProperties(realmConstructor.prototype, getOwnPropertyDescriptors({
|
|
|
|
permissions(arg) {
|
|
|
|
// If no argument is provided, return the Realm-level permissions
|
|
|
|
if (arg === undefined) {
|
|
|
|
return this.objects('__Realm').filtered(`id = 0`)[0];
|
|
|
|
} else {
|
|
|
|
// Else try to find the corresponding Class-level permissions
|
|
|
|
let schemaName = this._schemaName(arg);
|
|
|
|
let classPermissions = this.objects('__Class').filtered(`name = '${schemaName}'`);
|
|
|
|
if (classPermissions.length === 0) {
|
|
|
|
throw Error(`Could not find Class-level permissions for '${schemaName}'`);
|
|
|
|
}
|
|
|
|
return classPermissions[0];
|
|
|
|
}
|
|
|
|
},
|
2018-10-10 10:00:04 +00:00
|
|
|
|
|
|
|
subscriptions(name) {
|
|
|
|
let all_subscriptions = this.objects('__ResultSets');
|
|
|
|
if (name) {
|
|
|
|
if (typeof(name) !== 'string') {
|
|
|
|
throw new Error(`string expected - got ${typeof(name)}.`);
|
|
|
|
}
|
|
|
|
if (name.includes('*') || name.includes('?')) {
|
|
|
|
all_subscriptions = all_subscriptions.filtered(`name LIKE '${name}'`);
|
|
|
|
} else {
|
|
|
|
all_subscriptions = all_subscriptions.filtered(`name == '${name}'`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let listOfSubscriptions = [];
|
|
|
|
for (var subscription of all_subscriptions) {
|
|
|
|
let matches_property = subscription['matches_property'];
|
|
|
|
let sub = {
|
|
|
|
name: subscription['name'],
|
|
|
|
objectType: matches_property.substr(0, matches_property.length-8), // remove _matches
|
|
|
|
query: subscription['query'],
|
|
|
|
}
|
|
|
|
listOfSubscriptions.push(sub);
|
|
|
|
}
|
|
|
|
return listOfSubscriptions;
|
|
|
|
},
|
|
|
|
|
|
|
|
unsubscribe(name) {
|
|
|
|
if (typeof(name) === 'string') {
|
|
|
|
if (name !== '') {
|
|
|
|
let named_subscriptions = this.objects('__ResultSets').filtered(`name == '${name}'`);
|
|
|
|
if (named_subscriptions.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let doCommit = false;
|
|
|
|
if (!this.isInTransaction) {
|
|
|
|
this.beginTransaction();
|
|
|
|
doCommit = true;
|
|
|
|
}
|
|
|
|
this.delete(named_subscriptions);
|
|
|
|
if (doCommit) {
|
|
|
|
this.commitTransaction();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new Error('Non-empty string expected.');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new Error(`string expected - got ${typeof(name)}.`);
|
|
|
|
}
|
|
|
|
}
|
2018-10-04 08:09:31 +00:00
|
|
|
}));
|
|
|
|
|
2018-10-16 07:49:16 +00:00
|
|
|
Object.defineProperties(realmConstructor, getOwnPropertyDescriptors({
|
|
|
|
_extendQueryBasedSchema(schema) {
|
|
|
|
addSchemaIfNeeded(schema, realmConstructor.Permissions.Class);
|
|
|
|
addSchemaIfNeeded(schema, realmConstructor.Permissions.Permission);
|
|
|
|
addSchemaIfNeeded(schema, realmConstructor.Permissions.Realm);
|
|
|
|
addSchemaIfNeeded(schema, realmConstructor.Permissions.Role);
|
|
|
|
addSchemaIfNeeded(schema, realmConstructor.Permissions.User);
|
|
|
|
addSchemaIfNeeded(schema, realmConstructor.Subscription.ResultSets);
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
}
|
2018-10-04 08:09:31 +00:00
|
|
|
|
2016-10-10 14:17:05 +00:00
|
|
|
// TODO: Remove this now useless object.
|
|
|
|
var types = Object.freeze({
|
|
|
|
'BOOL': 'bool',
|
|
|
|
'INT': 'int',
|
|
|
|
'FLOAT': 'float',
|
|
|
|
'DOUBLE': 'double',
|
|
|
|
'STRING': 'string',
|
|
|
|
'DATE': 'date',
|
|
|
|
'DATA': 'data',
|
|
|
|
'OBJECT': 'object',
|
|
|
|
'LIST': 'list',
|
|
|
|
});
|
|
|
|
Object.defineProperty(realmConstructor, 'Types', {
|
|
|
|
get: function() {
|
|
|
|
if (typeof console != 'undefined') {
|
|
|
|
/* global console */
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
var stack = new Error().stack.split("\n").slice(2).join("\n");
|
|
|
|
var msg = '`Realm.Types` is deprecated! Please specify the type name as lowercase string instead!\n'+stack;
|
|
|
|
if (console.warn != undefined) {
|
|
|
|
console.warn(msg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log(msg);
|
|
|
|
}
|
|
|
|
/* eslint-enable no-console */
|
|
|
|
}
|
|
|
|
return types;
|
|
|
|
},
|
|
|
|
configurable: true
|
|
|
|
});
|
2017-03-22 12:52:41 +00:00
|
|
|
}
|