UNPKG

diffusion

Version:

Diffusion JavaScript client

58 lines (45 loc) 1.82 kB
var _implements = require('util/interface')._implements; var DataTypes = require('data/datatypes'); var TopicResult = require('features/topics/topic-result'); var api = require('../../../topics/fetch-request'); var TopicType = require('../../../topics/topic-type'); var TimeSeriesEventDataType = require('timeseries/time-series-event-datatype'); var TIME_SERIES_DATA_TYPE = TimeSeriesEventDataType.create({ name: function() { return "event data type"; }, readValue: function(buffer) { return buffer; }, toBytes: function(val) { return val; } }); var FetchResultImpl = _implements( api.FetchResult, function FetchResultImpl(dataType, result) { var resultList = result.results.map(function(topicResult) { var value; if (topicResult.value !== undefined) { if (topicResult.type === TopicType.TIME_SERIES) { value = TIME_SERIES_DATA_TYPE.readAs( TIME_SERIES_DATA_TYPE.valueClass, topicResult.value); } else { var topicDataType = DataTypes.get(topicResult.type); value = topicDataType.readAs(dataType.valueClass, topicResult.value); } } return new TopicResult( topicResult.path, topicResult.type, value, result.properties.length===0 ? {} : result.properties[topicResult.propertiesIndex] ); }); this.results = function() { return resultList; }; this.hasMore = function() { return result.hasMore; }; } ); module.exports = FetchResultImpl; module.exports.TIME_SERIES_DATA_TYPE = TIME_SERIES_DATA_TYPE;