aboutsummaryrefslogtreecommitdiff
path: root/static/ts/types.ts
blob: a01f6672838781ae895d775af70e16b5009bb24d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/**
 * Collection of type information for calendar data.
 * @module
 */

export {
    ical_type,
    valid_input_types,
    JCalProperty, JCal,
    xcal, uid,
    ChangeLogEntry
}


/** Name of all valid icalendar types. */
let all_types = [
    'text',
    'uri',
    'binary',
    'float',        /* Number.type = 'float' */
    'integer',      /* Number.type = 'integer' */
    'date-time',    /* Date */
    'date',         /* Date.dateonly = true */
    'duration',     /* TODO */
    'period',       /* TODO */
    'utc-offset',   /* TODO */
    'cal-address',
    'recur',        /* RRule */
    'boolean',      /* boolean */
]


/** The union of all elements in `all_types`. */
type ical_type
    = 'text'
    | 'uri'
    | 'binary'
    | 'float'
    | 'integer'
    | 'date-time'
    | 'date'
    | 'duration'
    | 'period'
    | 'utc-offset'
    | 'cal-address'
    | 'recur'
    | 'boolean'
    | 'unknown'

/**
 * All known names properties (top level keys) can have.
 * Such as "calscale", "dtstart", ...
 */
let property_names = [
    'calscale', 'method', 'prodid', 'version', 'attach', 'categories',
    'class', 'comment', 'description', 'geo', 'location', 'percent-complete',
    'priority', 'resources', 'status', 'summary', 'completed', 'dtend', 'due',
    'dtstart', 'duration', 'freebusy', 'transp', 'tzid', 'tzname', 'tzoffsetfrom',
    'tzoffsetto', 'tzurl', 'attendee', 'contact', 'organizer', 'recurrence-id',
    'related-to', 'url', 'uid', 'exdate', 'exrule', 'rdate', 'rrule', 'action',
    'repeat', 'trigger', 'created', 'dtstamp', 'last-modified', 'sequence', 'request-status'
];


/**
 * Which property fields each component can hold.
 *
 * ```json
 * { 'VCALENDAR': ['PRODID', 'VERSION', 'CALSCALE', 'METHOD'],
 *     ...
 * }
 * ```
 */
let valid_fields: Map<string, string[]> = new Map([
    ['VCALENDAR', ['PRODID', 'VERSION', 'CALSCALE', 'METHOD']],
    ['VEVENT', ['DTSTAMP', 'UID', 'DTSTART', 'CLASS', 'CREATED',
        'DESCRIPTION', 'GEO', 'LAST-MODIFIED', 'LOCATION',
        'ORGANIZER', 'PRIORITY', 'SEQUENCE', 'STATUS',
        'SUMMARY', 'TRANSP', 'URL', 'RECURRENCE-ID',
        'RRULE', 'DTEND', 'DURATION', 'ATTACH', 'ATTENDEE',
        'CATEGORIES', 'COMMENT', 'CONTACT', 'EXDATE',
        'REQUEST-STATUS', 'RELATED-TO', 'RESOURCES', 'RDATE']],
    ['VTODO', ['DTSTAMP', 'UID', 'CLASS', 'COMPLETED', 'CREATED',
        'DESCRIPTION', 'DTSTART', 'GEO', 'LAST-MODIFIED',
        'LOCATION', 'ORGANIZER', 'PERCENT-COMPLETE', 'PRIORITY',
        'RECURRENCE-ID', 'SEQUENCE', 'STATUS', 'SUMMARY', 'URL',
        'RRULE', 'DUE', 'DURATION', 'ATTACH', 'ATTENDEE', 'CATEGORIES',
        'COMMENT', 'CONTACT', 'EXDATE', 'REQUEST-STATUS', 'RELATED-TO',
        'RESOURCES', 'RDATE',]],
    ['VJOURNAL', ['DTSTAMP', 'UID', 'CLASS', 'CREATED', 'DTSTART', 'LAST-MODIFIED',
        'ORGANIZER', 'RECURRENCE-ID', 'SEQUENCE', 'STATUS', 'SUMMARY',
        'URL', 'RRULE', 'ATTACH', 'ATTENDEE', 'CATEGORIES', 'COMMENT',
        'CONTACT', 'DESCRIPTION', 'EXDATE', 'RELATED-TO', 'RDATE',
        'REQUEST-STATUS']],
    ['VFREEBUSY', ['DTSTAMP', 'UID', 'CONTACT', 'DTSTART', 'DTEND',
        'ORGANIZER', 'URL', 'ATTENDEE', 'COMMENT', 'FREEBUSY',
        'REQUEST-STATUS']],
    ['VTIMEZONE', ['TZID', 'LAST-MODIFIED', 'TZURL']],
    ['VALARM', ['ACTION', 'TRIGGER', 'DURATION', 'REPEAT', 'ATTACH',
        'DESCRIPTION', 'SUMMARY', 'ATTENDEE']],
    ['STANDARD', ['DTSTART', 'TZOFFSETFROM', 'TZOFFSETTO', 'RRULE',
        'COMMENT', 'RDATE', 'TZNAME']],
])

valid_fields.set('DAYLIGHT', valid_fields.get('STANDARD')!);

/**
   All registered property types for VComponents.

   Note that only some of these are valid for each type of component (VCALENDAR,
   VEVENT, ...), and that they all support both iana and `x-` extensions.
 */
