@thingmate/zekta-time-series 0.1.0 → 1.0.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/CHANGELOG.md +22 -0
- package/CONTRIBUTING.md +99 -43
- package/README.md +230 -2
- package/package.json +27 -41
- package/src/bucket.private/helpers.private/temp-files/temp-files.d.ts +15 -0
- package/src/bucket.private/helpers.private/temp-files/temp-files.js +47 -0
- package/src/bucket.private/helpers.private/temp-files/temp-files.js.map +1 -0
- package/src/bucket.private/zekta-time-bucket.d.ts +80 -0
- package/src/bucket.private/zekta-time-bucket.js +504 -0
- package/src/bucket.private/zekta-time-bucket.js.map +1 -0
- package/src/config/v1/zekta-time-series-config-v1-schema.d.ts +11 -0
- package/src/config/v1/zekta-time-series-config-v1-schema.js +12 -0
- package/src/config/v1/zekta-time-series-config-v1-schema.js.map +1 -0
- package/src/config/v1/zekta-time-series-config-v1.d.ts +11 -0
- package/src/config/v1/zekta-time-series-config-v1.js +2 -0
- package/src/config/v1/zekta-time-series-config-v1.js.map +1 -0
- package/src/config/zekta-time-series-config.d.ts +6 -0
- package/src/config/zekta-time-series-config.js +2 -0
- package/src/config/zekta-time-series-config.js.map +1 -0
- package/{helpers.private → src/helpers.private}/binary-search/binary-search.js +1 -2
- package/src/helpers.private/binary-search/binary-search.js.map +1 -0
- package/{helpers.private → src/helpers.private}/handle-promise-all-settled-result.d.ts +6 -0
- package/{helpers.private → src/helpers.private}/handle-promise-all-settled-result.js +6 -0
- package/src/helpers.private/handle-promise-all-settled-result.js.map +1 -0
- package/{helpers.private → src/helpers.private}/resizeable-buffer.d.ts +6 -0
- package/{helpers.private → src/helpers.private}/resizeable-buffer.js +7 -3
- package/src/helpers.private/resizeable-buffer.js.map +1 -0
- package/src/helpers.private/safe-write-file/safe-write-file.d.ts +13 -0
- package/src/helpers.private/safe-write-file/safe-write-file.js +29 -0
- package/src/helpers.private/safe-write-file/safe-write-file.js.map +1 -0
- package/src/helpers.private/throw-if-time-is-invalid/throw-if-time-is-invalid.d.ts +6 -0
- package/src/helpers.private/throw-if-time-is-invalid/throw-if-time-is-invalid.js +11 -0
- package/src/helpers.private/throw-if-time-is-invalid/throw-if-time-is-invalid.js.map +1 -0
- package/{index.d.ts → src/index.d.ts} +3 -1
- package/src/index.js +8 -0
- package/src/index.js.map +1 -0
- package/{specializations → src/specializations}/bytes/zekta-bytes-time-series.d.ts +21 -1
- package/src/specializations/bytes/zekta-bytes-time-series.js +152 -0
- package/src/specializations/bytes/zekta-bytes-time-series.js.map +1 -0
- package/src/specializations/number/zekta-number-time-series.d.ts +51 -0
- package/{specializations → src/specializations}/number/zekta-number-time-series.js +32 -11
- package/src/specializations/number/zekta-number-time-series.js.map +1 -0
- package/src/specializations/text/zekta-text-time-series.d.ts +36 -0
- package/{specializations → src/specializations}/text/zekta-text-time-series.js +20 -2
- package/src/specializations/text/zekta-text-time-series.js.map +1 -0
- package/src/zekta-time-series.d.ts +78 -0
- package/src/zekta-time-series.js +280 -0
- package/src/zekta-time-series.js.map +1 -0
- package/helpers.private/binary-search/binary-search.js.map +0 -1
- package/helpers.private/handle-promise-all-settled-result.js.map +0 -1
- package/helpers.private/resizeable-buffer.js.map +0 -1
- package/index.js +0 -6
- package/index.js.map +0 -1
- package/specializations/bytes/zekta-bytes-time-series.js +0 -87
- package/specializations/bytes/zekta-bytes-time-series.js.map +0 -1
- package/specializations/number/zekta-number-time-series.d.ts +0 -20
- package/specializations/number/zekta-number-time-series.js.map +0 -1
- package/specializations/text/zekta-text-time-series.d.ts +0 -16
- package/specializations/text/zekta-text-time-series.js.map +0 -1
- package/zekta-time-bucket.d.ts +0 -35
- package/zekta-time-bucket.js +0 -324
- package/zekta-time-bucket.js.map +0 -1
- package/zekta-time-series.d.ts +0 -25
- package/zekta-time-series.js +0 -194
- package/zekta-time-series.js.map +0 -1
- /package/{helpers.private → src/helpers.private}/binary-search/binary-search.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zekta-time-series-config.js","sourceRoot":"","sources":["../../../src/config/zekta-time-series-config.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary-search.js","sourceRoot":"","sources":["../../../../src/helpers.private/binary-search/binary-search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,OAAkC;IAC7E,IAAI,GAAG,GAAW,CAAC,CAAC;IACpB,IAAI,IAAI,GAAW,MAAM,GAAG,CAAC,CAAC;IAE9B,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;QACnB,MAAM,GAAG,GAAW,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAEjD,MAAM,MAAM,GAAW,OAAO,CAAC,GAAG,CAAC,CAAC;QAEpC,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;YACjB,OAAO,GAAG,CAAC;QACb,CAAC;aAAM,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;QAChB,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,GAAG,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
export type HandlePromiseAllSettledResultOutputValue<GResults extends readonly PromiseSettledResult<unknown>[]> = {
|
|
2
2
|
-readonly [GKey in keyof GResults]: GResults[GKey] extends PromiseSettledResult<infer GValue> ? GValue : never;
|
|
3
3
|
};
|
|
4
|
+
/**
|
|
5
|
+
* Unwraps "Promise.allSettled" results: returns the fulfilled values in
|
|
6
|
+
* order, or throws when any promise rejected — the rejection reason directly
|
|
7
|
+
* when a single promise failed, or an "AggregateError" carrying every reason
|
|
8
|
+
* otherwise.
|
|
9
|
+
*/
|
|
4
10
|
export declare function handlePromiseAllSettledResult<GResults extends readonly PromiseSettledResult<unknown>[]>(results: GResults): HandlePromiseAllSettledResultOutputValue<GResults>;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unwraps "Promise.allSettled" results: returns the fulfilled values in
|
|
3
|
+
* order, or throws when any promise rejected — the rejection reason directly
|
|
4
|
+
* when a single promise failed, or an "AggregateError" carrying every reason
|
|
5
|
+
* otherwise.
|
|
6
|
+
*/
|
|
1
7
|
export function handlePromiseAllSettledResult(results) {
|
|
2
8
|
const errors = results.filter((result) => {
|
|
3
9
|
return result.status === 'rejected';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-promise-all-settled-result.js","sourceRoot":"","sources":["../../../src/helpers.private/handle-promise-all-settled-result.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B,CAE3C,OAAiB;IACjB,MAAM,MAAM,GAAqC,OAAO,CAAC,MAAM,CAC7D,CAAC,MAAqC,EAAmC,EAAE;QACzE,OAAO,MAAM,CAAC,MAAM,KAAK,UAAU,CAAC;IACtC,CAAC,CACF,CAAC;IAEF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAqC,EAAW,EAAE;YACpE,OAAQ,MAA0C,CAAC,KAAK,CAAC;QAC3D,CAAC,CAAuD,CAAC;IAC3D,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,cAAc,CACtB,MAAM,CAAC,GAAG,CAAC,CAAC,KAA4B,EAAW,EAAE;YACnD,OAAO,KAAK,CAAC,MAAM,CAAC;QACtB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A growable byte buffer, addressable as raw bytes ("bytes") or as a
|
|
3
|
+
* DataView ("view"), whose growth keeps the existing content.
|
|
4
|
+
*/
|
|
1
5
|
export declare class ResizeableBuffer {
|
|
2
6
|
#private;
|
|
3
7
|
constructor(buffer?: ArrayBuffer, byteOffset?: number, byteLength?: number);
|
|
@@ -7,3 +11,5 @@ export declare class ResizeableBuffer {
|
|
|
7
11
|
get length(): number;
|
|
8
12
|
resize(newLength: number): void;
|
|
9
13
|
}
|
|
14
|
+
declare function getOptimalBufferLength(length: number): number;
|
|
15
|
+
export { getOptimalBufferLength };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A growable byte buffer, addressable as raw bytes ("bytes") or as a
|
|
3
|
+
* DataView ("view"), whose growth keeps the existing content.
|
|
4
|
+
*/
|
|
1
5
|
export class ResizeableBuffer {
|
|
2
6
|
#buffer;
|
|
3
7
|
#view;
|
|
@@ -49,9 +53,9 @@ export class ResizeableBuffer {
|
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
function getOptimalBufferLength(length) {
|
|
52
|
-
return (
|
|
56
|
+
return (2 **
|
|
53
57
|
Math.ceil(Math.log2(length) /* number of bytes to store the data */ +
|
|
54
|
-
0.5 /* adds a "half-byte" of margin */)) /* round to the upper limit */
|
|
55
|
-
0);
|
|
58
|
+
0.5 /* adds a "half-byte" of margin */)); /* round to the upper limit */
|
|
56
59
|
}
|
|
60
|
+
export { getOptimalBufferLength };
|
|
57
61
|
//# sourceMappingURL=resizeable-buffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resizeable-buffer.js","sourceRoot":"","sources":["../../../src/helpers.private/resizeable-buffer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IAC3B,OAAO,CAAc;IACrB,KAAK,CAAwB;IAC7B,MAAM,CAA0B;IAChC,OAAO,C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C;gBAC1C,MAAM,SAAS,GAAgB,IAAI,WAAW,CAC5C,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC,EAC1D;oBACE,aAAa;iBACd,CACF,CAAC;gBACF,MAAM,YAAY,GAAe,IAAI,CAAC,MAAM,CAAC;gBAC7C,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;gBACzB,IAAI,CAAC,KAAK,GAAG,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC;gBACrC,IAAI,CAAC,MAAM,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC;gBACxC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;IAC3B,CAAC;CACF;AAED,SAAS,sBAAsB,CAAC,MAAc;IAC5C,OAAO,CACL,CAAC;QACD,IAAI,CAAC,IAAI,CACP,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,uCAAuC;YACvD,GAAG,CAAC,kCAAkC,CACzC,CACF,CAAC,CAAC,8BAA8B;AACnC,CAAC;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Path } from '@xstd/path';
|
|
2
|
+
/**
|
|
3
|
+
* Writes "data" to "filePath" through a temp file: the content is written
|
|
4
|
+
* aside and synced, then atomically renamed onto its final name. An
|
|
5
|
+
* interrupted write leaves either no file or a leftover temp file, never
|
|
6
|
+
* partial content under the final name. The temp file must live in the same
|
|
7
|
+
* directory as "filePath", or in a directory known to share its filesystem,
|
|
8
|
+
* otherwise the rename fails (EXDEV). A failure removes the temp file
|
|
9
|
+
* best-effort and rethrows the original error; if the cleanup itself fails,
|
|
10
|
+
* a "SuppressedError" is thrown instead, carrying the cleanup error in
|
|
11
|
+
* "error" and the original one in "suppressed".
|
|
12
|
+
*/
|
|
13
|
+
export declare function safeWriteFile(filePath: Path, tempFilePath: Path, data: Uint8Array): Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {} from '@xstd/path';
|
|
2
|
+
import { rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
/**
|
|
4
|
+
* Writes "data" to "filePath" through a temp file: the content is written
|
|
5
|
+
* aside and synced, then atomically renamed onto its final name. An
|
|
6
|
+
* interrupted write leaves either no file or a leftover temp file, never
|
|
7
|
+
* partial content under the final name. The temp file must live in the same
|
|
8
|
+
* directory as "filePath", or in a directory known to share its filesystem,
|
|
9
|
+
* otherwise the rename fails (EXDEV). A failure removes the temp file
|
|
10
|
+
* best-effort and rethrows the original error; if the cleanup itself fails,
|
|
11
|
+
* a "SuppressedError" is thrown instead, carrying the cleanup error in
|
|
12
|
+
* "error" and the original one in "suppressed".
|
|
13
|
+
*/
|
|
14
|
+
export async function safeWriteFile(filePath, tempFilePath, data) {
|
|
15
|
+
try {
|
|
16
|
+
await writeFile(tempFilePath.toString(), data, { flush: true });
|
|
17
|
+
await rename(tempFilePath.toString(), filePath.toString());
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
try {
|
|
21
|
+
await rm(tempFilePath.toString(), { force: true });
|
|
22
|
+
}
|
|
23
|
+
catch (cleanupError) {
|
|
24
|
+
throw new SuppressedError(cleanupError, error, 'Failed to remove the temp file after a failed safe write.');
|
|
25
|
+
}
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=safe-write-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-write-file.js","sourceRoot":"","sources":["../../../../src/helpers.private/safe-write-file/safe-write-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,QAAc,EACd,YAAkB,EAClB,IAAgB;IAEhB,IAAI,CAAC;QACH,MAAM,SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAChE,MAAM,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC7D,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACrD,CAAC;QAAC,OAAO,YAAqB,EAAE,CAAC;YAC/B,MAAM,IAAI,eAAe,CACvB,YAAY,EACZ,KAAK,EACL,2DAA2D,CAC5D,CAAC;QACJ,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throws if the time is not a finite number: non-finite times would corrupt
|
|
3
|
+
* the sorted bucket list (bucket resolution happens before bucket validation),
|
|
4
|
+
* and the bytes specializations must reject them before storing any file.
|
|
5
|
+
*/
|
|
6
|
+
export declare function throwIfTimeIsInvalid(time: number): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throws if the time is not a finite number: non-finite times would corrupt
|
|
3
|
+
* the sorted bucket list (bucket resolution happens before bucket validation),
|
|
4
|
+
* and the bytes specializations must reject them before storing any file.
|
|
5
|
+
*/
|
|
6
|
+
export function throwIfTimeIsInvalid(time) {
|
|
7
|
+
if (!Number.isFinite(time)) {
|
|
8
|
+
throw new RangeError(`Invalid time: ${time}`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=throw-if-time-is-invalid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throw-if-time-is-invalid.js","sourceRoot":"","sources":["../../../../src/helpers.private/throw-if-time-is-invalid/throw-if-time-is-invalid.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,UAAU,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;AACH,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './zekta-time-series.ts';
|
|
2
|
-
export * from './zekta-time-bucket.ts';
|
|
3
2
|
export * from './specializations/text/zekta-text-time-series.ts';
|
|
4
3
|
export * from './specializations/number/zekta-number-time-series.ts';
|
|
5
4
|
export * from './specializations/bytes/zekta-bytes-time-series.ts';
|
|
5
|
+
export * from './config/zekta-time-series-config.ts';
|
|
6
|
+
export * from './config/v1/zekta-time-series-config-v1-schema.ts';
|
|
7
|
+
export * from './config/v1/zekta-time-series-config-v1.ts';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './zekta-time-series.js';
|
|
2
|
+
export * from './specializations/text/zekta-text-time-series.js';
|
|
3
|
+
export * from './specializations/number/zekta-number-time-series.js';
|
|
4
|
+
export * from './specializations/bytes/zekta-bytes-time-series.js';
|
|
5
|
+
export * from './config/zekta-time-series-config.js';
|
|
6
|
+
export * from './config/v1/zekta-time-series-config-v1-schema.js';
|
|
7
|
+
export * from './config/v1/zekta-time-series-config-v1.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,kDAAkD,CAAC;AACjE,cAAc,sDAAsD,CAAC;AACrE,cAAc,oDAAoD,CAAC;AACnE,cAAc,sCAAsC,CAAC;AACrD,cAAc,mDAAmD,CAAC;AAClE,cAAc,4CAA4C,CAAC"}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import { TimeSeries, type TimeSeriesDeleteOptions, type TimeSeriesEntry, type TimeSeriesSelectOptions } from '@thingmate/time-series';
|
|
2
2
|
import { type PathInput } from '@xstd/path';
|
|
3
|
-
import { type ZektaTimeBucketFlushOptions } from '../../zekta-time-bucket.ts';
|
|
3
|
+
import { type ZektaTimeBucketFlushOptions } from '../../bucket.private/zekta-time-bucket.ts';
|
|
4
4
|
import { type OpenZektaTimeSeriesOptions } from '../../zekta-time-series.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Options for opening (or creating) a "ZektaBytesTimeSeries": the series
|
|
7
|
+
* options, without "valueByteLength" (the values are content-addressed
|
|
8
|
+
* sha256 identifiers, always 32 bytes).
|
|
9
|
+
*/
|
|
5
10
|
export interface OpenZektaBytesTimeSeriesOptions extends Omit<OpenZektaTimeSeriesOptions, 'valueByteLength'> {
|
|
6
11
|
readonly dirPath: PathInput;
|
|
7
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* A time series that stores byte-array values of any length. Each value is
|
|
15
|
+
* stored once and referenced by its sha256 hash: identical values share the
|
|
16
|
+
* same storage.
|
|
17
|
+
*
|
|
18
|
+
* "delete" leaves the storage of removed values in place (it may be shared
|
|
19
|
+
* with the remaining entries); "drop" removes it entirely.
|
|
20
|
+
*/
|
|
8
21
|
export declare class ZektaBytesTimeSeries extends TimeSeries<Uint8Array> {
|
|
9
22
|
#private;
|
|
10
23
|
static open({ dirPath, ...options }: OpenZektaBytesTimeSeriesOptions): Promise<ZektaBytesTimeSeries>;
|
|
@@ -14,5 +27,12 @@ export declare class ZektaBytesTimeSeries extends TimeSeries<Uint8Array> {
|
|
|
14
27
|
select(options?: TimeSeriesSelectOptions): Promise<readonly TimeSeriesEntry<Uint8Array>[]>;
|
|
15
28
|
delete(options?: TimeSeriesDeleteOptions): Promise<void>;
|
|
16
29
|
drop(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Removes the stored files that are no longer referenced by any entry.
|
|
32
|
+
*
|
|
33
|
+
* It reads every entry of the series: call it after deletions, when you
|
|
34
|
+
* want to reclaim their storage.
|
|
35
|
+
*/
|
|
36
|
+
compact(): Promise<void>;
|
|
17
37
|
flush(options?: ZektaTimeBucketFlushOptions): Promise<void>;
|
|
18
38
|
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { TimeSeries, } from '@thingmate/time-series';
|
|
2
|
+
import { uint8ArrayToHex } from '@xstd/hex';
|
|
3
|
+
import { Path } from '@xstd/path';
|
|
4
|
+
import { sha256 } from '@xstd/sha256';
|
|
5
|
+
import { mkdir, readFile, readdir, rm } from 'node:fs/promises';
|
|
6
|
+
import { cleanupBucketTempFiles, createBucketTempFileName, } from '../../bucket.private/helpers.private/temp-files/temp-files.js';
|
|
7
|
+
import {} from '../../bucket.private/zekta-time-bucket.js';
|
|
8
|
+
import { handlePromiseAllSettledResult } from '../../helpers.private/handle-promise-all-settled-result.js';
|
|
9
|
+
import { safeWriteFile } from '../../helpers.private/safe-write-file/safe-write-file.js';
|
|
10
|
+
import { throwIfTimeIsInvalid } from '../../helpers.private/throw-if-time-is-invalid/throw-if-time-is-invalid.js';
|
|
11
|
+
import { ZektaTimeSeries } from '../../zekta-time-series.js';
|
|
12
|
+
/* CLASS */
|
|
13
|
+
/**
|
|
14
|
+
* A time series that stores byte-array values of any length. Each value is
|
|
15
|
+
* stored once and referenced by its sha256 hash: identical values share the
|
|
16
|
+
* same storage.
|
|
17
|
+
*
|
|
18
|
+
* "delete" leaves the storage of removed values in place (it may be shared
|
|
19
|
+
* with the remaining entries); "drop" removes it entirely.
|
|
20
|
+
*/
|
|
21
|
+
export class ZektaBytesTimeSeries extends TimeSeries {
|
|
22
|
+
static async open({ dirPath, ...options }) {
|
|
23
|
+
const timeSeries = await ZektaTimeSeries.open({
|
|
24
|
+
...options,
|
|
25
|
+
dirPath,
|
|
26
|
+
valueByteLength: 32,
|
|
27
|
+
});
|
|
28
|
+
const filesPath = Path.of(dirPath).concat('files');
|
|
29
|
+
/* the blob stores write their temp files in the files directory: leftover
|
|
30
|
+
temp files from interrupted stores are cleaned up like the bucket ones */
|
|
31
|
+
await cleanupBucketTempFiles(filesPath);
|
|
32
|
+
return new ZektaBytesTimeSeries({ timeSeries, filesPath });
|
|
33
|
+
}
|
|
34
|
+
#timeSeries;
|
|
35
|
+
#filesPath;
|
|
36
|
+
#queue;
|
|
37
|
+
constructor({ timeSeries, filesPath }) {
|
|
38
|
+
super();
|
|
39
|
+
this.#timeSeries = timeSeries;
|
|
40
|
+
this.#filesPath = filesPath;
|
|
41
|
+
this.#queue = Promise.resolve();
|
|
42
|
+
}
|
|
43
|
+
#run(task) {
|
|
44
|
+
return (this.#queue = this.#queue.then(task, task));
|
|
45
|
+
}
|
|
46
|
+
/* OPERATIONS */
|
|
47
|
+
async #storeFile(data) {
|
|
48
|
+
const id = sha256(data);
|
|
49
|
+
const path = this.#filesPath.concat(uint8ArrayToHex(id));
|
|
50
|
+
/* the temp file lives in the same directory (same filesystem), the rename
|
|
51
|
+
inside "safeWriteFile" is atomic */
|
|
52
|
+
const tempFilePath = this.#filesPath.concat(createBucketTempFileName());
|
|
53
|
+
await mkdir(path.dirname().toString(), {
|
|
54
|
+
recursive: true,
|
|
55
|
+
});
|
|
56
|
+
await safeWriteFile(path, tempFilePath, data);
|
|
57
|
+
return id;
|
|
58
|
+
}
|
|
59
|
+
push(time, value) {
|
|
60
|
+
return this.#run(async () => {
|
|
61
|
+
/* validated before the store: a rejected push must not store any file */
|
|
62
|
+
throwIfTimeIsInvalid(time);
|
|
63
|
+
return this.#timeSeries.push(time, await this.#storeFile(value));
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
insert(entries) {
|
|
67
|
+
return this.#run(async () => {
|
|
68
|
+
/* every entry is validated before anything is stored: a rejected batch
|
|
69
|
+
must not leave any stored file behind */
|
|
70
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
71
|
+
throwIfTimeIsInvalid(entries[i].time);
|
|
72
|
+
}
|
|
73
|
+
return this.#timeSeries.insert(handlePromiseAllSettledResult(await Promise.allSettled(entries.map(({ value }) => {
|
|
74
|
+
return this.#storeFile(value);
|
|
75
|
+
}))).map((id, index) => {
|
|
76
|
+
return {
|
|
77
|
+
time: entries[index].time,
|
|
78
|
+
value: id,
|
|
79
|
+
};
|
|
80
|
+
}));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
select(options) {
|
|
84
|
+
return this.#run(async () => {
|
|
85
|
+
return handlePromiseAllSettledResult(await Promise.allSettled((await this.#timeSeries.select(options)).map(async ({ time, value, }) => {
|
|
86
|
+
return {
|
|
87
|
+
time,
|
|
88
|
+
value: await readFile(this.#filesPath.concat(uint8ArrayToHex(value)).toString()),
|
|
89
|
+
};
|
|
90
|
+
})));
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
delete(options) {
|
|
94
|
+
return this.#run(() => {
|
|
95
|
+
return this.#timeSeries.delete(options);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
drop() {
|
|
99
|
+
return this.#run(async () => {
|
|
100
|
+
/* the files directory is removed only once no id remains on disk:
|
|
101
|
+
removing it earlier would leave the persisted buckets referencing
|
|
102
|
+
missing blobs if a crash happens in between */
|
|
103
|
+
await this.#timeSeries.drop();
|
|
104
|
+
await this.#timeSeries.flush();
|
|
105
|
+
await rm(this.#filesPath.toString(), {
|
|
106
|
+
recursive: true,
|
|
107
|
+
force: true,
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Removes the stored files that are no longer referenced by any entry.
|
|
113
|
+
*
|
|
114
|
+
* It reads every entry of the series: call it after deletions, when you
|
|
115
|
+
* want to reclaim their storage.
|
|
116
|
+
*/
|
|
117
|
+
async compact() {
|
|
118
|
+
return this.#run(async () => {
|
|
119
|
+
/* the referenced identifiers are read after everything is persisted:
|
|
120
|
+
removing a file still referenced on disk would leave a dangling entry
|
|
121
|
+
if a crash happens in between */
|
|
122
|
+
await this.#timeSeries.flush();
|
|
123
|
+
const referencedIds = new Set((await this.#timeSeries.select()).map(({ value }) => {
|
|
124
|
+
return uint8ArrayToHex(value);
|
|
125
|
+
}));
|
|
126
|
+
let fileNames;
|
|
127
|
+
try {
|
|
128
|
+
fileNames = await readdir(this.#filesPath.toString());
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (error.code === 'ENOENT') {
|
|
132
|
+
return; /* nothing stored yet */
|
|
133
|
+
}
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
await Promise.all(fileNames
|
|
137
|
+
.filter((fileName) => {
|
|
138
|
+
return !referencedIds.has(fileName);
|
|
139
|
+
})
|
|
140
|
+
.map((fileName) => {
|
|
141
|
+
return rm(this.#filesPath.concat(fileName).toString(), { force: true });
|
|
142
|
+
}));
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/* FLUSH */
|
|
146
|
+
flush(options) {
|
|
147
|
+
return this.#run(() => {
|
|
148
|
+
return this.#timeSeries.flush(options);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=zekta-bytes-time-series.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zekta-bytes-time-series.js","sourceRoot":"","sources":["../../../../src/specializations/bytes/zekta-bytes-time-series.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,GAIX,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAkB,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,EA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,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YAC1E,CAAC,CAAC,CACL,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,WAAW;IAEF,KAAK,CAAC,OAAqC;QAClD,OAAO,IAAI,CAAC,IAAI,CAAC,GAAkB,EAAE;YACnC,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { TimeSeries, type TimeSeriesDeleteOptions, type TimeSeriesEntry, type TimeSeriesSelectOptions } from '@thingmate/time-series';
|
|
2
|
+
import { type PathInput } from '@xstd/path';
|
|
3
|
+
import { type ZektaTimeBucketFlushOptions } from '../../bucket.private/zekta-time-bucket.ts';
|
|
4
|
+
import { type OpenZektaTimeSeriesOptions } from '../../zekta-time-series.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Options for opening (or creating) a "ZektaNumberTimeSeries": the series
|
|
7
|
+
* options, without "valueByteLength" (derived from "type").
|
|
8
|
+
*/
|
|
9
|
+
export interface OpenZektaNumberTimeSeriesOptions extends Omit<OpenZektaTimeSeriesOptions, 'valueByteLength'> {
|
|
10
|
+
readonly dirPath: PathInput;
|
|
11
|
+
readonly type: ZektaNumberTimeSeriesType;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Value types supported by "ZektaNumberTimeSeries".
|
|
15
|
+
*
|
|
16
|
+
* Values are never validated: each type stores whatever it is given, with
|
|
17
|
+
* the underlying DataView setter semantics:
|
|
18
|
+
* - u8/i8/u16/i16/u32/i32: values are taken modulo the type range
|
|
19
|
+
* (300 stored in "u8" reads back 44), non-integers are truncated toward
|
|
20
|
+
* zero, NaN stores 0;
|
|
21
|
+
* - f16/f32: values are rounded to the type precision, values beyond the
|
|
22
|
+
* type range overflow to +/-Infinity;
|
|
23
|
+
* - f64: every JavaScript number is stored losslessly.
|
|
24
|
+
*
|
|
25
|
+
* Passing values that fit the type is the caller's responsibility.
|
|
26
|
+
*/
|
|
27
|
+
export type ZektaNumberTimeSeriesType = 'u8' | 'i8' | 'u16' | 'i16' | 'u32' | 'i32' | 'f16' | 'f32' | 'f64';
|
|
28
|
+
/**
|
|
29
|
+
* A time series that stores numbers with the fixed byte length of the given
|
|
30
|
+
* "ZektaNumberTimeSeriesType".
|
|
31
|
+
*
|
|
32
|
+
* See the type documentation for how values are converted before being
|
|
33
|
+
* stored.
|
|
34
|
+
*
|
|
35
|
+
* The "type" is only an open-time option: it is not persisted with the
|
|
36
|
+
* series. Re-opening with a different type of the same byte length ("u8" as
|
|
37
|
+
* "i8", "u16" as "i16", "f32" as "i32", ...) succeeds and silently
|
|
38
|
+
* reinterprets the stored bytes (a "u8" 255 reads back -1 as "i8"): always
|
|
39
|
+
* re-open with the original type.
|
|
40
|
+
*/
|
|
41
|
+
export declare class ZektaNumberTimeSeries extends TimeSeries<number> {
|
|
42
|
+
#private;
|
|
43
|
+
static open({ type, ...options }: OpenZektaNumberTimeSeriesOptions): Promise<ZektaNumberTimeSeries>;
|
|
44
|
+
private constructor();
|
|
45
|
+
push(time: number, value: number): Promise<void>;
|
|
46
|
+
insert(entries: readonly TimeSeriesEntry<number>[]): Promise<void>;
|
|
47
|
+
select(options?: TimeSeriesSelectOptions): Promise<readonly TimeSeriesEntry<number>[]>;
|
|
48
|
+
delete(options?: TimeSeriesDeleteOptions): Promise<void>;
|
|
49
|
+
drop(): Promise<void>;
|
|
50
|
+
flush(options?: ZektaTimeBucketFlushOptions): Promise<void>;
|
|
51
|
+
}
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import { TimeSeries, } from '@thingmate/time-series';
|
|
2
2
|
import {} from '@xstd/path';
|
|
3
|
-
import {} from
|
|
4
|
-
import { ZektaTimeSeries } from
|
|
3
|
+
import {} from '../../bucket.private/zekta-time-bucket.js';
|
|
4
|
+
import { ZektaTimeSeries } from '../../zekta-time-series.js';
|
|
5
5
|
/* CLASS */
|
|
6
|
+
/**
|
|
7
|
+
* A time series that stores numbers with the fixed byte length of the given
|
|
8
|
+
* "ZektaNumberTimeSeriesType".
|
|
9
|
+
*
|
|
10
|
+
* See the type documentation for how values are converted before being
|
|
11
|
+
* stored.
|
|
12
|
+
*
|
|
13
|
+
* The "type" is only an open-time option: it is not persisted with the
|
|
14
|
+
* series. Re-opening with a different type of the same byte length ("u8" as
|
|
15
|
+
* "i8", "u16" as "i16", "f32" as "i32", ...) succeeds and silently
|
|
16
|
+
* reinterprets the stored bytes (a "u8" 255 reads back -1 as "i8"): always
|
|
17
|
+
* re-open with the original type.
|
|
18
|
+
*/
|
|
6
19
|
export class ZektaNumberTimeSeries extends TimeSeries {
|
|
7
20
|
static async open({ type, ...options }) {
|
|
8
21
|
return new ZektaNumberTimeSeries({
|
|
@@ -54,7 +67,7 @@ export class ZektaNumberTimeSeries extends TimeSeries {
|
|
|
54
67
|
return this.#timeSeries.flush(options);
|
|
55
68
|
}
|
|
56
69
|
}
|
|
57
|
-
|
|
70
|
+
// BYTE_LENGTH
|
|
58
71
|
function zektaNumberTimeSeriesTypeToByteLength(type) {
|
|
59
72
|
switch (type) {
|
|
60
73
|
case 'u8':
|
|
@@ -62,6 +75,7 @@ function zektaNumberTimeSeriesTypeToByteLength(type) {
|
|
|
62
75
|
return 1;
|
|
63
76
|
case 'u16':
|
|
64
77
|
case 'i16':
|
|
78
|
+
case 'f16':
|
|
65
79
|
return 2;
|
|
66
80
|
case 'u32':
|
|
67
81
|
case 'i32':
|
|
@@ -73,8 +87,12 @@ function zektaNumberTimeSeriesTypeToByteLength(type) {
|
|
|
73
87
|
throw new Error(`Unsupported type: ${type}`);
|
|
74
88
|
}
|
|
75
89
|
}
|
|
90
|
+
// TO_UINT8_ARRAY
|
|
76
91
|
function zektaNumberTimeSeriesTypeToNumberToUint8Array(type) {
|
|
77
92
|
switch (type) {
|
|
93
|
+
/* each conversion allocates its own output: the converted value is written
|
|
94
|
+
later (queued operations, batched inserts), a shared buffer would be reused
|
|
95
|
+
before the writes happen */
|
|
78
96
|
case 'u8':
|
|
79
97
|
return (input) => {
|
|
80
98
|
const output = new Uint8Array(1);
|
|
@@ -111,6 +129,12 @@ function zektaNumberTimeSeriesTypeToNumberToUint8Array(type) {
|
|
|
111
129
|
new DataView(output.buffer, output.byteOffset, output.byteLength).setInt32(0, input, true);
|
|
112
130
|
return output;
|
|
113
131
|
};
|
|
132
|
+
case 'f16':
|
|
133
|
+
return (input) => {
|
|
134
|
+
const output = new Uint8Array(2);
|
|
135
|
+
new DataView(output.buffer, output.byteOffset, output.byteLength).setFloat16(0, input, true);
|
|
136
|
+
return output;
|
|
137
|
+
};
|
|
114
138
|
case 'f32':
|
|
115
139
|
return (input) => {
|
|
116
140
|
const output = new Uint8Array(4);
|
|
@@ -127,46 +151,43 @@ function zektaNumberTimeSeriesTypeToNumberToUint8Array(type) {
|
|
|
127
151
|
throw new Error(`Unsupported type: ${type}`);
|
|
128
152
|
}
|
|
129
153
|
}
|
|
154
|
+
// TO_NUMBER
|
|
130
155
|
function zektaNumberTimeSeriesTypeToUint8ArrayToNumber(type) {
|
|
131
156
|
switch (type) {
|
|
132
157
|
case 'u8':
|
|
133
158
|
return (input) => {
|
|
134
|
-
console.assert(input.byteLength === 1);
|
|
135
159
|
return new DataView(input.buffer, input.byteOffset, input.byteLength).getUint8(0);
|
|
136
160
|
};
|
|
137
161
|
case 'i8':
|
|
138
162
|
return (input) => {
|
|
139
|
-
console.assert(input.byteLength === 1);
|
|
140
163
|
return new DataView(input.buffer, input.byteOffset, input.byteLength).getInt8(0);
|
|
141
164
|
};
|
|
142
165
|
case 'u16':
|
|
143
166
|
return (input) => {
|
|
144
|
-
console.assert(input.byteLength === 2);
|
|
145
167
|
return new DataView(input.buffer, input.byteOffset, input.byteLength).getUint16(0, true);
|
|
146
168
|
};
|
|
147
169
|
case 'i16':
|
|
148
170
|
return (input) => {
|
|
149
|
-
console.assert(input.byteLength === 2);
|
|
150
171
|
return new DataView(input.buffer, input.byteOffset, input.byteLength).getInt16(0, true);
|
|
151
172
|
};
|
|
152
173
|
case 'u32':
|
|
153
174
|
return (input) => {
|
|
154
|
-
console.assert(input.byteLength === 4);
|
|
155
175
|
return new DataView(input.buffer, input.byteOffset, input.byteLength).getUint32(0, true);
|
|
156
176
|
};
|
|
157
177
|
case 'i32':
|
|
158
178
|
return (input) => {
|
|
159
|
-
console.assert(input.byteLength === 4);
|
|
160
179
|
return new DataView(input.buffer, input.byteOffset, input.byteLength).getInt32(0, true);
|
|
161
180
|
};
|
|
181
|
+
case 'f16':
|
|
182
|
+
return (input) => {
|
|
183
|
+
return new DataView(input.buffer, input.byteOffset, input.byteLength).getFloat16(0, true);
|
|
184
|
+
};
|
|
162
185
|
case 'f32':
|
|
163
186
|
return (input) => {
|
|
164
|
-
console.assert(input.byteLength === 4);
|
|
165
187
|
return new DataView(input.buffer, input.byteOffset, input.byteLength).getFloat32(0, true);
|
|
166
188
|
};
|
|
167
189
|
case 'f64':
|
|
168
190
|
return (input) => {
|
|
169
|
-
console.assert(input.byteLength === 8);
|
|
170
191
|
return new DataView(input.buffer, input.byteOffset, input.byteLength).getFloat64(0, true);
|
|
171
192
|
};
|
|
172
193
|
default:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zekta-number-time-series.js","sourceRoot":"","sources":["../../../../src/specializations/number/zekta-number-time-series.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,GAIX,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAkB,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAoC,MAAM,2CAA2C,CAAC;AAC7F,OAAO,EAAmC,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAiC9F,WAAW;AAEX;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,qBAAsB,SAAQ,UAAkB;IAC3D,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAChB,IAAI,EACJ,GAAG,OAAO,EACu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@thingmate/time-series';
|
|
2
|
+
import { type ZektaTimeBucketFlushOptions } from '../../bucket.private/zekta-time-bucket.ts';
|
|
3
|
+
import { type OpenZektaBytesTimeSeriesOptions } from '../bytes/zekta-bytes-time-series.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Options for opening (or creating) a "ZektaTextTimeSeries": the
|
|
6
|
+
* "ZektaBytesTimeSeries" options (text values are stored as UTF-8 blobs).
|
|
7
|
+
*/
|
|
8
|
+
export interface OpenZektaTextTimeSeriesOptions extends OpenZektaBytesTimeSeriesOptions {
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Time series of text values, stored through the content-addressed
|
|
12
|
+
* "ZektaBytesTimeSeries".
|
|
13
|
+
*
|
|
14
|
+
* Values are never validated: any well-formed string round-trips losslessly
|
|
15
|
+
* (UTF-8), but strings containing lone surrogates are silently stored with
|
|
16
|
+
* U+FFFD replacement characters in their place (TextEncoder semantics).
|
|
17
|
+
* Passing well-formed strings is the caller's responsibility.
|
|
18
|
+
*/
|
|
19
|
+
export declare class ZektaTextTimeSeries extends TimeSeries<string> {
|
|
20
|
+
#private;
|
|
21
|
+
static open(options: OpenZektaTextTimeSeriesOptions): Promise<ZektaTextTimeSeries>;
|
|
22
|
+
private constructor();
|
|
23
|
+
push(time: number, value: string): Promise<void>;
|
|
24
|
+
insert(entries: readonly TimeSeriesEntry<string>[]): Promise<void>;
|
|
25
|
+
select(options?: TimeSeriesSelectOptions): Promise<readonly TimeSeriesEntry<string>[]>;
|
|
26
|
+
delete(options?: TimeSeriesDeleteOptions): Promise<void>;
|
|
27
|
+
drop(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Removes the stored files that are no longer referenced by any entry.
|
|
30
|
+
*
|
|
31
|
+
* It reads every entry of the series: call it after deletions, when you
|
|
32
|
+
* want to reclaim their storage.
|
|
33
|
+
*/
|
|
34
|
+
compact(): Promise<void>;
|
|
35
|
+
flush(options?: ZektaTimeBucketFlushOptions): Promise<void>;
|
|
36
|
+
}
|