[database] cleanup linting issues

This commit is contained in:
Salakar
2019-06-03 18:58:45 +01:00
parent 43489d93eb
commit bfe13f2bed
30 changed files with 143 additions and 96 deletions

View File

@@ -15,7 +15,7 @@
*
*/
import {ReactNativeFirebaseNamespace} from "@react-native-firebase/app-types";
import { ReactNativeFirebaseNamespace } from '@react-native-firebase/app-types';
/**
* @firebase firebase

View File

@@ -8,6 +8,7 @@ import { isObject } from './validate';
* @param joiner
* @returns {*}
*/
// eslint-disable-next-line import/prefer-default-export
export function deepGet(object, path, joiner = '/') {
if (!isObject(object) && !Array.isArray(object)) return undefined;
const keys = path.split(joiner);

View File

@@ -1,9 +1,6 @@
const PUSH_CHARS = '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
const PUSH_CHARS =
'-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
const AUTO_ID_CHARS =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const AUTO_ID_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
// timestamp of last push, used to prevent local collisions if you push twice in one ms.
let lastPushTime = 0;
@@ -69,9 +66,7 @@ export function generateFirestoreId(): string {
let autoId = '';
for (let i = 0; i < 20; i++) {
autoId += AUTO_ID_CHARS.charAt(
Math.floor(Math.random() * AUTO_ID_CHARS.length)
);
autoId += AUTO_ID_CHARS.charAt(Math.floor(Math.random() * AUTO_ID_CHARS.length));
}
return autoId;
}

View File

@@ -100,7 +100,7 @@ export function isValidPath(path) {
return typeof path === 'string' && path.length !== 0 && !INVALID_PATH_REGEX.test(path);
}
// eslint-disable-next-line no-control-regex
// eslint-disable-next-line no-control-regex,no-useless-escape
export const INVALID_KEY_REGEX = /[\[\].#$\/\u0000-\u001F\u007F]/;
/**

View File

@@ -49,6 +49,7 @@ describe('config()', () => {
await firebase.config().fetch(0);
firebase.config().lastFetchStatus.should.equal(firebase.config.LastFetchStatus.SUCCESS);
// TODO leave logger here - need to investigate flakey test
// eslint-disable-next-line no-console
console.log(firebase.config().lastFetchTime, date);
should.equal(firebase.config().lastFetchTime >= date, true);
});

View File

@@ -32,13 +32,21 @@ const CONTENT = {
exports.seed = function seed(path) {
return Promise.all([
firebase.database().ref(`${path}/types`).set(CONTENT.TYPES),
firebase.database().ref(`${path}/query`).set(CONTENT.QUERY),
firebase
.database()
.ref(`${path}/types`)
.set(CONTENT.TYPES),
firebase
.database()
.ref(`${path}/query`)
.set(CONTENT.QUERY),
]);
};
exports.wipe = function wipe(path) {
return firebase.database().ref(path)
return firebase
.database()
.ref(path)
.remove();
};

View File

@@ -16,7 +16,6 @@
*/
describe(`database().ref('.info/connected')`, () => {
after(() => firebase.database().goOnline());
it('returns false when used with once', async () => {
@@ -43,9 +42,7 @@ describe(`database().ref('.info/connected')`, () => {
const callback = sinon.spy();
await firebase.database().goOffline();
const ref = firebase
.database()
.ref('.info/connected');
const ref = firebase.database().ref('.info/connected');
const handler = $ => {
callback($.val());

View File

@@ -20,7 +20,6 @@ const { PATH, wipe } = require('../helpers');
const TEST_PATH = `${PATH}/onDisconnectCancel`;
describe('database().ref().onDisconnect().cancel()', () => {
after(() => wipe(TEST_PATH));
afterEach(() => {
@@ -29,7 +28,10 @@ describe('database().ref().onDisconnect().cancel()', () => {
});
it('throws if onComplete is not a function', () => {
const ref = firebase.database().ref(TEST_PATH).onDisconnect();
const ref = firebase
.database()
.ref(TEST_PATH)
.onDisconnect();
try {
ref.cancel('foo');
return Promise.reject(new Error('Did not throw an Error.'));

View File

@@ -20,7 +20,6 @@ const { PATH, wipe } = require('../helpers');
const TEST_PATH = `${PATH}/onDisconnectRemove`;
describe('database().ref().onDisconnect().remove()', () => {
after(() => wipe(TEST_PATH));
afterEach(() => {
@@ -29,7 +28,10 @@ describe('database().ref().onDisconnect().remove()', () => {
});
it('throws if onComplete is not a function', () => {
const ref = firebase.database().ref(TEST_PATH).onDisconnect();
const ref = firebase
.database()
.ref(TEST_PATH)
.onDisconnect();
try {
ref.remove('foo');
return Promise.reject(new Error('Did not throw an Error.'));
@@ -40,7 +42,10 @@ describe('database().ref().onDisconnect().remove()', () => {
});
it('removes a node whilst offline', async () => {
const ref = firebase.database().ref(TEST_PATH).child('removeMe');
const ref = firebase
.database()
.ref(TEST_PATH)
.child('removeMe');
await ref.set('foobar');
@@ -54,7 +59,10 @@ describe('database().ref().onDisconnect().remove()', () => {
it('calls back to the onComplete function', async () => {
const callback = sinon.spy();
const ref = firebase.database().ref(TEST_PATH).child('removeMe');
const ref = firebase
.database()
.ref(TEST_PATH)
.child('removeMe');
// Set an initial value
await ref.set('foo');

View File

@@ -15,12 +15,11 @@
*
*/
const { PATH, seed, wipe } = require('../helpers');
const { PATH, wipe } = require('../helpers');
const TEST_PATH = `${PATH}/onDisconnectSet`;
describe('database().ref().onDisconnect().set()', () => {
after(() => wipe(TEST_PATH));
afterEach(() => {
@@ -29,7 +28,10 @@ describe('database().ref().onDisconnect().set()', () => {
});
it('throws if value is not a defined', () => {
const ref = firebase.database().ref(TEST_PATH).onDisconnect();
const ref = firebase
.database()
.ref(TEST_PATH)
.onDisconnect();
try {
ref.set();
return Promise.reject(new Error('Did not throw an Error.'));
@@ -40,7 +42,10 @@ describe('database().ref().onDisconnect().set()', () => {
});
it('throws if onComplete is not a function', () => {
const ref = firebase.database().ref(TEST_PATH).onDisconnect();
const ref = firebase
.database()
.ref(TEST_PATH)
.onDisconnect();
try {
ref.set(null, 'foo');
return Promise.reject(new Error('Did not throw an Error.'));

View File

@@ -20,7 +20,6 @@ const { PATH, wipe } = require('../helpers');
const TEST_PATH = `${PATH}/onDisconnectSetWithPriority`;
describe('database().ref().onDisconnect().setWithPriority()', () => {
after(() => wipe(TEST_PATH));
afterEach(() => {
@@ -29,7 +28,10 @@ describe('database().ref().onDisconnect().setWithPriority()', () => {
});
it('throws if value is not a defined', () => {
const ref = firebase.database().ref(TEST_PATH).onDisconnect();
const ref = firebase
.database()
.ref(TEST_PATH)
.onDisconnect();
try {
ref.setWithPriority();
return Promise.reject(new Error('Did not throw an Error.'));
@@ -40,7 +42,10 @@ describe('database().ref().onDisconnect().setWithPriority()', () => {
});
it('throws if priority is not a valid type', () => {
const ref = firebase.database().ref(TEST_PATH).onDisconnect();
const ref = firebase
.database()
.ref(TEST_PATH)
.onDisconnect();
try {
ref.setWithPriority(null, { foo: 'bar' });
return Promise.reject(new Error('Did not throw an Error.'));
@@ -51,7 +56,10 @@ describe('database().ref().onDisconnect().setWithPriority()', () => {
});
it('throws if onComplete is not a function', () => {
const ref = firebase.database().ref(TEST_PATH).onDisconnect();
const ref = firebase
.database()
.ref(TEST_PATH)
.onDisconnect();
try {
ref.setWithPriority(null, 1, 'foo');
return Promise.reject(new Error('Did not throw an Error.'));

View File

@@ -79,9 +79,12 @@ describe('database().ref().onDisconnect().update()', () => {
},
});
await ref.child('foo').onDisconnect().update({
bar: value,
});
await ref
.child('foo')
.onDisconnect()
.update({
bar: value,
});
await firebase.database().goOffline();
await firebase.database().goOnline();

View File

@@ -37,14 +37,25 @@ describe('database().ref().isEqual()', () => {
it('returns false if the query is different', async () => {
const query = await firebase.database().ref();
const other = await firebase.database().ref().limitToLast(2);
const other = await firebase
.database()
.ref()
.limitToLast(2);
const same = query.isEqual(other);
same.should.eql(false);
});
it('returns true if the query is created differently', async () => {
const query = await firebase.database().ref().limitToFirst(1).orderByChild('foo');
const other = await firebase.database().ref().orderByChild('foo').limitToFirst(1);
const query = await firebase
.database()
.ref()
.limitToFirst(1)
.orderByChild('foo');
const other = await firebase
.database()
.ref()
.orderByChild('foo')
.limitToFirst(1);
const same = query.isEqual(other);
same.should.eql(true);
});

View File

@@ -30,7 +30,10 @@ describe('database().ref().keepSynced()', () => {
});
it('toggles keepSynced on and off without throwing', async () => {
const ref = firebase.database().ref('noop').orderByValue();
const ref = firebase
.database()
.ref('noop')
.orderByValue();
await ref.keepSynced(true);
await ref.keepSynced(false);
});

View File

@@ -20,7 +20,6 @@ const { PATH } = require('../helpers');
const TEST_PATH = `${PATH}/on`;
describe('database().ref().on()', () => {
it('throws if event type is invalid', async () => {
try {
await firebase

View File

@@ -38,7 +38,10 @@ describe('database().ref().orderByPriority()', () => {
});
it('order by priority', async () => {
const ref = firebase.database().ref(TEST_PATH).child('query');
const ref = firebase
.database()
.ref(TEST_PATH)
.child('query');
await Promise.all([
ref.child('a').setPriority(2),
@@ -47,9 +50,7 @@ describe('database().ref().orderByPriority()', () => {
]);
try {
const snapshot = await ref
.orderByPriority()
.once('value');
const snapshot = await ref.orderByPriority().once('value');
const expected = ['c', 'a', 'b'];

View File

@@ -38,7 +38,10 @@ describe('database().ref().orderByValue()', () => {
});
it('order by value', async () => {
const ref = firebase.database().ref(TEST_PATH).child('query');
const ref = firebase
.database()
.ref(TEST_PATH)
.child('query');
await ref.set({
a: 2,
@@ -47,9 +50,7 @@ describe('database().ref().orderByValue()', () => {
});
try {
const snapshot = await ref
.orderByValue()
.once('value');
const snapshot = await ref.orderByValue().once('value');
const expected = ['c', 'a', 'b'];

View File

@@ -16,11 +16,12 @@
*/
describe('database().ref().toJSON()', () => {
it('returns a string version of the current query path', async () => {
const res = firebase.database().ref('foo/bar/baz').toJSON();
const res = firebase
.database()
.ref('foo/bar/baz')
.toJSON();
const expected = `${firebase.database()._customUrlOrRegion}/foo/bar/baz`;
should.equal(res, expected);
});
});

View File

@@ -19,7 +19,10 @@
describe('database().ref().onDisconnect()', () => {
it('returns a new DatabaseOnDisconnect instance', () => {
const instance = firebase.database().ref().onDisconnect();
const instance = firebase
.database()
.ref()
.onDisconnect();
instance.constructor.name.should.eql('DatabaseOnDisconnect');
});
});

View File

@@ -15,16 +15,12 @@
*
*/
const { PATH, seed, wipe } = require('../helpers');
// const { PATH, seed, wipe } = require('../helpers');
const TEST_PATH = `${PATH}/push`;
describe('database().ref().push()', () => {
// const TEST_PATH = `${PATH}/push`;
xdescribe('database().ref().push()', () => {
// before(() => seed(TEST_PATH));
// after(() => wipe(TEST_PATH));
// TODO
});

View File

@@ -20,13 +20,15 @@ const { PATH, seed, wipe } = require('../helpers');
const TEST_PATH = `${PATH}/set`;
describe('database().ref().set()', () => {
before(() => seed(TEST_PATH));
after(() => wipe(TEST_PATH));
it('throws if no value is provided', async () => {
try {
await firebase.database().ref(TEST_PATH).set();
await firebase
.database()
.ref(TEST_PATH)
.set();
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(`'value' must be defined`);
@@ -36,7 +38,10 @@ describe('database().ref().set()', () => {
it('throws if onComplete is not a function', async () => {
try {
await firebase.database().ref(TEST_PATH).set(null, 'foo');
await firebase
.database()
.ref(TEST_PATH)
.set(null, 'foo');
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(`'onComplete' must be a function if provided`);

View File

@@ -20,13 +20,15 @@ const { PATH, CONTENT, seed, wipe } = require('../helpers');
const TEST_PATH = `${PATH}/priority`;
describe('database().ref().setPriority()', () => {
before(() => seed(TEST_PATH));
after(() => wipe(TEST_PATH));
it('throws if priority is not a valid type', async () => {
try {
await firebase.database().ref().setPriority({});
await firebase
.database()
.ref()
.setPriority({});
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(`'priority' must be a number, string or null value`);
@@ -36,7 +38,10 @@ describe('database().ref().setPriority()', () => {
it('throws if onComplete is not a function', async () => {
try {
await firebase.database().ref().setPriority(null, 'foo');
await firebase
.database()
.ref()
.setPriority(null, 'foo');
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(`'onComplete' must be a function if provided`);

View File

@@ -15,12 +15,11 @@
*
*/
const { PATH, CONTENT, seed, wipe } = require('../helpers');
const { PATH, seed, wipe } = require('../helpers');
const TEST_PATH = `${PATH}/setWithPriority`;
describe('database().ref().setWithPriority()', () => {
before(() => seed(TEST_PATH));
after(() => wipe(TEST_PATH));

View File

@@ -56,9 +56,12 @@ describe('database().ref().update()', () => {
await firebase
.database()
.ref(`${PATH}/update`)
.update({
foo: 'bar',
}, 'foo');
.update(
{
foo: 'bar',
},
'foo',
);
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(`'onComplete' must be a function if provided`);

View File

@@ -17,7 +17,6 @@
*/
import {
isArray,
isBoolean,
isFunction,
isNull,

View File

@@ -21,7 +21,7 @@ import {
pathParent,
pathChild,
isValidPath,
generateDatabaseId,
// generateDatabaseId,
isNumber,
isNull,
isUndefined,
@@ -216,12 +216,7 @@ export default class DatabaseReference extends DatabaseQuery {
};
// start the transaction natively
this._database._transaction.add(
this,
transactionUpdate,
onCompleteWrapper,
applyLocally
);
this._database._transaction.add(this, transactionUpdate, onCompleteWrapper, applyLocally);
});
}
@@ -255,15 +250,15 @@ export default class DatabaseReference extends DatabaseQuery {
* @param onComplete
* @returns {DatabaseReference}
*/
push(value, onComplete) {
// TODO validate value?
//
// const id = generateDatabaseId(this._database._serverTime);
// const pushRef = this.child(id);
// const thennablePushRef = this.child(id);
//
// return thennablePushRef;
}
// push(value, onComplete) {
// TODO validate value?
//
// const id = generateDatabaseId(this._database._serverTime);
// const pushRef = this.child(id);
// const thennablePushRef = this.child(id);
//
// return thennablePushRef;
// }
/**
* @url https://firebase.google.com/docs/reference/js/firebase.database.Reference#ondisconnect

View File

@@ -17,7 +17,6 @@
*/
import NativeError from '@react-native-firebase/app/lib/internal/NativeFirebaseError';
import DatabaseDataSnapshot from './DatabaseDataSnapshot';
let transactionId = 0;

View File

@@ -364,8 +364,7 @@ export namespace Database {
onDisconnect(): OnDisconnect;
}
export interface ThenableReference extends Reference {
}
export interface ThenableReference extends Reference {}
/**
* A Query sorts and filters the data at a Database location so only a subset of the child data
@@ -1154,7 +1153,7 @@ export namespace Database {
*
* @param enabled Whether debug logging is enabled.
*/
setLoggingEnabled(enabled: boolean): void
setLoggingEnabled(enabled: boolean): void;
/**
* By default Firebase Database will use up to 10MB of disk space to cache data. If the cache grows beyond this size,
@@ -1187,8 +1186,10 @@ declare module '@react-native-firebase/database' {
import { ReactNativeFirebaseNamespace } from '@react-native-firebase/app-types';
const FirebaseNamespaceExport: {} & ReactNativeFirebaseNamespace;
export const firebase = FirebaseNamespaceExport;
const DatabaseDefaultExport: ReactNativeFirebaseModuleAndStatics<Database.Module,
Database.Statics>;
const DatabaseDefaultExport: ReactNativeFirebaseModuleAndStatics<
Database.Module,
Database.Statics
>;
export default DatabaseDefaultExport;
}

View File

@@ -98,7 +98,7 @@ class FirebaseDatabaseModule extends FirebaseModule {
throw new Error(
`firebase.app().database().refFromURL(*) 'url' must be the same domain as the current instance (${
this._customUrlOrRegion
}). To use a different database domain, create a new Firebase instance.`,
}). To use a different database domain, create a new Firebase instance.`,
);
}

View File

@@ -20,9 +20,7 @@ import type { ReactNativeFirebaseModule } from '@react-native-firebase/app-types
export interface Statics {}
export interface Module extends ReactNativeFirebaseModule {
}
export interface Module extends ReactNativeFirebaseModule {}
declare module '@react-native-firebase/database' {
import type {