type known_ical_types
    = 'ACTION'
    | 'ATTACH'
    | 'ATTENDEE'
    | 'CALSCALE'
    | 'CATEGORIES'
    | 'CLASS'
    | 'COMMENT'
    | 'COMPLETED'
    | 'CONTACT'
    | 'CREATED'
    | 'DESCRIPTION'
    | 'DTEND'
    | 'DTSTAMP'
    | 'DTSTART'
    | 'DUE'
    | 'DURATION'
    | 'EXDATE'
    | 'FREEBUSY'
    | 'GEO'
    | 'LAST-MODIFIED'
    | 'LOCATION'
    | 'METHOD'
    | 'ORGANIZER'
    | 'PERCENT-COMPLETE'
    | 'PRIORITY'
    | 'PRODID'
    | 'RDATE'
    | 'RECURRENCE-ID'
    | 'RELATED-TO'
    | 'REPEAT'
    | 'REQUEST-STATUS'
    | 'RESOURCES'
    | 'RRULE'
    | 'SEQUENCE'
    | 'STATUS'
    | 'SUMMARY'
    | 'TRANSP'
    | 'TRIGGER'
    | 'TZID'
    | 'TZNAME'
    | 'TZOFFSETFROM'
    | 'TZOFFSETTO'
    | 'TZURL'
    | 'URL'
    | 'VERSION'

/**
 * Which types are valid to store under each property.
 * If multiple values are an option for that property, then
 * the list of possibilities will contain a sub-list (see example).
 *
 * ```json
 * { 'DTSTART': ['date', 'date-time'],
 *   'CATEGORIES': [['text']],
 *   ...
 * }
 * ```
 */
let valid_input_types: Map<string, Array<ical_type | ical_type[]>> =
    new Map([
        ['ACTION', ['text']], // AUDIO|DISPLAY|EMAIL|*other*
        ['ATTACH', ['uri', 'binary']],
        ['ATTENDEE', ['cal-address']],
        ['CALSCALE', ['text']],
        ['CATEGORIES', [['text']]],
        ['CLASS', ['text']], // PUBLIC|PRIVATE|CONFIDENTIAL|*other*
        ['COMMENT', ['text']],
        ['COMPLETED', ['date-time']],
        ['CONTACT', ['text']],
        ['CREATED', ['date-time']],
        ['DESCRIPTION', ['text']],
        ['DTEND', ['date', 'date-time']],
        ['DTSTAMP', ['date-time']],
        ['DTSTART', ['date', 'date-time']],
        ['DUE', ['date', 'date-time']],
        ['DURATION', ['duration']],
        ['EXDATE', [['date', 'date-time']]],
        ['EXRULE', []], /* deprecated */
        ['FREEBUSY', [['period']]],
        ['GEO', ['float']], // pair of floats
        ['LAST-MODIFIED', ['date-time']],
        ['LOCATION', ['text']],
        ['METHOD', ['text']],
        ['ORGANIZER', ['cal-address']],
        ['PERCENT-COMPLETE', ['integer']], // 0-100
        ['PRIORITY', ['integer']], // 0-9
        ['PRODID', ['text']],
        ['RDATE', [['date', 'date-time', 'period']]],
        ['RECURRENCE-ID', ['date', 'date-time']],
        ['RELATED-TO', ['text']],
        ['REPEAT', ['integer']],
        ['REQUEST-STATUS', ['text']],
        ['RESOURCES', [['text']]],
        ['RRULE', ['recur']],
        ['SEQUENCE', ['integer']],
        ['STATUS', ['text']], // see 3.8.1.11
        ['SUMMARY', ['text']],
        ['TRANSP', ['text']], // OPAQUE|TRANSPARENT
        ['TRIGGER', ['duration', 'date-time']],
        ['TZID', ['text']],
        ['TZNAME', ['text']],
        ['TZOFFSETFROM', ['utc-offset']],
        ['TZOFFSETTO', ['utc-offset']],
        ['TZURL', ['uri']],
        ['UID', ['text']],
        ['URL', ['uri']],
        ['VERSION', ['text']],
    ])

// type JCalLine {
// }

/** The UID of a VEvent, to make declarations clearer.  */
type uid = string

/* TODO is this type correct?
   What really are valid values for any? Does that depend on ical_type? Why is the tail a list?
   What really is the type for the parameter map?
*/
/* TODO link to RFC 7265 (jCal) */
/**
 * Alias for a record consisting of
 * - the name of the type, as a string
 * - all parameters of the object, as a `Record<String, any>`
 * - An `ical_type` value, noting the type of the final field(s)
 * - and one or more values of the type specified by the third field.
 */
type JCalProperty
    = [string, Record<string, any>, ical_type, any]
    | [string, Record<string, any>, ical_type, ...any[]]

/**
   Base type for JCal documents.

   Each VComponent in a JCal document is of this form.

   - The first element is the components type
     ('vevent', 'vcalendar', ...), in all lower case
   - The second element is is all properties directly
     on the component.
   - The third element is a list of all children.
*/
type JCal = [string, JCalProperty[], JCal[]]

/** The xml namespace name for xcalendar */
const xcal = "urn:ietf:params:xml:ns:icalendar-2.0";

/**
   An entry into a changelog.

   This is primarily used by VEvent, to track what has happened during a
   session.
 */
interface ChangeLogEntry {
    /**
       Type of change

       'property' is used for changes to properties.

       'calendar' is used when the containing calendar of a VEVENT is changed
    */
    type: 'calendar' | 'property',
    /** The name of the filed changed */
    name: string,
    /** The previous value, `null` if just created */
    from: string | null,
    /** The new value, `null` if removed */
    to: string | null,
}