diffusion
Version:
Diffusion JavaScript client
76 lines (75 loc) • 2.86 kB
JavaScript
;
/**
* @module FetchRequest
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.FetchResultImpl = exports.TIME_SERIES_DATA_TYPE = void 0;
var any_datatype_1 = require("./../../data/any-datatype");
var topic_result_1 = require("./../../features/topics/topic-result");
var time_series_event_datatype_1 = require("./../../timeseries/time-series-event-datatype");
exports.TIME_SERIES_DATA_TYPE = time_series_event_datatype_1.TimeSeriesEventDataType.create({
name: function () { return 'event data type'; },
readValue: function (buffer) { return buffer; },
toBytes: function (val) { return val; }
});
/**
* Implementation of the FetchResult interface
*/
var FetchResultImpl = /** @class */ (function () {
/**
* Create a new FetchResultImpl instance
*
* @param dataType the datatype of the results
* @param result the results
*/
function FetchResultImpl(dataType, result, context) {
this.resultList = result.results.map(function (topicResult) {
var value;
// only set a value if there is one in the FetchTopicResult
if (topicResult.value !== undefined) {
if (topicResult.type === context.TopicTypeEnum.TIME_SERIES) {
var event_1 = exports.TIME_SERIES_DATA_TYPE.readAs(exports.TIME_SERIES_DATA_TYPE.valueClass, topicResult.value);
if (dataType instanceof context.TimeSeriesEventDataType || dataType instanceof any_datatype_1.AnyDataTypeImpl) {
value = event_1;
}
else {
value = dataType.readAs(dataType.valueClass, event_1.value);
}
}
else {
var topicDataType = context.DataTypes.get(topicResult.type);
value = topicDataType.readAs(dataType.valueClass, topicResult.value);
}
}
return new topic_result_1.TopicResultImpl(topicResult.path, topicResult.type, value, result.properties.length === 0 ? {} :
result.properties[topicResult.propertiesIndex], topicResult.topicSizeInfo);
});
this.hasMoreFlag = result.hasMore;
}
/**
* @inheritdoc
*/
FetchResultImpl.prototype.results = function () {
return this.resultList;
};
/**
* @inheritdoc
*/
FetchResultImpl.prototype.hasMore = function () {
return this.hasMoreFlag;
};
/**
* @inheritdoc
*/
FetchResultImpl.prototype.size = function () {
return this.resultList.length;
};
/**
* @inheritdoc
*/
FetchResultImpl.prototype.isEmpty = function () {
return this.resultList.length === 0;
};
return FetchResultImpl;
}());
exports.FetchResultImpl = FetchResultImpl;