@atombender/hydrant-api
Advanced tools
Comparing version 0.0.26 to 0.0.27
@@ -15,3 +15,4 @@ 'use strict'; | ||
exports.deserializeTopKQuery = deserializeTopKQuery; | ||
exports.serializeResults = serializeResults; | ||
exports.serializeResultSet = serializeResultSet; | ||
exports.deserializeResultSet = deserializeResultSet; | ||
exports.serializeTable = serializeTable; | ||
@@ -41,2 +42,4 @@ exports.deserializeTable = deserializeTable; | ||
var _results = require('./results'); | ||
var _schemas = require('./schemas'); | ||
@@ -324,6 +327,51 @@ | ||
function serializeResults(results) { | ||
return results; | ||
function serializeResultSet(resultSet) { | ||
return { | ||
group: serializeGroup(resultSet.group) | ||
}; | ||
function serializeGroup(group) { | ||
if (!group) { | ||
return null; | ||
} | ||
return { | ||
id: group.dimension.id, | ||
buckets: group.buckets.map(serializeBucket) | ||
}; | ||
} | ||
function serializeBucket(bucket) { | ||
return { | ||
key: bucket.key, | ||
count: bucket.count, | ||
buckets: (bucket.buckets || []).map(serializeBucket) | ||
}; | ||
} | ||
} | ||
function deserializeResultSet(raw, schema) { | ||
if (raw.group) { | ||
return new _results.ResultSet(parseGroup(raw.group)); | ||
} | ||
return null; | ||
function parseGroup(rawGroup) { | ||
var dimension = (0, _underscore.find)(schema.dimensions, function (d) { | ||
return d.id == rawGroup.id; | ||
}); | ||
if (!dimension) { | ||
throw new Error('Could not find dimension: ' + rawGroup.id); | ||
} | ||
var buckets = _immutable2['default'].Set((rawGroup.buckets || []).map(parseBucket)); | ||
return new _results.ResultGroup(dimension, buckets); | ||
} | ||
function parseBucket(rawBucket) { | ||
var bucket = new _results.ResultBucket(rawBucket.key); | ||
bucket.count = rawBucket.count; | ||
bucket.buckets = _immutable2['default'].Set((rawBucket.buckets || []).map(parseBucket)); | ||
return bucket; | ||
} | ||
} | ||
function serializeTable(table) { | ||
@@ -330,0 +378,0 @@ return { |
@@ -86,9 +86,31 @@ 'use strict'; | ||
var ResultGroup = (function () { | ||
function ResultGroup(dimension) { | ||
var buckets = arguments[1] === undefined ? null : arguments[1]; | ||
_classCallCheck(this, ResultGroup); | ||
this.dimension = dimension; | ||
this.buckets = buckets ? _immutable2['default'].Set(buckets) : _immutable2['default'].Set(); | ||
} | ||
_createClass(ResultGroup, [{ | ||
key: 'toString', | ||
value: function toString() { | ||
return 'ResultGroup dimension={this.dimension.toString()}'; | ||
} | ||
}]); | ||
return ResultGroup; | ||
})(); | ||
exports.ResultGroup = ResultGroup; | ||
var ResultSet = (function () { | ||
function ResultSet() { | ||
var buckets = arguments[0] === undefined ? null : arguments[0]; | ||
var group = arguments[0] === undefined ? null : arguments[0]; | ||
_classCallCheck(this, ResultSet); | ||
this.buckets = buckets ? _immutable2['default'].Set(buckets) : _immutable2['default'].Set(); | ||
this.group = group; | ||
} | ||
@@ -95,0 +117,0 @@ |
{ | ||
"name": "@atombender/hydrant-api", | ||
"version": "0.0.26", | ||
"version": "0.0.27", | ||
"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
123864
3240