Fragiola

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

fieldtyperequireddescription
idstringno
kindstringno
titlestringyes
startstringyesYYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00)
endstringnoYYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00)
allDaybooleanyes
timeZonestringnoan IANA time zone name (America/Sao_Paulo)
calendarIdstringno
recurrenceobjectnothe occurrences of a recurring event (requires recurrence())
sourceIdstringnothe event source it came from (requires eventSources())
dataJSONnothe app's data (any JSON)
editablebooleanno
startEditablebooleanno
durationEditablebooleanno
deletablebooleanno

Result

fieldtyperequireddescription
eventIdstringyes
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

fieldtyperequireddescription
eventIdstringyesthe event
titlestringno
startstringnoYYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00)
endstringnoYYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00)
allDaybooleanno
timeZonestring | nullno
calendarIdstring | nullno
occurrenceIdstringnothe occurrence edited, <eventId>@<original start> (requires recurrence())
scope"this" | "following" | "all"nowhich occurrences of a recurring event change (requires recurrence())

Result

fieldtyperequireddescription
eventIdstringyes
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):

fieldtyperequireddescription
eventIdstringyesthe event
startstringyesYYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00)
allDaybooleanno
occurrenceIdstringnothe occurrence edited, <eventId>@<original start> (requires recurrence())
scope"this" | "following" | "all"nowhich occurrences of a recurring event change (requires recurrence())

One of (2 of 2):

fieldtyperequireddescription
eventIdstringyesthe event
deltaobjectyes
occurrenceIdstringnothe occurrence edited, <eventId>@<original start> (requires recurrence())
scope"this" | "following" | "all"nowhich occurrences of a recurring event change (requires recurrence())

Result

fieldtyperequireddescription
eventIdstringyes
startstringyesYYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00)
endstringyesYYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00)
allDaybooleanyes
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

fieldtyperequireddescription
eventIdstringyesthe event
edge"start" | "end"yes
tostringyesYYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00)
occurrenceIdstringnothe occurrence edited, <eventId>@<original start> (requires recurrence())
scope"this" | "following" | "all"nowhich occurrences of a recurring event change (requires recurrence())

Result

fieldtyperequireddescription
eventIdstringyes
startstringyesYYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00)
endstringyesYYYY-MM-DD for an all-day event, an RFC 3339 date-time with its offset otherwise (2026-11-26T09:30:00-03:00)
allDaybooleanyes
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

fieldtyperequireddescription
eventIdstringyesthe event
occurrenceIdstringnothe occurrence edited, <eventId>@<original start> (requires recurrence())
scope"this" | "following" | "all"nowhich occurrences of a recurring event change (requires recurrence())

Result

fieldtyperequireddescription
eventIdstringyes
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

fieldtyperequireddescription
eventIdstringyesthe event
kindstringno
dataJSONnothe app's data (any JSON)

Result

fieldtyperequireddescription
eventIdstringyes
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

fieldtyperequireddescription
eventIdstringyesthe event
editableboolean | nullno
startEditableboolean | nullno
durationEditableboolean | nullno
deletableboolean | nullno

Result

fieldtyperequireddescription
eventIdstringyes
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

fieldtyperequireddescription
eventsobject[]yes

Result

fieldtyperequireddescription
eventIdsstring[]yes
removedEventIdsstring[]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

fieldtyperequireddescription
idstringno
titlestringyes
editablebooleanno
visiblebooleanno
dataJSONnothe app's data (any JSON)

Result

fieldtyperequireddescription
calendarIdstringyes
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

fieldtyperequireddescription
calendarIdstringyesthe calendar
titlestringno
editableboolean | nullno
dataJSONnothe app's data (any JSON)

Result

fieldtyperequireddescription
calendarIdstringyes
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

fieldtyperequireddescription
calendarIdstringyesthe calendar
events"remove" | "keep"yes

Result

fieldtyperequireddescription
calendarIdstringyes
removedEventIdsstring[]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

fieldtyperequireddescription
calendarIdstringyesthe calendar
visiblebooleanyes

Result

fieldtyperequireddescription
calendarIdstringyes
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

fieldtyperequireddescription
settingsobjectyes

Result

fieldtyperequireddescription
settingsobjectyes
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

fieldtyperequireddescription
type"month" | "week" | "day" | "days" | "list"yes
daysintegerno
durationintegerno

Result

fieldtyperequireddescription
viewobjectyes
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

fieldtyperequireddescription
datestring | objectyes

Result

fieldtyperequireddescription
viewobjectyes
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

fieldtyperequireddescription
viewobjectyes
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

fieldtyperequireddescription
viewobjectyes
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

fieldtyperequireddescription
viewobjectyes
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

fieldtyperequireddescription
commandsobject[]yesthe commands, in order

Result

fieldtyperequireddescription
resultsJSON[]yeseach 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

fieldtyperequireddescription
eventIdstringyesthe event
recurrenceobject | nullyes

Result

fieldtyperequireddescription
eventIdstringyes
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

fieldtyperequireddescription
sourceIdstringyesthe event source
rangeobjectyes
eventsobject[]yes

Result

fieldtyperequireddescription
sourceIdstringyes
eventIdsstring[]yes
removedEventIdsstring[]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

fieldtyperequireddescription
sourceIdstringnothe event source
rangeobjectno

Result

fieldtyperequireddescription
sourceIdsstring[]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

fieldtyperequireddescription
sourceIdstringyesthe event source
rangeobjectyes
loadingbooleanyes

Result

fieldtyperequireddescription
sourceIdstringyes
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

fieldtyperequireddescription
startstringyesthe first day (YYYY-MM-DD) of an all-day range, else its first instant (RFC 3339 with its offset)
endstringyesits end, exclusive, of the same kind as start
allDaybooleanyes

Result

fieldtyperequireddescription
startstringyesthe first day (YYYY-MM-DD) of an all-day range, else its first instant (RFC 3339 with its offset)
endstringyesits end, exclusive, of the same kind as start
allDaybooleanyes
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

fieldtyperequireddescription
clearedbooleanyes
model.run("selection.clear", {});
model.dispatch({"command":"selection.clear","payload":{}});