@camstack/types 1.2.445 → 1.2.447

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.
@@ -15,6 +15,7 @@ export declare const RemoteBindingActionSchema: z.ZodObject<{
15
15
  cap: z.ZodString;
16
16
  method: z.ZodString;
17
17
  args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
18
+ argUnits: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
18
19
  deviceId: z.ZodNumber;
19
20
  }, z.core.$strip>;
20
21
  export type RemoteBindingAction = z.infer<typeof RemoteBindingActionSchema>;
@@ -24,6 +25,7 @@ export declare const RemoteBindingSchema: z.ZodObject<{
24
25
  cap: z.ZodString;
25
26
  method: z.ZodString;
26
27
  args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
28
+ argUnits: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
27
29
  deviceId: z.ZodNumber;
28
30
  }, z.core.$strip>;
29
31
  }, z.core.$strip>;
@@ -50,6 +52,7 @@ export declare const RemoteConfigSchema: z.ZodObject<{
50
52
  cap: z.ZodString;
51
53
  method: z.ZodString;
52
54
  args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
55
+ argUnits: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
53
56
  deviceId: z.ZodNumber;
54
57
  }, z.core.$strip>;
55
58
  }, z.core.$strip>>;
@@ -8,6 +8,9 @@ export { UnitConversionError, unitDimension, convertUnit, tryConvertUnit, tryCon
8
8
  export type { UnitConversionReason } from './convert.js';
9
9
  export { DEFAULT_DISPLAY_PREFERENCE, DISPLAY_PREFERENCES, QUANTITY_BASE, ReadingQuantitySchema, baseUnitOf, displayUnitFor, historyUnitFor, isReadingQuantity, readingMeta, } from './quantity.js';
10
10
  export type { DisplayPreference, ReadingMeta, ReadingQuantity } from './quantity.js';
11
+ export { baseUnitForQuantity, unitsForQuantity } from './quantity-units.js';
12
+ export { QuantityUnitError, QuantityValueSchema, convertQuantityInput, isQuantityValue, paramMeta, paramMetaOf, } from './quantity-input.js';
13
+ export type { ConvertQuantityInput, ParamMeta, QuantityUnitErrorCode, QuantityValue, } from './quantity-input.js';
11
14
  export { thresholdToBase, thresholdToDisplay } from './threshold.js';
12
15
  export { formatReading } from './format-reading.js';
13
16
  export type { FormatReadingInput, FormattedReading } from './format-reading.js';
@@ -0,0 +1,58 @@
1
+ /**
2
+ * A number a person types for a physical quantity — the input side of the
3
+ * value + unit contract (D972).
4
+ *
5
+ * Readings are stored in the base unit of their quantity (D944); a cap method
6
+ * param is stored in the unit its input schema DECLARES (`paramMeta`). The
7
+ * wire pair {@link QuantityValue} says "this number is expressed in this
8
+ * unit"; {@link convertQuantityInput} brings it to the stored unit and refuses,
9
+ * with a typed {@link QuantityUnitError}, a unit that cannot be that quantity.
10
+ */
11
+ import { z } from 'zod';
12
+ import { type ReadingQuantity } from './quantity.js';
13
+ export type QuantityUnitErrorCode = 'non-finite' | 'unknown-unit' | 'cross-dimension'
14
+ /** A unit was given for a field or param that is not a quantity. */
15
+ | 'no-quantity';
16
+ /** A unit that cannot be applied to the number it was given with. */
17
+ export declare class QuantityUnitError extends Error {
18
+ readonly code: QuantityUnitErrorCode;
19
+ constructor(code: QuantityUnitErrorCode, message: string);
20
+ }
21
+ /** The wire pair: `value` is expressed in `unit`. */
22
+ export declare const QuantityValueSchema: z.ZodObject<{
23
+ value: z.ZodNumber;
24
+ unit: z.ZodString;
25
+ }, z.core.$strip>;
26
+ export type QuantityValue = z.infer<typeof QuantityValueSchema>;
27
+ export declare function isQuantityValue(candidate: unknown): candidate is QuantityValue;
28
+ export interface ConvertQuantityInput {
29
+ readonly value: number;
30
+ /** The unit `value` is expressed in, as the person picked it. */
31
+ readonly unit: string;
32
+ /** The unit to store: the quantity base, or a param's declared unit. */
33
+ readonly target: string;
34
+ }
35
+ /**
36
+ * `value` expressed in `unit`, brought to `target`. Throws
37
+ * {@link QuantityUnitError} for a non-finite value, an unknown unit or a unit
38
+ * of another dimension — never guesses.
39
+ */
40
+ export declare function convertQuantityInput(input: ConvertQuantityInput): number;
41
+ /** What a method input field declares: the quantity and the unit its value is in. */
42
+ export interface ParamMeta {
43
+ readonly [key: string]: unknown;
44
+ readonly quantity: ReadingQuantity;
45
+ readonly unit: string;
46
+ }
47
+ /**
48
+ * Zod `.meta()` bag for a cap METHOD param that is a physical quantity — the
49
+ * input-side twin of `readingMeta`. The value is carried in `unit` (a gram
50
+ * portion stays in grams); the unit must belong to the quantity, checked once
51
+ * when the cap is declared.
52
+ */
53
+ export declare function paramMeta(declared: {
54
+ readonly quantity: ReadingQuantity;
55
+ readonly unit: string;
56
+ }): ParamMeta;
57
+ /** The `paramMeta` on a method input field (or its unwrapped leaf), if any. */
58
+ export declare function paramMetaOf(field: z.ZodType): ParamMeta | undefined;
@@ -0,0 +1,8 @@
1
+ import { type ReadingQuantity } from './quantity.js';
2
+ /** The unit a reading of `quantity` is stored in, or `undefined` when it has none. */
3
+ export declare function baseUnitForQuantity(quantity: ReadingQuantity): string | undefined;
4
+ /**
5
+ * The units a person can enter a number of `quantity` in — base unit first.
6
+ * Empty when the quantity carries no unit.
7
+ */
8
+ export declare function unitsForQuantity(quantity: ReadingQuantity): readonly string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/types",
3
- "version": "1.2.445",
3
+ "version": "1.2.447",
4
4
  "description": "Shared types, interfaces, and model catalogs for the CamStack detection ecosystem",
5
5
  "keywords": [
6
6
  "camstack",