@moltenship/calendar 1.0.0-rc.1 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -4
- package/dist/index.d.mts +2 -2
- package/docs/accessibility.md +304 -0
- package/docs/agents/changes.md +449 -0
- package/docs/agents/coding-agents.md +117 -0
- package/docs/agents/connect.md +435 -0
- package/docs/agents/deleting.md +296 -0
- package/docs/agents/reference.md +512 -0
- package/docs/agents/server.md +317 -0
- package/docs/agents/webmcp.md +153 -0
- package/docs/agents.md +353 -0
- package/docs/annotations.md +196 -0
- package/docs/api/changes.md +248 -0
- package/docs/api/dnd-kit.md +267 -0
- package/docs/api/events.md +152 -0
- package/docs/api/ics.md +524 -0
- package/docs/api/primitives.md +168 -0
- package/docs/api/react.md +236 -0
- package/docs/api/recurrence.md +586 -0
- package/docs/api/solid.md +460 -0
- package/docs/api/store.md +92 -0
- package/docs/api/temporal.md +172 -0
- package/docs/api.md +57 -0
- package/docs/availability.md +573 -0
- package/docs/comparison.md +279 -0
- package/docs/concepts/anatomy.md +73 -0
- package/docs/concepts/events.md +164 -0
- package/docs/concepts/how-it-works.md +95 -0
- package/docs/concepts/recurrence.md +127 -0
- package/docs/concepts/state.md +244 -0
- package/docs/concepts/time.md +170 -0
- package/docs/guides/dnd-kit.md +333 -0
- package/docs/guides/google-calendar-sync.md +1246 -0
- package/docs/guides/google-calendar.md +367 -0
- package/docs/guides/ics.md +486 -0
- package/docs/guides/motion.md +414 -0
- package/docs/guides/nextjs-app-router.md +630 -0
- package/docs/guides/nextjs.md +149 -0
- package/docs/guides/performance.md +103 -0
- package/docs/guides/recurring-events.md +583 -0
- package/docs/guides/tanstack-query.md +485 -0
- package/docs/index.md +118 -0
- package/docs/installation.md +194 -0
- package/docs/interactions.md +408 -0
- package/docs/llms.txt +86 -0
- package/docs/migrating-to-2.md +322 -0
- package/docs/quick-start.md +159 -0
- package/docs/stylex.md +265 -0
- package/docs/testing.md +581 -0
- package/docs/theme-builder.md +81 -0
- package/docs/theming.md +169 -0
- package/docs/undo-redo.md +339 -0
- package/docs/views/agenda.md +221 -0
- package/docs/views/custom-views.md +192 -0
- package/docs/views/month.md +109 -0
- package/docs/views/resource-columns.md +261 -0
- package/docs/views/resource-timeline.md +225 -0
- package/docs/views/scrolling.md +192 -0
- package/docs/views/week-and-day.md +257 -0
- package/docs/views/year.md +138 -0
- package/docs/views.md +69 -0
- package/package.json +41 -14
- package/skills/moltenship-time/SKILL.md +75 -0
- package/skills/moltenship-time/references/agent-ready.md +272 -0
- package/skills/moltenship-time/references/changes.md +188 -0
- package/skills/moltenship-time/references/compose.md +168 -0
- package/skills/moltenship-time/references/mistakes.md +98 -0
- package/skills/moltenship-time/references/solid.md +202 -0
- package/skills/moltenship-time/references/state.md +129 -0
- package/skills/moltenship-time/references/testing.md +176 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Events and snapshots
|
|
2
|
+
|
|
3
|
+
Adapters, event ranges, validation, snapshots, and queries.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/api/events
|
|
6
|
+
|
|
7
|
+
Exported from `@moltenship/calendar` and from `@moltenship/calendar-core`.
|
|
8
|
+
|
|
9
|
+
## Adapter
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const eventAdapter = defineEventAdapter<TEvent>()({ getId, getTitle, getInterval, getResourceIds });
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`defineEventAdapter` returns your adapter unchanged. The two calls let TypeScript fix `TEvent` first
|
|
16
|
+
and then infer the ID types from `getId` and `getResourceIds`.
|
|
17
|
+
|
|
18
|
+
| Name | Type | Default | Description |
|
|
19
|
+
| ---------------- | ------------------------------------------ | ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
20
|
+
| `getId` | `(event) => string \| number` | | Required. A unique ID: a non-empty string or a finite number. |
|
|
21
|
+
| `getTitle` | `(event) => string` | | Required. The display title. |
|
|
22
|
+
| `getInterval` | `(event) => CalendarEventInterval` | | Required. When the event happens. See [ranges](#ranges). |
|
|
23
|
+
| `getResourceIds` | `(event) => readonly (string \| number)[]` | | Required. The resources the event belongs to. Return `[]` for none. |
|
|
24
|
+
| `getRevision` | `(event) => string \| number` | | Changes whenever the record changes. Lets Time reuse work for unchanged records after a refetch. |
|
|
25
|
+
| `isReadOnly` | `(event) => boolean` | `false` | Marks events users can't change. Exposed as `isReadOnly` on normalized events. |
|
|
26
|
+
| `isBusy` | `(event) => boolean` | `timed and floating events are busy; all-day events are free` | Whether the event makes its resources busy, as "show as busy" or "free" does. Exposed as `isBusy` on normalized events. See [busy or available](../availability.md#busy-or-available). |
|
|
27
|
+
|
|
28
|
+
`createCanonicalEventAdapter()` returns an adapter for records already in Time's `CalendarEvent`
|
|
29
|
+
shape (`id`, `title`, `kind`, `start`, `end`, optional `resourceIds`, and `data`).
|
|
30
|
+
|
|
31
|
+
## Ranges
|
|
32
|
+
|
|
33
|
+
`getInterval` returns one of three shapes. In every one, `start` is included and `end` is excluded,
|
|
34
|
+
and `start` must come before `end`.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
type CalendarEventInterval =
|
|
38
|
+
| { kind: "timed"; start: Temporal.Instant; end: Temporal.Instant; sourceTimeZone?: string }
|
|
39
|
+
| { kind: "all-day"; start: Temporal.PlainDate; end: Temporal.PlainDate }
|
|
40
|
+
| { kind: "floating"; start: Temporal.PlainDateTime; end: Temporal.PlainDateTime };
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
See [Time and time zones](../concepts/time.md) for when to use each.
|
|
44
|
+
|
|
45
|
+
## Validation helpers
|
|
46
|
+
|
|
47
|
+
These check values before they reach the calendar. They return a result instead of throwing.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { isEventId, validateCalendarEvent } from "@moltenship/calendar";
|
|
51
|
+
|
|
52
|
+
isEventId("meeting-1"); // true
|
|
53
|
+
|
|
54
|
+
const result = validateCalendarEvent({
|
|
55
|
+
id: "meeting-1",
|
|
56
|
+
title: "Standup",
|
|
57
|
+
kind: "timed",
|
|
58
|
+
start: Temporal.Instant.from("2026-10-08T07:15:00Z"),
|
|
59
|
+
end: Temporal.Instant.from("2026-10-08T07:00:00Z"),
|
|
60
|
+
data: null,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
result.valid; // false
|
|
64
|
+
result.valid || result.issues; // [{ code: "start-not-before-end", kind: "timed" }]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
| Function | Checks |
|
|
68
|
+
| ------------------------------------------------------ | ---------------------------------------------------------------------------------------- |
|
|
69
|
+
| `isEventId(value)`, `isResourceId(value)` | A non-empty string or a finite number |
|
|
70
|
+
| `validateCalendarEvent(event)` | A `CalendarEvent`: its ID, resource IDs, and range |
|
|
71
|
+
| `validateCalendarEventInterval(interval, comparators)` | A range, using the `{ instant, plainDate, plainDateTime }` comparison functions you pass |
|
|
72
|
+
|
|
73
|
+
## Snapshots
|
|
74
|
+
|
|
75
|
+
A snapshot is a frozen, indexed copy of your events. `Root` builds one for you and exposes it as
|
|
76
|
+
`meta.eventSnapshot`. Outside React, build one yourself:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { createEventSnapshotCache } from "@moltenship/calendar";
|
|
80
|
+
|
|
81
|
+
const snapshots = createEventSnapshotCache(eventAdapter, { queryCacheSize: 128 });
|
|
82
|
+
const snapshot = snapshots.getSnapshot(events);
|
|
83
|
+
|
|
84
|
+
snapshots.getSnapshot(events) === snapshot; // true while `events` is the same array
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Keep one cache per adapter and reuse it. `getSnapshot` returns the same snapshot for the same array
|
|
88
|
+
and builds a new one, reusing what it can, for a new array. For a one-off snapshot, call
|
|
89
|
+
`createEventSnapshot(events, eventAdapter, options)`.
|
|
90
|
+
|
|
91
|
+
| Name | Type | Default | Description |
|
|
92
|
+
| -------------------- | ------------------------------ | ------------------- | ---------------------------------------------------- |
|
|
93
|
+
| `invalidEventPolicy` | `"report-and-skip" \| "throw"` | `"report-and-skip"` | What to do with invalid records. |
|
|
94
|
+
| `queryCacheSize` | `number` | `128` | How many distinct query results each snapshot keeps. |
|
|
95
|
+
|
|
96
|
+
### Snapshot fields
|
|
97
|
+
|
|
98
|
+
| Field | Contents |
|
|
99
|
+
| --------------------------- | -------------------------------------------------------- |
|
|
100
|
+
| `events` | Valid events, normalized, in input order |
|
|
101
|
+
| `byId` | A read-only `Map` from ID to normalized event |
|
|
102
|
+
| `size` | Number of valid events |
|
|
103
|
+
| `issues` | Problems with skipped records (see below) |
|
|
104
|
+
| `version` | Goes up by one for each new snapshot from the same cache |
|
|
105
|
+
| `getQueryCacheStatistics()` | `capacity`, `size`, `hits`, `misses`, and `evictions` |
|
|
106
|
+
|
|
107
|
+
A normalized event has your record as `event`, plus `id`, `title`, `resourceIds`, `isReadOnly`,
|
|
108
|
+
`revision`, `inputIndex`, `isBusy` when the adapter has `isBusy`, and the range fields (`kind`, `start`,
|
|
109
|
+
`end`, and, on timed events, `sourceTimeZone` when the range has one). Inside a calendar, an event
|
|
110
|
+
with a change that is still saving also has `isPending: true` and shows its proposed range; see
|
|
111
|
+
[pending changes](../interactions.md#pending-changes).
|
|
112
|
+
|
|
113
|
+
## Queries
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
snapshot.queryTimed(instantInterval(start, end));
|
|
117
|
+
snapshot.queryAllDay(plainDateInterval(startDate, endDate));
|
|
118
|
+
snapshot.queryFloating(plainDateTimeInterval(startDateTime, endDateTime));
|
|
119
|
+
|
|
120
|
+
snapshot.queryTimed(range, { resourceIds: ["room-1"] });
|
|
121
|
+
snapshot.eventsForResource("room-1");
|
|
122
|
+
snapshot.get("meeting-1");
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
- Each query returns the events of one kind that overlap the range. Ranges are end-exclusive on both
|
|
126
|
+
sides, so an event ending exactly at the range start isn't included.
|
|
127
|
+
- Build ranges with `instantInterval`, `plainDateInterval`, and `plainDateTimeInterval` from
|
|
128
|
+
the [Temporal helpers](./temporal.md#ranges).
|
|
129
|
+
- `resourceIds` keeps events assigned to any of the listed resources. An empty list matches nothing.
|
|
130
|
+
- Results are frozen and in input order. Repeating a query returns the same array while it's in the
|
|
131
|
+
cache.
|
|
132
|
+
|
|
133
|
+
## Invalid records
|
|
134
|
+
|
|
135
|
+
With the default policy, invalid records are left out of the snapshot and listed in
|
|
136
|
+
`snapshot.issues`. In React they also appear as `invalid-event` [diagnostics](./react.md#diagnostics).
|
|
137
|
+
Each issue has the `event`, its `index` in your array, a `code`, and when known the `eventId`, the
|
|
138
|
+
adapter function that failed (`accessor`), the position of a bad resource ID (`resourceIndex`), and a
|
|
139
|
+
`message`.
|
|
140
|
+
|
|
141
|
+
| `code` | Cause |
|
|
142
|
+
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
143
|
+
| `adapter-error` | An adapter function threw, `getTitle` returned something other than a string, `getResourceIds` something other than an array, or `isReadOnly` or `isBusy` something other than a boolean |
|
|
144
|
+
| `invalid-event-id` | `getId` returned an empty string, `NaN`, or another non-ID value |
|
|
145
|
+
| `duplicate-event-id` | Another record already has this ID |
|
|
146
|
+
| `invalid-resource-id` | `getResourceIds` returned an array with a non-ID value (its position is `resourceIndex`) |
|
|
147
|
+
| `invalid-revision` | `getRevision` returned something other than a string or a finite number |
|
|
148
|
+
| `invalid-event-interval` | The range has an unknown `kind`, the wrong Temporal type, a `sourceTimeZone` that isn't a string, or fields that throw when read |
|
|
149
|
+
| `start-not-before-end` | The range is empty or reversed |
|
|
150
|
+
|
|
151
|
+
With `invalidEventPolicy: "throw"`, building the snapshot throws an
|
|
152
|
+
`InvalidCalendarEventSnapshotError` with every issue on its `issues` property instead.
|