ticlo-tsdb 0.0.0-stage → 0.1.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/LICENSE +373 -0
- package/README.md +52 -2
- package/dist/backend.d.ts +41 -0
- package/dist/backend.js +207 -0
- package/dist/db.d.ts +35 -0
- package/dist/db.js +246 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +4 -0
- package/dist/memoryCache.d.ts +25 -0
- package/dist/memoryCache.js +89 -0
- package/dist/rawFile.d.ts +54 -0
- package/dist/rawFile.js +528 -0
- package/dist/rollupFile.d.ts +43 -0
- package/dist/rollupFile.js +230 -0
- package/dist/series.d.ts +63 -0
- package/dist/series.js +1135 -0
- package/dist/store.d.ts +69 -0
- package/dist/store.js +39 -0
- package/dist/time.d.ts +39 -0
- package/dist/time.js +459 -0
- package/dist/types.d.ts +127 -0
- package/dist/types.js +1 -0
- package/package.json +36 -4
package/dist/db.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ServerCalendar } from './time.ts';
|
|
2
|
+
import type { NumericColumnResult, NumericQueryOptions, NumericQueryResult, SeriesConfig, SeriesMeta, TimestampInput, TsdbOptions, ValueQueryOptions, ValueQueryResult } from './types.ts';
|
|
3
|
+
export declare class Tsdb {
|
|
4
|
+
readonly calendar: ServerCalendar;
|
|
5
|
+
private readonly store;
|
|
6
|
+
private readonly valueCodec;
|
|
7
|
+
private readonly options;
|
|
8
|
+
private readonly numericSeries;
|
|
9
|
+
private readonly valueSeries;
|
|
10
|
+
private readonly catalog;
|
|
11
|
+
private flushTimer;
|
|
12
|
+
private closed;
|
|
13
|
+
private constructor();
|
|
14
|
+
static open(options: TsdbOptions): Promise<Tsdb>;
|
|
15
|
+
private loadSeriesInstance;
|
|
16
|
+
createSeries(id: string, config: SeriesConfig): Promise<SeriesMeta>;
|
|
17
|
+
ensureSeries(id: string, config: SeriesConfig): Promise<SeriesMeta>;
|
|
18
|
+
hasSeries(id: string): boolean;
|
|
19
|
+
getSeriesMeta(id: string): SeriesMeta | undefined;
|
|
20
|
+
listSeries(): SeriesMeta[];
|
|
21
|
+
deleteSeries(id: string): Promise<void>;
|
|
22
|
+
write(id: string, ts: TimestampInput, value: unknown): void;
|
|
23
|
+
writeNumeric(id: string, ts: TimestampInput, value: number | boolean): void;
|
|
24
|
+
writeBatch(id: string, entries: ReadonlyArray<{
|
|
25
|
+
ts: TimestampInput;
|
|
26
|
+
value: unknown;
|
|
27
|
+
}>): void;
|
|
28
|
+
markInterruption(id: string, ts?: TimestampInput): void;
|
|
29
|
+
queryNumericColumns(id: string, options: NumericQueryOptions): Promise<NumericColumnResult>;
|
|
30
|
+
queryNumeric(id: string, options: NumericQueryOptions): Promise<NumericQueryResult>;
|
|
31
|
+
queryValues(id: string, options: ValueQueryOptions): Promise<ValueQueryResult>;
|
|
32
|
+
subscribe(id: string, listener: (ts: number, value: unknown) => void): () => void;
|
|
33
|
+
flush(): Promise<void>;
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
}
|
package/dist/db.js
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { NodeFileBackend } from './backend.js';
|
|
2
|
+
import { normalizeSeriesConfig, NumericSeries, ValueSeries } from './series.js';
|
|
3
|
+
import { FileTsdbStore } from './store.js';
|
|
4
|
+
import { ServerCalendar, toEpochMs } from './time.js';
|
|
5
|
+
const defaultCodec = {
|
|
6
|
+
stringify: JSON.stringify,
|
|
7
|
+
parse: JSON.parse,
|
|
8
|
+
};
|
|
9
|
+
function makeDirKey(seq, id) {
|
|
10
|
+
const safe = id.replace(/[^a-zA-Z0-9_-]/g, '_').slice(0, 32) || 's';
|
|
11
|
+
return `${seq}_${safe}`;
|
|
12
|
+
}
|
|
13
|
+
export class Tsdb {
|
|
14
|
+
calendar;
|
|
15
|
+
store;
|
|
16
|
+
valueCodec;
|
|
17
|
+
options;
|
|
18
|
+
numericSeries = new Map();
|
|
19
|
+
valueSeries = new Map();
|
|
20
|
+
catalog;
|
|
21
|
+
flushTimer = null;
|
|
22
|
+
closed = false;
|
|
23
|
+
constructor(store, options, catalog) {
|
|
24
|
+
this.store = store;
|
|
25
|
+
this.valueCodec = options.valueCodec ?? defaultCodec;
|
|
26
|
+
this.options = options;
|
|
27
|
+
this.catalog = catalog;
|
|
28
|
+
this.calendar = new ServerCalendar(catalog.timezone, catalog.weekStartsOn);
|
|
29
|
+
}
|
|
30
|
+
static async open(options) {
|
|
31
|
+
const store = options.store ??
|
|
32
|
+
(options.backend
|
|
33
|
+
? new FileTsdbStore(options.backend)
|
|
34
|
+
: options.dir
|
|
35
|
+
? new FileTsdbStore(new NodeFileBackend(options.dir))
|
|
36
|
+
: null);
|
|
37
|
+
if (!store) {
|
|
38
|
+
throw new Error('Tsdb.open requires `dir`, `backend`, or `store`');
|
|
39
|
+
}
|
|
40
|
+
await store.open();
|
|
41
|
+
let catalog = await store.readCatalog();
|
|
42
|
+
if (!catalog) {
|
|
43
|
+
const cal = new ServerCalendar(options.timezone, options.weekStartsOn ?? 1);
|
|
44
|
+
catalog = {
|
|
45
|
+
version: 1,
|
|
46
|
+
timezone: cal.timezone,
|
|
47
|
+
weekStartsOn: cal.weekStartsOn,
|
|
48
|
+
nextSeq: 1,
|
|
49
|
+
series: {},
|
|
50
|
+
};
|
|
51
|
+
await store.writeCatalog(catalog);
|
|
52
|
+
}
|
|
53
|
+
const db = new Tsdb(store, options, catalog);
|
|
54
|
+
for (const meta of Object.values(catalog.series)) {
|
|
55
|
+
await db.loadSeriesInstance(meta);
|
|
56
|
+
}
|
|
57
|
+
const intervalMs = options.flushIntervalMs ?? 1000;
|
|
58
|
+
if (intervalMs > 0) {
|
|
59
|
+
db.flushTimer = setInterval(() => {
|
|
60
|
+
void db.flush();
|
|
61
|
+
}, intervalMs);
|
|
62
|
+
db.flushTimer.unref?.();
|
|
63
|
+
}
|
|
64
|
+
return db;
|
|
65
|
+
}
|
|
66
|
+
async loadSeriesInstance(meta) {
|
|
67
|
+
if (meta.config.kind === 'value') {
|
|
68
|
+
const s = new ValueSeries(meta, this.store, this.calendar, this.valueCodec);
|
|
69
|
+
await s.open();
|
|
70
|
+
this.valueSeries.set(meta.id, s);
|
|
71
|
+
return s;
|
|
72
|
+
}
|
|
73
|
+
const s = new NumericSeries(meta, this.store, this.calendar);
|
|
74
|
+
await s.open();
|
|
75
|
+
this.numericSeries.set(meta.id, s);
|
|
76
|
+
return s;
|
|
77
|
+
}
|
|
78
|
+
async createSeries(id, config) {
|
|
79
|
+
if (this.closed)
|
|
80
|
+
throw new Error('Tsdb is closed');
|
|
81
|
+
const existing = this.catalog.series[id];
|
|
82
|
+
if (existing) {
|
|
83
|
+
if (existing.config.kind !== config.kind) {
|
|
84
|
+
throw new Error(`Series "${id}" already exists with kind "${existing.config.kind}"`);
|
|
85
|
+
}
|
|
86
|
+
return existing;
|
|
87
|
+
}
|
|
88
|
+
const normalized = normalizeSeriesConfig(config, this.options.defaultSeriesConfig);
|
|
89
|
+
const meta = {
|
|
90
|
+
id,
|
|
91
|
+
dirKey: makeDirKey(this.catalog.nextSeq++, id),
|
|
92
|
+
config: normalized,
|
|
93
|
+
};
|
|
94
|
+
this.catalog.series[id] = meta;
|
|
95
|
+
await this.loadSeriesInstance(meta);
|
|
96
|
+
await this.store.writeCatalog(this.catalog);
|
|
97
|
+
return meta;
|
|
98
|
+
}
|
|
99
|
+
ensureSeries(id, config) {
|
|
100
|
+
const existing = this.catalog.series[id];
|
|
101
|
+
if (existing) {
|
|
102
|
+
if (existing.config.kind !== config.kind) {
|
|
103
|
+
return Promise.reject(new Error(`Series "${id}" already exists with kind "${existing.config.kind}"`));
|
|
104
|
+
}
|
|
105
|
+
return Promise.resolve(existing);
|
|
106
|
+
}
|
|
107
|
+
return this.createSeries(id, config);
|
|
108
|
+
}
|
|
109
|
+
hasSeries(id) {
|
|
110
|
+
return Object.hasOwn(this.catalog.series, id);
|
|
111
|
+
}
|
|
112
|
+
getSeriesMeta(id) {
|
|
113
|
+
return this.catalog.series[id];
|
|
114
|
+
}
|
|
115
|
+
listSeries() {
|
|
116
|
+
return Object.values(this.catalog.series);
|
|
117
|
+
}
|
|
118
|
+
async deleteSeries(id) {
|
|
119
|
+
const meta = this.catalog.series[id];
|
|
120
|
+
if (!meta)
|
|
121
|
+
return;
|
|
122
|
+
const num = this.numericSeries.get(id);
|
|
123
|
+
if (num) {
|
|
124
|
+
await num.close();
|
|
125
|
+
this.numericSeries.delete(id);
|
|
126
|
+
}
|
|
127
|
+
const val = this.valueSeries.get(id);
|
|
128
|
+
if (val) {
|
|
129
|
+
await val.close();
|
|
130
|
+
this.valueSeries.delete(id);
|
|
131
|
+
}
|
|
132
|
+
delete this.catalog.series[id];
|
|
133
|
+
await this.store.writeCatalog(this.catalog);
|
|
134
|
+
await this.store.deleteSeriesData(meta);
|
|
135
|
+
}
|
|
136
|
+
write(id, ts, value) {
|
|
137
|
+
const tsMs = toEpochMs(ts);
|
|
138
|
+
const num = this.numericSeries.get(id);
|
|
139
|
+
if (num) {
|
|
140
|
+
if (typeof value !== 'number' && typeof value !== 'boolean') {
|
|
141
|
+
throw new Error(`Numeric series "${id}" requires number or boolean value`);
|
|
142
|
+
}
|
|
143
|
+
num.write(tsMs, value);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const val = this.valueSeries.get(id);
|
|
147
|
+
if (val) {
|
|
148
|
+
val.write(tsMs, value);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
throw new Error(`Unknown series: ${id}`);
|
|
152
|
+
}
|
|
153
|
+
writeNumeric(id, ts, value) {
|
|
154
|
+
const num = this.numericSeries.get(id);
|
|
155
|
+
if (!num) {
|
|
156
|
+
throw new Error(`Unknown numeric series: ${id}`);
|
|
157
|
+
}
|
|
158
|
+
num.write(toEpochMs(ts), value);
|
|
159
|
+
}
|
|
160
|
+
writeBatch(id, entries) {
|
|
161
|
+
const num = this.numericSeries.get(id);
|
|
162
|
+
if (num) {
|
|
163
|
+
for (let i = 0; i < entries.length; ++i) {
|
|
164
|
+
const { ts, value } = entries[i];
|
|
165
|
+
num.write(toEpochMs(ts), value);
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const val = this.valueSeries.get(id);
|
|
170
|
+
if (val) {
|
|
171
|
+
for (let i = 0; i < entries.length; ++i) {
|
|
172
|
+
const { ts, value } = entries[i];
|
|
173
|
+
val.write(toEpochMs(ts), value);
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
throw new Error(`Unknown series: ${id}`);
|
|
178
|
+
}
|
|
179
|
+
markInterruption(id, ts) {
|
|
180
|
+
const num = this.numericSeries.get(id);
|
|
181
|
+
if (!num) {
|
|
182
|
+
throw new Error(`Unknown numeric series: ${id}`);
|
|
183
|
+
}
|
|
184
|
+
num.markInterruption(ts !== undefined ? toEpochMs(ts) : undefined);
|
|
185
|
+
}
|
|
186
|
+
queryNumericColumns(id, options) {
|
|
187
|
+
const num = this.numericSeries.get(id);
|
|
188
|
+
if (!num) {
|
|
189
|
+
return Promise.reject(new Error(`Unknown numeric series: ${id}`));
|
|
190
|
+
}
|
|
191
|
+
return num.queryColumns(options);
|
|
192
|
+
}
|
|
193
|
+
queryNumeric(id, options) {
|
|
194
|
+
const num = this.numericSeries.get(id);
|
|
195
|
+
if (!num) {
|
|
196
|
+
return Promise.reject(new Error(`Unknown numeric series: ${id}`));
|
|
197
|
+
}
|
|
198
|
+
return num.query(options);
|
|
199
|
+
}
|
|
200
|
+
queryValues(id, options) {
|
|
201
|
+
const val = this.valueSeries.get(id);
|
|
202
|
+
if (!val) {
|
|
203
|
+
return Promise.reject(new Error(`Unknown value series: ${id}`));
|
|
204
|
+
}
|
|
205
|
+
return val.query(options);
|
|
206
|
+
}
|
|
207
|
+
subscribe(id, listener) {
|
|
208
|
+
const num = this.numericSeries.get(id);
|
|
209
|
+
if (num)
|
|
210
|
+
return num.subscribe(listener);
|
|
211
|
+
const val = this.valueSeries.get(id);
|
|
212
|
+
if (val)
|
|
213
|
+
return val.subscribe(listener);
|
|
214
|
+
throw new Error(`Unknown series: ${id}`);
|
|
215
|
+
}
|
|
216
|
+
async flush() {
|
|
217
|
+
const tasks = [];
|
|
218
|
+
for (const num of this.numericSeries.values()) {
|
|
219
|
+
if (num.hasDirtyData)
|
|
220
|
+
tasks.push(num.flush());
|
|
221
|
+
}
|
|
222
|
+
for (const val of this.valueSeries.values()) {
|
|
223
|
+
if (val.hasDirtyData)
|
|
224
|
+
tasks.push(val.flush());
|
|
225
|
+
}
|
|
226
|
+
if (tasks.length > 0) {
|
|
227
|
+
await Promise.all(tasks);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
async close() {
|
|
231
|
+
if (this.closed)
|
|
232
|
+
return;
|
|
233
|
+
if (this.flushTimer) {
|
|
234
|
+
clearInterval(this.flushTimer);
|
|
235
|
+
this.flushTimer = null;
|
|
236
|
+
}
|
|
237
|
+
const closes = [];
|
|
238
|
+
for (const num of this.numericSeries.values())
|
|
239
|
+
closes.push(num.close());
|
|
240
|
+
for (const val of this.valueSeries.values())
|
|
241
|
+
closes.push(val.close());
|
|
242
|
+
await Promise.all(closes);
|
|
243
|
+
await this.store.close?.();
|
|
244
|
+
this.closed = true;
|
|
245
|
+
}
|
|
246
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Tsdb } from './db.ts';
|
|
2
|
+
export { MemoryBackend, NodeFileBackend } from './backend.ts';
|
|
3
|
+
export type { StorageBackend, StorageHandle } from './backend.ts';
|
|
4
|
+
export { FileTsdbStore } from './store.ts';
|
|
5
|
+
export type { NumericRawStore, RollupTierStore, TsdbStore, ValueRawStore } from './store.ts';
|
|
6
|
+
export { canTierServeInterval, parseInterval, selectAutoInterval, ServerCalendar, STANDARD_INTERVALS, TIER_STEP_MS, toEpochMs, } from './time.ts';
|
|
7
|
+
export type { ParsedInterval } from './time.ts';
|
|
8
|
+
export type { EncodedValueRecord, IntervalString, IntervalUnit, MemoryCacheConfig, NormalizedMemoryCacheConfig, NormalizedRawConfig, NormalizedSeriesConfig, NormalizedTierConfig, NumericColumnResult, NumericPoint, NumericQueryOptions, NumericQueryResult, RawOption, RollupTier, RollupType, SeriesConfig, SeriesKind, SeriesMeta, StandardInterval, TierOption, TimestampInput, TsdbOptions, ValueCodec, ValuePoint, ValueQueryOptions, ValueQueryResult, } from './types.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { Tsdb } from './db.js';
|
|
2
|
+
export { MemoryBackend, NodeFileBackend } from './backend.js';
|
|
3
|
+
export { FileTsdbStore } from './store.js';
|
|
4
|
+
export { canTierServeInterval, parseInterval, selectAutoInterval, ServerCalendar, STANDARD_INTERVALS, TIER_STEP_MS, toEpochMs, } from './time.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare class MemoryRingCache {
|
|
2
|
+
readonly capacity: number;
|
|
3
|
+
readonly maxAgeMs: number | undefined;
|
|
4
|
+
private readonly ts;
|
|
5
|
+
private readonly val;
|
|
6
|
+
private head;
|
|
7
|
+
private count;
|
|
8
|
+
constructor(capacity: number, maxAgeMs?: number);
|
|
9
|
+
get size(): number;
|
|
10
|
+
push(tsMs: number, value: number): void;
|
|
11
|
+
markGap(tsMs: number): void;
|
|
12
|
+
private pruneBefore;
|
|
13
|
+
getOldestTs(): number;
|
|
14
|
+
getNewestTs(): number;
|
|
15
|
+
/**
|
|
16
|
+
* Copy samples within [startMs, endMs] and optionally the latest sample strictly before startMs.
|
|
17
|
+
* NaN markers represent explicit data interruptions.
|
|
18
|
+
*/
|
|
19
|
+
copyRange(startMs: number, endMs: number): {
|
|
20
|
+
timestamps: Float64Array;
|
|
21
|
+
values: Float64Array;
|
|
22
|
+
length: number;
|
|
23
|
+
priorValue: number;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export class MemoryRingCache {
|
|
2
|
+
capacity;
|
|
3
|
+
maxAgeMs;
|
|
4
|
+
ts;
|
|
5
|
+
val;
|
|
6
|
+
head = 0;
|
|
7
|
+
count = 0;
|
|
8
|
+
constructor(capacity, maxAgeMs) {
|
|
9
|
+
this.capacity = Math.max(1, capacity);
|
|
10
|
+
this.maxAgeMs = maxAgeMs;
|
|
11
|
+
this.ts = new Float64Array(this.capacity);
|
|
12
|
+
this.val = new Float64Array(this.capacity);
|
|
13
|
+
}
|
|
14
|
+
get size() {
|
|
15
|
+
return this.count;
|
|
16
|
+
}
|
|
17
|
+
push(tsMs, value) {
|
|
18
|
+
const writeIdx = (this.head + this.count) % this.capacity;
|
|
19
|
+
if (this.count === this.capacity) {
|
|
20
|
+
this.head = (this.head + 1) % this.capacity;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
this.count++;
|
|
24
|
+
}
|
|
25
|
+
this.ts[writeIdx] = tsMs;
|
|
26
|
+
this.val[writeIdx] = value;
|
|
27
|
+
if (this.maxAgeMs !== undefined) {
|
|
28
|
+
this.pruneBefore(tsMs - this.maxAgeMs);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
markGap(tsMs) {
|
|
32
|
+
this.push(tsMs, Number.NaN);
|
|
33
|
+
}
|
|
34
|
+
pruneBefore(minTs) {
|
|
35
|
+
while (this.count > 0 && this.ts[this.head] < minTs) {
|
|
36
|
+
this.head = (this.head + 1) % this.capacity;
|
|
37
|
+
this.count--;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
getOldestTs() {
|
|
41
|
+
if (this.count === 0)
|
|
42
|
+
return Number.NaN;
|
|
43
|
+
return this.ts[this.head];
|
|
44
|
+
}
|
|
45
|
+
getNewestTs() {
|
|
46
|
+
if (this.count === 0)
|
|
47
|
+
return Number.NaN;
|
|
48
|
+
return this.ts[(this.head + this.count - 1) % this.capacity];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Copy samples within [startMs, endMs] and optionally the latest sample strictly before startMs.
|
|
52
|
+
* NaN markers represent explicit data interruptions.
|
|
53
|
+
*/
|
|
54
|
+
copyRange(startMs, endMs) {
|
|
55
|
+
if (this.count === 0) {
|
|
56
|
+
return { timestamps: new Float64Array(0), values: new Float64Array(0), length: 0, priorValue: Number.NaN };
|
|
57
|
+
}
|
|
58
|
+
let priorValue = Number.NaN;
|
|
59
|
+
let firstIdx = -1;
|
|
60
|
+
let lastIdx = -1;
|
|
61
|
+
for (let i = 0; i < this.count; ++i) {
|
|
62
|
+
const idx = (this.head + i) % this.capacity;
|
|
63
|
+
const t = this.ts[idx];
|
|
64
|
+
if (t < startMs) {
|
|
65
|
+
priorValue = this.val[idx];
|
|
66
|
+
}
|
|
67
|
+
else if (t <= endMs) {
|
|
68
|
+
if (firstIdx < 0)
|
|
69
|
+
firstIdx = i;
|
|
70
|
+
lastIdx = i;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (firstIdx < 0) {
|
|
77
|
+
return { timestamps: new Float64Array(0), values: new Float64Array(0), length: 0, priorValue };
|
|
78
|
+
}
|
|
79
|
+
const len = lastIdx - firstIdx + 1;
|
|
80
|
+
const timestamps = new Float64Array(len);
|
|
81
|
+
const values = new Float64Array(len);
|
|
82
|
+
for (let i = 0; i < len; ++i) {
|
|
83
|
+
const idx = (this.head + firstIdx + i) % this.capacity;
|
|
84
|
+
timestamps[i] = this.ts[idx];
|
|
85
|
+
values[i] = this.val[idx];
|
|
86
|
+
}
|
|
87
|
+
return { timestamps, values, length: len, priorValue };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { StorageBackend } from './backend.ts';
|
|
2
|
+
import type { NumericRawStore, ValueRawStore } from './store.ts';
|
|
3
|
+
import type { EncodedValueRecord } from './types.ts';
|
|
4
|
+
export declare class NumericRawFile implements NumericRawStore {
|
|
5
|
+
private readonly backend;
|
|
6
|
+
private readonly relPath;
|
|
7
|
+
private handle;
|
|
8
|
+
recordCount: number;
|
|
9
|
+
private sparseTs;
|
|
10
|
+
private minTs;
|
|
11
|
+
private maxTs;
|
|
12
|
+
private readonly headerBuf;
|
|
13
|
+
private readonly headerU8;
|
|
14
|
+
private readonly headerView;
|
|
15
|
+
constructor(backend: StorageBackend, relPath: string);
|
|
16
|
+
open(): Promise<void>;
|
|
17
|
+
private writeHeader;
|
|
18
|
+
private rebuildSparseIndex;
|
|
19
|
+
private findSparseBlockStart;
|
|
20
|
+
private findSparseBlockEnd;
|
|
21
|
+
appendBatch(interleaved: Float64Array, count: number): Promise<void>;
|
|
22
|
+
readRange(startMs: number, endMs: number, limit?: number, stripNaN?: boolean): Promise<{
|
|
23
|
+
timestamps: Float64Array;
|
|
24
|
+
values: Float64Array;
|
|
25
|
+
length: number;
|
|
26
|
+
truncated: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
readLastBefore(tsMs: number, inclusive?: boolean): Promise<{
|
|
29
|
+
ts: number;
|
|
30
|
+
value: number;
|
|
31
|
+
} | null>;
|
|
32
|
+
compact(minTsKeep?: number, maxRecords?: number): Promise<void>;
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
export declare class ValueRawFile implements ValueRawStore {
|
|
36
|
+
private readonly backend;
|
|
37
|
+
private readonly dataPath;
|
|
38
|
+
private readonly idxPath;
|
|
39
|
+
private dataHandle;
|
|
40
|
+
private idxHandle;
|
|
41
|
+
recordCount: number;
|
|
42
|
+
private dataBytes;
|
|
43
|
+
private idxTimestamps;
|
|
44
|
+
private idxOffsets;
|
|
45
|
+
constructor(backend: StorageBackend, dataPath: string, idxPath: string);
|
|
46
|
+
open(): Promise<void>;
|
|
47
|
+
private writeIdxHeader;
|
|
48
|
+
appendBatch(entries: ReadonlyArray<EncodedValueRecord>): Promise<void>;
|
|
49
|
+
readRange(startMs: number, endMs: number, limit?: number, order?: 'asc' | 'desc'): Promise<{
|
|
50
|
+
records: EncodedValueRecord[];
|
|
51
|
+
truncated: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
close(): Promise<void>;
|
|
54
|
+
}
|