@utiliread/primitives 1.0.0-144 → 1.0.0-146

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 (121) hide show
  1. package/dist/csv.d.ts +3 -3
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.mjs.map +1 -1
  4. package/package.json +1 -1
  5. package/src/aggregate-id.ts +9 -9
  6. package/src/breakdown-rule.spec.ts +61 -61
  7. package/src/breakdown-rule.ts +58 -58
  8. package/src/csv.spec.ts +42 -34
  9. package/src/csv.ts +9 -9
  10. package/src/cursor-navigation-state.spec.ts +194 -194
  11. package/src/cursor-navigation-state.ts +168 -168
  12. package/src/index.ts +61 -61
  13. package/src/measure-id.ts +17 -17
  14. package/src/measures/duration.ts +11 -11
  15. package/src/measures/energy.ts +13 -13
  16. package/src/measures/humidity.ts +3 -3
  17. package/src/measures/infocode.ts +3 -3
  18. package/src/measures/mass-flow.ts +19 -19
  19. package/src/measures/mass.ts +10 -10
  20. package/src/measures/noise.ts +5 -5
  21. package/src/measures/power.ts +23 -23
  22. package/src/measures/pressure.ts +9 -9
  23. package/src/measures/reactive-energy.ts +7 -7
  24. package/src/measures/reactive-power.ts +3 -3
  25. package/src/measures/temperature.ts +9 -9
  26. package/src/measures/time.ts +3 -3
  27. package/src/measures/volume-flow.ts +25 -25
  28. package/src/measures/volume.ts +3 -3
  29. package/src/medium.spec.ts +12 -12
  30. package/src/medium.ts +47 -47
  31. package/src/number-formatter.spec.ts +549 -549
  32. package/src/number-formatter.ts +118 -118
  33. package/src/optional.ts +1 -1
  34. package/src/precision-number.spec.ts +251 -251
  35. package/src/precision-number.ts +123 -123
  36. package/src/register-convention.spec.ts +52 -52
  37. package/src/register-convention.ts +70 -70
  38. package/src/register-definition.ts +23 -23
  39. package/src/register-id.ts +288 -288
  40. package/src/register-library.spec.ts +41 -41
  41. package/src/register-library.ts +64 -64
  42. package/src/register-pack.ts +5 -5
  43. package/src/register-utils.ts +6 -6
  44. package/src/registers/acoustic-noise.ts +52 -52
  45. package/src/registers/ambient-temperature.ts +52 -52
  46. package/src/registers/axioma-infocode.ts +16 -16
  47. package/src/registers/consumer.ts +17 -17
  48. package/src/registers/cooling-energy-inlet.ts +23 -23
  49. package/src/registers/cooling-energy-outlet.ts +23 -23
  50. package/src/registers/cooling-energy.ts +23 -23
  51. package/src/registers/cooling.ts +113 -113
  52. package/src/registers/device-addresses-kamdraft.ts +14 -14
  53. package/src/registers/device-addresses-msisdn.ts +14 -14
  54. package/src/registers/device-addresses-tchlr.ts +14 -14
  55. package/src/registers/device-addresses-wmbus.ts +17 -17
  56. package/src/registers/device-date-time.ts +9 -9
  57. package/src/registers/device-date.ts +9 -9
  58. package/src/registers/device-nominal-diameter.ts +9 -9
  59. package/src/registers/device-permanent-volume-flow.ts +9 -9
  60. package/src/registers/device-registers.ts +9 -9
  61. package/src/registers/device-samples.ts +37 -37
  62. package/src/registers/device-software-version.ts +8 -8
  63. package/src/registers/device-time.ts +9 -9
  64. package/src/registers/device.ts +16 -16
  65. package/src/registers/diehl-infocode.ts +44 -44
  66. package/src/registers/electrical-energy.ts +23 -23
  67. package/src/registers/energy-inlet.ts +23 -23
  68. package/src/registers/energy-outlet.ts +23 -23
  69. package/src/registers/error-operating-time.ts +23 -23
  70. package/src/registers/flow-temperature-aux.ts +52 -52
  71. package/src/registers/flow-temperature-inlet.ts +52 -52
  72. package/src/registers/flow-temperature-outlet.ts +52 -52
  73. package/src/registers/flow-temperature.ts +52 -52
  74. package/src/registers/heat-energy-inlet.ts +65 -65
  75. package/src/registers/heat-energy-outlet.ts +65 -65
  76. package/src/registers/heat-energy.ts +65 -65
  77. package/src/registers/index.ts +71 -71
  78. package/src/registers/infocode.ts +70 -70
  79. package/src/registers/kamstrup-module-type.ts +8 -8
  80. package/src/registers/kamstrup-multical-infocode.ts +58 -58
  81. package/src/registers/landis-gyr-infocode.ts +23 -23
  82. package/src/registers/landis-gyr-mbus-status.ts +23 -23
  83. package/src/registers/mass-flow-inlet.ts +52 -52
  84. package/src/registers/mass-flow-outlet.ts +52 -52
  85. package/src/registers/mass-flow.ts +52 -52
  86. package/src/registers/mass-inlet.ts +23 -23
  87. package/src/registers/mass-outlet.ts +23 -23
  88. package/src/registers/mass.ts +23 -23
  89. package/src/registers/mbus-format-string-signature.ts +8 -8
  90. package/src/registers/none.ts +8 -8
  91. package/src/registers/operating-time.ts +23 -23
  92. package/src/registers/place.ts +31 -31
  93. package/src/registers/power-inlet.ts +52 -52
  94. package/src/registers/power-outlet.ts +52 -52
  95. package/src/registers/power.ts +52 -52
  96. package/src/registers/pressure-inlet.ts +52 -52
  97. package/src/registers/pressure-outlet.ts +52 -52
  98. package/src/registers/pressure.ts +52 -52
  99. package/src/registers/radiator-temperature.ts +52 -52
  100. package/src/registers/reactive-energy.ts +23 -23
  101. package/src/registers/relative-humidity.ts +8 -8
  102. package/src/registers/remaining-battery-time.ts +23 -23
  103. package/src/registers/time-last-exact-overhearing-arrived.ts +19 -19
  104. package/src/registers/time-last-installation-mounted.ts +19 -19
  105. package/src/registers/time-last-possible-candidate-overhearing-arrived.ts +21 -21
  106. package/src/registers/time-last-sampled.ts +19 -19
  107. package/src/registers/time.ts +45 -45
  108. package/src/registers/volume-flow-inlet.ts +52 -52
  109. package/src/registers/volume-flow-outlet.ts +52 -52
  110. package/src/registers/volume-flow.ts +52 -52
  111. package/src/registers/volume-inlet.ts +23 -23
  112. package/src/registers/volume-outlet.ts +23 -23
  113. package/src/registers/volume-pulse-input-a.ts +23 -23
  114. package/src/registers/volume-pulse-input-b.ts +23 -23
  115. package/src/registers/volume.ts +23 -23
  116. package/src/repository.spec.ts +30 -30
  117. package/src/repository.ts +26 -26
  118. package/src/step.spec.ts +37 -37
  119. package/src/step.ts +45 -45
  120. package/src/time-or-rule.ts +42 -42
  121. package/src/unit-id.ts +108 -108
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utiliread/primitives",
3
- "version": "1.0.0-144",
3
+ "version": "1.0.0-146",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -1,9 +1,9 @@
1
- export type AggregateId =
2
- | "instant"
3
- | "diff"
4
- | "min"
5
- | "max"
6
- | "avg"
7
- | "sum"
8
- | "cnt"
9
- | "ssq";
1
+ export type AggregateId =
2
+ | "instant"
3
+ | "diff"
4
+ | "min"
5
+ | "max"
6
+ | "avg"
7
+ | "sum"
8
+ | "cnt"
9
+ | "ssq";
@@ -1,61 +1,61 @@
1
- import { BreakdownRule } from "./breakdown-rule";
2
- import { DateTime } from "luxon";
3
- import { TimeOrRule } from ".";
4
- import { expect } from "chai";
5
-
6
- describe("ctor", () => {
7
- it("creates", () => {
8
- expect(
9
- BreakdownRule({ origin: "", count: 1, period: "hour" }),
10
- ).to.equal("/1hour");
11
- expect(
12
- BreakdownRule({ origin: "", count: 2, period: "hour" }),
13
- ).to.equal("/2hours");
14
- expect(
15
- BreakdownRule({ origin: "day", count: 1, period: "hour" }),
16
- ).to.equal("day/1hour");
17
- expect(
18
- BreakdownRule({ origin: "day", count: 2, period: "hour" }),
19
- ).to.equal("day/2hours");
20
-
21
- expect(BreakdownRule("", 1, "hour")).to.equal("/1hour");
22
- expect(BreakdownRule("", 2, "hour")).to.equal("/2hours");
23
- expect(BreakdownRule("day", 1, "hour")).to.equal("day/1hour");
24
- expect(BreakdownRule("day", 2, "hour")).to.equal("day/2hours");
25
- });
26
- });
27
-
28
- describe("split", () => {
29
- it("splits without origin", () => {
30
- const { origin, count, period } = BreakdownRule.split("/1hour");
31
- expect(origin).to.equal("");
32
- expect(count).to.equal(1);
33
- expect(period).to.equal("hour");
34
- });
35
-
36
- it("splits with simple origin", () => {
37
- const { origin, count, period } = BreakdownRule.split("day/1hour");
38
- expect(origin).to.equal("day");
39
- expect(count).to.equal(1);
40
- expect(period).to.equal("hour");
41
- });
42
-
43
- it("splits with complex origin and plural count", () => {
44
- const { origin, count, period } = BreakdownRule.split(
45
- "day+PT1H_year^month/10hours",
46
- );
47
- expect(origin).to.equal("day+PT1H_year^month");
48
- expect(count).to.equal(10);
49
- expect(period).to.equal("hour");
50
- });
51
-
52
- it("splits with time origin", () => {
53
- const { origin, count, period } = BreakdownRule.split(
54
- "2024-01-25T00:00:00.000+01:00/1hour",
55
- );
56
- expect(TimeOrRule.isTime(origin)).to.equal(true);
57
- expect(+origin).to.equal(+DateTime.local(2024, 1, 25));
58
- expect(count).to.equal(1);
59
- expect(period).to.equal("hour");
60
- });
61
- });
1
+ import { BreakdownRule } from "./breakdown-rule";
2
+ import { DateTime } from "luxon";
3
+ import { TimeOrRule } from ".";
4
+ import { expect } from "chai";
5
+
6
+ describe("ctor", () => {
7
+ it("creates", () => {
8
+ expect(
9
+ BreakdownRule({ origin: "", count: 1, period: "hour" }),
10
+ ).to.equal("/1hour");
11
+ expect(
12
+ BreakdownRule({ origin: "", count: 2, period: "hour" }),
13
+ ).to.equal("/2hours");
14
+ expect(
15
+ BreakdownRule({ origin: "day", count: 1, period: "hour" }),
16
+ ).to.equal("day/1hour");
17
+ expect(
18
+ BreakdownRule({ origin: "day", count: 2, period: "hour" }),
19
+ ).to.equal("day/2hours");
20
+
21
+ expect(BreakdownRule("", 1, "hour")).to.equal("/1hour");
22
+ expect(BreakdownRule("", 2, "hour")).to.equal("/2hours");
23
+ expect(BreakdownRule("day", 1, "hour")).to.equal("day/1hour");
24
+ expect(BreakdownRule("day", 2, "hour")).to.equal("day/2hours");
25
+ });
26
+ });
27
+
28
+ describe("split", () => {
29
+ it("splits without origin", () => {
30
+ const { origin, count, period } = BreakdownRule.split("/1hour");
31
+ expect(origin).to.equal("");
32
+ expect(count).to.equal(1);
33
+ expect(period).to.equal("hour");
34
+ });
35
+
36
+ it("splits with simple origin", () => {
37
+ const { origin, count, period } = BreakdownRule.split("day/1hour");
38
+ expect(origin).to.equal("day");
39
+ expect(count).to.equal(1);
40
+ expect(period).to.equal("hour");
41
+ });
42
+
43
+ it("splits with complex origin and plural count", () => {
44
+ const { origin, count, period } = BreakdownRule.split(
45
+ "day+PT1H_year^month/10hours",
46
+ );
47
+ expect(origin).to.equal("day+PT1H_year^month");
48
+ expect(count).to.equal(10);
49
+ expect(period).to.equal("hour");
50
+ });
51
+
52
+ it("splits with time origin", () => {
53
+ const { origin, count, period } = BreakdownRule.split(
54
+ "2024-01-25T00:00:00.000+01:00/1hour",
55
+ );
56
+ expect(TimeOrRule.isTime(origin)).to.equal(true);
57
+ expect(+origin).to.equal(+DateTime.local(2024, 1, 25));
58
+ expect(count).to.equal(1);
59
+ expect(period).to.equal("hour");
60
+ });
61
+ });
@@ -1,58 +1,58 @@
1
- import { TimeOrRule } from "./time-or-rule";
2
-
3
- export type BreakdownRule = string;
4
- export type BreakdownPeriod = "hour" | "day" | "week" | "month" | "year";
5
-
6
- interface BreakdownRuleInit {
7
- origin: TimeOrRule;
8
- count: number;
9
- period: BreakdownPeriod;
10
- }
11
-
12
- export function BreakdownRule(init: BreakdownRuleInit): BreakdownRule;
13
- export function BreakdownRule(
14
- origin: TimeOrRule,
15
- count: number,
16
- period: BreakdownPeriod,
17
- ): BreakdownRule;
18
- export function BreakdownRule(...params: any[]): BreakdownRule {
19
- let init: BreakdownRuleInit;
20
- switch (params.length) {
21
- case 1:
22
- init = params[0];
23
- break;
24
- case 3:
25
- init = {
26
- origin: params[0],
27
- count: params[1],
28
- period: params[2],
29
- };
30
- break;
31
- default:
32
- throw new TypeError("Invalid breakdown rule format");
33
- }
34
- const periodName =
35
- Math.abs(init.count) == 1 ? init.period : init.period + "s";
36
- return `${init.origin}/${init.count}${periodName}`;
37
- }
38
-
39
- export namespace BreakdownRule {
40
- const regex = new RegExp("(.*)/([-+]?[0-9]+)(hour|day|week|month|year)s?");
41
- export function split(rule: BreakdownRule) {
42
- const match = regex.exec(rule);
43
- if (!match) {
44
- throw new Error("Invalid breakdown rule format");
45
- }
46
- const origin = match[1];
47
- const count = parseInt(match[2]);
48
- let period = match[3];
49
- if (period.endsWith("s")) {
50
- period = period.substring(0, period.length - 1);
51
- }
52
- return {
53
- origin: TimeOrRule.parse(origin),
54
- count,
55
- period: period as BreakdownPeriod,
56
- };
57
- }
58
- }
1
+ import { TimeOrRule } from "./time-or-rule";
2
+
3
+ export type BreakdownRule = string;
4
+ export type BreakdownPeriod = "hour" | "day" | "week" | "month" | "year";
5
+
6
+ interface BreakdownRuleInit {
7
+ origin: TimeOrRule;
8
+ count: number;
9
+ period: BreakdownPeriod;
10
+ }
11
+
12
+ export function BreakdownRule(init: BreakdownRuleInit): BreakdownRule;
13
+ export function BreakdownRule(
14
+ origin: TimeOrRule,
15
+ count: number,
16
+ period: BreakdownPeriod,
17
+ ): BreakdownRule;
18
+ export function BreakdownRule(...params: any[]): BreakdownRule {
19
+ let init: BreakdownRuleInit;
20
+ switch (params.length) {
21
+ case 1:
22
+ init = params[0];
23
+ break;
24
+ case 3:
25
+ init = {
26
+ origin: params[0],
27
+ count: params[1],
28
+ period: params[2],
29
+ };
30
+ break;
31
+ default:
32
+ throw new TypeError("Invalid breakdown rule format");
33
+ }
34
+ const periodName =
35
+ Math.abs(init.count) == 1 ? init.period : init.period + "s";
36
+ return `${init.origin}/${init.count}${periodName}`;
37
+ }
38
+
39
+ export namespace BreakdownRule {
40
+ const regex = new RegExp("(.*)/([-+]?[0-9]+)(hour|day|week|month|year)s?");
41
+ export function split(rule: BreakdownRule) {
42
+ const match = regex.exec(rule);
43
+ if (!match) {
44
+ throw new Error("Invalid breakdown rule format");
45
+ }
46
+ const origin = match[1];
47
+ const count = parseInt(match[2]);
48
+ let period = match[3];
49
+ if (period.endsWith("s")) {
50
+ period = period.substring(0, period.length - 1);
51
+ }
52
+ return {
53
+ origin: TimeOrRule.parse(origin),
54
+ count,
55
+ period: period as BreakdownPeriod,
56
+ };
57
+ }
58
+ }
package/src/csv.spec.ts CHANGED
@@ -1,34 +1,42 @@
1
- import { expect } from "chai";
2
-
3
- import { csv, type Csv } from "./csv";
4
-
5
- type Equal<A, B> =
6
- (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2
7
- ? true
8
- : false;
9
- type Expect<T extends true> = T;
10
-
11
- describe("csv", () => {
12
- it("should join values with commas", () => {
13
- expect(csv(["a", "b", "c"])).to.equal("a,b,c");
14
- });
15
-
16
- it("should return empty string for empty array", () => {
17
- expect(csv([])).to.equal("");
18
- });
19
-
20
- it("should infer Csv type from tuple values", () => {
21
- const value = csv(["hello", "world"] as const);
22
-
23
- const _typeCheck: Expect<Equal<typeof value, Csv<"hello" | "world">>> =
24
- true;
25
- expect(_typeCheck).to.equal(true);
26
- });
27
-
28
- it("should allow assignment to matching Csv union", () => {
29
- const value = csv(["x", "y"] as const);
30
- const accepted: Csv<"x" | "y"> = value;
31
-
32
- expect(accepted).to.equal("x,y");
33
- });
34
- });
1
+ import { expect } from "chai";
2
+
3
+ import { csv, type Csv } from "./csv";
4
+
5
+ type Equal<A, B> =
6
+ (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2
7
+ ? true
8
+ : false;
9
+ type Expect<T extends true> = T;
10
+
11
+ describe("csv", () => {
12
+ it("should infer Csv type from single value", () => {
13
+ // single value "hello" is implicitly assignable to Csv<"hello" | "world">
14
+ const _wider: Csv<"hello" | "world"> = "hello";
15
+
16
+ // @ts-expect-error - "invalid" is not assignable to Csv<"hello" | "world">
17
+ const _invalid: Csv<"hello" | "world"> = "invalid";
18
+ });
19
+
20
+ it("should join values with commas", () => {
21
+ expect(csv(["a", "b", "c"])).to.equal("a,b,c");
22
+ });
23
+
24
+ it("should return empty string for empty array", () => {
25
+ expect(csv([])).to.equal("");
26
+ });
27
+
28
+ it("should infer Csv type from tuple values", () => {
29
+ const value = csv(["hello", "world"] as const);
30
+
31
+ const _typeCheck: Expect<Equal<typeof value, Csv<"hello" | "world">>> =
32
+ true;
33
+ expect(_typeCheck).to.equal(true);
34
+ });
35
+
36
+ it("should allow assignment to matching Csv union", () => {
37
+ const value = csv(["x", "y"] as const);
38
+ const accepted: Csv<"x" | "y"> = value;
39
+
40
+ expect(accepted).to.equal("x,y");
41
+ });
42
+ });
package/src/csv.ts CHANGED
@@ -1,9 +1,9 @@
1
- export type Csv<T extends string = string> = string & {
2
- readonly __csvValuesBrand?: T;
3
- };
4
-
5
- export function csv<const T extends readonly string[]>(
6
- values: T,
7
- ): Csv<T[number]> {
8
- return values.join(",") as Csv<T[number]>;
9
- }
1
+ export type Csv<T extends string = string> =
2
+ | T
3
+ | (string & { readonly __csvValuesBrand: T });
4
+
5
+ export function csv<const T extends readonly string[]>(
6
+ values: T,
7
+ ): Csv<T[number]> {
8
+ return values.join(",") as Csv<T[number]>;
9
+ }