Skip to content

Commit

Permalink
Removed mocha-eslint and eslint-config-node-services
Browse files Browse the repository at this point in the history
  • Loading branch information
hknustwmf committed Jan 23, 2019
1 parent 84a8308 commit 67900a4
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 93 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
@@ -0,0 +1,2 @@
test/
coverage/
35 changes: 34 additions & 1 deletion .eslintrc.yml
@@ -1 +1,34 @@
extends: 'eslint-config-node-services'
extends:
- 'wikimedia/server'

plugins:
- json
- jsdoc

rules:
array-bracket-spacing:
- off
camelcase:
- error
- properties: never
computed-property-spacing:
- error
- never
indent:
- error
- 4
- SwitchCase: 1
MemberExpression: 'off'
no-multi-spaces:
- off
# defined in eslint-config-wikimedia to avoid breaking IE. Not needed here
no-restricted-syntax:
- off
no-underscore-dangle:
- off
no-unused-vars:
- error
- args: none
space-in-parens:
- error
- never
10 changes: 4 additions & 6 deletions index.js
@@ -1,4 +1,4 @@
"use strict";
'use strict';

/*
* SQLite-backed table storage service
Expand Down Expand Up @@ -79,7 +79,7 @@ class RBSQLite {
}
const domain = req.params.domain;
return this.store.get(domain, req.body)
.then(res => ({
.then((res) => ({
status: res.items.length ? 200 : 404,
body: res
}))
Expand Down Expand Up @@ -146,7 +146,7 @@ class RBSQLite {
getTableSchema(rb, req) {
const domain = req.params.domain;
return this.store.getTableSchema(domain, req.params.table)
.then(res => ({
.then((res) => ({
status: 200,
body: res.schema
}))
Expand All @@ -173,7 +173,7 @@ class RBSQLite {
// deleted
status: 204
})
.catch(e => ({
.catch((e) => ({
status: 500,
body: {
type: 'delete_error',
Expand Down Expand Up @@ -205,7 +205,6 @@ class RBSQLite {
}
}


/**
* Factory
* @param {Object} options
Expand All @@ -218,4 +217,3 @@ function makeRBSQLite(options) {
}

module.exports = makeRBSQLite;

55 changes: 27 additions & 28 deletions lib/SchemaMigrator.js
@@ -1,4 +1,4 @@
"use strict";
'use strict';

const dbu = require('./dbutils');
const P = require('bluebird');
Expand Down Expand Up @@ -50,29 +50,29 @@ class Attributes {
const currSet = new Set(Object.keys(this.current));
const propSet = new Set(Object.keys(this.proposed));

this.addColumns = Array.from(propSet).filter(x => !currSet.has(x));
this.addColumns = Array.from(propSet).filter((x) => !currSet.has(x));
// TODO: null-out deleted columns
// We can't delete the column in SQLite, but we would remove it from * projection
this.delColumns = Array.from(currSet).filter(x => !propSet.has(x));
this.delColumns = Array.from(currSet).filter((x) => !propSet.has(x));
}

_colType(col) {
return this.newSchema.converters[this.newSchema.attributes[col]].type;
}

_alterTableAdd(col) {
const colIndex = this.newSchema.index
&& this.newSchema.index.find(index => index.attribute === col);
const colIndex = this.newSchema.index &&
this.newSchema.index.find((index) => index.attribute === col);
if (colIndex && colIndex.type === 'static') {
if (!dbu.staticTableExist(this.oldSchema)) {
return dbu.buildStaticsTableSql(this.newSchema, this.table);
} else {
return `${this._alterTable(`${this.table}_static`)} `
+ `ADD COLUMN ${dbu.fieldName(col)} ${this._colType(col)}`;
return `${this._alterTable(`${this.table}_static`)} ` +
`ADD COLUMN ${dbu.fieldName(col)} ${this._colType(col)}`;
}
} else {
return `${this._alterTable(`${this.table}_data`)} `
+ `ADD COLUMN ${dbu.fieldName(col)} ${this._colType(col)}`;
return `${this._alterTable(`${this.table}_data`)} ` +
`ADD COLUMN ${dbu.fieldName(col)} ${this._colType(col)}`;
}
}

Expand All @@ -85,10 +85,10 @@ class Attributes {
const sql = this._alterTableAdd(col);
return this.client.run([{ sql }])
.catch((e) => {
const regex = new RegExp(`Invalid column name ${col} because `
+ `it conflicts with an existing column`);
if (!regex.test(e.message)
&& !/duplicate column name/.test(e.message)) {
const regex = new RegExp(`Invalid column name ${col} because ` +
'it conflicts with an existing column');
if (!regex.test(e.message) &&
!/duplicate column name/.test(e.message)) {
// Ignore the error if the column already exists.
throw (e);
}
Expand All @@ -99,7 +99,7 @@ class Attributes {

Attributes.prototype.validate = () => {};

Attributes.prototype._alterTable = fullTableName => `ALTER TABLE [${fullTableName}]`;
Attributes.prototype._alterTable = (fullTableName) => `ALTER TABLE [${fullTableName}]`;

/**
* Index definition migrations
Expand All @@ -111,8 +111,8 @@ class Index {
this.currentSchema = parentMigrator.current;
this.proposedSchema = parentMigrator.proposed;

this.addIndex = proposed.filter(x => !this._hasSameIndex(this.current, x));
this.delIndex = current.filter(x => !this._hasSameIndex(this.proposed, x));
this.addIndex = proposed.filter((x) => !this._hasSameIndex(this.current, x));
this.delIndex = current.filter((x) => !this._hasSameIndex(this.proposed, x));

this.alteredColumns = [];

Expand All @@ -136,8 +136,8 @@ class Index {
}

validate() {
if (this.addIndex.some(index => index.type !== 'static')
|| this.delIndex.some(index => index.type !== 'static')) {
if (this.addIndex.some((index) => index.type !== 'static') ||
this.delIndex.some((index) => index.type !== 'static')) {
throw new Error('Only static index additions and removals supported');
}
if (this.alteredColumns.length > 0) {
Expand All @@ -147,15 +147,14 @@ class Index {
}

Index.prototype._hasSameIndex = (indexes, proposedIndex) =>
indexes.some(idx => idx.attribute === proposedIndex.attribute
&& idx.type === proposedIndex.type
&& idx.order === proposedIndex.order);
indexes.some((idx) => idx.attribute === proposedIndex.attribute &&
idx.type === proposedIndex.type &&
idx.order === proposedIndex.order);

Index.prototype.migrate = () => {
// The migration is happening on individual attribute migration
};


/**
* Version handling
*/
Expand Down Expand Up @@ -198,10 +197,10 @@ const migrationHandlers = {
* Note: The schemas themselves are not validated, only the migration; schema
* input should be validated ahead of time).
*
* @param {object] client; an instance of DB
* @param {object} schemaFrom; current schema info object.
* @param {object} schemaTo; proposed schema info object.
* @throws {Error} if the proposed migration fails to validate
* @param {Object} client an instance of DB
* @param {Object} schemaFrom current schema info object.
* @param {Object} schemaTo proposed schema info object.
* @throws {Error} if the proposed migration fails to validate
*/
class SchemaMigrator {
constructor(db, req, table, current, proposed) {
Expand All @@ -212,7 +211,7 @@ class SchemaMigrator {
this.proposed = proposed;

this.migrators = Object.keys(migrationHandlers)
.map(key => new migrationHandlers[key](this, current[key], proposed[key]));
.map((key) => new migrationHandlers[key](this, current[key], proposed[key]));

this._validate();
}
Expand All @@ -228,7 +227,7 @@ class SchemaMigrator {
* @return {Promise} a promise that resolves when the migration tasks are complete
*/
migrate() {
return P.each(this.migrators, migrator => migrator.migrate());
return P.each(this.migrators, (migrator) => migrator.migrate());
}
}

Expand Down
16 changes: 8 additions & 8 deletions lib/clientWrapper.js
@@ -1,4 +1,4 @@
"use strict";
'use strict';

const P = require('bluebird');
const sqlite3 = require('sqlite3').verbose();
Expand Down Expand Up @@ -54,9 +54,9 @@ class Wrapper {
return client.run_p('begin immediate')
.thenReturn(client)
.catch((err) => {
if (err && err.cause
&& err.cause.code === 'SQLITE_BUSY'
&& retryCount++ < this.retryLimit) {
if (err && err.cause &&
err.cause.code === 'SQLITE_BUSY' &&
retryCount++ < this.retryLimit) {
return P.delay(this.randomDelay())
.then(() => beginTransaction(client));
} else {
Expand All @@ -69,7 +69,7 @@ class Wrapper {
return this.connectionPool.acquire()
.then(beginTransaction)
.then((client) => {
queries = queries.filter(query => query && query.sql);
queries = queries.filter((query) => query && query.sql);
return P.each(queries, (query) => {
if (this.conf.show_sql) {
this.log(query.sql);
Expand Down Expand Up @@ -108,9 +108,9 @@ class Wrapper {
const operation = () => {
return query.all_p(params)
.catch((err) => {
if (err && err.cause
&& err.cause.code === 'SQLITE_BUSY'
&& retryCount++ < this.retryLimit) {
if (err && err.cause &&
err.cause.code === 'SQLITE_BUSY' &&
retryCount++ < this.retryLimit) {
return P.delay(this.randomDelay())
.then(operation);
} else {
Expand Down
12 changes: 6 additions & 6 deletions lib/db.js
@@ -1,4 +1,4 @@
"use strict";
'use strict';

const dbu = require('./dbutils');
const P = require('bluebird');
Expand Down Expand Up @@ -90,17 +90,17 @@ class DB {
status: 400,
body: {
type: 'bad_request',
title: `The table already exists`
+ `, and its schema cannot be upgraded `
+ `to the requested schema (${error}).`,
title: 'The table already exists' +
', and its schema cannot be upgraded ' +
`to the requested schema (${error}).`,
tableName,
schema: schemaInfo
}
});
}
createOperation = migrator.migrate()
.then(() => {
this.queryCache.keys().filter(key => key.indexOf(tableName) === 0)
this.queryCache.keys().filter((key) => key.indexOf(tableName) === 0)
.forEach((key) => {
this.queryCache.del(key);
});
Expand Down Expand Up @@ -152,7 +152,7 @@ class DB {

if (!this.schemaCache[tableName]) {
return this._getSchema(tableName)
.then(schema => deleteRequest(schema));
.then((schema) => deleteRequest(schema));
} else {
const schema = this.schemaCache[tableName];
delete this.schemaCache[tableName];
Expand Down

0 comments on commit 67900a4

Please sign in to comment.