API: core (@fragiola/calendar)
Commands
Every command of the calendar model, generated from its catalogue.
Every change to a calendar is a command: model.run(name, payload) from code, or
model.dispatch({ command, payload }) for untrusted JSON. A command never throws on bad
input: it returns { ok: true, value } or { ok: false, error: { code, message, path } }
with the codes unknown_command, invalid_payload, not_found, refused, vetoed,
queued and middleware_error. model.get("commands") lists the same commands with their
JSON Schemas, ready to become an assistant's tools.
Events
event.add
Add an event. An all-day event takes YYYY-MM-DD dates, a timed one RFC 3339 date-times with their offset; end is exclusive and, when left out, defaultAllDayDuration days or defaultTimedDuration minutes after start. An id left out is generated.
Payload
| field | type | required | description |
|---|---|---|---|
id | string | no | |
kind | string | no | |
title | string | yes | |
start | string | yes | YYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00) |
end | string | no | YYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00) |
allDay | boolean | yes | |
timeZone | string | no | an IANA time zone name (America/Sao_Paulo) |
calendarId | string | no | |
recurrence | object | no | the occurrences of a recurring event (requires recurrence()) |
sourceId | string | no | the event source it came from (requires eventSources()) |
data | JSON | no | the app's data (any JSON) |
editable | boolean | no | |
startEditable | boolean | no | |
durationEditable | boolean | no | |
deletable | boolean | no |
Result
| field | type | required | description |
|---|---|---|---|
eventId | string | yes |
model.run("event.add", {"title":"Review","start":"2026-11-26T14:00:00-03:00","end":"2026-11-26T15:00:00-03:00","allDay":false,"calendarId":"work"});
model.dispatch({"command":"event.add","payload":{"title":"Review","start":"2026-11-26T14:00:00-03:00","end":"2026-11-26T15:00:00-03:00","allDay":false,"calendarId":"work"}});event.update
Change an event's fields: its title, its times (start and end in the form of its allDay after the change), its home timeZone or its calendarId (null removes either). Needs the event to be editable.
Payload
| field | type | required | description |
|---|---|---|---|
eventId | string | yes | the event |
title | string | no | |
start | string | no | YYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00) |
end | string | no | YYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00) |
allDay | boolean | no | |
timeZone | string | null | no | |
calendarId | string | null | no | |
occurrenceId | string | no | the occurrence edited, <eventId>@<original start> (requires recurrence()) |
scope | "this" | "following" | "all" | no | which occurrences of a recurring event change (requires recurrence()) |
Result
| field | type | required | description |
|---|---|---|---|
eventId | string | yes |
model.run("event.update", {"eventId":"standup","title":"Daily standup"});
model.dispatch({"command":"event.update","payload":{"eventId":"standup","title":"Daily standup"}});event.move
Move an event keeping its duration: to a new start (a date onto the all-day row, a date-time into the time grid; allDay says which, default the event's; between the two it takes the default duration unless allDayMaintainDuration), or by a delta (whole days keep the wall clock in the event's zone across DST, minutes are exact; minutes make an all-day event timed). Needs its start to be editable.
Payload
One of (1 of 2):
| field | type | required | description |
|---|---|---|---|
eventId | string | yes | the event |
start | string | yes | YYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00) |
allDay | boolean | no | |
occurrenceId | string | no | the occurrence edited, <eventId>@<original start> (requires recurrence()) |
scope | "this" | "following" | "all" | no | which occurrences of a recurring event change (requires recurrence()) |
One of (2 of 2):
| field | type | required | description |
|---|---|---|---|
eventId | string | yes | the event |
delta | object | yes | |
occurrenceId | string | no | the occurrence edited, <eventId>@<original start> (requires recurrence()) |
scope | "this" | "following" | "all" | no | which occurrences of a recurring event change (requires recurrence()) |
Result
| field | type | required | description |
|---|---|---|---|
eventId | string | yes | |
start | string | yes | YYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00) |
end | string | yes | YYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00) |
allDay | boolean | yes |
model.run("event.move", {"eventId":"standup","delta":{"days":1}});
model.dispatch({"command":"event.move","payload":{"eventId":"standup","delta":{"days":1}}});event.resize
Move one edge of an event: its end (exclusive; needs its duration to be editable) or its start (needs its start to be editable), to a date (all-day) or a date-time (timed). An end not after the start is refused.
Payload
| field | type | required | description |
|---|---|---|---|
eventId | string | yes | the event |
edge | "start" | "end" | yes | |
to | string | yes | YYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00) |
occurrenceId | string | no | the occurrence edited, <eventId>@<original start> (requires recurrence()) |
scope | "this" | "following" | "all" | no | which occurrences of a recurring event change (requires recurrence()) |
Result
| field | type | required | description |
|---|---|---|---|
eventId | string | yes | |
start | string | yes | YYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00) |
end | string | yes | YYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00) |
allDay | boolean | yes |
model.run("event.resize", {"eventId":"standup","edge":"end","to":"2026-11-26T10:00:00-03:00"});
model.dispatch({"command":"event.resize","payload":{"eventId":"standup","edge":"end","to":"2026-11-26T10:00:00-03:00"}});event.remove
Remove an event. Needs it to be deletable.
Payload
| field | type | required | description |
|---|---|---|---|
eventId | string | yes | the event |
occurrenceId | string | no | the occurrence edited, <eventId>@<original start> (requires recurrence()) |
scope | "this" | "following" | "all" | no | which occurrences of a recurring event change (requires recurrence()) |
Result
| field | type | required | description |
|---|---|---|---|
eventId | string | yes |
model.run("event.remove", {"eventId":"trip"});
model.dispatch({"command":"event.remove","payload":{"eventId":"trip"}});event.set-data
Replace an event's data (the app's, any JSON) and, with kind, the kind that types it. Leaving data out removes it.
Payload
| field | type | required | description |
|---|---|---|---|
eventId | string | yes | the event |
kind | string | no | |
data | JSON | no | the app's data (any JSON) |
Result
| field | type | required | description |
|---|---|---|---|
eventId | string | yes |
model.run("event.set-data", {"eventId":"standup","data":{"room":"Blue"}});
model.dispatch({"command":"event.set-data","payload":{"eventId":"standup","data":{"room":"Blue"}}});event.set-flags
Set an event's permission flags (editable, startEditable, durationEditable, deletable); null removes the event's own, so its calendar's or the settings' applies.
Payload
| field | type | required | description |
|---|---|---|---|
eventId | string | yes | the event |
editable | boolean | null | no | |
startEditable | boolean | null | no | |
durationEditable | boolean | null | no | |
deletable | boolean | null | no |
Result
| field | type | required | description |
|---|---|---|---|
eventId | string | yes |
model.run("event.set-flags", {"eventId":"standup","durationEditable":false});
model.dispatch({"command":"event.set-flags","payload":{"eventId":"standup","durationEditable":false}});event.set-all
Replace every event with events (an app's controlled list: give each its id). An event object the calendar already holds is kept as it is; the others are validated like the document's. The edit flags and the constraints, which guard the user's edits, do not apply; an event source's fetched ranges stay as they are (a list that drops a source's events does not refetch them).
Payload
| field | type | required | description |
|---|---|---|---|
events | object[] | yes |
Result
| field | type | required | description |
|---|---|---|---|
eventIds | string[] | yes | |
removedEventIds | string[] | yes |
model.run("event.set-all", {"events":[{"id":"standup","title":"Standup","start":"2026-11-26T09:00:00-03:00","end":"2026-11-26T09:15:00-03:00","allDay":false}]});
model.dispatch({"command":"event.set-all","payload":{"events":[{"id":"standup","title":"Standup","start":"2026-11-26T09:00:00-03:00","end":"2026-11-26T09:15:00-03:00","allDay":false}]}});Calendars
calendar.add
Add a calendar: a category of events (calendarId on an event), with its title (the app's), its data, whether its events are editable by default and whether they are visible. An id left out is generated.
Payload
| field | type | required | description |
|---|---|---|---|
id | string | no | |
title | string | yes | |
editable | boolean | no | |
visible | boolean | no | |
data | JSON | no | the app's data (any JSON) |
Result
| field | type | required | description |
|---|---|---|---|
calendarId | string | yes |
model.run("calendar.add", {"id":"home","title":"Home"});
model.dispatch({"command":"calendar.add","payload":{"id":"home","title":"Home"}});calendar.update
Change a calendar's title, its data, or whether its events are editable by default (null removes it, so the settings' applies).
Payload
| field | type | required | description |
|---|---|---|---|
calendarId | string | yes | the calendar |
title | string | no | |
editable | boolean | null | no | |
data | JSON | no | the app's data (any JSON) |
Result
| field | type | required | description |
|---|---|---|---|
calendarId | string | yes |
model.run("calendar.update", {"calendarId":"work","editable":false});
model.dispatch({"command":"calendar.update","payload":{"calendarId":"work","editable":false}});calendar.remove
Remove a calendar, and either its events (events: "remove") or only their calendarId (events: "keep").
Payload
| field | type | required | description |
|---|---|---|---|
calendarId | string | yes | the calendar |
events | "remove" | "keep" | yes |
Result
| field | type | required | description |
|---|---|---|---|
calendarId | string | yes | |
removedEventIds | string[] | yes |
model.run("calendar.remove", {"calendarId":"work","events":"keep"});
model.dispatch({"command":"calendar.remove","payload":{"calendarId":"work","events":"keep"}});calendar.set-visible
Show or hide a calendar's events in every view.
Payload
| field | type | required | description |
|---|---|---|---|
calendarId | string | yes | the calendar |
visible | boolean | yes |
Result
| field | type | required | description |
|---|---|---|---|
calendarId | string | yes |
model.run("calendar.set-visible", {"calendarId":"work","visible":false});
model.dispatch({"command":"calendar.set-visible","payload":{"calendarId":"work","visible":false}});Settings
settings.set
Change settings: each field given replaces the setting (the display timeZone, IANA or "local"; locale; firstDayOfWeek; hiddenDays; the time grid's slots; validRange; dayMaxEvents; eventOrder; the default durations; the edit flags; with their features, businessHours, eventConstraint, selectConstraint, overlap, eventSources). null removes an optional one (firstDayOfWeek, snapDuration, validRange, startEditable, durationEditable, deletable, and the settings of features) so its default applies.
Payload
| field | type | required | description |
|---|---|---|---|
settings | object | yes |
Result
| field | type | required | description |
|---|---|---|---|
settings | object | yes |
model.run("settings.set", {"settings":{"firstDayOfWeek":1,"hiddenDays":[0,6]}});
model.dispatch({"command":"settings.set","payload":{"settings":{"firstDayOfWeek":1,"hiddenDays":[0,6]}}});View and navigation
view.set
Change the view type, keeping the anchor date: month, week, day, days (with days: 1–14 days that are not hidden) or list (with an optional duration in days; without it, the anchor's month).
Payload
| field | type | required | description |
|---|---|---|---|
type | "month" | "week" | "day" | "days" | "list" | yes | |
days | integer | no | |
duration | integer | no |
Result
| field | type | required | description |
|---|---|---|---|
view | object | yes |
model.run("view.set", {"type":"days","days":3});
model.dispatch({"command":"view.set","payload":{"type":"days","days":3}});view.go-to
Show the view around a date (YYYY-MM-DD, or { year, month, day } as a date picker gives it). A date outside validRange is refused.
Payload
| field | type | required | description |
|---|---|---|---|
date | string | object | yes |
Result
| field | type | required | description |
|---|---|---|---|
view | object | yes |
model.run("view.go-to", {"date":"2026-12-24"});
model.dispatch({"command":"view.go-to","payload":{"date":"2026-12-24"}});view.next
Show the next range, by the view's own step: a month, a week, a day, days days that are not hidden, or a list's duration (its month without one). Refused when it would show only dates outside validRange.
Payload
No fields.
Result
| field | type | required | description |
|---|---|---|---|
view | object | yes |
model.run("view.next", {});
model.dispatch({"command":"view.next","payload":{}});view.previous
Show the previous range, by the view's own step (as view.next). Refused when it would show only dates outside validRange.
Payload
No fields.
Result
| field | type | required | description |
|---|---|---|---|
view | object | yes |
model.run("view.previous", {});
model.dispatch({"command":"view.previous","payload":{}});view.today
Show the view around today (the model's clock, in the display zone). Refused when today is outside validRange.
Payload
No fields.
Result
| field | type | required | description |
|---|---|---|---|
view | object | yes |
model.run("view.today", {});
model.dispatch({"command":"view.today","payload":{}});Batches
batch
Run several commands as one step: they apply in order, each seeing the result of the ones before it, and either all of them apply (one event, one undo step) or none does (the first failure is returned, at its path in commands).
Payload
| field | type | required | description |
|---|---|---|---|
commands | object[] | yes | the commands, in order |
Result
| field | type | required | description |
|---|---|---|---|
results | JSON[] | yes | each command's value, in order |
It may run as a transient step ({ transient: true }).
model.run("batch", {"commands":[{"command":"view.set","payload":{"type":"week"}},{"command":"view.next","payload":{}}]});
model.dispatch({"command":"batch","payload":{"commands":[{"command":"view.set","payload":{"type":"week"}},{"command":"view.next","payload":{}}]}});Recurrence
With the recurrence() feature installed:
import { recurrence } from "@fragiola/calendar/recurrence";
const model = createCalendarModel(json, { features: [recurrence()] });Without it, its commands are not_found.
event.set-recurrence
Make an event recurring, change its recurrence, or (null) make it a single event again. rule is an RFC 5545 RRULE of the subset FREQ (DAILY, WEEKLY, MONTHLY, YEARLY), INTERVAL, COUNT, UNTIL, BYDAY (2TU, -1FR in monthly and yearly rules), BYMONTHDAY, BYMONTH, WKST, expanded from the event's start at its wall-clock time in its zone; exdates are the original starts left out; overrides change one occurrence's title, or its start and end (and allDay), by its original start. Needs the event to be editable.
Payload
| field | type | required | description |
|---|---|---|---|
eventId | string | yes | the event |
recurrence | object | null | yes |
Result
| field | type | required | description |
|---|---|---|---|
eventId | string | yes |
model.run("event.set-recurrence", {"eventId":"standup","recurrence":{"rule":"FREQ=WEEKLY;BYDAY=MO,WE,FR","exdates":["2026-11-27T09:30:00-03:00"]}});
model.dispatch({"command":"event.set-recurrence","payload":{"eventId":"standup","recurrence":{"rule":"FREQ=WEEKLY;BYDAY=MO,WE,FR","exdates":["2026-11-27T09:30:00-03:00"]}}});Event sources
With the eventSources() feature installed:
import { eventSources } from "@fragiola/calendar/event-sources";
const model = createCalendarModel(json, { features: [eventSources()] });Without it, its commands are not_found.
event-sources.receive
Merge the events a source returned for a range of days (YYYY-MM-DD, end exclusive): the source's events touching the range (or with a received id) are replaced by events, atomically, and the range is marked fetched (and no longer loading). Events without a calendarId take the source's; their sourceId is the source.
Payload
| field | type | required | description |
|---|---|---|---|
sourceId | string | yes | the event source |
range | object | yes | |
events | object[] | yes |
Result
| field | type | required | description |
|---|---|---|---|
sourceId | string | yes | |
eventIds | string[] | yes | |
removedEventIds | string[] | yes |
model.run("event-sources.receive", {"sourceId":"holidays","range":{"start":"2026-11-01","end":"2026-12-01"},"events":[{"id":"republic-day","title":"Republic Day","start":"2026-11-15","end":"2026-11-16","allDay":true}]});
model.dispatch({"command":"event-sources.receive","payload":{"sourceId":"holidays","range":{"start":"2026-11-01","end":"2026-12-01"},"events":[{"id":"republic-day","title":"Republic Day","start":"2026-11-15","end":"2026-11-16","allDay":true}]}});event-sources.invalidate
Forget what was fetched, so ranges-to-fetch asks for it again (a refetch): of one source or of every source, within a range of days or all of it. Events stay until the next event-sources.receive replaces them.
Payload
| field | type | required | description |
|---|---|---|---|
sourceId | string | no | the event source |
range | object | no |
Result
| field | type | required | description |
|---|---|---|---|
sourceIds | string[] | yes |
model.run("event-sources.invalidate", {"sourceId":"holidays"});
model.dispatch({"command":"event-sources.invalidate","payload":{"sourceId":"holidays"}});event-sources.set-loading
Mark a range of days of a source as being fetched (loading: true, so ranges-to-fetch leaves it out) or not any more (loading: false: the fetch failed or was cancelled).
Payload
| field | type | required | description |
|---|---|---|---|
sourceId | string | yes | the event source |
range | object | yes | |
loading | boolean | yes |
Result
| field | type | required | description |
|---|---|---|---|
sourceId | string | yes |
model.run("event-sources.set-loading", {"sourceId":"holidays","range":{"start":"2026-11-01","end":"2026-12-01"},"loading":true});
model.dispatch({"command":"event-sources.set-loading","payload":{"sourceId":"holidays","range":{"start":"2026-11-01","end":"2026-12-01"},"loading":true}});Selection
With the selection() feature installed:
import { selection } from "@fragiola/calendar/selection";
const model = createCalendarModel(json, { features: [selection()] });Without it, its commands are not_found.
selection.set
Select a range of days (allDay, dates as YYYY-MM-DD, end exclusive) or of time (RFC 3339 date-times with their offsets). Refused outside validRange, and when selectConstraint refuses it (with constraints()). The selection is view state of the model, not part of the document.
Payload
| field | type | required | description |
|---|---|---|---|
start | string | yes | the first day (YYYY-MM-DD) of an all-day range, else its first instant (RFC 3339 with its offset) |
end | string | yes | its end, exclusive, of the same kind as start |
allDay | boolean | yes |
Result
| field | type | required | description |
|---|---|---|---|
start | string | yes | the first day (YYYY-MM-DD) of an all-day range, else its first instant (RFC 3339 with its offset) |
end | string | yes | its end, exclusive, of the same kind as start |
allDay | boolean | yes |
model.run("selection.set", {"start":"2026-11-26T14:00:00-03:00","end":"2026-11-26T15:30:00-03:00","allDay":false});
model.dispatch({"command":"selection.set","payload":{"start":"2026-11-26T14:00:00-03:00","end":"2026-11-26T15:30:00-03:00","allDay":false}});selection.clear
Clear the selected range; cleared says whether there was one.
Payload
No fields.
Result
| field | type | required | description |
|---|---|---|---|
cleared | boolean | yes |
model.run("selection.clear", {});
model.dispatch({"command":"selection.clear","payload":{}});