Docs

Units & Semantics

Reach for this when a numeric property tracks a physical measurement — a temperature, a flow rate, a power draw. Declaring the quantity with semanticType makes Sixb validate the unit on every telemetry value, so you can't silently mix Celsius readings with millibars.

Money is not a unit. Business amounts are modeled as amount (double) plus a currency stringEnum — there is no Currency quantitative type. Only the physical quantities listed below are valid semanticType values.

The canonical business domain is unitless: Project.progress and Department.headcount are plain telemetry integers with no semanticType. Units come into play only when a property tracks a physical quantity — for example a facility temperature an operations platform also records:

TS
import { defineObjectType, prop } from "@sixb/core/ontology"

export const Facility = defineObjectType({
  id: "Facility",
  name: "Facility",
  properties: [
    prop("id", "string", { required: true, primary: true }),
    prop("name", "string", { required: true }),
    prop("temperature", "double", {
      mode: "telemetry",
      semanticType: "Temperature",
    }),
  ],
})

semanticType

semanticType is an option on prop(...) whose value is a quantitative type id ("Temperature", "Pressure", "Power", …). It only makes sense on numeric schemas — "double", "integer", or "decimal".

AspectDetail
Whereprop(id, schema, { semanticType }), an ObjectFieldSchema, or a value type
TypeA QuantitativeTypeId from the catalog
EffectConstrains which unit strings are valid for telemetry on the property
InheritanceA property referencing a value type inherits that value type's semanticType

Declare it once on a shared value type to keep many properties consistent:

TS
import { defineValueType } from "@sixb/core/ontology"

export const TemperatureReading = defineValueType({
  id: "temperatureReading",
  name: "Temperature Reading",
  schema: "double",
  semanticType: "Temperature",
})

Any property that references temperatureReading inherits the Temperature constraint automatically.

How units validate telemetry

When you append telemetry, pass the reading's unit. Sixb resolves the property's semantic type (from the property or its value type) and checks the unit against the quantity's catalog before writing.

TS
await sixb
  .objects(Facility)
  .byId("facility-1")
  .telemetry(Facility.p.temperature)
  .append({ value: 21.5, unit: "degreeCelsius", at: new Date() })

The rules:

Property stateunit providedResult
Has semanticTypeValid unit for the quantityAccepted
Has semanticTypeInvalid unit for the quantityThrows Invalid unit '…'
Has semanticTypeMissingThrows Missing unit for telemetry property …
No semanticTypeAny unitThrows does not define semanticType and cannot accept a unit
No semanticTypeMissingAccepted (unitless)

Errors are [Sixb]-prefixed. The invalid-unit message names the property path and quantity:

TXT
[Sixb] Invalid unit 'millibar' for Facility.temperature (Temperature)

The quantitative types catalog

The registry lives in @sixb/core (and is re-exported from @sixb/core/ontology), keyed by quantitative type id. Each entry names a physical quantity and lists its valid units, where every unit has a name and a display symbol. The full set of ids:

Quantitative type idMeasures
AccelerationRate of change of velocity
AngleRotation between two rays
AngularAccelerationRate of change of angular velocity
AngularVelocityRate of rotation around an axis
ApparentEnergyIntegral of apparent power over time
ApparentPowerRMS voltage × RMS current in an AC circuit
AreaExtent of a two-dimensional surface
CapacitanceAbility to store an electric charge
ConcentrationAmount of substance per unit volume/mass
CurrentFlow of electric charge
DataRateData transferred per unit time
DataSizeAmount of digital information
DensityMass per unit volume
DistanceHow far apart two points are
ElectricChargeQuantity of electric charge
EnergyCapacity to do work
EnergyRateRate of energy transfer or conversion
ForceInteraction that changes an object's motion
FrequencyOccurrences per unit time
HumidityAbsolute moisture content (mass per volume)
IlluminanceLuminous flux on a surface per area
InductanceOpposition to change in current
IonizingRadiationDoseAbsorbed dose of ionizing radiation
IrradianceEM radiation power per unit area
LatitudeAngular distance north/south of the equator
LengthOne-dimensional extent
LongitudeAngular distance east/west of the prime meridian
LuminanceLuminous intensity per unit area
LuminosityEM energy emitted per unit time
LuminousFluxTotal visible light emitted by a source
LuminousIntensityLuminous flux per unit solid angle
MagneticFluxTotal magnetic field through an area
MagneticInductionMagnetic flux density
MassQuantity of matter
MassFlowRateMass passing a point per unit time
PowerRate of energy transfer or work
PressureForce applied per unit area
RadioactivityRate of radioactive decay
ReactiveEnergyIntegral of reactive power over time
ReactivePowerPower oscillating between source and load
RelativeDensityDensity relative to a reference substance
RelativeHumidityCurrent moisture vs. saturation capacity
ResistanceOpposition to flow of electric current
SoundPressureLocal pressure deviation caused by sound
TemperatureDegree of hotness or coldness
ThrustReaction force from expelling mass
TimeSpanDuration of time (numeric)
TorqueRotational force
VelocitySpeed in a given direction
VoltageElectric potential difference
VolumeExtent of a three-dimensional space
VolumeFlowRateVolume of fluid passing a point per unit time

A few example unit sets:

QuantityUnit ids
TemperaturedegreeCelsius, degreeFahrenheit, kelvin
Pressurebar, pascal, kilopascal, millibar, poundPerSquareInch, …
Powerwatt, kilowatt, megawatt, horsepower, …
Energyjoule, kilojoule, wattHour, kilowattHour, …

Units API

These helpers and types are exported from @sixb/core for browsing and validating units at runtime:

ExportSignatureReturns
quantitativeTypesconst registryThe full catalog, keyed by quantitative type id
getUnit(unitId)(string)The unit (name, symbol) plus its quantitativeTypeId, or undefined
getUnitsFor(qtId)(string)The Record<string, Unit> of valid units, or undefined
isValidUnit(qtId, unitId)(string, string)boolean — is the unit valid for the quantity
getUnitSymbol(unitId)(string)The display symbol, or undefined
isQuantitativeTypeId(value)(string)Type guard for QuantitativeTypeId
isUnitId(value)(string)Type guard for UnitId

Type-level helpers: QuantitativeTypeId, UnitId, and UnitsOf<Q> (the unit id union for one quantity).

TS
import { getUnit, getUnitSymbol, isValidUnit, quantitativeTypes } from "@sixb/core"

quantitativeTypes.Temperature.units.degreeCelsius.symbol // "°C"

isValidUnit("Temperature", "degreeCelsius") // true
isValidUnit("Temperature", "millibar")      // false

getUnitSymbol("kilowattHour") // "kWh"
getUnit("degreeCelsius")
// => { name: "Degree Celsius", symbol: "°C", quantitativeTypeId: "Temperature" }
TS
import type { UnitsOf } from "@sixb/core"

type TempUnit = UnitsOf<"Temperature">
// => "degreeCelsius" | "degreeFahrenheit" | "kelvin"

Search docs

Search the documentation