// What the events of several interfaces have in common. import { CAUSES } from "./catalog.js"; import type { Cause } from "./catalog.js"; import { s } from "./schema.js"; /** The time of an event: now, unless the payload says when. */ export const timestamp = s.defaulted(s.dateTime(), () => new Date().toISOString()); /** * The payload of an event that happened at a time and for a reason: ActivationStarted, DoorbellPress. Both are * required by Alexa. The cause is the usual one of the event unless the payload names another. */ export const happened = (usually: Cause) => s.object({ cause: s.defaulted(s.object({ type: s.enum(...CAUSES) }), () => ({ type: usually })), timestamp, });