camel case
This commit is contained in:
parent
f9082dad94
commit
d4719d5707
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
);
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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 ?
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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 ');
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
)`;
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ module.exports = class NamedMapMapConfigProvider extends BaseMapConfigProvider {
|
||||
},
|
||||
batch: {
|
||||
username: this.user,
|
||||
apiKey: apiKey
|
||||
apiKey
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user