ticlo-tsdb 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rawFile.d.ts CHANGED
@@ -76,7 +76,7 @@ export declare class ValueRawFile implements ValueRawStore {
76
76
  private findLastChunkAtOrBefore;
77
77
  private readChunkBody;
78
78
  private decodeRecordAt;
79
- readRange(startMs: number, endMs: number, limit?: number, order?: 'asc' | 'desc'): Promise<{
79
+ readRange(startMs: number, endMs: number, limit?: number): Promise<{
80
80
  records: EncodedValueRecord[];
81
81
  truncated: boolean;
82
82
  }>;
package/dist/rawFile.js CHANGED
@@ -808,7 +808,7 @@ export class ValueRawFile {
808
808
  nextPos,
809
809
  };
810
810
  }
811
- async readRange(startMs, endMs, limit, order = 'asc') {
811
+ async readRange(startMs, endMs, limit) {
812
812
  if (!this.opened)
813
813
  await this.open();
814
814
  if (this.chunks.length === 0)
@@ -821,39 +821,9 @@ export class ValueRawFile {
821
821
  const hasLimit = limit !== undefined && limit >= 0;
822
822
  const records = [];
823
823
  let truncated = false;
824
- if (order === 'asc') {
825
- for (let ci = firstChunkIdx; ci <= lastChunkIdx; ++ci) {
826
- const chunk = this.chunks[ci];
827
- const { u8, dv, bodyLen } = await this.readChunkBody(chunk);
828
- let pos = 0;
829
- while (pos + VAL_RECORD_HEADER_BYTES <= bodyLen) {
830
- const recTs = dv.getFloat64(pos, true);
831
- const payloadLen = dv.getUint32(pos + 8, true);
832
- if (recTs > endMs)
833
- break;
834
- if (recTs >= startMs) {
835
- if (hasLimit && records.length >= limit) {
836
- truncated = true;
837
- break;
838
- }
839
- const decoded = this.decodeRecordAt(u8, dv, pos);
840
- records.push(decoded.rec);
841
- pos = decoded.nextPos;
842
- }
843
- else {
844
- pos += VAL_RECORD_HEADER_BYTES + payloadLen;
845
- }
846
- }
847
- if (truncated)
848
- break;
849
- }
850
- return { records, truncated };
851
- }
852
- // Descending order: walk chunks backwards and matching offsets backwards.
853
- for (let ci = lastChunkIdx; ci >= firstChunkIdx; --ci) {
824
+ for (let ci = firstChunkIdx; ci <= lastChunkIdx; ++ci) {
854
825
  const chunk = this.chunks[ci];
855
826
  const { u8, dv, bodyLen } = await this.readChunkBody(chunk);
856
- const matchOffsets = [];
857
827
  let pos = 0;
858
828
  while (pos + VAL_RECORD_HEADER_BYTES <= bodyLen) {
859
829
  const recTs = dv.getFloat64(pos, true);
@@ -861,16 +831,17 @@ export class ValueRawFile {
861
831
  if (recTs > endMs)
862
832
  break;
863
833
  if (recTs >= startMs) {
864
- matchOffsets.push(pos);
834
+ if (hasLimit && records.length >= limit) {
835
+ truncated = true;
836
+ break;
837
+ }
838
+ const decoded = this.decodeRecordAt(u8, dv, pos);
839
+ records.push(decoded.rec);
840
+ pos = decoded.nextPos;
865
841
  }
866
- pos += VAL_RECORD_HEADER_BYTES + payloadLen;
867
- }
868
- for (let mi = matchOffsets.length - 1; mi >= 0; --mi) {
869
- if (hasLimit && records.length >= limit) {
870
- truncated = true;
871
- break;
842
+ else {
843
+ pos += VAL_RECORD_HEADER_BYTES + payloadLen;
872
844
  }
873
- records.push(this.decodeRecordAt(u8, dv, matchOffsets[mi]).rec);
874
845
  }
875
846
  if (truncated)
876
847
  break;
package/dist/series.js CHANGED
@@ -1091,7 +1091,6 @@ export class ValueSeries {
1091
1091
  async query(options) {
1092
1092
  const startMs = toEpochMs(options.start);
1093
1093
  const endMs = toEpochMs(options.end);
1094
- const order = options.order ?? 'asc';
1095
1094
  const timezone = this.calendar.timezone;
1096
1095
  if (endMs < startMs) {
1097
1096
  return { points: [], truncated: false, timezone };
@@ -1103,24 +1102,7 @@ export class ValueSeries {
1103
1102
  pendingMatches.push(item);
1104
1103
  }
1105
1104
  }
1106
- if (order === 'desc') {
1107
- pendingMatches.reverse();
1108
- if (options.limit !== undefined && options.limit >= 0 && pendingMatches.length >= options.limit) {
1109
- return {
1110
- points: pendingMatches.slice(0, options.limit),
1111
- truncated: pendingMatches.length > options.limit || this.file.recordCount > 0,
1112
- timezone,
1113
- };
1114
- }
1115
- const remainingLimit = options.limit !== undefined && options.limit >= 0 ? options.limit - pendingMatches.length : undefined;
1116
- const diskRes = await this.file.readRange(startMs, endMs, remainingLimit, 'desc');
1117
- return {
1118
- points: pendingMatches.concat(this.decodeRecords(diskRes.records)),
1119
- truncated: diskRes.truncated,
1120
- timezone,
1121
- };
1122
- }
1123
- const diskRes = await this.file.readRange(startMs, endMs, options.limit, 'asc');
1105
+ const diskRes = await this.file.readRange(startMs, endMs, options.limit);
1124
1106
  const diskPoints = this.decodeRecords(diskRes.records);
1125
1107
  if (diskRes.truncated || pendingMatches.length === 0) {
1126
1108
  return { points: diskPoints, truncated: diskRes.truncated, timezone };
package/dist/store.d.ts CHANGED
@@ -47,7 +47,7 @@ export interface ValueRawStore {
47
47
  readonly byteSize?: number;
48
48
  open(): Promise<void>;
49
49
  appendBatch(entries: ReadonlyArray<EncodedValueRecord>): Promise<void>;
50
- readRange(startMs: number, endMs: number, limit?: number, order?: 'asc' | 'desc'): Promise<{
50
+ readRange(startMs: number, endMs: number, limit?: number): Promise<{
51
51
  records: EncodedValueRecord[];
52
52
  truncated: boolean;
53
53
  }>;
package/dist/types.d.ts CHANGED
@@ -149,7 +149,6 @@ export interface ValueQueryOptions {
149
149
  start: TimestampInput;
150
150
  end: TimestampInput;
151
151
  limit?: number;
152
- order?: 'asc' | 'desc';
153
152
  }
154
153
  export interface ValuePoint {
155
154
  ts: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ticlo-tsdb",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "High-performance embedded TypeScript time-series database with configurable dense rollups",
5
5
  "license": "MPL-2.0",
6
6
  "author": {