diffusion
Version:
Diffusion JavaScript client
163 lines (162 loc) • 5.48 kB
JavaScript
;
/**
* @module Timeseries
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_RANGE_QUERY = exports.RangeQueryParameters = exports.QueryTypes = exports.QueryType = exports.StreamStructures = exports.StreamStructure = void 0;
var range_1 = require("./../../features/time-series/range");
var enumerize_1 = require("./../../util/enumerize");
var math_1 = require("./../../util/math");
var require_non_null_1 = require("./../../util/require-non-null");
/**
* Timeseries stream structure
*
* Value type of the {@link StreamStructures} enum-like object
*/
var StreamStructure = /** @class */ (function () {
/**
* Create a new StreamStructure instance
*
* @param id the id of the stream structure
* @param name the name of the stream structure
*/
function StreamStructure(id, name) {
this.id = id;
this.name = name;
}
/**
* Convert object to string
*
* @return a string representation of the StreamStructure
*/
StreamStructure.prototype.toString = function () {
return this.name;
};
return StreamStructure;
}());
exports.StreamStructure = StreamStructure;
/**
* Enum-like object for timeseries stream structures
*/ // eslint-disable-next-line @typescript-eslint/naming-convention
exports.StreamStructures = {
/**
* A value event stream
*/
VALUE_EVENT_STREAM: new StreamStructure(1, 'VALUE_EVENT_STREAM'),
/**
* An edit event stream
*/
EDIT_EVENT_STREAM: new StreamStructure(2, 'EDIT_EVENT_STREAM')
};
enumerize_1.enumerize(exports.StreamStructures);
Object.freeze(exports.StreamStructures);
/**
* Timeseries query type
*
* Value type of the {@link QueryTypes} enum-like object
*/
var QueryType = /** @class */ (function () {
/**
* Create a new QueryType instance
*
* @param id the id of the stream structure
* @param streamStructure the stream structure associated with the query type
*/
function QueryType(id, streamStructure) {
this.id = id;
this.streamStructure = streamStructure;
}
return QueryType;
}());
exports.QueryType = QueryType;
/**
* Enum-like object for timeseries query types
*/ // eslint-disable-next-line @typescript-eslint/naming-convention
exports.QueryTypes = {
/**
* A values query type
*/
VALUES: new QueryType(0, exports.StreamStructures.VALUE_EVENT_STREAM),
/**
* A query type for all edits
*/
ALL_EDITS: new QueryType(1, exports.StreamStructures.EDIT_EVENT_STREAM),
/**
* A query type for the latest edits
*/
LATEST_EDITS: new QueryType(2, exports.StreamStructures.EDIT_EVENT_STREAM)
};
enumerize_1.enumerize(exports.QueryTypes);
Object.freeze(exports.QueryTypes);
/**
* Range query parameters
*
* These parameters are used in the {@link RangeQueryImpl} implementation of
* {@link RangeQuery}.
*
* An instance of RangeQueryParameters is an immutable object and follows the
* builder pattern to create modifications of itself.
*/
var RangeQueryParameters = /** @class */ (function () {
/**
* Create a new RangeQueryParameters instance
*
* @param queryType the query type
* @param viewRange the view range
* @param editRange the edit range
* @param limit the limit on the number of entries
*/
function RangeQueryParameters(queryType, viewRange, editRange, limit) {
this.queryType = queryType;
this.viewRange = viewRange;
this.editRange = editRange;
this.limit = limit;
}
/**
* Create a copy of the range query parameters with a modified
* view range.
*
* @param range the new view range
* @return a modified range query
*/
RangeQueryParameters.prototype.withViewRange = function (range) {
return new RangeQueryParameters(this.queryType, range, this.editRange, this.limit);
};
/**
* Create a copy of the range query parameters with a modified
* edit range.
*
* @param range the new edit range
* @return a modified range query
*/
RangeQueryParameters.prototype.withEditRange = function (range) {
return new RangeQueryParameters(this.queryType, this.viewRange, range, this.limit);
};
/**
* Create a copy of the range query parameters with a modified
* limit.
*
* @param limit the new limit
* @return a modified range query
* @throws an {@link IllegalArgumentError} if the limit is negative
*/
RangeQueryParameters.prototype.withLimit = function (limit) {
return new RangeQueryParameters(this.queryType, this.viewRange, this.editRange, require_non_null_1.requireNonNegative(limit, 'limit'));
};
/**
* Create a copy of the range query parameters with a modified
* query type.
*
* @param type the new query type
* @return a modified range query
*/
RangeQueryParameters.prototype.withQueryType = function (type) {
return new RangeQueryParameters(type, this.viewRange, this.editRange, this.limit);
};
return RangeQueryParameters;
}());
exports.RangeQueryParameters = RangeQueryParameters;
/**
* A default range query
*/
exports.DEFAULT_RANGE_QUERY = Object.freeze(new RangeQueryParameters(exports.QueryTypes.VALUES, range_1.DEFAULT_RANGE, range_1.DEFAULT_RANGE, math_1.MAX_SAFE_INTEGER));