An immutable event made of a temporal key and typed payload data.
Constructor
new Event(key: K, data: D)
new Event(new Time(Date.now()), { value: 1 })Creates an immutable event from a key and typed payload object.
Methods
asInterval
asInterval(value: IntervalValue): Event<Interval, D>
event.asInterval("bucket-a")Converts the event key to a labeled Interval covering the same extent.
asInterval(getValue: (event: Event<K, D>) => IntervalValue): Event<Interval, D>
event.asInterval("bucket-a")Converts the event key to a labeled Interval covering the same extent.
asTime
asTime(options?: { at?: 'begin' | 'end' | 'center' }): Event<Time, D>
event.asTime({ at: "center" })Converts the event key to a point-in-time key using the supplied anchor within the current extent.
asTimeRange
asTimeRange(): Event<TimeRange, D>
event.asTimeRange()Converts the event key to an unlabeled TimeRange covering the same extent.
begin
begin(): number
event.begin()Returns the inclusive event start in milliseconds since epoch.
collapse
collapse(keys: Keys, output: Name, reducer: (values: Pick<D, Keys[number]>) => R): Event<K, Readonly<Omit<D, Keys[number]> & Record<Name, R>>>
event.collapse(["in", "out"], "avg", fn)Collapses selected payload fields into a single derived field using the supplied reducer.
collapse(keys: Keys, output: Name, reducer: (values: Pick<D, Keys[number]>) => R, options: { append: true }): Event<K, Readonly<D & Record<Name, R>>>
event.collapse(["in", "out"], "avg", fn)Collapses selected payload fields into a single derived field using the supplied reducer.
contains
contains(other: TemporalLike): boolean
event.contains(time)Returns true when the event extent fully contains the supplied temporal value.
data
data(): Readonly<D>
event.data()Returns the immutable event payload.
end
end(): number
event.end()Returns the inclusive event end in milliseconds since epoch.
get
get(field: Field): Readonly<D>[Field]
event.get("value")Returns a single payload field by name.
intersection
intersection(other: TemporalLike): TimeRange | undefined
event.intersection(range)Returns the temporal intersection of the event extent and the supplied value, if any.
isAfter
isAfter(other: TemporalLike): boolean
event.isAfter(range)Returns true when the event begins strictly after the supplied temporal value ends.
isBefore
isBefore(other: TemporalLike): boolean
event.isBefore(range)Returns true when the event ends strictly before the supplied temporal value begins.
key
key(): K
event.key()Returns the event key.
merge
merge(patch: U): Event<K, Readonly<D & U>>
event.merge({ host: "api-1" })Returns a new event with a shallow payload merge applied.
overlaps
overlaps(other: TemporalLike): boolean
event.overlaps(range)Returns true when the event extent overlaps the supplied temporal value.
rename
rename(mapping: Mapping): Event<K, Readonly<{ [Name in string as Name extends keyof Mapping ? Mapping[Name] extends string ? any[any] : Name : Name]: D[Name] }>>
event.rename({ cpu: "usage" })Returns a new event with payload fields renamed according to the supplied mapping.
select
select(keys: Keys): Event<K, Readonly<Pick<D, Keys[number]>>>
event.select("cpu", "healthy")Returns a new event containing only the selected payload fields.
set
set(field: Field, value: D[Field]): Event<K, D>
event.set("value", 2)Returns a new event with one payload field replaced.
timeRange
timeRange(): TimeRange
event.timeRange()Returns the event extent as a TimeRange.
toJsonRow
toJsonRow(schema: S, options?: { rowFormat?: 'array' }): JsonRowForSchema<S>
event.toJsonRow(schema)Returns the JSON-shape row
for this event — like Event.toRow but with the key
serialized to its JSON form (numeric ms / [start, end] /
[value, start, end]) and undefined cells emitted as null.
Pass { rowFormat: 'object' } to get the schema-keyed object
shape instead of the array tuple.
Mirrors TimeSeries.toJSON's row-level serialization, so
event.toJsonRow(schema) plugs straight into a wire envelope
that the receiver feeds into LiveSeries.pushJson(...) or
LiveSeries.fromJSON(...).
Trust contract: same as Event.toRow — no validation
against schema. Mismatched column names produce null
cells in the JSON output (serializeJsonValue(undefined)),
which round-trip through pushJson as undefined. Pass the
same as const schema the event was originally produced under.
toJsonRow(schema: S, options: { rowFormat: 'object' }): JsonObjectRowForSchema<S>
event.toJsonRow(schema)Returns the JSON-shape row
for this event — like Event.toRow but with the key
serialized to its JSON form (numeric ms / [start, end] /
[value, start, end]) and undefined cells emitted as null.
Pass { rowFormat: 'object' } to get the schema-keyed object
shape instead of the array tuple.
Mirrors TimeSeries.toJSON's row-level serialization, so
event.toJsonRow(schema) plugs straight into a wire envelope
that the receiver feeds into LiveSeries.pushJson(...) or
LiveSeries.fromJSON(...).
Trust contract: same as Event.toRow — no validation
against schema. Mismatched column names produce null
cells in the JSON output (serializeJsonValue(undefined)),
which round-trip through pushJson as undefined. Pass the
same as const schema the event was originally produced under.
toRow
toRow(schema: S): RowForSchema<S>
event.toRow(schema)Returns the typed-row tuple for
this event in the column order declared by schema — [key, ...values].
Use this in batch-listener fanout to convert a stream of Event
objects into the same shape LiveSeries.toRows() /
pushMany(rows) consume, without walking columns by hand:
live.on('batch', (events) => {
const rows = events.map((e) => e.toRow(schema));
sendOverWire(rows); // codec of your choice
});
Trust contract: no validation against schema. If the
caller passes a schema whose value-column names don't match the
event's payload keys, data[col.name] is undefined for every
mismatched column and the row is silently corrupt — downstream
pushMany(rows) accepts it (column count matches), but reads
via event.get('col') from the resulting events return
undefined. Pass the same as const schema the event was
originally produced under.
trim
trim(other: TemporalLike): Event<K, D> | undefined
event.trim(range)Returns a new event clipped to the supplied temporal value, if the event overlaps it.
type
type(): K['kind']
event.type()Returns the underlying key kind.
withKey
withKey(key: NextKey): Event<NextKey, D>
event.withKey(new Time(Date.now()))Returns a new event with the same payload and a different key.