1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-27 23:28:38 +02:00

First pass at linting lib dir

This commit is contained in:
Laurent Cozic
2019-07-29 15:43:53 +02:00
parent 64b7bc3d62
commit 86dc72b204
170 changed files with 4140 additions and 3119 deletions
ReactNativeClient/lib
ArrayUtils.jsBaseApplication.jsBaseModel.jsBaseSyncTarget.jsCache.jsClipperServer.jsDropboxApi.jsEventDispatcher.jsHtmlToMd.jsJoplinError.jsModelCache.jsObjectUtils.jsSyncTargetDropbox.jsSyncTargetFilesystem.jsSyncTargetMemory.jsSyncTargetNextcloud.jsSyncTargetOneDrive.jsSyncTargetOneDriveDev.jsSyncTargetRegistry.jsSyncTargetWebDAV.jsTaskQueue.jsTemplateUtils.jsWebDavApi.jsWelcomeUtils.js
components
database-driver-node.jsdatabase-driver-react-native.jsdatabase.jsdialogs.jsfile-api-driver-dropbox.jsfile-api-driver-local.jsfile-api-driver-memory.jsfile-api-driver-onedrive.jsfile-api-driver-webdav.jsfile-api.jsfolders-screen-utils.jsfs-driver-base.jsfs-driver-dummy.jsfs-driver-node.jsfs-driver-rn.jsgeolocation-node.jsgeolocation-react.jshtmlUtils.jsimport-enex-md-gen.jsimport-enex.jsjoplin-database.jslayout-utils.jslocale.jslogger.jsmarkJsUtils.jsmarkdownUtils.jsmarkupLanguageUtils.js
migrations
mime-utils.js
models
net-utils.jsonedrive-api.jsparameters.jsparseUri.jspath-utils.jspoor-man-intervals.jspromise-utils.jsrandomClipperPort.jsreact-logger.jsreducer.jsregistry.js
renderers
services
shim-init-node.jsshim-init-react.jsshim.jsstring-utils-common.jsstring-utils.jssynchronizer.jstime-utils.jsurlUtils.jsuuid.jswelcomeAssets.js

@ -4,7 +4,6 @@ const { time } = require('lib/time-utils.js');
const Mutex = require('async-mutex').Mutex;
class BaseModel {
static modelType() {
throw new Error('Must be overriden');
}
@ -15,7 +14,7 @@ class BaseModel {
static addModelMd(model) {
if (!model) return model;
if (Array.isArray(model)) {
let output = [];
for (let i = 0; i < model.length; i++) {
@ -144,9 +143,11 @@ class BaseModel {
if (!options) options = {};
let sql = 'SELECT count(*) as total FROM `' + this.tableName() + '`';
if (options.where) sql += ' WHERE ' + options.where;
return this.db().selectOne(sql).then((r) => {
return r ? r['total'] : 0;
});
return this.db()
.selectOne(sql)
.then(r => {
return r ? r['total'] : 0;
});
}
static load(id) {
@ -175,7 +176,7 @@ class BaseModel {
}
sql += ' ORDER BY ' + items.join(', ');
}
if (options.limit) sql += ' LIMIT ' + options.limit;
return { sql: sql, params: params };
@ -184,7 +185,7 @@ class BaseModel {
static async allIds(options = null) {
let q = this.applySqlOptions(options, 'SELECT id FROM `' + this.tableName() + '`');
const rows = await this.db().selectAll(q.sql, q.params);
return rows.map((r) => r.id);
return rows.map(r => r.id);
}
static async all(options = null) {
@ -230,16 +231,20 @@ class BaseModel {
static modelSelectOne(sql, params = null) {
if (params === null) params = [];
return this.db().selectOne(sql, params).then((model) => {
return this.filter(this.addModelMd(model));
});
return this.db()
.selectOne(sql, params)
.then(model => {
return this.filter(this.addModelMd(model));
});
}
static modelSelectAll(sql, params = null) {
if (params === null) params = [];
return this.db().selectAll(sql, params).then((models) => {
return this.filterArray(this.addModelMd(models));
});
return this.db()
.selectAll(sql, params)
.then(models => {
return this.filterArray(this.addModelMd(models));
});
}
static loadByField(fieldName, fieldValue, options = null) {
@ -284,7 +289,9 @@ class BaseModel {
static saveMutex(modelOrId) {
const noLockMutex = {
acquire: function() { return null; }
acquire: function() {
return null;
},
};
if (!modelOrId) return noLockMutex;
@ -317,7 +324,7 @@ class BaseModel {
}
static saveQuery(o, options) {
let temp = {}
let temp = {};
let fieldNames = this.fieldNames();
for (let i = 0; i < fieldNames.length; i++) {
let n = fieldNames[i];
@ -455,13 +462,12 @@ class BaseModel {
} finally {
this.releaseSaveMutex(o, mutexRelease);
}
return output;
}
static isNew(object, options) {
if (options && ('isNew' in options)) {
if (options && 'isNew' in options) {
// options.isNew can be "auto" too
if (options.isNew === true) return true;
if (options.isNew === false) return false;
@ -489,7 +495,7 @@ class BaseModel {
if (output[n] === true) {
output[n] = 1;
} else if (output[n] === false) {
output[n] = 0;
output[n] = 0;
} else {
const t = this.fieldType(n, Database.TYPE_UNKNOWN);
if (t === Database.TYPE_INT) {
@ -497,7 +503,7 @@ class BaseModel {
}
}
}
return output;
}
@ -513,35 +519,19 @@ class BaseModel {
const idFieldName = options.idFieldName ? options.idFieldName : 'id';
const sql = 'DELETE FROM ' + this.tableName() + ' WHERE ' + idFieldName + ' IN ("' + ids.join('","') + '")';
return this.db().exec(sql);
}
}
static db() {
if (!this.db_) throw new Error('Accessing database before it has been initialised');
return this.db_;
return this.db_;
}
static isReady() {
return !!this.db_;
}
}
BaseModel.typeEnum_ = [
['TYPE_NOTE', 1],
['TYPE_FOLDER', 2],
['TYPE_SETTING', 3],
['TYPE_RESOURCE', 4],
['TYPE_TAG', 5],
['TYPE_NOTE_TAG', 6],
['TYPE_SEARCH', 7],
['TYPE_ALARM', 8],
['TYPE_MASTER_KEY', 9],
['TYPE_ITEM_CHANGE', 10],
['TYPE_NOTE_RESOURCE', 11],
['TYPE_RESOURCE_LOCAL_STATE', 12],
['TYPE_REVISION', 13],
['TYPE_MIGRATION', 14],
];
BaseModel.typeEnum_ = [['TYPE_NOTE', 1], ['TYPE_FOLDER', 2], ['TYPE_SETTING', 3], ['TYPE_RESOURCE', 4], ['TYPE_TAG', 5], ['TYPE_NOTE_TAG', 6], ['TYPE_SEARCH', 7], ['TYPE_ALARM', 8], ['TYPE_MASTER_KEY', 9], ['TYPE_ITEM_CHANGE', 10], ['TYPE_NOTE_RESOURCE', 11], ['TYPE_RESOURCE_LOCAL_STATE', 12], ['TYPE_REVISION', 13], ['TYPE_MIGRATION', 14]];
for (let i = 0; i < BaseModel.typeEnum_.length; i++) {
const e = BaseModel.typeEnum_[i];
@ -552,4 +542,4 @@ BaseModel.db_ = null;
BaseModel.dispatch = function(o) {};
BaseModel.saveMutexes_ = {};
module.exports = BaseModel;
module.exports = BaseModel;