@craftguild/jscalendar 0.5.3 → 0.5.5

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.
Files changed (124) hide show
  1. package/README.md +128 -92
  2. package/dist/index.cjs +3923 -0
  3. package/dist/index.d.cts +802 -0
  4. package/dist/index.d.mts +802 -0
  5. package/dist/index.mjs +3927 -0
  6. package/package.json +46 -31
  7. package/dist/__tests__/builders.test.d.ts +0 -1
  8. package/dist/__tests__/builders.test.js +0 -101
  9. package/dist/__tests__/calendar-extra.test.d.ts +0 -1
  10. package/dist/__tests__/calendar-extra.test.js +0 -221
  11. package/dist/__tests__/calendar.test.d.ts +0 -1
  12. package/dist/__tests__/calendar.test.js +0 -97
  13. package/dist/__tests__/ical-extra.test.d.ts +0 -1
  14. package/dist/__tests__/ical-extra.test.js +0 -87
  15. package/dist/__tests__/ical.test.d.ts +0 -1
  16. package/dist/__tests__/ical.test.js +0 -72
  17. package/dist/__tests__/index.test.d.ts +0 -1
  18. package/dist/__tests__/index.test.js +0 -9
  19. package/dist/__tests__/patch.test.d.ts +0 -1
  20. package/dist/__tests__/patch.test.js +0 -47
  21. package/dist/__tests__/recurrence.test.d.ts +0 -1
  22. package/dist/__tests__/recurrence.test.js +0 -640
  23. package/dist/__tests__/search.test.d.ts +0 -1
  24. package/dist/__tests__/search.test.js +0 -264
  25. package/dist/__tests__/timezones.test.d.ts +0 -1
  26. package/dist/__tests__/timezones.test.js +0 -12
  27. package/dist/__tests__/utils.test.d.ts +0 -1
  28. package/dist/__tests__/utils.test.js +0 -127
  29. package/dist/__tests__/validation.test.d.ts +0 -1
  30. package/dist/__tests__/validation.test.js +0 -224
  31. package/dist/ical.d.ts +0 -13
  32. package/dist/ical.js +0 -270
  33. package/dist/index.d.ts +0 -3
  34. package/dist/index.js +0 -2
  35. package/dist/jscal/base.d.ts +0 -89
  36. package/dist/jscal/base.js +0 -173
  37. package/dist/jscal/builders.d.ts +0 -183
  38. package/dist/jscal/builders.js +0 -287
  39. package/dist/jscal/constants.d.ts +0 -11
  40. package/dist/jscal/constants.js +0 -11
  41. package/dist/jscal/datetime.d.ts +0 -14
  42. package/dist/jscal/datetime.js +0 -42
  43. package/dist/jscal/defaults.d.ts +0 -31
  44. package/dist/jscal/defaults.js +0 -102
  45. package/dist/jscal/duration.d.ts +0 -43
  46. package/dist/jscal/duration.js +0 -75
  47. package/dist/jscal/event.d.ts +0 -23
  48. package/dist/jscal/event.js +0 -78
  49. package/dist/jscal/group.d.ts +0 -31
  50. package/dist/jscal/group.js +0 -69
  51. package/dist/jscal/guards.d.ts +0 -19
  52. package/dist/jscal/guards.js +0 -25
  53. package/dist/jscal/ids.d.ts +0 -11
  54. package/dist/jscal/ids.js +0 -77
  55. package/dist/jscal/normalize.d.ts +0 -32
  56. package/dist/jscal/normalize.js +0 -45
  57. package/dist/jscal/task.d.ts +0 -23
  58. package/dist/jscal/task.js +0 -67
  59. package/dist/jscal/types.d.ts +0 -38
  60. package/dist/jscal/types.js +0 -1
  61. package/dist/jscal.d.ts +0 -145
  62. package/dist/jscal.js +0 -126
  63. package/dist/patch.d.ts +0 -18
  64. package/dist/patch.js +0 -216
  65. package/dist/recurrence/constants.d.ts +0 -13
  66. package/dist/recurrence/constants.js +0 -13
  67. package/dist/recurrence/date-utils.d.ts +0 -125
  68. package/dist/recurrence/date-utils.js +0 -259
  69. package/dist/recurrence/expand.d.ts +0 -23
  70. package/dist/recurrence/expand.js +0 -315
  71. package/dist/recurrence/rule-candidates.d.ts +0 -21
  72. package/dist/recurrence/rule-candidates.js +0 -120
  73. package/dist/recurrence/rule-generate.d.ts +0 -11
  74. package/dist/recurrence/rule-generate.js +0 -36
  75. package/dist/recurrence/rule-matchers.d.ts +0 -34
  76. package/dist/recurrence/rule-matchers.js +0 -120
  77. package/dist/recurrence/rule-normalize.d.ts +0 -9
  78. package/dist/recurrence/rule-normalize.js +0 -57
  79. package/dist/recurrence/rule-selectors.d.ts +0 -7
  80. package/dist/recurrence/rule-selectors.js +0 -21
  81. package/dist/recurrence/rules.d.ts +0 -14
  82. package/dist/recurrence/rules.js +0 -57
  83. package/dist/recurrence/types.d.ts +0 -27
  84. package/dist/recurrence/types.js +0 -1
  85. package/dist/recurrence.d.ts +0 -2
  86. package/dist/recurrence.js +0 -1
  87. package/dist/search.d.ts +0 -44
  88. package/dist/search.js +0 -292
  89. package/dist/timezones/chunk_1.d.ts +0 -2
  90. package/dist/timezones/chunk_1.js +0 -72
  91. package/dist/timezones/chunk_2.d.ts +0 -2
  92. package/dist/timezones/chunk_2.js +0 -72
  93. package/dist/timezones/chunk_3.d.ts +0 -2
  94. package/dist/timezones/chunk_3.js +0 -72
  95. package/dist/timezones/chunk_4.d.ts +0 -2
  96. package/dist/timezones/chunk_4.js +0 -72
  97. package/dist/timezones/chunk_5.d.ts +0 -2
  98. package/dist/timezones/chunk_5.js +0 -72
  99. package/dist/timezones/chunk_6.d.ts +0 -2
  100. package/dist/timezones/chunk_6.js +0 -72
  101. package/dist/timezones/chunk_7.d.ts +0 -2
  102. package/dist/timezones/chunk_7.js +0 -6
  103. package/dist/timezones.d.ts +0 -9
  104. package/dist/timezones.js +0 -452
  105. package/dist/types.d.ts +0 -246
  106. package/dist/types.js +0 -1
  107. package/dist/utils.d.ts +0 -82
  108. package/dist/utils.js +0 -164
  109. package/dist/validate/asserts.d.ts +0 -155
  110. package/dist/validate/asserts.js +0 -381
  111. package/dist/validate/constants.d.ts +0 -25
  112. package/dist/validate/constants.js +0 -33
  113. package/dist/validate/error.d.ts +0 -19
  114. package/dist/validate/error.js +0 -25
  115. package/dist/validate/validators-common.d.ts +0 -64
  116. package/dist/validate/validators-common.js +0 -390
  117. package/dist/validate/validators-objects.d.ts +0 -8
  118. package/dist/validate/validators-objects.js +0 -70
  119. package/dist/validate/validators-recurrence.d.ts +0 -15
  120. package/dist/validate/validators-recurrence.js +0 -115
  121. package/dist/validate/validators.d.ts +0 -1
  122. package/dist/validate/validators.js +0 -1
  123. package/dist/validate.d.ts +0 -2
  124. package/dist/validate.js +0 -2
