@remit/calendar-service 0.0.17 → 0.0.19
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/dist/accept.d.ts +71 -0
- package/dist/accept.js +159 -0
- package/dist/build.d.ts +79 -0
- package/dist/build.js +196 -0
- package/dist/correct.d.ts +4 -0
- package/dist/correct.js +22 -0
- package/dist/errors.d.ts +56 -0
- package/dist/errors.js +1 -0
- package/dist/etag.d.ts +9 -0
- package/{src/etag.ts → dist/etag.js} +1 -3
- package/dist/expand.d.ts +73 -0
- package/dist/expand.js +188 -0
- package/dist/feed.d.ts +81 -0
- package/dist/feed.js +157 -0
- package/dist/fixtures.d.ts +19 -0
- package/dist/fixtures.js +37 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +15 -0
- package/dist/memory-store.d.ts +105 -0
- package/dist/memory-store.js +319 -0
- package/dist/parse.d.ts +39 -0
- package/dist/parse.js +87 -0
- package/dist/project.d.ts +30 -0
- package/dist/project.js +57 -0
- package/dist/put.d.ts +52 -0
- package/dist/put.js +78 -0
- package/dist/reopen.d.ts +14 -0
- package/dist/reopen.js +92 -0
- package/dist/scope.d.ts +70 -0
- package/dist/scope.js +687 -0
- package/dist/subscribe.d.ts +96 -0
- package/dist/subscribe.js +298 -0
- package/dist/suggest.d.ts +74 -0
- package/dist/suggest.js +138 -0
- package/dist/time.d.ts +76 -0
- package/dist/time.js +164 -0
- package/dist/window.d.ts +85 -0
- package/dist/window.js +161 -0
- package/package.json +40 -35
- package/src/accept.test.ts +0 -403
- package/src/accept.ts +0 -229
- package/src/build.test.ts +0 -113
- package/src/build.ts +0 -311
- package/src/correct.test.ts +0 -173
- package/src/correct.ts +0 -40
- package/src/errors.ts +0 -62
- package/src/etag.test.ts +0 -54
- package/src/expand.test.ts +0 -361
- package/src/expand.ts +0 -303
- package/src/feed.test.ts +0 -334
- package/src/feed.ts +0 -203
- package/src/feeds/google-secret-address.ics +0 -99
- package/src/fixtures.ts +0 -52
- package/src/index.ts +0 -125
- package/src/memory-store.ts +0 -404
- package/src/parse.test.ts +0 -264
- package/src/parse.ts +0 -138
- package/src/project.test.ts +0 -247
- package/src/project.ts +0 -122
- package/src/put.test.ts +0 -320
- package/src/put.ts +0 -123
- package/src/reopen.test.ts +0 -531
- package/src/reopen.ts +0 -190
- package/src/scope.test.ts +0 -1421
- package/src/scope.ts +0 -1003
- package/src/subscribe.test.ts +0 -578
- package/src/subscribe.ts +0 -420
- package/src/suggest.test.ts +0 -376
- package/src/suggest.ts +0 -244
- package/src/time.ts +0 -260
- package/src/window.test.ts +0 -648
- package/src/window.ts +0 -281
- package/tsconfig.json +0 -8
package/src/parse.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import ICAL from "ical.js";
|
|
2
|
-
import { type CalendarResult, calendarFailure } from "./errors.js";
|
|
3
|
-
|
|
4
|
-
/** Components a VEVENT-only collection accepts at the top level of a resource. */
|
|
5
|
-
const ACCEPTED_COMPONENTS = new Set(["vevent", "vtimezone"]);
|
|
6
|
-
|
|
7
|
-
export interface ParsedCalendar {
|
|
8
|
-
/** The VCALENDAR, with every property and component the input carried. */
|
|
9
|
-
component: ICAL.Component;
|
|
10
|
-
/** The VEVENT without a RECURRENCE-ID. */
|
|
11
|
-
master: ICAL.Component;
|
|
12
|
-
/** The VEVENTs carrying a RECURRENCE-ID, in document order. */
|
|
13
|
-
overrides: ICAL.Component[];
|
|
14
|
-
uid: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Serializes a VCALENDAR back to iCalendar text.
|
|
19
|
-
*
|
|
20
|
-
* Lossless by construction: ical.js keeps every property it parsed, including
|
|
21
|
-
* ones it has no design rule for, so an X- property or a whole unknown
|
|
22
|
-
* component survives the round trip. The output is always CRLF (RFC 5545 3.1),
|
|
23
|
-
* whatever the input used.
|
|
24
|
-
*
|
|
25
|
-
* The write path does not call this. A resource is stored as the bytes it
|
|
26
|
-
* arrived in — LF-only ones included — because the etag is a digest of exactly
|
|
27
|
-
* what the writer sent; running a stored resource through here would rewrite
|
|
28
|
-
* its line endings, refold its long lines, and move the tag of a resource
|
|
29
|
-
* nobody edited. This is for building a VCALENDAR, not for keeping one.
|
|
30
|
-
*/
|
|
31
|
-
export const serializeCalendar = (component: ICAL.Component): string =>
|
|
32
|
-
component.toString();
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* ical.js's parser in a promise, so unreadable bytes arrive as a rejection to
|
|
36
|
-
* branch on rather than a synchronous throw.
|
|
37
|
-
*/
|
|
38
|
-
export const readCalendarComponent = (
|
|
39
|
-
icalData: string,
|
|
40
|
-
): Promise<CalendarResult<ICAL.Component>> =>
|
|
41
|
-
new Promise<ICAL.Component>((resolve) => {
|
|
42
|
-
resolve(new ICAL.Component(ICAL.parse(icalData)));
|
|
43
|
-
}).then(
|
|
44
|
-
(component) => ({ ok: true, value: component }) as const,
|
|
45
|
-
(error: unknown) =>
|
|
46
|
-
calendarFailure<ICAL.Component>(
|
|
47
|
-
"MalformedIcalendar",
|
|
48
|
-
error instanceof Error ? error.message : "unreadable iCalendar data",
|
|
49
|
-
),
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Reads and validates a VCALENDAR carrying exactly one event.
|
|
54
|
-
*
|
|
55
|
-
* Every refusal is a returned value. The input is client-supplied bytes, so a
|
|
56
|
-
* malformed resource is an ordinary outcome of this function rather than a
|
|
57
|
-
* fault.
|
|
58
|
-
*/
|
|
59
|
-
export const parseCalendar = async (
|
|
60
|
-
icalData: string,
|
|
61
|
-
): Promise<CalendarResult<ParsedCalendar>> => {
|
|
62
|
-
const read = await readCalendarComponent(icalData);
|
|
63
|
-
if (!read.ok) return read;
|
|
64
|
-
const component = read.value;
|
|
65
|
-
|
|
66
|
-
if (component.name !== "vcalendar") {
|
|
67
|
-
// A document with nothing in it names nothing: ical.js reads empty bytes
|
|
68
|
-
// as a component with no name at all, and a suggestion read out of prose
|
|
69
|
-
// carries exactly that. Naming what arrived is for a document that has a
|
|
70
|
-
// root to name.
|
|
71
|
-
return calendarFailure(
|
|
72
|
-
"NotACalendar",
|
|
73
|
-
component.name
|
|
74
|
-
? `expected a VCALENDAR, found ${component.name.toUpperCase()}`
|
|
75
|
-
: "expected a VCALENDAR, found nothing",
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const unsupported = component
|
|
80
|
-
.getAllSubcomponents()
|
|
81
|
-
.map((child) => child.name)
|
|
82
|
-
.find((name) => !ACCEPTED_COMPONENTS.has(name));
|
|
83
|
-
if (unsupported) {
|
|
84
|
-
return calendarFailure(
|
|
85
|
-
"UnsupportedComponent",
|
|
86
|
-
`this calendar stores VEVENT only, and the resource carries a ${unsupported.toUpperCase()}`,
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const events = component.getAllSubcomponents("vevent");
|
|
91
|
-
if (events.length === 0) {
|
|
92
|
-
return calendarFailure("NoEvent", "the resource carries no VEVENT");
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const masters = events.filter((event) => !event.hasProperty("recurrence-id"));
|
|
96
|
-
if (masters.length === 0) {
|
|
97
|
-
return calendarFailure(
|
|
98
|
-
"NoMasterEvent",
|
|
99
|
-
"every VEVENT carries a RECURRENCE-ID, so there is no event for them to override",
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
if (masters.length > 1) {
|
|
103
|
-
return calendarFailure(
|
|
104
|
-
"MultipleMasterEvents",
|
|
105
|
-
`one resource holds one event, and this one holds ${masters.length}`,
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const master = masters[0] as ICAL.Component;
|
|
110
|
-
const uid = master.getFirstPropertyValue("uid");
|
|
111
|
-
if (typeof uid !== "string" || uid === "") {
|
|
112
|
-
return calendarFailure("MissingUid", "the VEVENT declares no UID");
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const mismatched = events.find(
|
|
116
|
-
(event) => event.getFirstPropertyValue("uid") !== uid,
|
|
117
|
-
);
|
|
118
|
-
if (mismatched) {
|
|
119
|
-
return calendarFailure(
|
|
120
|
-
"MismatchedUid",
|
|
121
|
-
"the VEVENTs in this resource declare different UIDs",
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (!master.hasProperty("dtstart")) {
|
|
126
|
-
return calendarFailure("MissingDtStart", "the VEVENT declares no DTSTART");
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
ok: true,
|
|
131
|
-
value: {
|
|
132
|
-
component,
|
|
133
|
-
master,
|
|
134
|
-
overrides: events.filter((event) => event.hasProperty("recurrence-id")),
|
|
135
|
-
uid,
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
};
|
package/src/project.test.ts
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { describe, it } from "node:test";
|
|
3
|
-
import { AMSTERDAM_VTIMEZONE, ical, singleEvent } from "./fixtures.js";
|
|
4
|
-
import { parseCalendar } from "./parse.js";
|
|
5
|
-
import { projectCalendar } from "./project.js";
|
|
6
|
-
|
|
7
|
-
const project = async (icalData: string, timezone = "") => {
|
|
8
|
-
const parsed = await parseCalendar(icalData);
|
|
9
|
-
assert.ok(parsed.ok, `expected a parse, got ${JSON.stringify(parsed)}`);
|
|
10
|
-
return projectCalendar(parsed.value, timezone);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const projection = async (icalData: string, timezone = "") => {
|
|
14
|
-
const result = await project(icalData, timezone);
|
|
15
|
-
assert.ok(result.ok, `expected a projection, got ${JSON.stringify(result)}`);
|
|
16
|
-
return result.value;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
describe("projectCalendar", () => {
|
|
20
|
-
it("projects the columns a UTC event carries", async () => {
|
|
21
|
-
const value = await projection(
|
|
22
|
-
singleEvent(
|
|
23
|
-
"DTSTART:20260826T090000Z",
|
|
24
|
-
"DTEND:20260826T100000Z",
|
|
25
|
-
"SUMMARY:Quarterly review",
|
|
26
|
-
"STATUS:TENTATIVE",
|
|
27
|
-
"TRANSP:TRANSPARENT",
|
|
28
|
-
"SEQUENCE:3",
|
|
29
|
-
),
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
assert.deepEqual(value, {
|
|
33
|
-
icalUid: "fixture@example.com",
|
|
34
|
-
summary: "Quarterly review",
|
|
35
|
-
dtStart: "2026-08-26T09:00:00+00:00",
|
|
36
|
-
dtEnd: "2026-08-26T10:00:00+00:00",
|
|
37
|
-
allDay: false,
|
|
38
|
-
zoneCertainty: "Explicit",
|
|
39
|
-
status: "Tentative",
|
|
40
|
-
transparency: "Transparent",
|
|
41
|
-
hasRecurrence: false,
|
|
42
|
-
sequence: 3,
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("gives an event that states neither the RFC's defaults", async () => {
|
|
47
|
-
const value = await projection(
|
|
48
|
-
singleEvent("DTSTART:20260826T090000Z", "DTEND:20260826T100000Z"),
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
assert.equal(value.status, "Confirmed");
|
|
52
|
-
assert.equal(value.transparency, "Opaque");
|
|
53
|
-
assert.equal(value.summary, "");
|
|
54
|
-
assert.equal(value.sequence, 0);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("keeps the event's own offset, resolved from the VTIMEZONE it carries", async () => {
|
|
58
|
-
const value = await projection(
|
|
59
|
-
ical(
|
|
60
|
-
"BEGIN:VCALENDAR",
|
|
61
|
-
"VERSION:2.0",
|
|
62
|
-
...AMSTERDAM_VTIMEZONE,
|
|
63
|
-
"BEGIN:VEVENT",
|
|
64
|
-
"UID:fixture@example.com",
|
|
65
|
-
"DTSTART;TZID=Europe/Amsterdam:20260826T090000",
|
|
66
|
-
"DTEND;TZID=Europe/Amsterdam:20260826T100000",
|
|
67
|
-
"END:VEVENT",
|
|
68
|
-
"END:VCALENDAR",
|
|
69
|
-
),
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
assert.equal(value.dtStart, "2026-08-26T09:00:00+02:00");
|
|
73
|
-
assert.equal(value.dtEnd, "2026-08-26T10:00:00+02:00");
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("resolves a TZID the resource carries no VTIMEZONE for", async () => {
|
|
77
|
-
const value = await projection(
|
|
78
|
-
singleEvent(
|
|
79
|
-
"DTSTART;TZID=Europe/Berlin:20260826T090000",
|
|
80
|
-
"DTEND;TZID=Europe/Berlin:20260826T100000",
|
|
81
|
-
),
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
assert.equal(value.dtStart, "2026-08-26T09:00:00+02:00");
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("reads a floating time in the collection's timezone", async () => {
|
|
88
|
-
const value = await projection(
|
|
89
|
-
singleEvent("DTSTART:20260826T090000", "DTEND:20260826T100000"),
|
|
90
|
-
"Europe/Berlin",
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
assert.equal(value.dtStart, "2026-08-26T09:00:00+02:00");
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("marks a zone nothing could resolve as ambiguous rather than reading it as UTC in silence", async () => {
|
|
97
|
-
// A Windows zone name with no VTIMEZONE. The event still gets an instant —
|
|
98
|
-
// there is nothing else to give it — but a two-hour error that presents as
|
|
99
|
-
// a fact is the failure this marker exists to prevent.
|
|
100
|
-
const value = await projection(
|
|
101
|
-
singleEvent(
|
|
102
|
-
"DTSTART;TZID=W. Europe Standard Time:20260826T090000",
|
|
103
|
-
"DTEND;TZID=W. Europe Standard Time:20260826T100000",
|
|
104
|
-
),
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
assert.equal(value.dtStart, "2026-08-26T09:00:00+00:00");
|
|
108
|
-
assert.equal(value.zoneCertainty, "Ambiguous");
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("marks a floating time as local to the collection", async () => {
|
|
112
|
-
const value = await projection(
|
|
113
|
-
singleEvent("DTSTART:20260826T090000", "DTEND:20260826T100000"),
|
|
114
|
-
"Europe/Berlin",
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
assert.equal(value.zoneCertainty, "Local");
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("marks a zone that resolved as explicit, however it resolved", async () => {
|
|
121
|
-
const fromVtimezone = await projection(
|
|
122
|
-
ical(
|
|
123
|
-
"BEGIN:VCALENDAR",
|
|
124
|
-
"VERSION:2.0",
|
|
125
|
-
...AMSTERDAM_VTIMEZONE,
|
|
126
|
-
"BEGIN:VEVENT",
|
|
127
|
-
"UID:fixture@example.com",
|
|
128
|
-
"DTSTART;TZID=Europe/Amsterdam:20260826T090000",
|
|
129
|
-
"DTEND;TZID=Europe/Amsterdam:20260826T100000",
|
|
130
|
-
"END:VEVENT",
|
|
131
|
-
"END:VCALENDAR",
|
|
132
|
-
),
|
|
133
|
-
);
|
|
134
|
-
const fromPlatform = await projection(
|
|
135
|
-
singleEvent(
|
|
136
|
-
"DTSTART;TZID=Europe/Berlin:20260826T090000",
|
|
137
|
-
"DTEND;TZID=Europe/Berlin:20260826T100000",
|
|
138
|
-
),
|
|
139
|
-
);
|
|
140
|
-
const fromUtc = await projection(
|
|
141
|
-
singleEvent("DTSTART:20260826T090000Z", "DTEND:20260826T100000Z"),
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
assert.equal(fromVtimezone.zoneCertainty, "Explicit");
|
|
145
|
-
assert.equal(fromPlatform.zoneCertainty, "Explicit");
|
|
146
|
-
assert.equal(fromUtc.zoneCertainty, "Explicit");
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it("projects an all-day event as midnight with an exclusive end", async () => {
|
|
150
|
-
const value = await projection(
|
|
151
|
-
singleEvent("DTSTART;VALUE=DATE:20260826", "DTEND;VALUE=DATE:20260828"),
|
|
152
|
-
"Europe/Berlin",
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
assert.equal(value.allDay, true);
|
|
156
|
-
assert.equal(value.dtStart, "2026-08-26T00:00:00+02:00");
|
|
157
|
-
assert.equal(value.dtEnd, "2026-08-28T00:00:00+02:00");
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it("ends a one-day all-day event on the following day, per RFC 5545", async () => {
|
|
161
|
-
const value = await projection(
|
|
162
|
-
singleEvent("DTSTART;VALUE=DATE:20260826"),
|
|
163
|
-
"Europe/Berlin",
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
assert.equal(value.dtEnd, "2026-08-27T00:00:00+02:00");
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("resolves an end stated as a DURATION", async () => {
|
|
170
|
-
const value = await projection(
|
|
171
|
-
singleEvent("DTSTART:20260826T090000Z", "DURATION:PT90M"),
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
assert.equal(value.dtEnd, "2026-08-26T10:30:00+00:00");
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("marks an event that recurs", async () => {
|
|
178
|
-
const withRrule = await projection(
|
|
179
|
-
singleEvent("DTSTART:20260826T090000Z", "RRULE:FREQ=WEEKLY;COUNT=3"),
|
|
180
|
-
);
|
|
181
|
-
const withRdate = await projection(
|
|
182
|
-
singleEvent("DTSTART:20260826T090000Z", "RDATE:20260902T090000Z"),
|
|
183
|
-
);
|
|
184
|
-
const withOnlyOverrides = await projection(
|
|
185
|
-
ical(
|
|
186
|
-
"BEGIN:VCALENDAR",
|
|
187
|
-
"VERSION:2.0",
|
|
188
|
-
"BEGIN:VEVENT",
|
|
189
|
-
"UID:fixture@example.com",
|
|
190
|
-
"DTSTART:20260826T090000Z",
|
|
191
|
-
"DTEND:20260826T100000Z",
|
|
192
|
-
"END:VEVENT",
|
|
193
|
-
"BEGIN:VEVENT",
|
|
194
|
-
"UID:fixture@example.com",
|
|
195
|
-
"RECURRENCE-ID:20260902T090000Z",
|
|
196
|
-
"DTSTART:20260902T110000Z",
|
|
197
|
-
"DTEND:20260902T120000Z",
|
|
198
|
-
"END:VEVENT",
|
|
199
|
-
"END:VCALENDAR",
|
|
200
|
-
),
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
assert.equal(withRrule.hasRecurrence, true);
|
|
204
|
-
assert.equal(withRdate.hasRecurrence, true);
|
|
205
|
-
assert.equal(withOnlyOverrides.hasRecurrence, true);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it("refuses an event that ends before it starts, naming both times", async () => {
|
|
209
|
-
const result = await project(
|
|
210
|
-
singleEvent("DTSTART:20260826T100000Z", "DTEND:20260826T090000Z"),
|
|
211
|
-
);
|
|
212
|
-
|
|
213
|
-
assert.ok(!result.ok);
|
|
214
|
-
assert.equal(result.error.code, "BackwardsEnd");
|
|
215
|
-
assert.match(result.error.message, /2026-08-26T09:00:00Z/);
|
|
216
|
-
assert.match(result.error.message, /2026-08-26T10:00:00Z/);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("refuses an event whose end precedes its start only once zones are applied", async () => {
|
|
220
|
-
// 09:30 in Amsterdam is 07:30Z, half an hour before the 08:00Z start — a
|
|
221
|
-
// comparison of the wall-clock strings would have called this fine.
|
|
222
|
-
const result = await project(
|
|
223
|
-
ical(
|
|
224
|
-
"BEGIN:VCALENDAR",
|
|
225
|
-
"VERSION:2.0",
|
|
226
|
-
...AMSTERDAM_VTIMEZONE,
|
|
227
|
-
"BEGIN:VEVENT",
|
|
228
|
-
"UID:fixture@example.com",
|
|
229
|
-
"DTSTART:20260826T080000Z",
|
|
230
|
-
"DTEND;TZID=Europe/Amsterdam:20260826T093000",
|
|
231
|
-
"END:VEVENT",
|
|
232
|
-
"END:VCALENDAR",
|
|
233
|
-
),
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
assert.ok(!result.ok);
|
|
237
|
-
assert.equal(result.error.code, "BackwardsEnd");
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it("accepts a zero-length event", async () => {
|
|
241
|
-
const value = await projection(
|
|
242
|
-
singleEvent("DTSTART:20260826T090000Z", "DTEND:20260826T090000Z"),
|
|
243
|
-
);
|
|
244
|
-
|
|
245
|
-
assert.equal(value.dtEnd, "2026-08-26T09:00:00+00:00");
|
|
246
|
-
});
|
|
247
|
-
});
|
package/src/project.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import type { CalendarObjectItem } from "@remit/data-ports";
|
|
2
|
-
import { CalendarEventStatus, CalendarTransparency } from "@remit/domain-enums";
|
|
3
|
-
import ICAL from "ical.js";
|
|
4
|
-
import { type CalendarResult, calendarFailure } from "./errors.js";
|
|
5
|
-
import type { ParsedCalendar } from "./parse.js";
|
|
6
|
-
import { resolveTime, tzidOf } from "./time.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The columns `CalendarObject` carries beside its bytes. Every one of them is
|
|
10
|
-
* read out of the VEVENT here and nowhere else, so the row can only ever
|
|
11
|
-
* describe the `icalData` it was written with.
|
|
12
|
-
*/
|
|
13
|
-
export type CalendarObjectProjection = Pick<
|
|
14
|
-
CalendarObjectItem,
|
|
15
|
-
| "icalUid"
|
|
16
|
-
| "summary"
|
|
17
|
-
| "dtStart"
|
|
18
|
-
| "dtEnd"
|
|
19
|
-
| "allDay"
|
|
20
|
-
| "zoneCertainty"
|
|
21
|
-
| "status"
|
|
22
|
-
| "transparency"
|
|
23
|
-
| "hasRecurrence"
|
|
24
|
-
| "sequence"
|
|
25
|
-
>;
|
|
26
|
-
|
|
27
|
-
const STATUS_BY_ICAL: Record<string, CalendarObjectItem["status"]> = {
|
|
28
|
-
CONFIRMED: CalendarEventStatus.Confirmed,
|
|
29
|
-
TENTATIVE: CalendarEventStatus.Tentative,
|
|
30
|
-
CANCELLED: CalendarEventStatus.Cancelled,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const TRANSPARENCY_BY_ICAL: Record<string, CalendarObjectItem["transparency"]> =
|
|
34
|
-
{
|
|
35
|
-
OPAQUE: CalendarTransparency.Opaque,
|
|
36
|
-
TRANSPARENT: CalendarTransparency.Transparent,
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const readString = (component: ICAL.Component, name: string): string => {
|
|
40
|
-
const value = component.getFirstPropertyValue(name);
|
|
41
|
-
return typeof value === "string" ? value : "";
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* The fields that describe one VEVENT rather than the series it belongs to.
|
|
46
|
-
*
|
|
47
|
-
* Read per occurrence as well as per resource: an override VEVENT carries its
|
|
48
|
-
* own summary, status and transparency, and a range read that took them from
|
|
49
|
-
* the master would draw the old title over an edited instance and count a
|
|
50
|
-
* cancelled one as busy time.
|
|
51
|
-
*/
|
|
52
|
-
export type CalendarEventDisplay = Pick<
|
|
53
|
-
CalendarObjectItem,
|
|
54
|
-
"summary" | "status" | "transparency"
|
|
55
|
-
>;
|
|
56
|
-
|
|
57
|
-
export const projectEventDisplay = (
|
|
58
|
-
component: ICAL.Component,
|
|
59
|
-
): CalendarEventDisplay => ({
|
|
60
|
-
summary: readString(component, "summary"),
|
|
61
|
-
status:
|
|
62
|
-
STATUS_BY_ICAL[readString(component, "status").toUpperCase()] ??
|
|
63
|
-
CalendarEventStatus.Confirmed,
|
|
64
|
-
transparency:
|
|
65
|
-
TRANSPARENCY_BY_ICAL[readString(component, "transp").toUpperCase()] ??
|
|
66
|
-
CalendarTransparency.Opaque,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Whether the resource expands to more than its master instance — an RRULE, an
|
|
71
|
-
* RDATE, or an override VEVENT. The overrides count: a client that edits one
|
|
72
|
-
* instance of a series and then deletes the rule leaves a resource with nothing
|
|
73
|
-
* but a master and its exceptions, and every one of those is still an
|
|
74
|
-
* occurrence somebody has to see.
|
|
75
|
-
*/
|
|
76
|
-
export const hasRecurrence = (calendar: ParsedCalendar): boolean =>
|
|
77
|
-
calendar.master.hasProperty("rrule") ||
|
|
78
|
-
calendar.master.hasProperty("rdate") ||
|
|
79
|
-
calendar.overrides.length > 0;
|
|
80
|
-
|
|
81
|
-
export const projectCalendar = (
|
|
82
|
-
calendar: ParsedCalendar,
|
|
83
|
-
collectionTimezone: string,
|
|
84
|
-
): CalendarResult<CalendarObjectProjection> => {
|
|
85
|
-
const event = new ICAL.Event(calendar.master);
|
|
86
|
-
const start = resolveTime(
|
|
87
|
-
event.startDate,
|
|
88
|
-
tzidOf(calendar.master.getFirstProperty("dtstart")),
|
|
89
|
-
collectionTimezone,
|
|
90
|
-
);
|
|
91
|
-
const end = resolveTime(
|
|
92
|
-
event.endDate,
|
|
93
|
-
tzidOf(
|
|
94
|
-
calendar.master.getFirstProperty("dtend") ??
|
|
95
|
-
calendar.master.getFirstProperty("dtstart"),
|
|
96
|
-
),
|
|
97
|
-
collectionTimezone,
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
if (end.instantMs < start.instantMs) {
|
|
101
|
-
return calendarFailure(
|
|
102
|
-
"BackwardsEnd",
|
|
103
|
-
`the event ends at ${end.isoUtc}, before it starts at ${start.isoUtc}`,
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const sequence = calendar.master.getFirstPropertyValue("sequence");
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
ok: true,
|
|
111
|
-
value: {
|
|
112
|
-
icalUid: calendar.uid,
|
|
113
|
-
dtStart: start.isoOffset,
|
|
114
|
-
dtEnd: end.isoOffset,
|
|
115
|
-
allDay: start.isDate,
|
|
116
|
-
zoneCertainty: start.certainty,
|
|
117
|
-
...projectEventDisplay(calendar.master),
|
|
118
|
-
hasRecurrence: hasRecurrence(calendar),
|
|
119
|
-
sequence: typeof sequence === "number" ? sequence : 0,
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
};
|