camel case
This commit is contained in:
parent
f9082dad94
commit
d4719d5707
@ -133,7 +133,7 @@ function prepareAdapterMapConfig (mapConfigAdapter) {
|
|||||||
return function prepareAdapterMapConfigMiddleware (req, res, next) {
|
return function prepareAdapterMapConfigMiddleware (req, res, next) {
|
||||||
const requestMapConfig = req.body;
|
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 { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals;
|
||||||
const params = Object.assign({ dbuser, dbname, dbpassword, dbhost, dbport }, req.query);
|
const params = Object.assign({ dbuser, dbname, dbpassword, dbhost, dbport }, req.query);
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ function prepareAdapterMapConfig (mapConfigAdapter) {
|
|||||||
},
|
},
|
||||||
batch: {
|
batch: {
|
||||||
username: user,
|
username: user,
|
||||||
apiKey: api_key
|
apiKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -181,12 +181,12 @@ function createLayergroup (mapBackend, userLimitsBackend, pgConnection, affected
|
|||||||
const requestMapConfig = req.body;
|
const requestMapConfig = req.body;
|
||||||
|
|
||||||
const { context } = res.locals;
|
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 { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals;
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
cache_buster,
|
cache_buster: cacheBuster,
|
||||||
api_key,
|
api_key: apiKey,
|
||||||
dbuser,
|
dbuser,
|
||||||
dbname,
|
dbname,
|
||||||
dbpassword,
|
dbpassword,
|
||||||
|
@ -100,7 +100,7 @@ function getTemplate ({ label }) {
|
|||||||
function prepareLayerFilterFromPreviewLayers ({ namedMapProviderCache, label }) {
|
function prepareLayerFilterFromPreviewLayers ({ namedMapProviderCache, label }) {
|
||||||
return function prepareLayerFilterFromPreviewLayersMiddleware (req, res, next) {
|
return function prepareLayerFilterFromPreviewLayersMiddleware (req, res, next) {
|
||||||
const { template } = res.locals;
|
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) {
|
if (!template || !template.view || !template.view.preview_layers) {
|
||||||
return next();
|
return next();
|
||||||
@ -119,21 +119,21 @@ function prepareLayerFilterFromPreviewLayers ({ namedMapProviderCache, label })
|
|||||||
return next();
|
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 { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals;
|
||||||
const { template_id, format } = req.params;
|
const { template_id: templateId, format } = req.params;
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
user,
|
user,
|
||||||
token,
|
token,
|
||||||
cache_buster,
|
cache_buster: cacheBuster,
|
||||||
api_key,
|
api_key: apiKey,
|
||||||
dbuser,
|
dbuser,
|
||||||
dbname,
|
dbname,
|
||||||
dbpassword,
|
dbpassword,
|
||||||
dbhost,
|
dbhost,
|
||||||
dbport,
|
dbport,
|
||||||
template_id,
|
template_id: templateId,
|
||||||
format
|
format
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ function prepareLayerFilterFromPreviewLayers ({ namedMapProviderCache, label })
|
|||||||
params.layer = layerVisibilityFilter.join(',');
|
params.layer = layerVisibilityFilter.join(',');
|
||||||
|
|
||||||
// recreates the provider
|
// 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) {
|
if (err) {
|
||||||
err.label = label;
|
err.label = label;
|
||||||
return next(err);
|
return next(err);
|
||||||
|
@ -6,12 +6,12 @@ module.exports = function setLastModifiedHeader () {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
const { mapConfigProvider, cache_buster } = res.locals;
|
const { mapConfigProvider, cache_buster: cacheBuster } = res.locals;
|
||||||
|
|
||||||
if (cache_buster) {
|
if (cacheBuster) {
|
||||||
const cacheBuster = parseInt(cache_buster, 10);
|
const cacheBusterTimestamp = parseInt(cacheBuster, 10);
|
||||||
const lastModifiedDate = Number.isFinite(cacheBuster) && cacheBuster !== 0
|
const lastModifiedDate = Number.isFinite(cacheBusterTimestamp) && cacheBusterTimestamp !== 0
|
||||||
? new Date(cacheBuster)
|
? new Date(cacheBusterTimestamp)
|
||||||
: new Date();
|
: new Date();
|
||||||
|
|
||||||
res.set('Last-Modified', lastModifiedDate.toUTCString());
|
res.set('Last-Modified', lastModifiedDate.toUTCString());
|
||||||
|
@ -10,16 +10,16 @@ module.exports = function createMapStoreMapConfigProvider (
|
|||||||
forcedFormat = null
|
forcedFormat = null
|
||||||
) {
|
) {
|
||||||
return function createMapStoreMapConfigProviderMiddleware (req, res, next) {
|
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 { 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 { layer: layerFromQuery } = req.query;
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
user,
|
user,
|
||||||
token,
|
token,
|
||||||
cache_buster,
|
cache_buster: cacheBuster,
|
||||||
api_key,
|
api_key: apiKey,
|
||||||
dbuser,
|
dbuser,
|
||||||
dbname,
|
dbname,
|
||||||
dbpassword,
|
dbpassword,
|
||||||
@ -29,7 +29,7 @@ module.exports = function createMapStoreMapConfigProvider (
|
|||||||
z,
|
z,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
scale_factor,
|
scale_factor: scaleFactor,
|
||||||
format
|
format
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,22 +2,22 @@
|
|||||||
|
|
||||||
module.exports = function getNamedMapProvider ({ namedMapProviderCache, label, forcedFormat = null }) {
|
module.exports = function getNamedMapProvider ({ namedMapProviderCache, label, forcedFormat = null }) {
|
||||||
return function getNamedMapProviderMiddleware (req, res, next) {
|
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 { 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 { layer: layerFromQuery } = req.query;
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
user,
|
user,
|
||||||
token,
|
token,
|
||||||
cache_buster,
|
cache_buster: cacheBuster,
|
||||||
api_key,
|
api_key: apiKey,
|
||||||
dbuser,
|
dbuser,
|
||||||
dbname,
|
dbname,
|
||||||
dbpassword,
|
dbpassword,
|
||||||
dbhost,
|
dbhost,
|
||||||
dbport,
|
dbport,
|
||||||
template_id,
|
template_id: templateId,
|
||||||
layer: (layerFromQuery || layerFromParams),
|
layer: (layerFromQuery || layerFromParams),
|
||||||
z,
|
z,
|
||||||
x,
|
x,
|
||||||
@ -30,9 +30,9 @@ module.exports = function getNamedMapProvider ({ namedMapProviderCache, label, f
|
|||||||
params.layer = params.layer || 'all';
|
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) {
|
if (err) {
|
||||||
err.label = label;
|
err.label = label;
|
||||||
return next(err);
|
return next(err);
|
||||||
|
@ -148,8 +148,8 @@ function getTemplate (
|
|||||||
return function getTemplateMiddleware (req, res, next) {
|
return function getTemplateMiddleware (req, res, next) {
|
||||||
const templateParams = req.body;
|
const templateParams = req.body;
|
||||||
const { user, dbuser, dbname, dbpassword, dbhost, dbport } = res.locals;
|
const { user, dbuser, dbname, dbpassword, dbhost, dbport } = res.locals;
|
||||||
const { template_id } = req.params;
|
const { template_id: templateId } = req.params;
|
||||||
const { auth_token } = req.query;
|
const { auth_token: authToken } = req.query;
|
||||||
|
|
||||||
const params = Object.assign({ dbuser, dbname, dbpassword, dbhost, dbport }, req.query);
|
const params = Object.assign({ dbuser, dbname, dbpassword, dbhost, dbport }, req.query);
|
||||||
|
|
||||||
@ -161,9 +161,9 @@ function getTemplate (
|
|||||||
mapConfigAdapter,
|
mapConfigAdapter,
|
||||||
affectedTablesCache,
|
affectedTablesCache,
|
||||||
user,
|
user,
|
||||||
template_id,
|
templateId,
|
||||||
templateParams,
|
templateParams,
|
||||||
auth_token,
|
authToken,
|
||||||
params
|
params
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -32,15 +32,15 @@ AuthBackend.prototype.authorizedBySigner = function (req, res, callback) {
|
|||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var layergroup_id = res.locals.token;
|
var layergroupId = res.locals.token;
|
||||||
var auth_token = req.query.auth_token;
|
var authToken = req.query.auth_token;
|
||||||
|
|
||||||
this.mapStore.load(layergroup_id, function (err, mapConfig) {
|
this.mapStore.load(layergroupId, function (err, mapConfig) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(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);
|
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');
|
throw new Error('Invalid aggregation input, expressions should be and object with valid functions');
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const { aggregate_function, aggregated_column } of Object.values(expressions)) {
|
for (const { aggregate_function: aggregateFunction, aggregated_column: aggregatedColumn } of Object.values(expressions)) {
|
||||||
if (typeof aggregated_column !== 'string') {
|
if (typeof aggregatedColumn !== 'string') {
|
||||||
throw new Error('Invalid aggregation input, aggregated column should be an 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');
|
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) {
|
if (params.bbox && queryRewriteData) {
|
||||||
var bbox_filter_definition = {
|
var bboxFilterDefinition = {
|
||||||
type: 'bbox',
|
type: 'bbox',
|
||||||
options: {
|
options: {
|
||||||
column: 'the_geom_webmercator',
|
column: 'the_geom_webmercator',
|
||||||
@ -125,7 +125,7 @@ function getQueryRewriteData (mapConfig, dataviewDefinition, params) {
|
|||||||
bbox: params.bbox
|
bbox: params.bbox
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
queryRewriteData = _.extend(queryRewriteData, { bbox_filter: bbox_filter_definition });
|
queryRewriteData = _.extend(queryRewriteData, { bbox_filter: bboxFilterDefinition });
|
||||||
}
|
}
|
||||||
|
|
||||||
return queryRewriteData;
|
return queryRewriteData;
|
||||||
|
@ -10,24 +10,24 @@ function FilterStatsBackends (pgQueryRunner) {
|
|||||||
module.exports = FilterStatsBackends;
|
module.exports = FilterStatsBackends;
|
||||||
|
|
||||||
function getEstimatedRows (pgQueryRunner, username, query, callback) {
|
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) {
|
if (err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var rows;
|
var rows;
|
||||||
if (result_rows[0] && result_rows[0]['QUERY PLAN'] &&
|
if (resultRows[0] && resultRows[0]['QUERY PLAN'] &&
|
||||||
result_rows[0]['QUERY PLAN'][0] && result_rows[0]['QUERY PLAN'][0].Plan) {
|
resultRows[0]['QUERY PLAN'][0] && resultRows[0]['QUERY PLAN'][0].Plan) {
|
||||||
rows = result_rows[0]['QUERY PLAN'][0].Plan['Plan Rows'];
|
rows = resultRows[0]['QUERY PLAN'][0].Plan['Plan Rows'];
|
||||||
}
|
}
|
||||||
return callback(null, rows);
|
return callback(null, rows);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
FilterStatsBackends.prototype.getFilterStats = function (username, unfiltered_query, filters, callback) {
|
FilterStatsBackends.prototype.getFilterStats = function (username, unfilteredQuery, filters, callback) {
|
||||||
var stats = {};
|
var stats = {};
|
||||||
|
|
||||||
getEstimatedRows(this.pgQueryRunner, username, unfiltered_query, (err, rows) => {
|
getEstimatedRows(this.pgQueryRunner, username, unfilteredQuery, (err, rows) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ FilterStatsBackends.prototype.getFilterStats = function (username, unfiltered_qu
|
|||||||
}
|
}
|
||||||
|
|
||||||
var analysisFilter = new AnalysisFilter(filters);
|
var analysisFilter = new AnalysisFilter(filters);
|
||||||
var query = analysisFilter.sql(unfiltered_query);
|
var query = analysisFilter.sql(unfilteredQuery);
|
||||||
|
|
||||||
getEstimatedRows(this.pgQueryRunner, username, query, (err, rows) => {
|
getEstimatedRows(this.pgQueryRunner, username, query, (err, rows) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -12,7 +12,7 @@ var util = require('util');
|
|||||||
//
|
//
|
||||||
// See http://github.com/CartoDB/Windshaft-cartodb/wiki/Template-maps
|
// 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
|
// See https://github.com/CartoDB/node-redis-mpool
|
||||||
// Needs version 0.x.x of the API.
|
// 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
|
// 'max_user_templates' limit on the number of per-user
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
function TemplateMaps (redis_pool, opts) {
|
function TemplateMaps (redisPool, opts) {
|
||||||
if (!(this instanceof TemplateMaps)) {
|
if (!(this instanceof TemplateMaps)) {
|
||||||
return new TemplateMaps();
|
return new TemplateMaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
|
|
||||||
this.redis_pool = redis_pool;
|
this.redisPool = redisPool;
|
||||||
this.opts = opts || {};
|
this.opts = opts || {};
|
||||||
|
|
||||||
// Database containing templates
|
// Database containing templates
|
||||||
@ -44,7 +44,7 @@ function TemplateMaps (redis_pool, opts) {
|
|||||||
//
|
//
|
||||||
// 1. User templates: set of per-user map templates
|
// 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}}');
|
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.
|
* @param callback - function to pass results too.
|
||||||
*/
|
*/
|
||||||
TemplateMaps.prototype._redisCmd = function (redisFunc, redisArgs, callback) {
|
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) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
redisClient[redisFunc.toUpperCase()](...redisArgs, (err, data) => {
|
redisClient[redisFunc.toUpperCase()](...redisArgs, (err, data) => {
|
||||||
this.redis_pool.release(this.db_signatures, redisClient);
|
this.redisPool.release(this.db_signatures, redisClient);
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@ -215,7 +215,7 @@ TemplateMaps.prototype._checkUserTemplatesLimit = function (userTemplatesKey, ow
|
|||||||
// @param template layergroup template, see
|
// @param template layergroup template, see
|
||||||
// http://github.com/CartoDB/Windshaft-cartodb/wiki/Template-maps#template-format
|
// 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)
|
// Return template identifier (only valid for given user)
|
||||||
//
|
//
|
||||||
TemplateMaps.prototype.addTemplate = function (owner, template, callback) {
|
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 owner cartodb username of the template owner
|
||||||
//
|
//
|
||||||
// @param tpl_id template identifier as returned
|
// @param tplId template identifier as returned
|
||||||
// by addTemplate or listTemplates
|
// by addTemplate or listTemplates
|
||||||
//
|
//
|
||||||
// @param callback function(err)
|
// @param callback function(err)
|
||||||
//
|
//
|
||||||
TemplateMaps.prototype.delTemplate = function (owner, tpl_id, callback) {
|
TemplateMaps.prototype.delTemplate = function (owner, tplId, callback) {
|
||||||
this._redisCmd('HDEL', [this.key_usr_tpl({ owner: owner }), tpl_id], (err, deleted) => {
|
this._redisCmd('HDEL', [this.key_usr_tpl({ owner: owner }), tplId], (err, deleted) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!deleted) {
|
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();
|
return callback();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -289,14 +289,14 @@ TemplateMaps.prototype.delTemplate = function (owner, tpl_id, callback) {
|
|||||||
//
|
//
|
||||||
// @param owner cartodb username of the template owner
|
// @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
|
// @param template layergroup template, see
|
||||||
// http://github.com/CartoDB/Windshaft-cartodb/wiki/Template-maps#template-format
|
// http://github.com/CartoDB/Windshaft-cartodb/wiki/Template-maps#template-format
|
||||||
//
|
//
|
||||||
// @param callback function(err)
|
// @param callback function(err)
|
||||||
//
|
//
|
||||||
TemplateMaps.prototype.updTemplate = function (owner, tpl_id, template, callback) {
|
TemplateMaps.prototype.updTemplate = function (owner, tplId, template, callback) {
|
||||||
template = templateDefaults(template);
|
template = templateDefaults(template);
|
||||||
|
|
||||||
var invalidError = this._checkInvalidTemplate(template);
|
var invalidError = this._checkInvalidTemplate(template);
|
||||||
@ -304,19 +304,19 @@ TemplateMaps.prototype.updTemplate = function (owner, tpl_id, template, callback
|
|||||||
return callback(invalidError);
|
return callback(invalidError);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tpl_id !== template.name) {
|
if (tplId !== template.name) {
|
||||||
return callback(new Error(`Cannot update name of a map template ('${tpl_id}' != '${template.name}')`));
|
return callback(new Error(`Cannot update name of a map template ('${tplId}' != '${template.name}')`));
|
||||||
}
|
}
|
||||||
|
|
||||||
var userTemplatesKey = this.key_usr_tpl({ owner });
|
var userTemplatesKey = this.key_usr_tpl({ owner });
|
||||||
|
|
||||||
this._redisCmd('HGET', [userTemplatesKey, tpl_id], (err, beforeUpdateTemplate) => {
|
this._redisCmd('HGET', [userTemplatesKey, tplId], (err, beforeUpdateTemplate) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!beforeUpdateTemplate) {
|
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;
|
let templateString;
|
||||||
@ -355,7 +355,7 @@ TemplateMaps.prototype.updTemplate = function (owner, tpl_id, template, callback
|
|||||||
//
|
//
|
||||||
// @param owner cartodb username of the templates owner
|
// @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
|
// Returns a list of template identifiers
|
||||||
//
|
//
|
||||||
TemplateMaps.prototype.listTemplates = function (owner, callback) {
|
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 owner cartodb username of the template owner
|
||||||
//
|
//
|
||||||
// @param tpl_id template identifier as returned
|
// @param tplId template identifier as returned
|
||||||
// by addTemplate or listTemplates
|
// by addTemplate or listTemplates
|
||||||
//
|
//
|
||||||
// @param callback function(err, template)
|
// @param callback function(err, template)
|
||||||
// Return full template definition
|
// Return full template definition
|
||||||
//
|
//
|
||||||
TemplateMaps.prototype.getTemplate = function (owner, tpl_id, callback) {
|
TemplateMaps.prototype.getTemplate = function (owner, tplId, callback) {
|
||||||
this._redisCmd('HGET', [this.key_usr_tpl({ owner: owner }), tpl_id], (err, template) => {
|
this._redisCmd('HGET', [this.key_usr_tpl({ owner: owner }), tplId], (err, template) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@ -446,7 +446,7 @@ function isObject (val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TemplateMaps.prototype.instance = function (template, params) {
|
TemplateMaps.prototype.instance = function (template, params) {
|
||||||
var all_params = {};
|
var allParams = {};
|
||||||
var phold = template.placeholders || {};
|
var phold = template.placeholders || {};
|
||||||
Object.keys(phold).forEach(function (k) {
|
Object.keys(phold).forEach(function (k) {
|
||||||
var val = Object.prototype.hasOwnProperty.call(params, k) ? params[k] : phold[k].default;
|
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
|
// NOTE: should be checked at template create/update time
|
||||||
throw new Error("Invalid placeholder type '" + type + "'");
|
throw new Error("Invalid placeholder type '" + type + "'");
|
||||||
}
|
}
|
||||||
all_params[k] = val;
|
allParams[k] = val;
|
||||||
});
|
});
|
||||||
|
|
||||||
// NOTE: we're deep-cloning the layergroup here
|
// NOTE: we're deep-cloning the layergroup here
|
||||||
@ -481,7 +481,7 @@ TemplateMaps.prototype.instance = function (template, params) {
|
|||||||
|
|
||||||
if (layergroup.buffersize && isObject(layergroup.buffersize)) {
|
if (layergroup.buffersize && isObject(layergroup.buffersize)) {
|
||||||
Object.keys(layergroup.buffersize).forEach(function (k) {
|
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
|
// dynamic styling for this layer
|
||||||
lyropt.cartocss = params.styles[i];
|
lyropt.cartocss = params.styles[i];
|
||||||
} else if (lyropt.cartocss) {
|
} else if (lyropt.cartocss) {
|
||||||
lyropt.cartocss = _replaceVars(lyropt.cartocss, all_params);
|
lyropt.cartocss = _replaceVars(lyropt.cartocss, allParams);
|
||||||
}
|
}
|
||||||
if (lyropt.sql) {
|
if (lyropt.sql) {
|
||||||
lyropt.sql = _replaceVars(lyropt.sql, all_params);
|
lyropt.sql = _replaceVars(lyropt.sql, allParams);
|
||||||
}
|
}
|
||||||
// Anything else ?
|
// Anything else ?
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ module.exports = class AggregationMapConfig extends MapConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getAggregatedQuery (index) {
|
getAggregatedQuery (index) {
|
||||||
const { sql_raw, sql } = this.getLayer(index).options;
|
const { sql_raw: sqlRaw, sql } = this.getLayer(index).options;
|
||||||
const {
|
const {
|
||||||
// The default aggregation has no placement, columns or dimensions;
|
// The default aggregation has no placement, columns or dimensions;
|
||||||
// this enables the special "full-sample" aggregation.
|
// this enables the special "full-sample" aggregation.
|
||||||
@ -96,7 +96,7 @@ module.exports = class AggregationMapConfig extends MapConfig {
|
|||||||
} = this.getAggregation(index);
|
} = this.getAggregation(index);
|
||||||
|
|
||||||
return aggregationQuery({
|
return aggregationQuery({
|
||||||
query: sql_raw || sql,
|
query: sqlRaw || sql,
|
||||||
resolution,
|
resolution,
|
||||||
threshold,
|
threshold,
|
||||||
placement,
|
placement,
|
||||||
|
@ -51,22 +51,22 @@ module.exports.infoForOptions = (options) => {
|
|||||||
|
|
||||||
const SUPPORTED_AGGREGATE_FUNCTIONS = {
|
const SUPPORTED_AGGREGATE_FUNCTIONS = {
|
||||||
count: {
|
count: {
|
||||||
sql: (column_name, params) => `count(${params.aggregated_column || '*'})`
|
sql: (columnName, params) => `count(${params.aggregated_column || '*'})`
|
||||||
},
|
},
|
||||||
avg: {
|
avg: {
|
||||||
sql: (column_name, params) => `avg(${params.aggregated_column || column_name})`
|
sql: (columnName, params) => `avg(${params.aggregated_column || columnName})`
|
||||||
},
|
},
|
||||||
sum: {
|
sum: {
|
||||||
sql: (column_name, params) => `sum(${params.aggregated_column || column_name})`
|
sql: (columnName, params) => `sum(${params.aggregated_column || columnName})`
|
||||||
},
|
},
|
||||||
min: {
|
min: {
|
||||||
sql: (column_name, params) => `min(${params.aggregated_column || column_name})`
|
sql: (columnName, params) => `min(${params.aggregated_column || columnName})`
|
||||||
},
|
},
|
||||||
max: {
|
max: {
|
||||||
sql: (column_name, params) => `max(${params.aggregated_column || column_name})`
|
sql: (columnName, params) => `max(${params.aggregated_column || columnName})`
|
||||||
},
|
},
|
||||||
mode: {
|
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 || {});
|
}, ctx.columns || {});
|
||||||
};
|
};
|
||||||
|
|
||||||
const aggregateExpression = (column_name, column_parameters) => {
|
const aggregateExpression = (columnName, columnParameters) => {
|
||||||
const aggregate_function = column_parameters.aggregate_function || 'count';
|
const aggregateFunction = columnParameters.aggregate_function || 'count';
|
||||||
const aggregate_definition = SUPPORTED_AGGREGATE_FUNCTIONS[aggregate_function];
|
const aggregateDefinition = SUPPORTED_AGGREGATE_FUNCTIONS[aggregateFunction];
|
||||||
if (!aggregate_definition) {
|
if (!aggregateDefinition) {
|
||||||
throw new Error("Invalid Aggregate function: '" + aggregate_function + "'");
|
throw new Error("Invalid Aggregate function: '" + aggregateFunction + "'");
|
||||||
}
|
}
|
||||||
return aggregate_definition.sql(column_name, column_parameters);
|
return aggregateDefinition.sql(columnName, columnParameters);
|
||||||
};
|
};
|
||||||
|
|
||||||
const aggregateColumnDefs = ctx => {
|
const aggregateColumnDefs = ctx => {
|
||||||
const columns = aggregateColumns(ctx);
|
const columns = aggregateColumns(ctx);
|
||||||
return sep(Object.keys(columns).map(column_name => {
|
return sep(Object.keys(columns).map(columnName => {
|
||||||
const aggregate_expression = aggregateExpression(column_name, columns[column_name]);
|
const aggregate = aggregateExpression(columnName, columns[columnName]);
|
||||||
return `${aggregate_expression} AS ${column_name}`;
|
return `${aggregate} AS ${columnName}`;
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -241,17 +241,17 @@ const filterConditions = ctx => {
|
|||||||
const columns = aggregateColumns(ctx);
|
const columns = aggregateColumns(ctx);
|
||||||
const dimensions = aggregateDimensions(ctx);
|
const dimensions = aggregateDimensions(ctx);
|
||||||
const filters = aggregateFilters(ctx);
|
const filters = aggregateFilters(ctx);
|
||||||
return Object.keys(filters).map(filtered_column => {
|
return Object.keys(filters).map(filteredColumn => {
|
||||||
let filtered_expr;
|
let filteredExpr;
|
||||||
if (columns[filtered_column]) {
|
if (columns[filteredColumn]) {
|
||||||
filtered_expr = aggregateExpression(filtered_column, columns[filtered_column]);
|
filteredExpr = aggregateExpression(filteredColumn, columns[filteredColumn]);
|
||||||
} else if (dimensions[filtered_column]) {
|
} else if (dimensions[filteredColumn]) {
|
||||||
filtered_expr = dimensions[filtered_column];
|
filteredExpr = dimensions[filteredColumn];
|
||||||
}
|
}
|
||||||
if (!filtered_expr) {
|
if (!filteredExpr) {
|
||||||
throw new Error("Invalid filtered column: '" + filtered_column + "'");
|
throw new Error("Invalid filtered column: '" + filteredColumn + "'");
|
||||||
}
|
}
|
||||||
return filterConditionSQL(filtered_expr, filters[filtered_column]);
|
return filterConditionSQL(filteredExpr, filters[filteredColumn]);
|
||||||
}).join(' AND ');
|
}).join(' AND ');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -90,10 +90,10 @@ function createAggregationColumnNamesValidator (mapconfig) {
|
|||||||
function createAggregateFunctionValidator (mapconfig, validAggregatedFunctions) {
|
function createAggregateFunctionValidator (mapconfig, validAggregatedFunctions) {
|
||||||
return function validateAggregateFunction (value, key, index) {
|
return function validateAggregateFunction (value, key, index) {
|
||||||
Object.keys(value).forEach((columnName) => {
|
Object.keys(value).forEach((columnName) => {
|
||||||
const { aggregate_function } = value[columnName];
|
const { aggregate_function: aggregateFunction } = value[columnName];
|
||||||
|
|
||||||
if (!validAggregatedFunctions.includes(aggregate_function)) {
|
if (!validAggregatedFunctions.includes(aggregateFunction)) {
|
||||||
const message = `Unsupported aggregation function ${aggregate_function},` +
|
const message = `Unsupported aggregation function ${aggregateFunction},` +
|
||||||
` valid ones: ${validAggregatedFunctions.join(', ')}`;
|
` valid ones: ${validAggregatedFunctions.join(', ')}`;
|
||||||
throw createLayerError(message, mapconfig, index);
|
throw createLayerError(message, mapconfig, index);
|
||||||
}
|
}
|
||||||
@ -104,9 +104,9 @@ function createAggregateFunctionValidator (mapconfig, validAggregatedFunctions)
|
|||||||
function createAggregatedColumnValidator (mapconfig) {
|
function createAggregatedColumnValidator (mapconfig) {
|
||||||
return function validateAggregatedColumn (value, key, index) {
|
return function validateAggregatedColumn (value, key, index) {
|
||||||
Object.keys(value).forEach((columnName) => {
|
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';
|
const message = 'Invalid aggregated column, should be a non empty string';
|
||||||
throw createLayerError(message, mapconfig, index);
|
throw createLayerError(message, mapconfig, index);
|
||||||
}
|
}
|
||||||
|
@ -187,12 +187,12 @@ function validateParameters (params, checker) {
|
|||||||
if (missingParams.length) {
|
if (missingParams.length) {
|
||||||
errors.push(`Missing parameters: ${missingParams.join(', ')}`);
|
errors.push(`Missing parameters: ${missingParams.join(', ')}`);
|
||||||
}
|
}
|
||||||
const params_errors = checker(params);
|
const paramsErrors = checker(params);
|
||||||
errors.push(...params_errors.errors);
|
errors.push(...paramsErrors.errors);
|
||||||
if (errors.length) {
|
if (errors.length) {
|
||||||
throw new Error(`Invalid time dimension:\n${errors.join('\n')}`);
|
throw new Error(`Invalid time dimension:\n${errors.join('\n')}`);
|
||||||
}
|
}
|
||||||
return params_errors.params;
|
return paramsErrors.params;
|
||||||
}
|
}
|
||||||
|
|
||||||
const VALID_CYCLIC_UNITS = Object.keys(cyclicParts);
|
const VALID_CYCLIC_UNITS = Object.keys(cyclicParts);
|
||||||
|
@ -91,16 +91,16 @@ module.exports = class Formula extends BaseDataview {
|
|||||||
const {
|
const {
|
||||||
result = 0,
|
result = 0,
|
||||||
nulls_count = 0,
|
nulls_count = 0,
|
||||||
nans_count,
|
nans_count: nansCount,
|
||||||
infinities_count
|
infinities_count: infinitiesCount
|
||||||
} = res.rows[0] || {};
|
} = res.rows[0] || {};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
operation: this.operation,
|
operation: this.operation,
|
||||||
result,
|
result,
|
||||||
nulls: nulls_count,
|
nulls: nulls_count,
|
||||||
nans: nans_count,
|
nans: nansCount,
|
||||||
infinities: infinities_count
|
infinities: infinitiesCount
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,16 +32,16 @@ WITH __wd_tz AS
|
|||||||
* our timezone so when calling date_trunc it falls into the correct bin
|
* our timezone so when calling date_trunc it falls into the correct bin
|
||||||
*/
|
*/
|
||||||
function dataBucketsQuery (ctx) {
|
function dataBucketsQuery (ctx) {
|
||||||
var condition_str = '';
|
var conditionStr = '';
|
||||||
|
|
||||||
if (ctx.start !== 0) {
|
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 (ctx.end !== 0) {
|
||||||
if (condition_str === '') {
|
if (conditionStr === '') {
|
||||||
condition_str = `WHERE ${ctx.column} <= to_timestamp(${ctx.end})`;
|
conditionStr = `WHERE ${ctx.column} <= to_timestamp(${ctx.end})`;
|
||||||
} else {
|
} 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}
|
${ctx.query}
|
||||||
) __source, __wd_tz
|
) __source, __wd_tz
|
||||||
${condition_str}
|
${conditionStr}
|
||||||
GROUP BY 1, __wd_tz.name
|
GROUP BY 1, __wd_tz.name
|
||||||
),`;
|
),`;
|
||||||
}
|
}
|
||||||
@ -67,22 +67,22 @@ __wd_buckets AS
|
|||||||
* the dataBucketsQuery
|
* the dataBucketsQuery
|
||||||
*/
|
*/
|
||||||
function allBucketsArrayQuery (ctx) {
|
function allBucketsArrayQuery (ctx) {
|
||||||
var extra_from = '';
|
var extraFrom = '';
|
||||||
var series_start = '';
|
var seriesStart = '';
|
||||||
var series_end = '';
|
var seriesEnd = '';
|
||||||
|
|
||||||
if (ctx.start === 0) {
|
if (ctx.start === 0) {
|
||||||
extra_from = ', __wd_buckets GROUP BY __wd_tz.name';
|
extraFrom = ', __wd_buckets GROUP BY __wd_tz.name';
|
||||||
series_start = 'min(__wd_buckets.timestamp)';
|
seriesStart = 'min(__wd_buckets.timestamp)';
|
||||||
} else {
|
} 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) {
|
if (ctx.end === 0) {
|
||||||
extra_from = ', __wd_buckets GROUP BY __wd_tz.name';
|
extraFrom = ', __wd_buckets GROUP BY __wd_tz.name';
|
||||||
series_end = 'max(__wd_buckets.timestamp)';
|
seriesEnd = 'max(__wd_buckets.timestamp)';
|
||||||
} else {
|
} 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 `
|
return `
|
||||||
@ -91,10 +91,10 @@ __wd_all_buckets AS
|
|||||||
SELECT ARRAY(
|
SELECT ARRAY(
|
||||||
SELECT
|
SELECT
|
||||||
generate_series(
|
generate_series(
|
||||||
${series_start},
|
${seriesStart},
|
||||||
${series_end},
|
${seriesEnd},
|
||||||
interval '${ctx.interval}') as bin_start
|
interval '${ctx.interval}') as bin_start
|
||||||
FROM __wd_tz${extra_from}
|
FROM __wd_tz${extraFrom}
|
||||||
) as bins
|
) as bins
|
||||||
)`;
|
)`;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ module.exports = class NamedMapMapConfigProvider extends BaseMapConfigProvider {
|
|||||||
},
|
},
|
||||||
batch: {
|
batch: {
|
||||||
username: this.user,
|
username: this.user,
|
||||||
apiKey: apiKey
|
apiKey
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -467,17 +467,17 @@ function withLayergroup (layergroupConfig, options, callback) {
|
|||||||
return `${signer ? `:${signer}@` : ''}`;
|
return `${signer ? `:${signer}@` : ''}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const cacheTpl = function ({ cache_buster, cacheBuster }) {
|
const cacheTpl = function ({ cacheBuster }) {
|
||||||
return `${cache_buster ? `:${cache_buster}` : `:${cacheBuster}`}`;
|
return `${cacheBuster ? `:${cacheBuster}` : ''}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const urlTpl = function ({ layergroupid, cache_buster = null, tile }) {
|
const urlTpl = function ({ layergroupid, cacheBuster, tile }) {
|
||||||
const { signer, token, cacheBuster } = LayergroupToken.parse(layergroupid);
|
const { signer, token, cacheBuster: cb } = LayergroupToken.parse(layergroupid);
|
||||||
const base = '/api/v1/map/';
|
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 = {
|
var request = {
|
||||||
url: finalUrl,
|
url: finalUrl,
|
||||||
|
Loading…
Reference in New Issue
Block a user