ravendb
Version:
RavenDB client for Node.js
79 lines • 4.2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionDocumentTypedTimeSeries = void 0;
const SessionTimeSeriesBase_js_1 = require("./SessionTimeSeriesBase.js");
const TypedTimeSeriesEntry_js_1 = require("./TimeSeries/TypedTimeSeriesEntry.js");
const TypeUtil_js_1 = require("../../Utility/TypeUtil.js");
const TimeSeriesValuesHelper_js_1 = require("./TimeSeries/TimeSeriesValuesHelper.js");
class SessionDocumentTypedTimeSeries extends SessionTimeSeriesBase_js_1.SessionTimeSeriesBase {
_clazz;
constructor(session, documentIdOrEntity, name, clazz) {
super(session, documentIdOrEntity, name);
this._clazz = clazz;
}
async get(startOrFrom, toOrPageSize, start, pageSize) {
if (TypeUtil_js_1.TypeUtil.isNumber(startOrFrom)) {
// get(start: number, pageSize: number)
return this._getTyped(null, null, startOrFrom, toOrPageSize);
}
else {
return this._getTyped(startOrFrom, toOrPageSize, 0, TypeUtil_js_1.TypeUtil.MAX_INT32);
}
}
async _getTyped(from, to, start, pageSize) {
if (this._notInCache(from, to)) {
const entries = await this.getTimeSeriesAndIncludes(from, to, null, start, pageSize);
if (!entries) {
return null;
}
return entries.map(x => x.asTypedEntry(this._clazz));
}
const results = await this._getFromCache(from, to, null, start, pageSize);
return results.map(x => x.asTypedEntry(this._clazz));
}
append(entryOrTimestamp, entry, tag) {
if (entryOrTimestamp instanceof TypedTimeSeriesEntry_js_1.TypedTimeSeriesEntry) {
this.append(entryOrTimestamp.timestamp, entryOrTimestamp.value, entryOrTimestamp.tag);
}
else {
const values = TimeSeriesValuesHelper_js_1.TimeSeriesValuesHelper.getValues(this._clazz, entry);
this._appendInternal(entryOrTimestamp, values, tag);
}
}
increment(entryOrTimestampOrValuesOrValue, valuesOrValueOrEntry) {
if (entryOrTimestampOrValuesOrValue instanceof Date) {
if (valuesOrValueOrEntry instanceof TypedTimeSeriesEntry_js_1.TypedTimeSeriesEntry) {
const values = valuesOrValueOrEntry.values ?? [valuesOrValueOrEntry.value];
return this.increment(valuesOrValueOrEntry.timestamp, values);
}
else if (TypeUtil_js_1.TypeUtil.isNumber(valuesOrValueOrEntry)) {
return this._incrementInternal(entryOrTimestampOrValuesOrValue, [valuesOrValueOrEntry]);
}
else if (TypeUtil_js_1.TypeUtil.isArray(valuesOrValueOrEntry)) {
return this._incrementInternal(entryOrTimestampOrValuesOrValue, valuesOrValueOrEntry);
}
else {
const values = TimeSeriesValuesHelper_js_1.TimeSeriesValuesHelper.getValues(this._clazz, valuesOrValueOrEntry);
return this._incrementInternal(entryOrTimestampOrValuesOrValue, values);
}
}
else {
if (entryOrTimestampOrValuesOrValue instanceof TypedTimeSeriesEntry_js_1.TypedTimeSeriesEntry) {
const values = entryOrTimestampOrValuesOrValue.values ?? [entryOrTimestampOrValuesOrValue.value];
return this.increment(entryOrTimestampOrValuesOrValue.timestamp, values);
}
else if (TypeUtil_js_1.TypeUtil.isArray(entryOrTimestampOrValuesOrValue)) {
return this._incrementInternal(new Date(), entryOrTimestampOrValuesOrValue);
}
else if (TypeUtil_js_1.TypeUtil.isNumber(entryOrTimestampOrValuesOrValue)) {
return this._incrementInternal(new Date(), [entryOrTimestampOrValuesOrValue]);
}
else {
const values = TimeSeriesValuesHelper_js_1.TimeSeriesValuesHelper.getValues(this._clazz, entryOrTimestampOrValuesOrValue);
return this._incrementInternal(new Date(), values);
}
}
}
}
exports.SessionDocumentTypedTimeSeries = SessionDocumentTypedTimeSeries;
//# sourceMappingURL=SessionDocumentTypedTimeSeries.js.map