Skip to Content
FFitDatadraft
Specification

Core & Sleep

Shared primitives, time variants, decimal quantities, UCUM unit subset, provenance, core.* records, and sleep.session.

@fitdata/core owns all shared primitives, envelopes, unit conversions, and the four cross-domain core.* records. It has no application or database dependency. sleep.session is composed in fitdata using the same core envelope and time primitives.

Shared primitives

Namespaced codes and extensions

  • Codes match /^[a-z][a-z0-9.-]*:[A-Za-z0-9_.-]+$/ (for example fitdata:heart_rate, fitdata:indoor_cycling, strava:calories).
  • Core objects use strict schemas that reject unknown properties.
  • Vendor- or app-specific fields belong under extensions, keyed by namespaced identifiers ("strava:source": { ... }).

Time variants

FitData never invents a midnight timestamp for a calendar date or a timezone for a numeric offset:

kindFieldsRules
instantatISO-8601 datetime with Z or explicit numeric UTC offset
intervalstart, durationSecondsNon-negative duration, maximum 1 year (31,536,000 s)
datedate, optional timezoneISO calendar date (YYYY-MM-DD); optional IANA timezone verified via runtime Intl

Quantities and decimal strings

Quantities pair value with a case-sensitive unit string. value accepts either a finite safe JSON number or a decimal string (^-?(?:0|[1-9]\d*)(?:\.\d+)?$). Decimal strings preserve exact source digits and trailing zeros, and metric range checks use exact decimal comparison (compareDecimal).

Units and conversions

convertQuantity({ value, from, to }) converts finite numbers across a reviewed UCUM-aligned subset:

DimensionSupported codes
Masskg, g, mg, ug, [lb_av], [oz_av]
VolumeL, mL, [foz_us], [foz_br], [cup_us], [cup_m], [tbs_us], [tsp_us], [tbs_m], [tsp_m]
Energykcal, kJ, J
Lengthm, km, cm, mm, [mi_i], [ft_i], [in_i]
Times, min, h, d
TemperatureCel, [degF], K

Unknown units and cross-dimension conversions fail explicitly. convertQuantity never infers food density.

Provenance

Optional provenance records how an entity was produced:

Provenance kindRequired fields
manualsource.provider
sensorsource.provider
importedsource.provider, mapper: { id, version }
derivedsource.provider, algorithm: { id, version }, inputs (references)

source can also include externalId, device, and originalSource.

Core record kinds

core.measurement

A point-in-time observation (revision lifecycle):

  • Required: metric (namespaced code), time, value.
  • Optional: laterality (left, right, bilateral).
  • value is a discriminated union: quantity, category (code), text, boolean, or absent (reason code).

core.series

A sampled time-series stream (revision lifecycle):

  • Required: interval, channels (1–16 { metric, unit } pairs), timing, samples, resolution (source or downsampled).
  • timing is either { kind: "regular", periodSeconds } or { kind: "irregular", offsetsSeconds }.
  • Every sample row width must equal channels.length. Missing readings are null. Irregular offsets must strictly increase and fit within interval.durationSeconds.

core.summary

Unified rollup for a day, interval, or meal (revision lifecycle):

  • Required: scope ({ kind: "day" }, { kind: "interval" }, or { kind: "meal", label }), time.
  • Optional: metrics (up to 500 MetricAmount entries), totals (up to 500 qualified nutrient totals), completeness (complete, partial, unknown), statistic (sum, minimum, maximum, last, mean), weighting (sample, time, not_applicable), sampleCount, coverage, source.

core.tombstone

Logical deletion marker (revision lifecycle):

  • Carries kind: "core.tombstone", id, revision, and optional recordedAt / provenance.
  • Contains no live domain payload.

Sleep: sleep.session

Owned by fitdata (SDK) using the core revisioned envelope:

  • Required: interval, stages (array of { stage, offsetSeconds, durationSeconds }), metrics.
  • Optional: isNap (boolean).
  • Semantic checks guarantee sleep stages do not overlap and fit within interval.durationSeconds. Gaps between stages remain valid and visible.

On this page