@atombender/hydrant-api
Advanced tools
Comparing version 0.0.21 to 0.0.22
@@ -11,2 +11,4 @@ 'use strict'; | ||
exports.deserializeQuery = deserializeQuery; | ||
exports.serializeTopKQuery = serializeTopKQuery; | ||
exports.deserializeTopKQuery = deserializeTopKQuery; | ||
exports.serializeTable = serializeTable; | ||
@@ -212,2 +214,53 @@ exports.deserializeTable = deserializeTable; | ||
function serializeTopKQuery(query) { | ||
var raw = {}; | ||
raw.filters = query.filters.map(function (f) { | ||
return { | ||
id: f.dimension.id, | ||
operator: f.operator, | ||
value: f.value | ||
}; | ||
}); | ||
if (query.dimension) { | ||
raw.dimension = { id: query.dimension.id }; | ||
} | ||
if (query.limit != null) { | ||
raw.limit = query.limit; | ||
} | ||
return raw; | ||
} | ||
function deserializeTopKQuery(rawQuery, schema) { | ||
console.log('deserializing topk query', rawQuery); | ||
var query = new _queries.TopKQuery(); | ||
query.setSchema(schema); | ||
if (rawQuery.dimension) { | ||
query.setDimension((0, _underscore.find)(schema.dimensions, function (d) { | ||
return d.id === rawQuery.dimension.id; | ||
})); | ||
} | ||
query.setFilters((rawQuery.filters || []).map(function (raw) { | ||
return parseFilter(raw, schema); | ||
})); | ||
if (rawQuery.limit != null) { | ||
query.setLimit(+rawQuery.limit); | ||
} | ||
console.log('query=', query); | ||
return query; | ||
function parseFilter(raw) { | ||
if (raw) { | ||
var dimension = (0, _underscore.find)(schema.dimensions, function (d) { | ||
return d.id === raw.id; | ||
}); | ||
if (!dimension) { | ||
throw new Error('Unknown dimension ' + id); | ||
} | ||
return new _queries.Filter(dimension, raw.operator, raw.value); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} | ||
function serializeTable(table) { | ||
@@ -214,0 +267,0 @@ return { |
@@ -129,2 +129,3 @@ 'use strict'; | ||
} | ||
return this; | ||
} | ||
@@ -135,2 +136,3 @@ }, { | ||
this.limit = limit; | ||
return this; | ||
} | ||
@@ -141,2 +143,3 @@ }, { | ||
this.eventTypes = eventTypes; | ||
return this; | ||
} | ||
@@ -147,2 +150,3 @@ }, { | ||
this.filters = filters; | ||
return this; | ||
} | ||
@@ -153,2 +157,3 @@ }, { | ||
this.timeInterval = timeInterval; | ||
return this; | ||
} | ||
@@ -159,2 +164,3 @@ }, { | ||
this.timeRange = timeRange; | ||
return this; | ||
} | ||
@@ -165,2 +171,3 @@ }, { | ||
this.timeframe = timeframe; | ||
return this; | ||
} | ||
@@ -171,2 +178,3 @@ }, { | ||
this.timeZone = timeZone; | ||
return this; | ||
} | ||
@@ -187,2 +195,3 @@ }, { | ||
}); | ||
return this; | ||
} | ||
@@ -233,3 +242,3 @@ }, { | ||
} | ||
if (this.filters.length !== other.filters || !(0, _underscore.every)((0, _underscore.zip)(this.filters, other.filters), function (_ref) { | ||
if (this.filters.length !== other.filters.length || !(0, _underscore.every)((0, _underscore.zip)(this.filters, other.filters), function (_ref) { | ||
var _ref2 = _slicedToArray(_ref, 2); | ||
@@ -282,1 +291,81 @@ | ||
exports.Query = Query; | ||
var TopKQuery = (function () { | ||
function TopKQuery() { | ||
_classCallCheck(this, TopKQuery); | ||
this.schema = null; | ||
this.filters = []; | ||
this.limit = null; | ||
this.dimension = null; | ||
} | ||
_createClass(TopKQuery, [{ | ||
key: 'setSchema', | ||
value: function setSchema(schema) { | ||
if ((schema && schema.id) !== (this.schema && this.schema.id)) { | ||
this.schema = schema; | ||
this.filters = []; | ||
} | ||
return this; | ||
} | ||
}, { | ||
key: 'setDimension', | ||
value: function setDimension(dimension) { | ||
this.dimension = dimension; | ||
return this; | ||
} | ||
}, { | ||
key: 'setLimit', | ||
value: function setLimit(limit) { | ||
this.limit = limit; | ||
return this; | ||
} | ||
}, { | ||
key: 'setFilters', | ||
value: function setFilters(filters) { | ||
this.filters = filters; | ||
return this; | ||
} | ||
}, { | ||
key: 'clone', | ||
value: function clone() { | ||
var query = new TopKQuery(); | ||
query.schema = this.schema; | ||
query.dimension = this.dimension; | ||
query.filters = (0, _underscore.clone)(this.filters); | ||
query.limit = this.limit; | ||
return query; | ||
} | ||
}, { | ||
key: 'equals', | ||
value: function equals(other) { | ||
if (!other instanceof TopKQuery) { | ||
return false; | ||
} | ||
if ((this.schema && this.schema.id) !== (other.schema && other.schema.id)) { | ||
return false; | ||
} | ||
if ((this.dimension && this.dimension.id) !== (other.dimension && other.dimension.id)) { | ||
return false; | ||
} | ||
if (this.limit !== other.limit) { | ||
return false; | ||
} | ||
if (this.filters.length !== other.filters.length || !(0, _underscore.every)((0, _underscore.zip)(this.filters, other.filters), function (_ref3) { | ||
var _ref32 = _slicedToArray(_ref3, 2); | ||
var a = _ref32[0]; | ||
var b = _ref32[1]; | ||
return a.equals(b); | ||
})) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
}]); | ||
return TopKQuery; | ||
})(); | ||
exports.TopKQuery = TopKQuery; |
{ | ||
"name": "@atombender/hydrant-api", | ||
"version": "0.0.21", | ||
"version": "0.0.22", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
115989
22
2985