Skip to content

@mostlyrightmd/core/temporal

A filtered, knowledge-time-bounded view over an array of rows.

Row extends object

— caller’s row type. Must have a string knowledge_time field.

new KnowledgeView<Row>(rows, asOf): KnowledgeView<Row>

readonly Row[]

TimePoint

KnowledgeView<Row>

get asOf(): TimePoint

The as-of cutoff supplied at construction.

TimePoint

rows(): readonly Row[]

Return a freshly filtered array — only rows where knowledge_time <= asOf. The returned array is a new reference each call (defensive copy semantics), so callers can mutate it without affecting subsequent calls.

readonly Row[]


Convenience wrapper for repeated leakage checks against a fixed asOf.

const detector = new LeakageDetector(asOf);
detector.check(trainingRows);
detector.check(featureRows);

new LeakageDetector(asOf): LeakageDetector

TimePoint

LeakageDetector

get asOf(): TimePoint

TimePoint

check<Row>(rows): void

Row extends object

readonly Row[]

void

checkIssuedAt<Row>(rows): void

Defensive non-null check for issuedAt.

Independent of asOf — the bound cutoff is irrelevant when the row carries no model-run time at all. Throws IssuedAtMissingError if any row’s issuedAt is null/undefined/empty.

Row extends object

readonly Row[]

void


UTC-aware timestamp wrapper.

Equivalent to Python’s mostlyright.core.TimePoint. Constructed from either a Date (rejects NaN/Infinity) or a tz-aware ISO 8601 string (rejects naive / date-only inputs). Stored as an epoch-ms Date (for display/timezone operations) plus an epoch-µs bigint (for comparisons).

Immutable: the underlying Date is hidden behind a private #utc field and toUTCDate() returns a defensive copy so callers cannot mutate the wrapped instant. The #epochMicros field carries full µs precision captured from string inputs with 4-6 digit fractional seconds.

new TimePoint(value): TimePoint

string | Date

TimePoint

after(other): boolean

TimePoint

boolean

asZone(tz): string

Format this instant in an IANA timezone via Intl.DateTimeFormat. Display helper only — canonical storage stays UTC.

Uses en-CA locale for a YYYY-MM-DD, HH:MM:SS shape that’s easy to grep in logs. The exact output format may vary slightly across Node releases; callers writing tests should use loose contains-style assertions.

string

string

before(other): boolean

TimePoint

boolean

equals(other): boolean

TimePoint

boolean

static now(): TimePoint

Return a TimePoint for the current UTC instant.

TimePoint

toEpochMicros(): bigint

Return the epoch microseconds as a bigint.

This is the comparison-safe accessor. JS Date only carries ms precision, so callers comparing toUTCDate().getTime() across two TimePoints constructed from .123456Z and .123789Z would see them as equal — they’re not. Use equals/before/after (or this accessor directly) to compare with full µs precision.

bigint

toISOString(): string

Return the canonical ISO 8601 UTC string (always ends in ‘Z’).

string

toPythonIso(): string

Return the Python-compatible ISO 8601 UTC string.

Where toISOString emits the JS-native "...Z" suffix and forces .000 millisecond padding, this method matches Python’s datetime.isoformat() output for a UTC-tz-aware datetime:

  • tz suffix is +00:00, never Z
  • subsecond portion is omitted when zero ("...T12:00:00+00:00")
  • microsecond portion appears as 6 digits when non-zero ("...T12:00:00.123456+00:00"); built from the µs-precision #epochMicros field so 4-6 digit fractional inputs round-trip exactly.

Used by error payloads (LeakageError.toDict, sample violations) so MCP clients comparing the on-wire string across the Python and TS SDKs see byte-equivalent values with full microsecond precision.

string

toUTCDate(): Date

Return a defensive copy of the underlying UTC Date.

Date

assertIssuedAtPopulated<Row>(rows): void

Throw IssuedAtMissingError if any row’s issuedAt is null/undefined/empty.

Mirrors Python assert_issued_at_populated(). A forecast row has to carry its model-run time to be leakage-safe; a missing issuedAt leaves no way to verify the cycle predated the asOf cutoff. The Open-Meteo fetcher derives issuedAt for every row it emits, so this check is a defensive net rather than an expected failure path.

Row extends object

readonly Row[]

void


assertNoLeakage<Row>(rows, asOf): void

Throw LeakageError if any row’s knowledge_time is strictly greater than asOf. Leak-free input returns void.

Loudly rejects rows whose knowledge_time is missing, not a string, or not a tz-aware ISO 8601 datetime — these raise SchemaValidationError (rule: required / datetime_dtype / tz_aware_utc), mirroring Python’s assert_no_leakage validation contract.

Row extends object

— caller’s row type. Must have a string knowledge_time field.

readonly Row[]

TimePoint

void