From d4719d57073982c00a2dc9d22839bc404e6309f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 14 Nov 2019 11:36:47 +0100 Subject: [PATCH] camel case --- lib/api/map/anonymous-map-controller.js | 10 ++-- lib/api/map/preview-template-controller.js | 14 ++--- lib/api/middlewares/last-modified-header.js | 10 ++-- .../map-store-map-config-provider.js | 10 ++-- lib/api/middlewares/named-map-provider.js | 14 ++--- lib/api/template/named-template-controller.js | 8 +-- lib/backends/auth.js | 8 +-- lib/backends/cluster.js | 6 +-- lib/backends/dataview.js | 4 +- lib/backends/filter-stats.js | 14 ++--- lib/backends/template-maps.js | 54 +++++++++---------- .../aggregation/aggregation-mapconfig.js | 4 +- lib/models/aggregation/aggregation-query.js | 48 ++++++++--------- .../aggregation/aggregation-validator.js | 10 ++-- lib/models/aggregation/time-dimension.js | 6 +-- lib/models/dataview/formula.js | 8 +-- .../dataview/histograms/date-histogram.js | 36 ++++++------- .../mapconfig/provider/named-map-provider.js | 2 +- test/acceptance/ported/support/test-client.js | 12 ++--- 19 files changed, 139 insertions(+), 139 deletions(-) diff --git a/lib/api/map/anonymous-map-controller.js b/lib/api/map/anonymous-map-controller.js index fd79089e..508e1cd8 100644 --- a/lib/api/map/anonymous-map-controller.js +++ b/lib/api/map/anonymous-map-controller.js @@ -133,7 +133,7 @@ function prepareAdapterMapConfig (mapConfigAdapter) { return function prepareAdapterMapConfigMiddleware (req, res, next) { const requestMapConfig = req.body; - const { user, api_key } = res.locals; + const { user, api_key: apiKey } = res.locals; const { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals; const params = Object.assign({ dbuser, dbname, dbpassword, dbhost, dbport }, req.query); @@ -149,7 +149,7 @@ function prepareAdapterMapConfig (mapConfigAdapter) { }, batch: { username: user, - apiKey: api_key + apiKey } } }; @@ -181,12 +181,12 @@ function createLayergroup (mapBackend, userLimitsBackend, pgConnection, affected const requestMapConfig = req.body; const { context } = res.locals; - const { user, cache_buster, api_key } = res.locals; + const { user, cache_buster: cacheBuster, api_key: apiKey } = res.locals; const { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals; const params = { - cache_buster, - api_key, + cache_buster: cacheBuster, + api_key: apiKey, dbuser, dbname, dbpassword, diff --git a/lib/api/map/preview-template-controller.js b/lib/api/map/preview-template-controller.js index b3093689..989bb8e1 100644 --- a/lib/api/map/preview-template-controller.js +++ b/lib/api/map/preview-template-controller.js @@ -100,7 +100,7 @@ function getTemplate ({ label }) { function prepareLayerFilterFromPreviewLayers ({ namedMapProviderCache, label }) { return function prepareLayerFilterFromPreviewLayersMiddleware (req, res, next) { const { template } = res.locals; - const { config, auth_token } = req.query; + const { config, auth_token: authToken } = req.query; if (!template || !template.view || !template.view.preview_layers) { return next(); @@ -119,21 +119,21 @@ function prepareLayerFilterFromPreviewLayers ({ namedMapProviderCache, label }) return next(); } - const { user, token, cache_buster, api_key } = res.locals; + const { user, token, cache_buster: cacheBuster, api_key: apiKey } = res.locals; const { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals; - const { template_id, format } = req.params; + const { template_id: templateId, format } = req.params; const params = { user, token, - cache_buster, - api_key, + cache_buster: cacheBuster, + api_key: apiKey, dbuser, dbname, dbpassword, dbhost, dbport, - template_id, + template_id: templateId, format }; @@ -141,7 +141,7 @@ function prepareLayerFilterFromPreviewLayers ({ namedMapProviderCache, label }) params.layer = layerVisibilityFilter.join(','); // recreates the provider - namedMapProviderCache.get(user, template_id, config, auth_token, params, (err, provider) => { + namedMapProviderCache.get(user, templateId, config, authToken, params, (err, provider) => { if (err) { err.label = label; return next(err); diff --git a/lib/api/middlewares/last-modified-header.js b/lib/api/middlewares/last-modified-header.js index bca3d5b9..4f00c0d2 100644 --- a/lib/api/middlewares/last-modified-header.js +++ b/lib/api/middlewares/last-modified-header.js @@ -6,12 +6,12 @@ module.exports = function setLastModifiedHeader () { return next(); } - const { mapConfigProvider, cache_buster } = res.locals; + const { mapConfigProvider, cache_buster: cacheBuster } = res.locals; - if (cache_buster) { - const cacheBuster = parseInt(cache_buster, 10); - const lastModifiedDate = Number.isFinite(cacheBuster) && cacheBuster !== 0 - ? new Date(cacheBuster) + if (cacheBuster) { + const cacheBusterTimestamp = parseInt(cacheBuster, 10); + const lastModifiedDate = Number.isFinite(cacheBusterTimestamp) && cacheBusterTimestamp !== 0 + ? new Date(cacheBusterTimestamp) : new Date(); res.set('Last-Modified', lastModifiedDate.toUTCString()); diff --git a/lib/api/middlewares/map-store-map-config-provider.js b/lib/api/middlewares/map-store-map-config-provider.js index b35519d3..3d8481bd 100644 --- a/lib/api/middlewares/map-store-map-config-provider.js +++ b/lib/api/middlewares/map-store-map-config-provider.js @@ -10,16 +10,16 @@ module.exports = function createMapStoreMapConfigProvider ( forcedFormat = null ) { return function createMapStoreMapConfigProviderMiddleware (req, res, next) { - const { user, token, cache_buster, api_key } = res.locals; + const { user, token, cache_buster: cacheBuster, api_key: apiKey } = res.locals; const { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals; - const { layer: layerFromParams, z, x, y, scale_factor, format } = req.params; + const { layer: layerFromParams, z, x, y, scale_factor: scaleFactor, format } = req.params; const { layer: layerFromQuery } = req.query; const params = { user, token, - cache_buster, - api_key, + cache_buster: cacheBuster, + api_key: apiKey, dbuser, dbname, dbpassword, @@ -29,7 +29,7 @@ module.exports = function createMapStoreMapConfigProvider ( z, x, y, - scale_factor, + scale_factor: scaleFactor, format }; diff --git a/lib/api/middlewares/named-map-provider.js b/lib/api/middlewares/named-map-provider.js index 161e827b..bcc9b767 100644 --- a/lib/api/middlewares/named-map-provider.js +++ b/lib/api/middlewares/named-map-provider.js @@ -2,22 +2,22 @@ module.exports = function getNamedMapProvider ({ namedMapProviderCache, label, forcedFormat = null }) { return function getNamedMapProviderMiddleware (req, res, next) { - const { user, token, cache_buster, api_key } = res.locals; + const { user, token, cache_buster: cacheBuster, api_key: apiKey } = res.locals; const { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals; - const { template_id, layer: layerFromParams, z, x, y, format } = req.params; + const { template_id: templateId, layer: layerFromParams, z, x, y, format } = req.params; const { layer: layerFromQuery } = req.query; const params = { user, token, - cache_buster, - api_key, + cache_buster: cacheBuster, + api_key: apiKey, dbuser, dbname, dbpassword, dbhost, dbport, - template_id, + template_id: templateId, layer: (layerFromQuery || layerFromParams), z, x, @@ -30,9 +30,9 @@ module.exports = function getNamedMapProvider ({ namedMapProviderCache, label, f params.layer = params.layer || 'all'; } - const { config, auth_token } = req.query; + const { config, auth_token: authToken } = req.query; - namedMapProviderCache.get(user, template_id, config, auth_token, params, (err, namedMapProvider) => { + namedMapProviderCache.get(user, templateId, config, authToken, params, (err, namedMapProvider) => { if (err) { err.label = label; return next(err); diff --git a/lib/api/template/named-template-controller.js b/lib/api/template/named-template-controller.js index 87c461ef..b7b3a865 100644 --- a/lib/api/template/named-template-controller.js +++ b/lib/api/template/named-template-controller.js @@ -148,8 +148,8 @@ function getTemplate ( return function getTemplateMiddleware (req, res, next) { const templateParams = req.body; const { user, dbuser, dbname, dbpassword, dbhost, dbport } = res.locals; - const { template_id } = req.params; - const { auth_token } = req.query; + const { template_id: templateId } = req.params; + const { auth_token: authToken } = req.query; const params = Object.assign({ dbuser, dbname, dbpassword, dbhost, dbport }, req.query); @@ -161,9 +161,9 @@ function getTemplate ( mapConfigAdapter, affectedTablesCache, user, - template_id, + templateId, templateParams, - auth_token, + authToken, params ); diff --git a/lib/backends/auth.js b/lib/backends/auth.js index c87e7405..2c9dd3ee 100644 --- a/lib/backends/auth.js +++ b/lib/backends/auth.js @@ -32,15 +32,15 @@ AuthBackend.prototype.authorizedBySigner = function (req, res, callback) { var self = this; - var layergroup_id = res.locals.token; - var auth_token = req.query.auth_token; + var layergroupId = res.locals.token; + var authToken = req.query.auth_token; - this.mapStore.load(layergroup_id, function (err, mapConfig) { + this.mapStore.load(layergroupId, function (err, mapConfig) { if (err) { return callback(err); } - var authorized = self.templateMaps.isAuthorized(mapConfig.obj().template, auth_token); + var authorized = self.templateMaps.isAuthorized(mapConfig.obj().template, authToken); return callback(null, authorized); }); diff --git a/lib/backends/cluster.js b/lib/backends/cluster.js index 438f2441..6a3429f0 100644 --- a/lib/backends/cluster.js +++ b/lib/backends/cluster.js @@ -223,12 +223,12 @@ function validateExpressions (expressions) { throw new Error('Invalid aggregation input, expressions should be and object with valid functions'); } - for (const { aggregate_function, aggregated_column } of Object.values(expressions)) { - if (typeof aggregated_column !== 'string') { + for (const { aggregate_function: aggregateFunction, aggregated_column: aggregatedColumn } of Object.values(expressions)) { + if (typeof aggregatedColumn !== 'string') { throw new Error('Invalid aggregation input, aggregated column should be an string'); } - if (typeof aggregate_function !== 'string') { + if (typeof aggregateFunction !== 'string') { throw new Error('Invalid aggregation input, aggregate function should be an string'); } } diff --git a/lib/backends/dataview.js b/lib/backends/dataview.js index 994f89f3..080718e1 100644 --- a/lib/backends/dataview.js +++ b/lib/backends/dataview.js @@ -115,7 +115,7 @@ function getQueryRewriteData (mapConfig, dataviewDefinition, params) { } if (params.bbox && queryRewriteData) { - var bbox_filter_definition = { + var bboxFilterDefinition = { type: 'bbox', options: { column: 'the_geom_webmercator', @@ -125,7 +125,7 @@ function getQueryRewriteData (mapConfig, dataviewDefinition, params) { bbox: params.bbox } }; - queryRewriteData = _.extend(queryRewriteData, { bbox_filter: bbox_filter_definition }); + queryRewriteData = _.extend(queryRewriteData, { bbox_filter: bboxFilterDefinition }); } return queryRewriteData; diff --git a/lib/backends/filter-stats.js b/lib/backends/filter-stats.js index 949613c7..d5ac456b 100644 --- a/lib/backends/filter-stats.js +++ b/lib/backends/filter-stats.js @@ -10,24 +10,24 @@ function FilterStatsBackends (pgQueryRunner) { module.exports = FilterStatsBackends; function getEstimatedRows (pgQueryRunner, username, query, callback) { - pgQueryRunner.run(username, 'EXPLAIN (FORMAT JSON)' + query, function (err, result_rows) { + pgQueryRunner.run(username, 'EXPLAIN (FORMAT JSON)' + query, function (err, resultRows) { if (err) { callback(err); return; } var rows; - if (result_rows[0] && result_rows[0]['QUERY PLAN'] && - result_rows[0]['QUERY PLAN'][0] && result_rows[0]['QUERY PLAN'][0].Plan) { - rows = result_rows[0]['QUERY PLAN'][0].Plan['Plan Rows']; + if (resultRows[0] && resultRows[0]['QUERY PLAN'] && + resultRows[0]['QUERY PLAN'][0] && resultRows[0]['QUERY PLAN'][0].Plan) { + rows = resultRows[0]['QUERY PLAN'][0].Plan['Plan Rows']; } return callback(null, rows); }); } -FilterStatsBackends.prototype.getFilterStats = function (username, unfiltered_query, filters, callback) { +FilterStatsBackends.prototype.getFilterStats = function (username, unfilteredQuery, filters, callback) { var stats = {}; - getEstimatedRows(this.pgQueryRunner, username, unfiltered_query, (err, rows) => { + getEstimatedRows(this.pgQueryRunner, username, unfilteredQuery, (err, rows) => { if (err) { return callback(err); } @@ -39,7 +39,7 @@ FilterStatsBackends.prototype.getFilterStats = function (username, unfiltered_qu } var analysisFilter = new AnalysisFilter(filters); - var query = analysisFilter.sql(unfiltered_query); + var query = analysisFilter.sql(unfilteredQuery); getEstimatedRows(this.pgQueryRunner, username, query, (err, rows) => { if (err) { diff --git a/lib/backends/template-maps.js b/lib/backends/template-maps.js index 01468061..e1e45c3e 100644 --- a/lib/backends/template-maps.js +++ b/lib/backends/template-maps.js @@ -12,7 +12,7 @@ var util = require('util'); // // See http://github.com/CartoDB/Windshaft-cartodb/wiki/Template-maps // -// @param redis_pool an instance of a "redis-mpool" +// @param redisPool an instance of a "redis-mpool" // See https://github.com/CartoDB/node-redis-mpool // Needs version 0.x.x of the API. // @@ -20,14 +20,14 @@ var util = require('util'); // 'max_user_templates' limit on the number of per-user // // -function TemplateMaps (redis_pool, opts) { +function TemplateMaps (redisPool, opts) { if (!(this instanceof TemplateMaps)) { return new TemplateMaps(); } EventEmitter.call(this); - this.redis_pool = redis_pool; + this.redisPool = redisPool; this.opts = opts || {}; // Database containing templates @@ -44,7 +44,7 @@ function TemplateMaps (redis_pool, opts) { // // 1. User templates: set of per-user map templates - // User templates (HASH:tpl_id->tpl_val) + // User templates (HASH:tplId->tpl_val) this.key_usr_tpl = dot.template('map_tpl|{{=it.owner}}'); } @@ -66,13 +66,13 @@ TemplateMaps.prototype._userTemplateLimit = function () { * @param callback - function to pass results too. */ TemplateMaps.prototype._redisCmd = function (redisFunc, redisArgs, callback) { - this.redis_pool.acquire(this.db_signatures, (err, redisClient) => { + this.redisPool.acquire(this.db_signatures, (err, redisClient) => { if (err) { return callback(err); } redisClient[redisFunc.toUpperCase()](...redisArgs, (err, data) => { - this.redis_pool.release(this.db_signatures, redisClient); + this.redisPool.release(this.db_signatures, redisClient); if (err) { return callback(err); } @@ -215,7 +215,7 @@ TemplateMaps.prototype._checkUserTemplatesLimit = function (userTemplatesKey, ow // @param template layergroup template, see // http://github.com/CartoDB/Windshaft-cartodb/wiki/Template-maps#template-format // -// @param callback function(err, tpl_id) +// @param callback function(err, tplId) // Return template identifier (only valid for given user) // TemplateMaps.prototype.addTemplate = function (owner, template, callback) { @@ -260,22 +260,22 @@ TemplateMaps.prototype.addTemplate = function (owner, template, callback) { // // @param owner cartodb username of the template owner // -// @param tpl_id template identifier as returned +// @param tplId template identifier as returned // by addTemplate or listTemplates // // @param callback function(err) // -TemplateMaps.prototype.delTemplate = function (owner, tpl_id, callback) { - this._redisCmd('HDEL', [this.key_usr_tpl({ owner: owner }), tpl_id], (err, deleted) => { +TemplateMaps.prototype.delTemplate = function (owner, tplId, callback) { + this._redisCmd('HDEL', [this.key_usr_tpl({ owner: owner }), tplId], (err, deleted) => { if (err) { return callback(err); } if (!deleted) { - return callback(new Error(`Template '${tpl_id}' of user '${owner}' does not exist`)); + return callback(new Error(`Template '${tplId}' of user '${owner}' does not exist`)); } - this.emit('delete', owner, tpl_id); + this.emit('delete', owner, tplId); return callback(); }); }; @@ -289,14 +289,14 @@ TemplateMaps.prototype.delTemplate = function (owner, tpl_id, callback) { // // @param owner cartodb username of the template owner // -// @param tpl_id template identifier as returned by addTemplate +// @param tplId template identifier as returned by addTemplate // // @param template layergroup template, see // http://github.com/CartoDB/Windshaft-cartodb/wiki/Template-maps#template-format // // @param callback function(err) // -TemplateMaps.prototype.updTemplate = function (owner, tpl_id, template, callback) { +TemplateMaps.prototype.updTemplate = function (owner, tplId, template, callback) { template = templateDefaults(template); var invalidError = this._checkInvalidTemplate(template); @@ -304,19 +304,19 @@ TemplateMaps.prototype.updTemplate = function (owner, tpl_id, template, callback return callback(invalidError); } - if (tpl_id !== template.name) { - return callback(new Error(`Cannot update name of a map template ('${tpl_id}' != '${template.name}')`)); + if (tplId !== template.name) { + return callback(new Error(`Cannot update name of a map template ('${tplId}' != '${template.name}')`)); } var userTemplatesKey = this.key_usr_tpl({ owner }); - this._redisCmd('HGET', [userTemplatesKey, tpl_id], (err, beforeUpdateTemplate) => { + this._redisCmd('HGET', [userTemplatesKey, tplId], (err, beforeUpdateTemplate) => { if (err) { return callback(err); } if (!beforeUpdateTemplate) { - return callback(new Error(`Template '${tpl_id}' of user '${owner}' does not exist`)); + return callback(new Error(`Template '${tplId}' of user '${owner}' does not exist`)); } let templateString; @@ -355,7 +355,7 @@ TemplateMaps.prototype.updTemplate = function (owner, tpl_id, template, callback // // @param owner cartodb username of the templates owner // -// @param callback function(err, tpl_id_list) +// @param callback function(err, tplId_list) // Returns a list of template identifiers // TemplateMaps.prototype.listTemplates = function (owner, callback) { @@ -366,14 +366,14 @@ TemplateMaps.prototype.listTemplates = function (owner, callback) { // // @param owner cartodb username of the template owner // -// @param tpl_id template identifier as returned +// @param tplId template identifier as returned // by addTemplate or listTemplates // // @param callback function(err, template) // Return full template definition // -TemplateMaps.prototype.getTemplate = function (owner, tpl_id, callback) { - this._redisCmd('HGET', [this.key_usr_tpl({ owner: owner }), tpl_id], (err, template) => { +TemplateMaps.prototype.getTemplate = function (owner, tplId, callback) { + this._redisCmd('HGET', [this.key_usr_tpl({ owner: owner }), tplId], (err, template) => { if (err) { return callback(err); } @@ -446,7 +446,7 @@ function isObject (val) { } TemplateMaps.prototype.instance = function (template, params) { - var all_params = {}; + var allParams = {}; var phold = template.placeholders || {}; Object.keys(phold).forEach(function (k) { var val = Object.prototype.hasOwnProperty.call(params, k) ? params[k] : phold[k].default; @@ -473,7 +473,7 @@ TemplateMaps.prototype.instance = function (template, params) { // NOTE: should be checked at template create/update time throw new Error("Invalid placeholder type '" + type + "'"); } - all_params[k] = val; + allParams[k] = val; }); // NOTE: we're deep-cloning the layergroup here @@ -481,7 +481,7 @@ TemplateMaps.prototype.instance = function (template, params) { if (layergroup.buffersize && isObject(layergroup.buffersize)) { Object.keys(layergroup.buffersize).forEach(function (k) { - layergroup.buffersize[k] = parseInt(_replaceVars(layergroup.buffersize[k], all_params), 10); + layergroup.buffersize[k] = parseInt(_replaceVars(layergroup.buffersize[k], allParams), 10); }); } @@ -492,10 +492,10 @@ TemplateMaps.prototype.instance = function (template, params) { // dynamic styling for this layer lyropt.cartocss = params.styles[i]; } else if (lyropt.cartocss) { - lyropt.cartocss = _replaceVars(lyropt.cartocss, all_params); + lyropt.cartocss = _replaceVars(lyropt.cartocss, allParams); } if (lyropt.sql) { - lyropt.sql = _replaceVars(lyropt.sql, all_params); + lyropt.sql = _replaceVars(lyropt.sql, allParams); } // Anything else ? } diff --git a/lib/models/aggregation/aggregation-mapconfig.js b/lib/models/aggregation/aggregation-mapconfig.js index 225486a4..493a5c96 100644 --- a/lib/models/aggregation/aggregation-mapconfig.js +++ b/lib/models/aggregation/aggregation-mapconfig.js @@ -83,7 +83,7 @@ module.exports = class AggregationMapConfig extends MapConfig { } getAggregatedQuery (index) { - const { sql_raw, sql } = this.getLayer(index).options; + const { sql_raw: sqlRaw, sql } = this.getLayer(index).options; const { // The default aggregation has no placement, columns or dimensions; // this enables the special "full-sample" aggregation. @@ -96,7 +96,7 @@ module.exports = class AggregationMapConfig extends MapConfig { } = this.getAggregation(index); return aggregationQuery({ - query: sql_raw || sql, + query: sqlRaw || sql, resolution, threshold, placement, diff --git a/lib/models/aggregation/aggregation-query.js b/lib/models/aggregation/aggregation-query.js index 24ba8062..775123a5 100644 --- a/lib/models/aggregation/aggregation-query.js +++ b/lib/models/aggregation/aggregation-query.js @@ -51,22 +51,22 @@ module.exports.infoForOptions = (options) => { const SUPPORTED_AGGREGATE_FUNCTIONS = { count: { - sql: (column_name, params) => `count(${params.aggregated_column || '*'})` + sql: (columnName, params) => `count(${params.aggregated_column || '*'})` }, avg: { - sql: (column_name, params) => `avg(${params.aggregated_column || column_name})` + sql: (columnName, params) => `avg(${params.aggregated_column || columnName})` }, sum: { - sql: (column_name, params) => `sum(${params.aggregated_column || column_name})` + sql: (columnName, params) => `sum(${params.aggregated_column || columnName})` }, min: { - sql: (column_name, params) => `min(${params.aggregated_column || column_name})` + sql: (columnName, params) => `min(${params.aggregated_column || columnName})` }, max: { - sql: (column_name, params) => `max(${params.aggregated_column || column_name})` + sql: (columnName, params) => `max(${params.aggregated_column || columnName})` }, mode: { - sql: (column_name, params) => `mode() WITHIN GROUP (ORDER BY ${params.aggregated_column || column_name})` + sql: (columnName, params) => `mode() WITHIN GROUP (ORDER BY ${params.aggregated_column || columnName})` } }; @@ -85,20 +85,20 @@ const aggregateColumns = ctx => { }, ctx.columns || {}); }; -const aggregateExpression = (column_name, column_parameters) => { - const aggregate_function = column_parameters.aggregate_function || 'count'; - const aggregate_definition = SUPPORTED_AGGREGATE_FUNCTIONS[aggregate_function]; - if (!aggregate_definition) { - throw new Error("Invalid Aggregate function: '" + aggregate_function + "'"); +const aggregateExpression = (columnName, columnParameters) => { + const aggregateFunction = columnParameters.aggregate_function || 'count'; + const aggregateDefinition = SUPPORTED_AGGREGATE_FUNCTIONS[aggregateFunction]; + if (!aggregateDefinition) { + throw new Error("Invalid Aggregate function: '" + aggregateFunction + "'"); } - return aggregate_definition.sql(column_name, column_parameters); + return aggregateDefinition.sql(columnName, columnParameters); }; const aggregateColumnDefs = ctx => { const columns = aggregateColumns(ctx); - return sep(Object.keys(columns).map(column_name => { - const aggregate_expression = aggregateExpression(column_name, columns[column_name]); - return `${aggregate_expression} AS ${column_name}`; + return sep(Object.keys(columns).map(columnName => { + const aggregate = aggregateExpression(columnName, columns[columnName]); + return `${aggregate} AS ${columnName}`; })); }; @@ -241,17 +241,17 @@ const filterConditions = ctx => { const columns = aggregateColumns(ctx); const dimensions = aggregateDimensions(ctx); const filters = aggregateFilters(ctx); - return Object.keys(filters).map(filtered_column => { - let filtered_expr; - if (columns[filtered_column]) { - filtered_expr = aggregateExpression(filtered_column, columns[filtered_column]); - } else if (dimensions[filtered_column]) { - filtered_expr = dimensions[filtered_column]; + return Object.keys(filters).map(filteredColumn => { + let filteredExpr; + if (columns[filteredColumn]) { + filteredExpr = aggregateExpression(filteredColumn, columns[filteredColumn]); + } else if (dimensions[filteredColumn]) { + filteredExpr = dimensions[filteredColumn]; } - if (!filtered_expr) { - throw new Error("Invalid filtered column: '" + filtered_column + "'"); + if (!filteredExpr) { + throw new Error("Invalid filtered column: '" + filteredColumn + "'"); } - return filterConditionSQL(filtered_expr, filters[filtered_column]); + return filterConditionSQL(filteredExpr, filters[filteredColumn]); }).join(' AND '); }; diff --git a/lib/models/aggregation/aggregation-validator.js b/lib/models/aggregation/aggregation-validator.js index 6af5f157..99ac4839 100644 --- a/lib/models/aggregation/aggregation-validator.js +++ b/lib/models/aggregation/aggregation-validator.js @@ -90,10 +90,10 @@ function createAggregationColumnNamesValidator (mapconfig) { function createAggregateFunctionValidator (mapconfig, validAggregatedFunctions) { return function validateAggregateFunction (value, key, index) { Object.keys(value).forEach((columnName) => { - const { aggregate_function } = value[columnName]; + const { aggregate_function: aggregateFunction } = value[columnName]; - if (!validAggregatedFunctions.includes(aggregate_function)) { - const message = `Unsupported aggregation function ${aggregate_function},` + + if (!validAggregatedFunctions.includes(aggregateFunction)) { + const message = `Unsupported aggregation function ${aggregateFunction},` + ` valid ones: ${validAggregatedFunctions.join(', ')}`; throw createLayerError(message, mapconfig, index); } @@ -104,9 +104,9 @@ function createAggregateFunctionValidator (mapconfig, validAggregatedFunctions) function createAggregatedColumnValidator (mapconfig) { return function validateAggregatedColumn (value, key, index) { Object.keys(value).forEach((columnName) => { - const { aggregated_column } = value[columnName]; + const { aggregated_column: aggregatedColumn } = value[columnName]; - if (typeof aggregated_column !== 'string' || aggregated_column <= 0) { + if (typeof aggregatedColumn !== 'string' || aggregatedColumn <= 0) { const message = 'Invalid aggregated column, should be a non empty string'; throw createLayerError(message, mapconfig, index); } diff --git a/lib/models/aggregation/time-dimension.js b/lib/models/aggregation/time-dimension.js index 7f023f01..c261ca75 100644 --- a/lib/models/aggregation/time-dimension.js +++ b/lib/models/aggregation/time-dimension.js @@ -187,12 +187,12 @@ function validateParameters (params, checker) { if (missingParams.length) { errors.push(`Missing parameters: ${missingParams.join(', ')}`); } - const params_errors = checker(params); - errors.push(...params_errors.errors); + const paramsErrors = checker(params); + errors.push(...paramsErrors.errors); if (errors.length) { throw new Error(`Invalid time dimension:\n${errors.join('\n')}`); } - return params_errors.params; + return paramsErrors.params; } const VALID_CYCLIC_UNITS = Object.keys(cyclicParts); diff --git a/lib/models/dataview/formula.js b/lib/models/dataview/formula.js index 3e5a37d9..cba18057 100644 --- a/lib/models/dataview/formula.js +++ b/lib/models/dataview/formula.js @@ -91,16 +91,16 @@ module.exports = class Formula extends BaseDataview { const { result = 0, nulls_count = 0, - nans_count, - infinities_count + nans_count: nansCount, + infinities_count: infinitiesCount } = res.rows[0] || {}; return { operation: this.operation, result, nulls: nulls_count, - nans: nans_count, - infinities: infinities_count + nans: nansCount, + infinities: infinitiesCount }; } diff --git a/lib/models/dataview/histograms/date-histogram.js b/lib/models/dataview/histograms/date-histogram.js index b4901582..61b6e974 100644 --- a/lib/models/dataview/histograms/date-histogram.js +++ b/lib/models/dataview/histograms/date-histogram.js @@ -32,16 +32,16 @@ WITH __wd_tz AS * our timezone so when calling date_trunc it falls into the correct bin */ function dataBucketsQuery (ctx) { - var condition_str = ''; + var conditionStr = ''; if (ctx.start !== 0) { - condition_str = `WHERE ${ctx.column} >= to_timestamp(${ctx.start})`; + conditionStr = `WHERE ${ctx.column} >= to_timestamp(${ctx.start})`; } if (ctx.end !== 0) { - if (condition_str === '') { - condition_str = `WHERE ${ctx.column} <= to_timestamp(${ctx.end})`; + if (conditionStr === '') { + conditionStr = `WHERE ${ctx.column} <= to_timestamp(${ctx.end})`; } else { - condition_str += ` and ${ctx.column} <= to_timestamp(${ctx.end})`; + conditionStr += ` and ${ctx.column} <= to_timestamp(${ctx.end})`; } } @@ -56,7 +56,7 @@ __wd_buckets AS ( ${ctx.query} ) __source, __wd_tz - ${condition_str} + ${conditionStr} GROUP BY 1, __wd_tz.name ),`; } @@ -67,22 +67,22 @@ __wd_buckets AS * the dataBucketsQuery */ function allBucketsArrayQuery (ctx) { - var extra_from = ''; - var series_start = ''; - var series_end = ''; + var extraFrom = ''; + var seriesStart = ''; + var seriesEnd = ''; if (ctx.start === 0) { - extra_from = ', __wd_buckets GROUP BY __wd_tz.name'; - series_start = 'min(__wd_buckets.timestamp)'; + extraFrom = ', __wd_buckets GROUP BY __wd_tz.name'; + seriesStart = 'min(__wd_buckets.timestamp)'; } else { - series_start = `date_trunc('${ctx.aggregation}', timezone(__wd_tz.name, to_timestamp(${ctx.start})))`; + seriesStart = `date_trunc('${ctx.aggregation}', timezone(__wd_tz.name, to_timestamp(${ctx.start})))`; } if (ctx.end === 0) { - extra_from = ', __wd_buckets GROUP BY __wd_tz.name'; - series_end = 'max(__wd_buckets.timestamp)'; + extraFrom = ', __wd_buckets GROUP BY __wd_tz.name'; + seriesEnd = 'max(__wd_buckets.timestamp)'; } else { - series_end = `date_trunc('${ctx.aggregation}', timezone(__wd_tz.name, to_timestamp(${ctx.end})))`; + seriesEnd = `date_trunc('${ctx.aggregation}', timezone(__wd_tz.name, to_timestamp(${ctx.end})))`; } return ` @@ -91,10 +91,10 @@ __wd_all_buckets AS SELECT ARRAY( SELECT generate_series( - ${series_start}, - ${series_end}, + ${seriesStart}, + ${seriesEnd}, interval '${ctx.interval}') as bin_start - FROM __wd_tz${extra_from} + FROM __wd_tz${extraFrom} ) as bins )`; } diff --git a/lib/models/mapconfig/provider/named-map-provider.js b/lib/models/mapconfig/provider/named-map-provider.js index 797f29ef..d0823f89 100644 --- a/lib/models/mapconfig/provider/named-map-provider.js +++ b/lib/models/mapconfig/provider/named-map-provider.js @@ -135,7 +135,7 @@ module.exports = class NamedMapMapConfigProvider extends BaseMapConfigProvider { }, batch: { username: this.user, - apiKey: apiKey + apiKey } }; diff --git a/test/acceptance/ported/support/test-client.js b/test/acceptance/ported/support/test-client.js index fdb17e71..48a773cf 100644 --- a/test/acceptance/ported/support/test-client.js +++ b/test/acceptance/ported/support/test-client.js @@ -467,17 +467,17 @@ function withLayergroup (layergroupConfig, options, callback) { return `${signer ? `:${signer}@` : ''}`; }; - const cacheTpl = function ({ cache_buster, cacheBuster }) { - return `${cache_buster ? `:${cache_buster}` : `:${cacheBuster}`}`; + const cacheTpl = function ({ cacheBuster }) { + return `${cacheBuster ? `:${cacheBuster}` : ''}`; }; - const urlTpl = function ({ layergroupid, cache_buster = null, tile }) { - const { signer, token, cacheBuster } = LayergroupToken.parse(layergroupid); + const urlTpl = function ({ layergroupid, cacheBuster, tile }) { + const { signer, token, cacheBuster: cb } = LayergroupToken.parse(layergroupid); const base = '/api/v1/map/'; - return `${base}${signerTpl({ signer })}${token}${cacheTpl({ cache_buster, cacheBuster })}${tile}`; + return `${base}${signerTpl({ signer })}${token}${cacheTpl({ cacheBuster: (cacheBuster || cb) })}${tile}`; }; - const finalUrl = urlTpl({ layergroupid, cache_buster: options.cache_buster, tile: layergroupUrl }); + const finalUrl = urlTpl({ layergroupid, cacheBuster: options.cache_buster, tile: layergroupUrl }); var request = { url: finalUrl,