@thingmate/zekta-time-series 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.
Files changed (31) hide show
  1. package/CONTRIBUTING.md +75 -0
  2. package/LICENSE +21 -0
  3. package/README.md +26 -0
  4. package/helpers.private/binary-search/binary-search.d.ts +22 -0
  5. package/helpers.private/binary-search/binary-search.js +41 -0
  6. package/helpers.private/binary-search/binary-search.js.map +1 -0
  7. package/helpers.private/handle-promise-all-settled-result.d.ts +4 -0
  8. package/helpers.private/handle-promise-all-settled-result.js +19 -0
  9. package/helpers.private/handle-promise-all-settled-result.js.map +1 -0
  10. package/helpers.private/resizeable-buffer.d.ts +9 -0
  11. package/helpers.private/resizeable-buffer.js +57 -0
  12. package/helpers.private/resizeable-buffer.js.map +1 -0
  13. package/index.d.ts +5 -0
  14. package/index.js +6 -0
  15. package/index.js.map +1 -0
  16. package/package.json +56 -0
  17. package/specializations/bytes/zekta-bytes-time-series.d.ts +18 -0
  18. package/specializations/bytes/zekta-bytes-time-series.js +87 -0
  19. package/specializations/bytes/zekta-bytes-time-series.js.map +1 -0
  20. package/specializations/number/zekta-number-time-series.d.ts +20 -0
  21. package/specializations/number/zekta-number-time-series.js +176 -0
  22. package/specializations/number/zekta-number-time-series.js.map +1 -0
  23. package/specializations/text/zekta-text-time-series.d.ts +16 -0
  24. package/specializations/text/zekta-text-time-series.js +51 -0
  25. package/specializations/text/zekta-text-time-series.js.map +1 -0
  26. package/zekta-time-bucket.d.ts +35 -0
  27. package/zekta-time-bucket.js +324 -0
  28. package/zekta-time-bucket.js.map +1 -0
  29. package/zekta-time-series.d.ts +25 -0
  30. package/zekta-time-series.js +194 -0
  31. package/zekta-time-series.js.map +1 -0
