mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-21 20:10:43 +00:00
Bumped version of ESLint, added eslinting of specs, make all linting pass
This commit is contained in:
parent
b01349087c
commit
06d277aacd
@ -6,4 +6,5 @@ build/
|
||||
node_modules/
|
||||
vendor/
|
||||
|
||||
/tests/test-runners/
|
||||
/tests/test-runners/
|
||||
/object-server-for-testing/
|
@ -1,10 +1,19 @@
|
||||
{
|
||||
"root": true,
|
||||
"env": {
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"rules": {
|
||||
"comma-dangle": 0,
|
||||
"no-empty": 0,
|
||||
"no-unused-vars": 1,
|
||||
"no-unused-vars": [
|
||||
"warn", {
|
||||
"varsIgnorePattern": "^_",
|
||||
"argsIgnorePattern": "^_"
|
||||
}
|
||||
],
|
||||
"strict": [2, "global"]
|
||||
}
|
||||
}
|
||||
|
47
docs/sync.js
47
docs/sync.js
@ -20,29 +20,30 @@
|
||||
* @memberof Realm
|
||||
*/
|
||||
class Sync {
|
||||
|
||||
/**
|
||||
* Set a global listener function.
|
||||
* @param {string} local_path - The path to the directory where realm files are stored [deprecated]
|
||||
* @param {string} server_url - The sync server to listen to
|
||||
* @param {SyncUser} admin_user - An admin user obtained by calling `new Realm.Sync.User.Admin`
|
||||
* @param {function(realm_name)} filter_callback - Return true to recieve changes for the given realm
|
||||
* @param {function(realm_name, realm, change_set)} change_callback - called on any realm changes with
|
||||
* the following arguments:
|
||||
* - `realm_name` - path of the Realm on which changes occurred
|
||||
* - `realm` - a `Realm` object for the changed Realm
|
||||
* - `change_set` - a dictionary of object names to arays of indexes indicating the indexes of objects of each type
|
||||
* which have been added, removed, or modified
|
||||
*/
|
||||
static setGlobalListener(local_path, server_url, admin_user, filter_callback, change_callback) {}
|
||||
|
||||
/**
|
||||
* Set the sync log level.
|
||||
* @param {string} log_level
|
||||
*/
|
||||
static setLogLevel(log_level) {}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a global listener function.
|
||||
* @param {string} local_path - The path to the directory where realm files are stored [deprecated]
|
||||
* @param {string} server_url - The sync server to listen to
|
||||
* @param {SyncUser} admin_user - An admin user obtained by calling `new Realm.Sync.User.Admin`
|
||||
* @param {function(realm_name)} filter_callback - Return true to recieve changes for the given realm
|
||||
* @param {function(realm_name, realm, change_set)} change_callback - called on any realm changes with
|
||||
* the following arguments:
|
||||
* - `realm_name` - path of the Realm on which changes occurred
|
||||
* - `realm` - a `Realm` object for the changed Realm
|
||||
* - `change_set` - a dictionary of object names to arays of indexes indicating the indexes of objects of each type
|
||||
* which have been added, removed, or modified
|
||||
*/
|
||||
Sync.setGlobalListener = function(local_path, server_url, admin_user, filter_callback, change_callback) {};
|
||||
|
||||
/**
|
||||
* Set the sync log level.
|
||||
* @param {string} log_level
|
||||
*/
|
||||
Sync.setLogLevel = function(log_level) {};
|
||||
|
||||
/**
|
||||
* @typedef Realm.Sync~LogLevel
|
||||
* @type {("error"|"info"|"debug")}
|
||||
@ -117,12 +118,12 @@ class User {
|
||||
* The keys in the dictionary are user identities, values are corresponding User objects.
|
||||
* @type {object}
|
||||
*/
|
||||
get all() {};
|
||||
get all() {}
|
||||
|
||||
/**
|
||||
* Get the currently logged in user.
|
||||
* Throws error if > 1 user logged in, returns undefined if no users logged in.
|
||||
* @type {User}
|
||||
*/
|
||||
get current() {};
|
||||
get current() {}
|
||||
}
|
||||
|
@ -1,5 +1,2 @@
|
||||
{
|
||||
"env": {
|
||||
"commonjs": true
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"env": {
|
||||
"es6": true,
|
||||
"worker": true
|
||||
"worker": true,
|
||||
"node": false
|
||||
},
|
||||
"globals": {
|
||||
"global": true
|
@ -52,7 +52,7 @@ export function fireMutationListeners(realmId) {
|
||||
}
|
||||
}
|
||||
|
||||
export function createCollection(prototype, realmId, info, mutable) {
|
||||
export function createCollection(prototype, realmId, info, _mutable) {
|
||||
let collection = Object.create(prototype);
|
||||
let size;
|
||||
|
||||
|
@ -145,7 +145,7 @@ Object.defineProperties(Realm, {
|
||||
set: util.setterForProperty('defaultPath'),
|
||||
},
|
||||
schemaVersion: {
|
||||
value: function(path, encryptionKey) {
|
||||
value: function(_path, _encryptionKey) {
|
||||
return rpc.callMethod(undefined, Realm[keys.id], 'schemaVersion', Array.from(arguments));
|
||||
}
|
||||
},
|
||||
|
@ -21,7 +21,7 @@
|
||||
import * as base64 from './base64';
|
||||
import { keys, objectTypes } from './constants';
|
||||
|
||||
const {id: idKey, realm: realmKey} = keys;
|
||||
const {id: idKey, realm: _realmKey} = keys;
|
||||
const registeredCallbacks = [];
|
||||
const typeConverters = {};
|
||||
|
||||
|
@ -28,7 +28,8 @@ module.exports = function(realmConstructor) {
|
||||
realmConstructor.Sync.AuthError = require('./errors').AuthError;
|
||||
|
||||
if (realmConstructor.Sync.cleanup) {
|
||||
process.on('exit', () => realmConstructor.Sync.cleanup());
|
||||
// FIXME: DOES THIS WORK ON BOTH NODE AND REACT NATIVE?
|
||||
process.on('exit', realmConstructor.Sync.cleanup);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ if (typeof Realm != 'undefined') {
|
||||
realmConstructor = require('./browser').default; // (exported as ES6 module)
|
||||
// eslint-disable-next-line
|
||||
} else if (typeof process == 'object' && (('' + process) == '[object process]' || typeof jest == 'object')) {
|
||||
// If process is defined, we're running in node.
|
||||
// Prevent React Native packager from seeing this module.
|
||||
var binary = node_require('node-pre-gyp');
|
||||
var path = node_require('path');
|
||||
|
@ -7,9 +7,10 @@ function node_require(module) {
|
||||
}
|
||||
|
||||
var post;
|
||||
if (typeof fetch != 'undefined') {
|
||||
if (typeof fetch !== 'undefined') {
|
||||
post = function(options, callback) {
|
||||
options.method = 'POST';
|
||||
// eslint-disable-next-line no-undef
|
||||
fetch(options.url, options)
|
||||
.then((response) => {
|
||||
if (response.status != 200) {
|
||||
|
@ -14,7 +14,8 @@
|
||||
"sqlite",
|
||||
"asyncstorage",
|
||||
"rocksdb",
|
||||
"leveldb"
|
||||
"leveldb",
|
||||
"realm"
|
||||
],
|
||||
"author": {
|
||||
"name": "Realm",
|
||||
@ -57,8 +58,9 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-eslint": "^6.0.4",
|
||||
"eslint": "^2.10.2",
|
||||
"eslint-plugin-react": "^5.1.1",
|
||||
"eslint": "^3.2.2",
|
||||
"eslint-plugin-jasmine": "^2.1.0",
|
||||
"eslint-plugin-react": "^6.7.0",
|
||||
"jsdoc": "^3.4.0",
|
||||
"semver": "^5.1.0"
|
||||
},
|
||||
|
@ -1,7 +1,9 @@
|
||||
{
|
||||
"env": {
|
||||
"commonjs": true
|
||||
"jasmine": true
|
||||
},
|
||||
"plugins": ["jasmine"],
|
||||
"extends": "plugin:jasmine/recommended",
|
||||
"globals": {
|
||||
"ArrayBuffer": false,
|
||||
"DataView": false,
|
||||
@ -14,5 +16,12 @@
|
||||
"Uint32Array": false,
|
||||
"Uint8Array": false,
|
||||
"Uint8ClampedArray": false
|
||||
},
|
||||
"rules": {
|
||||
"no-invalid-this": "off",
|
||||
"no-magic-numbers": "off",
|
||||
"jasmine/no-spec-dupes": ["error", "branch"],
|
||||
"jasmine/no-suite-dupes": ["error", "branch"],
|
||||
"no-console": "off"
|
||||
}
|
||||
}
|
@ -71,7 +71,7 @@ function createNotificationTest(config, getObservable, addListener, removeListen
|
||||
|
||||
worker.postMessage(messages[messageIndex++]);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function createCollectionChangeTest(config, createCollection, messages, expected, removeAll) {
|
||||
return createNotificationTest(
|
||||
@ -97,7 +97,7 @@ function createCollectionChangeTest(config, createCollection, messages, expected
|
||||
messages,
|
||||
expected.length
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
const ListObject = {
|
||||
name: 'ListObject',
|
||||
|
@ -18,8 +18,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var Realm = require('realm');
|
||||
|
||||
exports.TestObject = {
|
||||
name: 'TestObject',
|
||||
properties: {
|
||||
|
@ -22,7 +22,6 @@
|
||||
|
||||
const Realm = require('realm');
|
||||
const TestCase = require('./asserts');
|
||||
const schemas = require('./schemas');
|
||||
|
||||
function uuid() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||
@ -104,7 +103,7 @@ module.exports = {
|
||||
|
||||
// Can we open a realm with the registered user?
|
||||
TestCase.assertThrows(function() {
|
||||
var realm = new Realm({sync: {user: user, url: 'realm://localhost:9080/~/test'}});
|
||||
var _realm = new Realm({sync: {user: user, url: 'realm://localhost:9080/~/test'}});
|
||||
});
|
||||
})
|
||||
},
|
||||
@ -209,7 +208,7 @@ module.exports = {
|
||||
},
|
||||
|
||||
testAll() {
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise((resolve, _reject) => {
|
||||
let all;
|
||||
all = Realm.Sync.User.all;
|
||||
TestCase.assertArrayLength(Object.keys(all), 0);
|
||||
@ -246,7 +245,7 @@ module.exports = {
|
||||
},
|
||||
|
||||
testCurrent() {
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise((resolve, _reject) => {
|
||||
TestCase.assertUndefined(Realm.Sync.User.current);
|
||||
|
||||
callbackTest((callback) => Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', callback), (error, user1) => {
|
||||
|
@ -28,8 +28,6 @@ import {
|
||||
import React from 'react';
|
||||
import { runTests } from './tests';
|
||||
|
||||
const Realm = require('realm');
|
||||
|
||||
class ReactTests extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
|
@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var jasmineReporters = require('jasmine-reporters');
|
||||
var junitReporter = new jasmineReporters.JUnitXmlReporter({
|
||||
savePath: '.',
|
||||
|
@ -7,57 +7,57 @@ const Realm = require("realm");
|
||||
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
|
||||
|
||||
beforeEach(function(done) {
|
||||
this.objectServer = spawn("sync-bundle/start-object-server.command");
|
||||
this.objectServer.once("close", (code) => {
|
||||
if (typeof code === "number" && code != 0) {
|
||||
console.error(`Object Server exited with code ${code}`);
|
||||
process.exit(-1);
|
||||
}
|
||||
});
|
||||
describe('Sync Integration', () => {
|
||||
beforeEach(function(done) {
|
||||
this.objectServer = spawn("sync-bundle/start-object-server.command");
|
||||
this.objectServer.once("close", (code) => {
|
||||
if (typeof code === "number" && code != 0) {
|
||||
console.error(`Object Server exited with code ${code}`);
|
||||
process.exit(-1);
|
||||
}
|
||||
});
|
||||
|
||||
this.rl = readline.createInterface({ input: this.objectServer.stdout });
|
||||
this.rl.on("line", (line) => {
|
||||
var match;
|
||||
if ((match = line.match(/Connection\[1\]: Session\[1\]: Received: BIND\(server_path='\/(.+)',/))) {
|
||||
var adminUser = Realm.Sync.User.adminUser('http://127.0.0.1:9080/',
|
||||
fs.readFileSync("sync-bundle/admin_token.base64", "utf-8"));
|
||||
this.adminRealmPath = match[1];
|
||||
this.adminRealm = new Realm({
|
||||
path: "__admin.realm",
|
||||
sync: {
|
||||
user: adminUser,
|
||||
url: `realm://127.0.0.1:9080/${this.adminRealmPath}`
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
name: "RealmFile",
|
||||
properties: {
|
||||
id: 'string',
|
||||
path: 'string'
|
||||
this.rl = readline.createInterface({ input: this.objectServer.stdout });
|
||||
this.rl.on("line", (line) => {
|
||||
var match;
|
||||
if ((match = line.match(/Connection\[1\]: Session\[1\]: Received: BIND\(server_path='\/(.+)',/))) {
|
||||
var adminUser = Realm.Sync.User.adminUser('http://127.0.0.1:9080/',
|
||||
fs.readFileSync("sync-bundle/admin_token.base64", "utf-8"));
|
||||
this.adminRealmPath = match[1];
|
||||
this.adminRealm = new Realm({
|
||||
path: "__admin.realm",
|
||||
sync: {
|
||||
user: adminUser,
|
||||
url: `realm://127.0.0.1:9080/${this.adminRealmPath}`
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
name: "RealmFile",
|
||||
properties: {
|
||||
id: 'string',
|
||||
path: 'string'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
]
|
||||
});
|
||||
|
||||
done();
|
||||
}
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function(done) {
|
||||
this.rl.close();
|
||||
this.objectServer.kill('SIGKILL');
|
||||
this.adminRealm.close();
|
||||
afterEach(function(done) {
|
||||
this.rl.close();
|
||||
this.objectServer.kill('SIGKILL');
|
||||
this.adminRealm.close();
|
||||
|
||||
let reset = spawn("sync-bundle/reset-server-realms.command");
|
||||
reset.once("close", done);
|
||||
reset.stdin.write("yes\n");
|
||||
let reset = spawn("sync-bundle/reset-server-realms.command");
|
||||
reset.once("close", done);
|
||||
reset.stdin.write("yes\n");
|
||||
|
||||
Realm.clearTestState();
|
||||
});
|
||||
Realm.clearTestState();
|
||||
});
|
||||
|
||||
describe("Sync", function() {
|
||||
it("should work", function(done) {
|
||||
Realm.Sync.User.create('http://127.0.0.1:9080/', 'foo', 'bar', function(error) {
|
||||
if (error) {
|
||||
@ -71,11 +71,11 @@ describe("Sync", function() {
|
||||
return;
|
||||
}
|
||||
|
||||
var realm = new Realm({
|
||||
var _realm = new Realm({
|
||||
syncConfig: {
|
||||
identity: user.identity,
|
||||
identity: user.identity,
|
||||
url: 'realm://127.0.0.1:9080/~/demo/realm1'
|
||||
},
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
name: 'IntObject',
|
||||
@ -96,4 +96,5 @@ describe("Sync", function() {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user