@@ -1,183 +0,0 @@
1
- import type { Alert, AbsoluteTrigger, EventPatch, GroupPatch, Link, Location, NDay, OffsetTrigger, Participant, RecurrenceRule, Relation, TaskPatch, TimeZone, TimeZoneRule, VirtualLocation, Id } from "../types.js";
2
- declare const TYPE_PARTICIPANT = "Participant";
3
- declare const TYPE_LOCATION = "Location";
4
- declare const TYPE_VIRTUAL_LOCATION = "VirtualLocation";
5
- declare const TYPE_ALERT = "Alert";
6
- declare const TYPE_OFFSET_TRIGGER = "OffsetTrigger";
7
- declare const TYPE_ABSOLUTE_TRIGGER = "AbsoluteTrigger";
8
- declare const TYPE_RELATION = "Relation";
9
- declare const TYPE_LINK = "Link";
10
- declare const TYPE_TIME_ZONE = "TimeZone";
11
- declare const TYPE_TIME_ZONE_RULE = "TimeZoneRule";
12
- declare const TYPE_RECURRENCE_RULE = "RecurrenceRule";
13
- declare const TYPE_NDAY = "NDay";
14
- type WithOptionalType<T, TypeName extends string> = Omit<T, "@type"> & {
15
- "@type"?: TypeName;
16
- };
17
- export type ParticipantInput = WithOptionalType<Participant, typeof TYPE_PARTICIPANT>;
18
- export type LocationInput = WithOptionalType<Location, typeof TYPE_LOCATION>;
19
- export type VirtualLocationInput = WithOptionalType<VirtualLocation, typeof TYPE_VIRTUAL_LOCATION>;
20
- export type AlertInput = WithOptionalType<Alert, typeof TYPE_ALERT>;
21
- export type OffsetTriggerInput = WithOptionalType<OffsetTrigger, typeof TYPE_OFFSET_TRIGGER>;
22
- export type AbsoluteTriggerInput = WithOptionalType<AbsoluteTrigger, typeof TYPE_ABSOLUTE_TRIGGER>;
23
- export type RelationInput = WithOptionalType<Relation, typeof TYPE_RELATION>;
24
- export type LinkInput = WithOptionalType<Link, typeof TYPE_LINK>;
25
- export type TimeZoneInput = WithOptionalType<TimeZone, typeof TYPE_TIME_ZONE>;
26
- export type TimeZoneRuleInput = WithOptionalType<TimeZoneRule, typeof TYPE_TIME_ZONE_RULE>;
27
- export type RecurrenceRuleInput = WithOptionalType<RecurrenceRule, typeof TYPE_RECURRENCE_RULE>;
28
- export type NDayInput = WithOptionalType<NDay, typeof TYPE_NDAY>;
29
- export type EventPatchInput = EventPatch;
30
- export type TaskPatchInput = TaskPatch;
31
- export type GroupPatchInput = GroupPatch;
32
- export type IdValueInput<TInput> = {
33
- id?: Id;
34
- value: TInput;
35
- };
36
- /**
37
- * Build a Participant object with @type set and validated.
38
- * @param input Participant fields without @type.
39
- * @return Validated Participant object.
40
- */
41
- export declare function buildParticipant(input: ParticipantInput): Participant;
42
- /**
43
- * Build a Location object with @type set and validated.
44
- * @param input Location fields without @type.
45
- * @return Validated Location object.
46
- */
47
- export declare function buildLocation(input: LocationInput): Location;
48
- /**
49
- * Build a VirtualLocation object with @type set and validated.
50
- * @param input VirtualLocation fields without @type.
51
- * @return Validated VirtualLocation object.
52
- */
53
- export declare function buildVirtualLocation(input: VirtualLocationInput): VirtualLocation;
54
- /**
55
- * Build an Alert object with @type set and validated.
56
- * @param input Alert fields without @type.
57
- * @return Validated Alert object.
58
- */
59
- export declare function buildAlert(input: AlertInput): Alert;
60
- /**
61
- * Build an OffsetTrigger object with @type set and validated.
62
- * @param input OffsetTrigger fields without @type.
63
- * @return Validated OffsetTrigger object.
64
- */
65
- export declare function buildOffsetTrigger(input: OffsetTriggerInput): OffsetTrigger;
66
- /**
67
- * Build an AbsoluteTrigger object with @type set and validated.
68
- * @param input AbsoluteTrigger fields without @type.
69
- * @return Validated AbsoluteTrigger object.
70
- */
71
- export declare function buildAbsoluteTrigger(input: AbsoluteTriggerInput): AbsoluteTrigger;
72
- /**
73
- * Build a Relation object with @type set and validated.
74
- * @param input Relation fields without @type.
75
- * @return Validated Relation object.
76
- */
77
- export declare function buildRelation(input: RelationInput): Relation;
78
- /**
79
- * Build a Link object with @type set and validated.
80
- * @param input Link fields without @type.
81
- * @return Validated Link object.
82
- */
83
- export declare function buildLink(input: LinkInput): Link;
84
- /**
85
- * Build a TimeZone object with @type set and validated.
86
- * @param input TimeZone fields without @type.
87
- * @return Validated TimeZone object.
88
- */
89
- export declare function buildTimeZone(input: TimeZoneInput): TimeZone;
90
- /**
91
- * Build a TimeZoneRule object with @type set and validated.
92
- * @param input TimeZoneRule fields without @type.
93
- * @return Validated TimeZoneRule object.
94
- */
95
- export declare function buildTimeZoneRule(input: TimeZoneRuleInput): TimeZoneRule;
96
- /**
97
- * Build a RecurrenceRule object with @type set and validated.
98
- * @param input RecurrenceRule fields without @type.
99
- * @return Validated RecurrenceRule object.
100
- */
101
- export declare function buildRecurrenceRule(input: RecurrenceRuleInput): RecurrenceRule;
102
- /**
103
- * Build an NDay object with @type set and validated.
104
- * @param input NDay fields without @type.
105
- * @return Validated NDay object.
106
- */
107
- export declare function buildNDay(input: NDayInput): NDay;
108
- /**
109
- * Build a patch object for Event-like updates with JSON value validation.
110
- * @param input Patch fields for an event.
111
- * @return Validated PatchObject.
112
- */
113
- export declare function buildEventPatch(input: EventPatchInput): EventPatch;
114
- /**
115
- * Build a patch object for Task-like updates with JSON value validation.
116
- * @param input Patch fields for a task.
117
- * @return Validated PatchObject.
118
- */
119
- export declare function buildTaskPatch(input: TaskPatchInput): TaskPatch;
120
- /**
121
- * Build a patch object for Group-like updates with JSON value validation.
122
- * @param input Patch fields for a group.
123
- * @return Validated PatchObject.
124
- */
125
- export declare function buildGroupPatch(input: GroupPatchInput): GroupPatch;
126
- /**
127
- * Build a record keyed by Ids, optionally merging into an existing record.
128
- * @param items Items to store with optional explicit ids.
129
- * @param builder Builder function to validate each item.
130
- * @param idFn Optional ID generator for items without explicit ids.
131
- * @param existing Existing record to merge into.
132
- * @return Record keyed by ids with merged values.
133
- */
134
- export declare function buildIdMap<TInput, TOutput>(items: Array<IdValueInput<TInput>>, builder: (input: TInput) => TOutput, idFn?: (input: TInput, index: number) => Id, existing?: Record<Id, TOutput>): Record<Id, TOutput>;
135
- /**
136
- * Build a record of Participant objects keyed by Ids.
137
- * @param items Participant inputs with optional explicit ids.
138
- * @param existing Existing participant record to merge into.
139
- * @return Participant record keyed by Id.
140
- */
141
- export declare function buildParticipants(items: Array<IdValueInput<ParticipantInput>>, existing?: Record<Id, Participant>): Record<Id, Participant>;
142
- /**
143
- * Build a record of Location objects keyed by Ids.
144
- * @param items Location inputs with optional explicit ids.
145
- * @param existing Existing location record to merge into.
146
- * @return Location record keyed by Id.
147
- */
148
- export declare function buildLocations(items: Array<IdValueInput<LocationInput>>, existing?: Record<Id, Location>): Record<Id, Location>;
149
- /**
150
- * Build a record of VirtualLocation objects keyed by Ids.
151
- * @param items VirtualLocation inputs with optional explicit ids.
152
- * @param existing Existing virtual location record to merge into.
153
- * @return VirtualLocation record keyed by Id.
154
- */
155
- export declare function buildVirtualLocations(items: Array<IdValueInput<VirtualLocationInput>>, existing?: Record<Id, VirtualLocation>): Record<Id, VirtualLocation>;
156
- /**
157
- * Build a record of Alert objects keyed by Ids.
158
- * @param items Alert inputs with optional explicit ids.
159
- * @param existing Existing alert record to merge into.
160
- * @return Alert record keyed by Id.
161
- */
162
- export declare function buildAlerts(items: Array<IdValueInput<AlertInput>>, existing?: Record<Id, Alert>): Record<Id, Alert>;
163
- /**
164
- * Build a record of Link objects keyed by Ids.
165
- * @param items Link inputs with optional explicit ids.
166
- * @param existing Existing link record to merge into.
167
- * @return Link record keyed by Id.
168
- */
169
- export declare function buildLinks(items: Array<IdValueInput<LinkInput>>, existing?: Record<Id, Link>): Record<Id, Link>;
170
- /**
171
- * Build a record of Relation objects keyed by Ids.
172
- * @param items Relation inputs with optional explicit ids.
173
- * @param existing Existing relation record to merge into.
174
- * @return Relation record keyed by Id.
175
- */
176
- export declare function buildRelatedTo(items: Array<IdValueInput<RelationInput>>, existing?: Record<Id, Relation>): Record<Id, Relation>;
177
- /**
178
- * Build a record of TimeZone objects keyed by tzId.
179
- * @param items TimeZone inputs.
180
- * @return TimeZone record keyed by tzId.
181
- */
182
- export declare function buildTimeZoneMap(items: TimeZoneInput[]): Record<string, TimeZone>;
183
- export {};
@@ -1,287 +0,0 @@
1
- import { createId } from "./ids.js";
2
- import { validateAlert, validateLink, validateLocation, validateParticipant, validateRelation, validateTimeZoneObject, validateTimeZoneRule, validateVirtualLocation } from "../validate/validators-common.js";
3
- import { validateNDay, validateRecurrenceRule } from "../validate/validators-recurrence.js";
4
- import { fail } from "../validate/error.js";
5
- import { assertPatchObject, assertSignedDuration, assertString, assertUtcDateTime } from "../validate/asserts.js";
6
- const TYPE_PARTICIPANT = "Participant";
7
- const TYPE_LOCATION = "Location";
8
- const TYPE_VIRTUAL_LOCATION = "VirtualLocation";
9
- const TYPE_ALERT = "Alert";
10
- const TYPE_OFFSET_TRIGGER = "OffsetTrigger";
11
- const TYPE_ABSOLUTE_TRIGGER = "AbsoluteTrigger";
12
- const TYPE_RELATION = "Relation";
13
- const TYPE_LINK = "Link";
14
- const TYPE_TIME_ZONE = "TimeZone";
15
- const TYPE_TIME_ZONE_RULE = "TimeZoneRule";
16
- const TYPE_RECURRENCE_RULE = "RecurrenceRule";
17
- const TYPE_NDAY = "NDay";
18
- /**
19
- * Build a Participant object with @type set and validated.
20
- * @param input Participant fields without @type.
21
- * @return Validated Participant object.
22
- */
23
- export function buildParticipant(input) {
24
- if (input["@type"] && input["@type"] !== TYPE_PARTICIPANT) {
25
- fail("participant", `must have @type ${TYPE_PARTICIPANT}`);
26
- }
27
- const participant = { ...input, "@type": TYPE_PARTICIPANT };
28
- validateParticipant(participant, "participant");
29
- return participant;
30
- }
31
- /**
32
- * Build a Location object with @type set and validated.
33
- * @param input Location fields without @type.
34
- * @return Validated Location object.
35
- */
36
- export function buildLocation(input) {
37
- if (input["@type"] && input["@type"] !== TYPE_LOCATION) {
38
- fail("location", `must have @type ${TYPE_LOCATION}`);
39
- }
40
- const location = { ...input, "@type": TYPE_LOCATION };
41
- validateLocation(location, "location");
42
- return location;
43
- }
44
- /**
45
- * Build a VirtualLocation object with @type set and validated.
46
- * @param input VirtualLocation fields without @type.
47
- * @return Validated VirtualLocation object.
48
- */
49
- export function buildVirtualLocation(input) {
50
- if (input["@type"] && input["@type"] !== TYPE_VIRTUAL_LOCATION) {
51
- fail("virtualLocation", `must have @type ${TYPE_VIRTUAL_LOCATION}`);
52
- }
53
- const virtualLocation = { ...input, "@type": TYPE_VIRTUAL_LOCATION };
54
- validateVirtualLocation(virtualLocation, "virtualLocation");
55
- return virtualLocation;
56
- }
57
- /**
58
- * Build an Alert object with @type set and validated.
59
- * @param input Alert fields without @type.
60
- * @return Validated Alert object.
61
- */
62
- export function buildAlert(input) {
63
- if (input["@type"] && input["@type"] !== TYPE_ALERT) {
64
- fail("alert", `must have @type ${TYPE_ALERT}`);
65
- }
66
- const alert = { ...input, "@type": TYPE_ALERT };
67
- validateAlert(alert, "alert");
68
- return alert;
69
- }
70
- /**
71
- * Build an OffsetTrigger object with @type set and validated.
72
- * @param input OffsetTrigger fields without @type.
73
- * @return Validated OffsetTrigger object.
74
- */
75
- export function buildOffsetTrigger(input) {
76
- if (input["@type"] && input["@type"] !== TYPE_OFFSET_TRIGGER) {
77
- fail("offsetTrigger", `must have @type ${TYPE_OFFSET_TRIGGER}`);
78
- }
79
- const trigger = { ...input, "@type": TYPE_OFFSET_TRIGGER };
80
- assertSignedDuration(trigger.offset, "offsetTrigger.offset");
81
- assertString(trigger.relativeTo, "offsetTrigger.relativeTo");
82
- return trigger;
83
- }
84
- /**
85
- * Build an AbsoluteTrigger object with @type set and validated.
86
- * @param input AbsoluteTrigger fields without @type.
87
- * @return Validated AbsoluteTrigger object.
88
- */
89
- export function buildAbsoluteTrigger(input) {
90
- if (input["@type"] && input["@type"] !== TYPE_ABSOLUTE_TRIGGER) {
91
- fail("absoluteTrigger", `must have @type ${TYPE_ABSOLUTE_TRIGGER}`);
92
- }
93
- const trigger = { ...input, "@type": TYPE_ABSOLUTE_TRIGGER };
94
- assertUtcDateTime(trigger.when, "absoluteTrigger.when");
95
- return trigger;
96
- }
97
- /**
98
- * Build a Relation object with @type set and validated.
99
- * @param input Relation fields without @type.
100
- * @return Validated Relation object.
101
- */
102
- export function buildRelation(input) {
103
- if (input["@type"] && input["@type"] !== TYPE_RELATION) {
104
- fail("relation", `must have @type ${TYPE_RELATION}`);
105
- }
106
- const relation = { ...input, "@type": TYPE_RELATION };
107
- validateRelation(relation, "relation");
108
- return relation;
109
- }
110
- /**
111
- * Build a Link object with @type set and validated.
112
- * @param input Link fields without @type.
113
- * @return Validated Link object.
114
- */
115
- export function buildLink(input) {
116
- if (input["@type"] && input["@type"] !== TYPE_LINK) {
117
- fail("link", `must have @type ${TYPE_LINK}`);
118
- }
119
- const link = { ...input, "@type": TYPE_LINK };
120
- validateLink(link, "link");
121
- return link;
122
- }
123
- /**
124
- * Build a TimeZone object with @type set and validated.
125
- * @param input TimeZone fields without @type.
126
- * @return Validated TimeZone object.
127
- */
128
- export function buildTimeZone(input) {
129
- if (input["@type"] && input["@type"] !== TYPE_TIME_ZONE) {
130
- fail("timeZone", `must have @type ${TYPE_TIME_ZONE}`);
131
- }
132
- const timeZone = { ...input, "@type": TYPE_TIME_ZONE };
133
- validateTimeZoneObject(timeZone, "timeZone");
134
- return timeZone;
135
- }
136
- /**
137
- * Build a TimeZoneRule object with @type set and validated.
138
- * @param input TimeZoneRule fields without @type.
139
- * @return Validated TimeZoneRule object.
140
- */
141
- export function buildTimeZoneRule(input) {
142
- if (input["@type"] && input["@type"] !== TYPE_TIME_ZONE_RULE) {
143
- fail("timeZoneRule", `must have @type ${TYPE_TIME_ZONE_RULE}`);
144
- }
145
- const rule = { ...input, "@type": TYPE_TIME_ZONE_RULE };
146
- validateTimeZoneRule(rule, "timeZoneRule");
147
- return rule;
148
- }
149
- /**
150
- * Build a RecurrenceRule object with @type set and validated.
151
- * @param input RecurrenceRule fields without @type.
152
- * @return Validated RecurrenceRule object.
153
- */
154
- export function buildRecurrenceRule(input) {
155
- if (input["@type"] && input["@type"] !== TYPE_RECURRENCE_RULE) {
156
- fail("recurrenceRule", `must have @type ${TYPE_RECURRENCE_RULE}`);
157
- }
158
- const rule = { ...input, "@type": TYPE_RECURRENCE_RULE };
159
- validateRecurrenceRule(rule, "recurrenceRule");
160
- return rule;
161
- }
162
- /**
163
- * Build an NDay object with @type set and validated.
164
- * @param input NDay fields without @type.
165
- * @return Validated NDay object.
166
- */
167
- export function buildNDay(input) {
168
- if (input["@type"] && input["@type"] !== TYPE_NDAY) {
169
- fail("nday", `must have @type ${TYPE_NDAY}`);
170
- }
171
- const nday = { ...input, "@type": TYPE_NDAY };
172
- validateNDay(nday, "nday");
173
- return nday;
174
- }
175
- /**
176
- * Build a patch object for Event-like updates with JSON value validation.
177
- * @param input Patch fields for an event.
178
- * @return Validated PatchObject.
179
- */
180
- export function buildEventPatch(input) {
181
- const patch = { ...input };
182
- assertPatchObject(patch, "eventPatch");
183
- return patch;
184
- }
185
- /**
186
- * Build a patch object for Task-like updates with JSON value validation.
187
- * @param input Patch fields for a task.
188
- * @return Validated PatchObject.
189
- */
190
- export function buildTaskPatch(input) {
191
- const patch = { ...input };
192
- assertPatchObject(patch, "taskPatch");
193
- return patch;
194
- }
195
- /**
196
- * Build a patch object for Group-like updates with JSON value validation.
197
- * @param input Patch fields for a group.
198
- * @return Validated PatchObject.
199
- */
200
- export function buildGroupPatch(input) {
201
- const patch = { ...input };
202
- assertPatchObject(patch, "groupPatch");
203
- return patch;
204
- }
205
- /**
206
- * Build a record keyed by Ids, optionally merging into an existing record.
207
- * @param items Items to store with optional explicit ids.
208
- * @param builder Builder function to validate each item.
209
- * @param idFn Optional ID generator for items without explicit ids.
210
- * @param existing Existing record to merge into.
211
- * @return Record keyed by ids with merged values.
212
- */
213
- export function buildIdMap(items, builder, idFn = () => createId(), existing) {
214
- const result = existing ? { ...existing } : {};
215
- items.forEach((item, index) => {
216
- const id = item.id ?? idFn(item.value, index);
217
- result[id] = builder(item.value);
218
- });
219
- return result;
220
- }
221
- /**
222
- * Build a record of Participant objects keyed by Ids.
223
- * @param items Participant inputs with optional explicit ids.
224
- * @param existing Existing participant record to merge into.
225
- * @return Participant record keyed by Id.
226
- */
227
- export function buildParticipants(items, existing) {
228
- return buildIdMap(items, buildParticipant, () => createId(), existing);
229
- }
230
- /**
231
- * Build a record of Location objects keyed by Ids.
232
- * @param items Location inputs with optional explicit ids.
233
- * @param existing Existing location record to merge into.
234
- * @return Location record keyed by Id.
235
- */
236
- export function buildLocations(items, existing) {
237
- return buildIdMap(items, buildLocation, () => createId(), existing);
238
- }
239
- /**
240
- * Build a record of VirtualLocation objects keyed by Ids.
241
- * @param items VirtualLocation inputs with optional explicit ids.
242
- * @param existing Existing virtual location record to merge into.
243
- * @return VirtualLocation record keyed by Id.
244
- */
245
- export function buildVirtualLocations(items, existing) {
246
- return buildIdMap(items, buildVirtualLocation, () => createId(), existing);
247
- }
248
- /**
249
- * Build a record of Alert objects keyed by Ids.
250
- * @param items Alert inputs with optional explicit ids.
251
- * @param existing Existing alert record to merge into.
252
- * @return Alert record keyed by Id.
253
- */
254
- export function buildAlerts(items, existing) {
255
- return buildIdMap(items, buildAlert, () => createId(), existing);
256
- }
257
- /**
258
- * Build a record of Link objects keyed by Ids.
259
- * @param items Link inputs with optional explicit ids.
260
- * @param existing Existing link record to merge into.
261
- * @return Link record keyed by Id.
262
- */
263
- export function buildLinks(items, existing) {
264
- return buildIdMap(items, buildLink, () => createId(), existing);
265
- }
266
- /**
267
- * Build a record of Relation objects keyed by Ids.
268
- * @param items Relation inputs with optional explicit ids.
269
- * @param existing Existing relation record to merge into.
270
- * @return Relation record keyed by Id.
271
- */
272
- export function buildRelatedTo(items, existing) {
273
- return buildIdMap(items, buildRelation, () => createId(), existing);
274
- }
275
- /**
276
- * Build a record of TimeZone objects keyed by tzId.
277
- * @param items TimeZone inputs.
278
- * @return TimeZone record keyed by tzId.
279
- */
280
- export function buildTimeZoneMap(items) {
281
- const result = {};
282
- items.forEach((item) => {
283
- const timeZone = buildTimeZone(item);
284
- result[timeZone.tzId] = timeZone;
285
- });
286
- return result;
287
- }
@@ -1,11 +0,0 @@
1
- export declare const TYPEOF_FUNCTION = "function";
2
- export declare const EMPTY_STRING = "";
3
- export declare const TYPE_EVENT = "Event";
4
- export declare const TYPE_TASK = "Task";
5
- export declare const TYPE_GROUP = "Group";
6
- export declare const STATUS_COMPLETED = "completed";
7
- export declare const STATUS_FAILED = "failed";
8
- export declare const STATUS_IN_PROCESS = "in-process";
9
- export declare const STATUS_NEEDS_ACTION = "needs-action";
10
- export declare const TRIGGER_OFFSET = "OffsetTrigger";
11
- export declare const KEY_PARTICIPANTS = "participants";
@@ -1,11 +0,0 @@
1
- export const TYPEOF_FUNCTION = "function";
2
- export const EMPTY_STRING = "";
3
- export const TYPE_EVENT = "Event";
4
- export const TYPE_TASK = "Task";
5
- export const TYPE_GROUP = "Group";
6
- export const STATUS_COMPLETED = "completed";
7
- export const STATUS_FAILED = "failed";
8
- export const STATUS_IN_PROCESS = "in-process";
9
- export const STATUS_NEEDS_ACTION = "needs-action";
10
- export const TRIGGER_OFFSET = "OffsetTrigger";
11
- export const KEY_PARTICIPANTS = "participants";
@@ -1,14 +0,0 @@
1
- import type { UTCDateTime } from "../types.js";
2
- import type { DateInput } from "./types.js";
3
- /**
4
- * Convert a Date input to a LocalDateTime string.
5
- * @param value Date or LocalDateTime string.
6
- * @return LocalDateTime string.
7
- */
8
- export declare function toLocalDateTime(value: DateInput): string;
9
- /**
10
- * Convert a Date input to a UTCDateTime string.
11
- * @param value Date or UTCDateTime string.
12
- * @return UTCDateTime string.
13
- */
14
- export declare function toUtcDateTime(value: DateInput): UTCDateTime;
@@ -1,42 +0,0 @@
1
- import { normalizeUtcDateTime } from "../utils.js";
2
- import { isStringValue } from "../utils.js";
3
- /**
4
- * Pad a number to two digits.
5
- * @param value Number to pad.
6
- * @return Zero-padded string.
7
- */
8
- function pad2(value) {
9
- return value.toString().padStart(2, "0");
10
- }
11
- /**
12
- * Convert a Date input to a LocalDateTime string.
13
- * @param value Date or LocalDateTime string.
14
- * @return LocalDateTime string.
15
- */
16
- export function toLocalDateTime(value) {
17
- if (isStringValue(value))
18
- return value;
19
- return [
20
- value.getFullYear().toString().padStart(4, "0"),
21
- "-",
22
- pad2(value.getMonth() + 1),
23
- "-",
24
- pad2(value.getDate()),
25
- "T",
26
- pad2(value.getHours()),
27
- ":",
28
- pad2(value.getMinutes()),
29
- ":",
30
- pad2(value.getSeconds()),
31
- ].join("");
32
- }
33
- /**
34
- * Convert a Date input to a UTCDateTime string.
35
- * @param value Date or UTCDateTime string.
36
- * @return UTCDateTime string.
37
- */
38
- export function toUtcDateTime(value) {
39
- if (isStringValue(value))
40
- return value;
41
- return normalizeUtcDateTime(value.toISOString());
42
- }
@@ -1,31 +0,0 @@
1
- import type { Alert, Event, JSCalendarObject, Participant, Task } from "../types.js";
2
- /**
3
- * Apply common defaults to the target.
4
- * @param data JSCalendar object to mutate.
5
- * @return The same object with defaults applied.
6
- */
7
- export declare function applyCommonDefaults<T extends JSCalendarObject>(data: T): T;
8
- /**
9
- * Apply event defaults to the target.
10
- * @param data Event to mutate.
11
- * @return The same event with defaults applied.
12
- */
13
- export declare function applyEventDefaults(data: Event): Event;
14
- /**
15
- * Apply task defaults to the target.
16
- * @param data Task to mutate.
17
- * @return The same task with defaults applied.
18
- */
19
- export declare function applyTaskDefaults(data: Task): Task;
20
- /**
21
- * Apply participant defaults to the target.
22
- * @param participant Participant to mutate.
23
- * @return The same participant with defaults applied.
24
- */
25
- export declare function applyParticipantDefaults(participant: Participant): Participant;
26
- /**
27
- * Apply alert defaults to the target.
28
- * @param alert Alert to mutate.
29
- * @return The same alert with defaults applied.
30
- */
31
- export declare function applyAlertDefaults(alert: Alert): Alert;
@@ -1,102 +0,0 @@
1
- import { STATUS_COMPLETED, STATUS_FAILED, STATUS_IN_PROCESS, STATUS_NEEDS_ACTION, TRIGGER_OFFSET } from "./constants.js";
2
- /**
3
- * Apply common defaults to the target.
4
- * @param data JSCalendar object to mutate.
5
- * @return The same object with defaults applied.
6
- */
7
- export function applyCommonDefaults(data) {
8
- if (data.sequence === undefined)
9
- data.sequence = 0;
10
- if (data.title === undefined)
11
- data.title = "";
12
- if (data.description === undefined)
13
- data.description = "";
14
- if (data.descriptionContentType === undefined)
15
- data.descriptionContentType = "text/plain";
16
- if (data.showWithoutTime === undefined)
17
- data.showWithoutTime = false;
18
- if (data.recurrenceIdTimeZone === undefined)
19
- data.recurrenceIdTimeZone = null;
20
- if (data.excluded === undefined)
21
- data.excluded = false;
22
- if (data.priority === undefined)
23
- data.priority = 0;
24
- if (data.freeBusyStatus === undefined)
25
- data.freeBusyStatus = "busy";
26
- if (data.privacy === undefined)
27
- data.privacy = "public";
28
- if (data.useDefaultAlerts === undefined)
29
- data.useDefaultAlerts = false;
30
- return data;
31
- }
32
- /**
33
- * Apply event defaults to the target.
34
- * @param data Event to mutate.
35
- * @return The same event with defaults applied.
36
- */
37
- export function applyEventDefaults(data) {
38
- if (data.duration === undefined)
39
- data.duration = "PT0S";
40
- if (data.status === undefined)
41
- data.status = "confirmed";
42
- return data;
43
- }
44
- /**
45
- * Apply task defaults to the target.
46
- * @param data Task to mutate.
47
- * @return The same task with defaults applied.
48
- */
49
- export function applyTaskDefaults(data) {
50
- if (data.progress === undefined) {
51
- const participants = data.participants ? Object.values(data.participants) : [];
52
- if (participants.length === 0) {
53
- data.progress = STATUS_NEEDS_ACTION;
54
- }
55
- else if (participants.every((p) => p.progress === STATUS_COMPLETED)) {
56
- data.progress = STATUS_COMPLETED;
57
- }
58
- else if (participants.some((p) => p.progress === STATUS_FAILED)) {
59
- data.progress = STATUS_FAILED;
60
- }
61
- else if (participants.some((p) => p.progress === STATUS_IN_PROCESS)) {
62
- data.progress = STATUS_IN_PROCESS;
63
- }
64
- else {
65
- data.progress = STATUS_NEEDS_ACTION;
66
- }
67
- }
68
- return data;
69
- }
70
- /**
71
- * Apply participant defaults to the target.
72
- * @param participant Participant to mutate.
73
- * @return The same participant with defaults applied.
74
- */
75
- export function applyParticipantDefaults(participant) {
76
- if (participant.participationStatus === undefined)
77
- participant.participationStatus = "needs-action";
78
- if (participant.expectReply === undefined)
79
- participant.expectReply = false;
80
- if (participant.scheduleAgent === undefined)
81
- participant.scheduleAgent = "server";
82
- if (participant.scheduleForceSend === undefined)
83
- participant.scheduleForceSend = false;
84
- if (participant.scheduleSequence === undefined)
85
- participant.scheduleSequence = 0;
86
- return participant;
87
- }
88
- /**
89
- * Apply alert defaults to the target.
90
- * @param alert Alert to mutate.
91
- * @return The same alert with defaults applied.
92
- */
93
- export function applyAlertDefaults(alert) {
94
- if (alert.action === undefined)
95
- alert.action = "display";
96
- if (alert.trigger["@type"] === TRIGGER_OFFSET) {
97
- if (alert.trigger.relativeTo === undefined) {
98
- alert.trigger.relativeTo = "start";
99
- }
100
- }
101
- return alert;
102
- }