@@ -0,0 +1,75 @@
1
+ # Contributing
2
+
3
+ This projet is open to everyone. Feel free to test the library, share it, improve it, and create merge requests.
4
+
5
+ ### Getting started
6
+
7
+ The library requires [Node.js](https://nodejs.org/en) `24+` and [yarn](https://yarnpkg.com/).
8
+
9
+ First, we have to use the correct version of node:
10
+
11
+ ```shell
12
+ nvm use
13
+ ```
14
+
15
+ If you don't have [nvm](https://github.com/nvm-sh/nvm), you may manually install and use Node.js 24+.
16
+
17
+ Then, we have to use the proper package manager (here `yarn`):
18
+
19
+ ```shell
20
+ corepack enable
21
+ ```
22
+
23
+ Start a local verdaccio:
24
+
25
+ ```shell
26
+ npx fabrique verdaccio
27
+ ```
28
+
29
+ And install the dependencies:
30
+
31
+ ```shell
32
+ yarn install
33
+ ```
34
+
35
+ ### Code
36
+
37
+ - The source code is located in the `src` directory.
38
+ - The projet uses [prettier](https://prettier.io/) to format the code. You'll want to enable and configure it in your IDE.
39
+ - The tests run with [vitest](https://vitest.dev)
40
+
41
+ ### Commands
42
+
43
+ - `fb:build`: builds the library.
44
+ - converts the typescript files into javascript files, copies the scss files, and assembles all the assets to create a package ready to be published.
45
+ - some files are handled differently:
46
+ - `*.protected.{ts,scss}` or `**/*.protected/**`: these files are exported under `package-name/protected`
47
+ - this is indented to expose parts of the code that should be restricted to advanced users only, or shared to other libraries requiring _internal_ control.
48
+ - `*.private.{ts,scss}` or `/*.private/**`: these files are **not** exported.
49
+ - this is indented to consume parts of the code internally, and not expose them publicly.
50
+ - `fb:format`: formats the code using `prettier`.
51
+ - `fb:test`: runs the tests using `vitest`.
52
+ - `fb:test:coverage`: runs the tests with coverage.
53
+ - by default, 100% code coverage is required, to enforce good quality.
54
+ - `fb:bench`: runs the bench tests.
55
+ - `fb:typedoc`: generates the documentation.
56
+ - if the library exposes publicly only a few and/or simple parts, the documentation may be defined in the `README.md` instead.
57
+ - `fb:prod`: builds the lib in `prod` mode.
58
+ - builds and publishes the lib on npm as a _prod_ version.
59
+ - `fb:dev`: builds the lib in `dev` mode.
60
+ - builds and publishes the lib on a local `verdaccio` with a `dev` tag.
61
+ - a local `verdaccio` is used to debug/test your library in another project:
62
+ - it is better than `npm link`, as it enforce a specific version, and allows some dependencies to be `dev` too.
63
+ - `fb:rc`: builds the lib in `rc` mode.
64
+ - builds and publishes the lib on npm with a `rc` tag.
65
+ - to test before production and final release
66
+
67
+ ### To create an MR
68
+
69
+ 1. fork the repository
70
+ 1. add the feature/fix by modifying the code in the `src/` directory
71
+ 1. add/write some tests until 100% code coverage is reached (run the tests with `yarn fb:test:coverage`)
72
+ 1. format the code, using the command `yarn fb:format`
73
+ 1. commit and push your work following the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) convention
74
+ 1. create an MR from your repository to the upstream repository, explaining clearly what was added/fixed.
75
+
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2026 Valentin Richard
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ [![npm (scoped)](https://img.shields.io/npm/v/@thingmate/zekta-time-series.svg)](https://www.npmjs.com/package/@thingmate/zekta-time-series)
2
+ ![npm](https://img.shields.io/npm/dm/@thingmate/zekta-time-series.svg)
3
+ ![NPM](https://img.shields.io/npm/l/@thingmate/zekta-time-series.svg)
4
+ ![npm type definitions](https://img.shields.io/npm/types/@thingmate/zekta-time-series.svg)
5
+
6
+ <picture>
7
+ <source height="64" media="(prefers-color-scheme: dark)" srcset="https://github.com/thingmate/website/blob/main/assets/logo/png/logo-large-dark.png?raw=true">
8
+ <source height="64" media="(prefers-color-scheme: light)" srcset="https://github.com/thingmate/website/blob/main/assets/logo/png/logo-large-light.png?raw=true">
9
+ <img height="64" alt="Shows a black logo in light color mode and a white one in dark color mode." src="https://github.com/thingmate/website/blob/main/assets/logo/png/logo-large-light.png?raw=true">
10
+ </picture>
11
+
12
+ ## @thingmate/zekta-time-series
13
+
14
+ Zekta time series implementation
15
+
16
+ ## 📦 Installation
17
+
18
+ ```shell
19
+ yarn add @thingmate/zekta-time-series
20
+ # or
21
+ npm install @thingmate/zekta-time-series --save
22
+ ```
23
+
24
+ ## 📜 Documentation
25
+
26
+ TODO
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Performs a binary search over an abstract _sorted_ `collection` of data and finds the index where a `value` may be _inserted_ while preserving the order.
3
+ *
4
+ * @param {number} length - The number of elements in the `collection`.
5
+ * @param {(index: number) => number} compare - A comparator function that is called with the current _insert_ index.
6
+ * It must compare the value at the current index with the value to be inserted => `(index: number): number => collection[index] - value` (assuming `collection[index]` and `value` are numbers).
7
+ * @returns {number} - The index where `value` may be safely inserted while preserving the order of the `collection`. Range: `[0, length]`.
8
+ *
9
+ * @example
10
+ *
11
+ * ```ts
12
+ * const values: number[] = [1, 2, 3, 4, 5];
13
+ * const valueToInsert: number = 1.5;
14
+ * values.splice(
15
+ * binarySearch(values.length, (index: number): number => values[index] - valueToInsert),
16
+ * 0,
17
+ * valueToInsert,
18
+ * );
19
+ * // values => [1, 1.5, 2, 3, 4, 5]
20
+ * ```
21
+ */
22
+ export declare function binarySearch(length: number, compare: (index: number) => number): number;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Performs a binary search over an abstract _sorted_ `collection` of data and finds the index where a `value` may be _inserted_ while preserving the order.
3
+ *
4
+ * @param {number} length - The number of elements in the `collection`.
5
+ * @param {(index: number) => number} compare - A comparator function that is called with the current _insert_ index.
6
+ * It must compare the value at the current index with the value to be inserted => `(index: number): number => collection[index] - value` (assuming `collection[index]` and `value` are numbers).
7
+ * @returns {number} - The index where `value` may be safely inserted while preserving the order of the `collection`. Range: `[0, length]`.
8
+ *
9
+ * @example
10
+ *
11
+ * ```ts
12
+ * const values: number[] = [1, 2, 3, 4, 5];
13
+ * const valueToInsert: number = 1.5;
14
+ * values.splice(
15
+ * binarySearch(values.length, (index: number): number => values[index] - valueToInsert),
16
+ * 0,
17
+ * valueToInsert,
18
+ * );
19
+ * // values => [1, 1.5, 2, 3, 4, 5]
20
+ * ```
21
+ */
22
+ export function binarySearch(length, compare) {
23
+ let low = 0;
24
+ let high = length - 1;
25
+ while (low <= high) {
26
+ const mid = Math.floor((low + high) / 2);
27
+ const result = compare(mid);
28
+ if (result === 0) {
29
+ low = mid;
30
+ break;
31
+ }
32
+ else if (result < 0) {
33
+ low = mid + 1;
34
+ }
35
+ else {
36
+ high = mid - 1;
37
+ }
38
+ }
39
+ return low;
40
+ }
41
+ //# sourceMappingURL=binary-search.js.map
@@ -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,GAAG,GAAG,GAAG,CAAC;YACV,MAAM;QACR,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"}
@@ -0,0 +1,4 @@
1
+ export type HandlePromiseAllSettledResultOutputValue<GResults extends readonly PromiseSettledResult<unknown>[]> = {
2
+ -readonly [GKey in keyof GResults]: GResults[GKey] extends PromiseSettledResult<infer GValue> ? GValue : never;
3
+ };
4
+ export declare function handlePromiseAllSettledResult<GResults extends readonly PromiseSettledResult<unknown>[]>(results: GResults): HandlePromiseAllSettledResultOutputValue<GResults>;
@@ -0,0 +1,19 @@
1
+ export function handlePromiseAllSettledResult(results) {
2
+ const errors = results.filter((result) => {
3
+ return result.status === 'rejected';
4
+ });
5
+ if (errors.length === 0) {
6
+ return results.map((result) => {
7
+ return result.value;
8
+ });
9
+ }
10
+ if (errors.length === 1) {
11
+ throw errors[0].reason;
12
+ }
13
+ else {
14
+ throw new AggregateError(errors.map((error) => {
15
+ return error.reason;
16
+ }));
17
+ }
18
+ }
19
+ //# sourceMappingURL=handle-promise-all-settled-result.js.map
@@ -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,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"}
@@ -0,0 +1,9 @@
1
+ export declare class ResizeableBuffer {
2
+ #private;
3
+ constructor(buffer?: ArrayBuffer, byteOffset?: number, byteLength?: number);
4
+ get buffer(): ArrayBuffer;
5
+ get view(): DataView<ArrayBuffer>;
6
+ get bytes(): Uint8Array<ArrayBuffer>;
7
+ get length(): number;
8
+ resize(newLength: number): void;
9
+ }
@@ -0,0 +1,57 @@
1
+ export class ResizeableBuffer {
2
+ #buffer;
3
+ #view;
4
+ #bytes;
5
+ #length;
6
+ constructor(buffer = new ArrayBuffer(0x100, {
7
+ maxByteLength: 0x100000000,
8
+ }), byteOffset, byteLength) {
9
+ this.#buffer = buffer;
10
+ this.#view = new DataView(buffer, byteOffset, byteLength);
11
+ this.#bytes = new Uint8Array(buffer, byteOffset, byteLength);
12
+ this.#length = byteLength ?? 0;
13
+ }
14
+ get buffer() {
15
+ return this.#buffer;
16
+ }
17
+ get view() {
18
+ return this.#view;
19
+ }
20
+ get bytes() {
21
+ return this.#bytes;
22
+ }
23
+ get length() {
24
+ return this.#length;
25
+ }
26
+ resize(newLength) {
27
+ if (this.#buffer.resizable) {
28
+ if (newLength > this.#buffer.maxByteLength) {
29
+ throw new Error('Size limit reached.');
30
+ }
31
+ if (newLength > this.#buffer.byteLength) {
32
+ this.#buffer.resize(Math.min(this.#buffer.maxByteLength, getOptimalBufferLength(newLength)));
33
+ }
34
+ }
35
+ else {
36
+ if (newLength > this.#buffer.byteLength) {
37
+ const maxByteLength = 0x100000000;
38
+ const newBuffer = new ArrayBuffer(Math.min(maxByteLength, getOptimalBufferLength(newLength)), {
39
+ maxByteLength,
40
+ });
41
+ const currentBytes = this.#bytes;
42
+ this.#buffer = newBuffer;
43
+ this.#view = new DataView(newBuffer);
44
+ this.#bytes = new Uint8Array(newBuffer);
45
+ this.#bytes.set(currentBytes);
46
+ }
47
+ }
48
+ this.#length = newLength;
49
+ }
50
+ }
51
+ function getOptimalBufferLength(length) {
52
+ return ((1 <<
53
+ 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);
56
+ }
57
+ //# 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,MAAM,OAAO,gBAAgB;IAC3B,OAAO,CAAc;IACrB,KAAK,CAAwB;IAC7B,MAAM,CAA0B;IAChC,OAAO,CAAS;IAEhB,YACE,SAAsB,IAAI,WAAW,CAAC,KAAK,EAAE;QAC3C,aAAa,EAAE,WAAW;KAC3B,CAAC,EACF,UAAmB,EACnB,UAAmB;QAEnB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;QAC1D,IAAI,CAAC,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;QAC7D,IAAI,CAAC,OAAO,GAAG,UAAU,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,MAAM;QACR,O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AC;YAChC,CAAC;QACH,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;IAC3B,CAAC;CACF;AAED,SAAS,sBAAsB,CAAC,MAAc;IAC5C,OAAO,CACL,CAAC,CAAC;QACA,IAAI,CAAC,IAAI,CACP,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,uCAAuC;YACvD,GAAG,CAAC,kCAAkC,CACzC,CAAC,CAAC,8BAA8B;QACnC,CAAC,CACF,CAAC;AACJ,CAAC"}
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './zekta-time-series.ts';
2
+ export * from './zekta-time-bucket.ts';
3
+ export * from './specializations/text/zekta-text-time-series.ts';
4
+ export * from './specializations/number/zekta-number-time-series.ts';
5
+ export * from './specializations/bytes/zekta-bytes-time-series.ts';
package/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./zekta-time-series.js";
2
+ export * from "./zekta-time-bucket.js";
3
+ export * from "./specializations/text/zekta-text-time-series.js";
4
+ export * from "./specializations/number/zekta-number-time-series.js";
5
+ export * from "./specializations/bytes/zekta-bytes-time-series.js";
6
+ //# sourceMappingURL=index.js.map
package/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,wBAAwB,CAAC;AACvC,cAAc,kDAAkD,CAAC;AACjE,cAAc,sDAAsD,CAAC;AACrE,cAAc,oDAAoD,CAAC"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@thingmate/zekta-time-series",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./index.js",
6
+ "scripts": {
7
+ "fb:build": "node fabrique/actions/cli/build.cli.js",
8
+ "fb:format": "prettier --write --ignore-unknown --config ./.prettierrc \"src/**/*.{js,jsx,ts,tsx,html,css,scss}\"",
9
+ "fb:test": "vitest",
10
+ "fb:test:coverage": "vitest run --coverage",
11
+ "fb:bench": "vitest bench",
12
+ "fb:typedoc": "typedoc --options typedoc.json --tsconfig tsconfig.json",
13
+ "fb:prod": "node fabrique/actions/cli/build-and-publish.cli.js --mode prod",
14
+ "fb:dev": "node fabrique/actions/cli/build-and-publish.cli.js --mode dev",
15
+ "fb:rc": "node fabrique/actions/cli/build-and-publish.cli.js --mode rc",
16
+ "fb:node:dev": "node --experimental-strip-types --watch src/main.ts",
17
+ "fb:node:dev:inspect": "node --experimental-strip-types --watch --inspect src/main.ts"
18
+ },
19
+ "description": "Zekta time series implementation",
20
+ "keywords": [],
21
+ "author": "Valentin Richard",
22
+ "license": "MIT",
23
+ "access": "public",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/thingmate/zekta-time-series.git"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^25.0.7",
30
+ "@vitest/coverage-istanbul": "^4.0.17",
31
+ "prettier": "^3.7.4",
32
+ "prettier-plugin-organize-imports": "^4.3.0",
33
+ "typedoc": "^0.28.16",
34
+ "typescript": "^5.9.3",
35
+ "vitest": "^4.0.17"
36
+ },
37
+ "packageManager": "yarn@4.12.0",
38
+ "fabrique": {
39
+ "version": "1.1.1",
40
+ "type": "lib"
41
+ },
42
+ "dependencies": {
43
+ "@thingmate/time-series": "^0.1.1",
44
+ "@xstd/hex": "^0.1.0",
45
+ "@xstd/path": "^1.0.0",
46
+ "@xstd/sha256": "^1.0.0"
47
+ },
48
+ "exports": {
49
+ ".": {
50
+ "types": "./index.d.ts",
51
+ "default": "./index.js"
52
+ }
53
+ },
54
+ "typings": "./index.d.ts",
55
+ "types": "./index.d.ts"
56
+ }
@@ -0,0 +1,18 @@
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 '../../zekta-time-bucket.ts';
4
+ import { type OpenZektaTimeSeriesOptions } from '../../zekta-time-series.ts';
5
+ export interface OpenZektaBytesTimeSeriesOptions extends Omit<OpenZektaTimeSeriesOptions, 'valueByteLength'> {
6
+ readonly dirPath: PathInput;
7
+ }
8
+ export declare class ZektaBytesTimeSeries extends TimeSeries<Uint8Array> {
9
+ #private;
10
+ static open({ dirPath, ...options }: OpenZektaBytesTimeSeriesOptions): Promise<ZektaBytesTimeSeries>;
11
+ private constructor();
12
+ push(time: number, value: Uint8Array): Promise<void>;
13
+ insert(entries: readonly TimeSeriesEntry<Uint8Array>[]): Promise<void>;
14
+ select(options?: TimeSeriesSelectOptions): Promise<readonly TimeSeriesEntry<Uint8Array>[]>;
15
+ delete(options?: TimeSeriesDeleteOptions): Promise<void>;
16
+ drop(): Promise<void>;
17
+ flush(options?: ZektaTimeBucketFlushOptions): Promise<void>;
18
+ }
@@ -0,0 +1,87 @@
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, writeFile } from 'node:fs/promises';
6
+ import { handlePromiseAllSettledResult } from "../../helpers.private/handle-promise-all-settled-result.js";
7
+ import {} from "../../zekta-time-bucket.js";
8
+ import { ZektaTimeSeries } from "../../zekta-time-series.js";
9
+ /* CLASS */
10
+ export class ZektaBytesTimeSeries extends TimeSeries {
11
+ static async open({ dirPath, ...options }) {
12
+ return new ZektaBytesTimeSeries({
13
+ timeSeries: await ZektaTimeSeries.open({
14
+ ...options,
15
+ dirPath,
16
+ valueByteLength: 32,
17
+ }),
18
+ filesPath: Path.of(dirPath).concat('files'),
19
+ });
20
+ }
21
+ #timeSeries;
22
+ #filesPath;
23
+ #queue;
24
+ constructor({ timeSeries, filesPath }) {
25
+ super();
26
+ this.#timeSeries = timeSeries;
27
+ this.#filesPath = filesPath;
28
+ this.#queue = Promise.resolve();
29
+ }
30
+ #run(task) {
31
+ return (this.#queue = this.#queue.then(task, task));
32
+ }
33
+ /* OPERATIONS */
34
+ async #storeFile(data) {
35
+ const id = sha256(data);
36
+ const path = this.#filesPath.concat(uint8ArrayToHex(id));
37
+ await mkdir(path.dirname().toString(), {
38
+ recursive: true,
39
+ });
40
+ await writeFile(path.toString(), data);
41
+ return id;
42
+ }
43
+ push(time, value) {
44
+ return this.#run(async () => {
45
+ return this.#timeSeries.push(time, await this.#storeFile(value));
46
+ });
47
+ }
48
+ insert(entries) {
49
+ return this.#run(async () => {
50
+ return this.#timeSeries.insert(handlePromiseAllSettledResult(await Promise.allSettled(entries.map(({ value }) => {
51
+ return this.#storeFile(value);
52
+ }))).map((id, index) => {
53
+ return {
54
+ time: entries[index].time,
55
+ value: id,
56
+ };
57
+ }));
58
+ });
59
+ }
60
+ select(options) {
61
+ return this.#run(async () => {
62
+ return handlePromiseAllSettledResult(await Promise.allSettled((await this.#timeSeries.select(options)).map(async ({ time, value, }) => {
63
+ return {
64
+ time,
65
+ value: await readFile(this.#filesPath.concat(uint8ArrayToHex(value)).toString()),
66
+ };
67
+ })));
68
+ });
69
+ }
70
+ delete(options) {
71
+ return this.#run(() => {
72
+ return this.#timeSeries.delete(options);
73
+ });
74
+ }
75
+ drop() {
76
+ return this.#run(() => {
77
+ return this.#timeSeries.drop();
78
+ });
79
+ }
80
+ /* FLUSH */
81
+ flush(options) {
82
+ return this.#run(() => {
83
+ return this.#timeSeries.flush(options);
84
+ });
85
+ }
86
+ }
87
+ //# 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,cA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AM,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAC1C,KAAK,EAAE,EACL,IAAI,EACJ,KAAK,GACuB,EAAwC,EAAE;gBACtE,OAAO;oBACL,IAAI;oBACJ,KAAK,EAAE,MAAM,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;iBACjF,CAAC;YACJ,CAAC,CACF,CACF,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAEQ,MAAM,CAAC,OAAiC;QAC/C,OAAO,IAAI,CAAC,IAAI,CAAC,GAAkB,EAAE;YACnC,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC;IAEQ,IAAI;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,GAAkB,EAAE;YACnC,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QACjC,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,20 @@
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 '../../zekta-time-bucket.ts';
4
+ import { type OpenZektaTimeSeriesOptions } from '../../zekta-time-series.ts';
5
+ export interface OpenZektaNumberTimeSeriesOptions extends Omit<OpenZektaTimeSeriesOptions, 'valueByteLength'> {
6
+ readonly dirPath: PathInput;
7
+ readonly type: ZektaNumberTimeSeriesType;
8
+ }
9
+ export type ZektaNumberTimeSeriesType = 'u8' | 'i8' | 'u16' | 'i16' | 'u32' | 'i32' | 'f32' | 'f64';
10
+ export declare class ZektaNumberTimeSeries extends TimeSeries<number> {
11
+ #private;
12
+ static open({ type, ...options }: OpenZektaNumberTimeSeriesOptions): Promise<ZektaNumberTimeSeries>;
13
+ private constructor();
14
+ push(time: number, value: number): Promise<void>;
15
+ insert(entries: TimeSeriesEntry<number>[]): Promise<void>;
16
+ select(options?: TimeSeriesSelectOptions): Promise<readonly TimeSeriesEntry<number>[]>;
17
+ delete(options?: TimeSeriesDeleteOptions): Promise<void>;
18
+ drop(): Promise<void>;
19
+ flush(options?: ZektaTimeBucketFlushOptions): Promise<void>;
20
+ }