@craftguild/jscalendar 0.2.0 → 0.3.0
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 +63 -0
- package/dist/__tests__/builders.test.d.ts +1 -0
- package/dist/__tests__/builders.test.js +82 -0
- package/dist/__tests__/calendar-extra.test.js +36 -0
- package/dist/__tests__/recurrence.test.js +123 -0
- package/dist/__tests__/search.test.js +27 -0
- package/dist/__tests__/utils.test.js +3 -0
- package/dist/__tests__/validation.test.js +113 -0
- package/dist/ical.d.ts +6 -0
- package/dist/ical.js +71 -3
- package/dist/jscal/base.d.ts +90 -0
- package/dist/jscal/base.js +181 -0
- package/dist/jscal/builders.d.ts +135 -0
- package/dist/jscal/builders.js +220 -0
- package/dist/jscal/constants.d.ts +11 -0
- package/dist/jscal/constants.js +11 -0
- package/dist/jscal/datetime.d.ts +14 -0
- package/dist/jscal/datetime.js +42 -0
- package/dist/jscal/defaults.d.ts +31 -0
- package/dist/jscal/defaults.js +102 -0
- package/dist/jscal/duration.d.ts +43 -0
- package/dist/jscal/duration.js +72 -0
- package/dist/jscal/event.d.ts +17 -0
- package/dist/jscal/event.js +71 -0
- package/dist/jscal/group.d.ts +25 -0
- package/dist/jscal/group.js +62 -0
- package/dist/jscal/guards.d.ts +19 -0
- package/dist/jscal/guards.js +25 -0
- package/dist/jscal/ids.d.ts +11 -0
- package/dist/jscal/ids.js +77 -0
- package/dist/jscal/normalize.d.ts +32 -0
- package/dist/jscal/normalize.js +45 -0
- package/dist/jscal/task.d.ts +17 -0
- package/dist/jscal/task.js +60 -0
- package/dist/jscal/types.d.ts +38 -0
- package/dist/jscal/types.js +1 -0
- package/dist/jscal.d.ts +77 -70
- package/dist/jscal.js +77 -465
- package/dist/patch.d.ts +13 -0
- package/dist/patch.js +166 -41
- package/dist/recurrence/constants.d.ts +13 -0
- package/dist/recurrence/constants.js +13 -0
- package/dist/recurrence/date-utils.d.ts +125 -0
- package/dist/recurrence/date-utils.js +259 -0
- package/dist/recurrence/expand.d.ts +23 -0
- package/dist/recurrence/expand.js +294 -0
- package/dist/recurrence/rule-candidates.d.ts +21 -0
- package/dist/recurrence/rule-candidates.js +120 -0
- package/dist/recurrence/rule-generate.d.ts +11 -0
- package/dist/recurrence/rule-generate.js +36 -0
- package/dist/recurrence/rule-matchers.d.ts +34 -0
- package/dist/recurrence/rule-matchers.js +120 -0
- package/dist/recurrence/rule-normalize.d.ts +9 -0
- package/dist/recurrence/rule-normalize.js +57 -0
- package/dist/recurrence/rule-selectors.d.ts +7 -0
- package/dist/recurrence/rule-selectors.js +21 -0
- package/dist/recurrence/rules.d.ts +14 -0
- package/dist/recurrence/rules.js +57 -0
- package/dist/recurrence/types.d.ts +27 -0
- package/dist/recurrence/types.js +1 -0
- package/dist/recurrence.d.ts +2 -15
- package/dist/recurrence.js +1 -674
- package/dist/search.d.ts +30 -0
- package/dist/search.js +92 -8
- package/dist/timezones/chunk_1.d.ts +2 -0
- package/dist/timezones/chunk_1.js +72 -0
- package/dist/timezones/chunk_2.d.ts +2 -0
- package/dist/timezones/chunk_2.js +72 -0
- package/dist/timezones/chunk_3.d.ts +2 -0
- package/dist/timezones/chunk_3.js +72 -0
- package/dist/timezones/chunk_4.d.ts +2 -0
- package/dist/timezones/chunk_4.js +72 -0
- package/dist/timezones/chunk_5.d.ts +2 -0
- package/dist/timezones/chunk_5.js +72 -0
- package/dist/timezones/chunk_6.d.ts +2 -0
- package/dist/timezones/chunk_6.js +72 -0
- package/dist/timezones/chunk_7.d.ts +2 -0
- package/dist/timezones/chunk_7.js +6 -0
- package/dist/timezones.d.ts +5 -0
- package/dist/timezones.js +14 -3
- package/dist/utils.d.ts +72 -0
- package/dist/utils.js +85 -1
- package/dist/validate/asserts.d.ts +155 -0
- package/dist/validate/asserts.js +381 -0
- package/dist/validate/constants.d.ts +25 -0
- package/dist/validate/constants.js +33 -0
- package/dist/validate/error.d.ts +19 -0
- package/dist/validate/error.js +25 -0
- package/dist/validate/validators-common.d.ts +64 -0
- package/dist/validate/validators-common.js +385 -0
- package/dist/validate/validators-objects.d.ts +8 -0
- package/dist/validate/validators-objects.js +70 -0
- package/dist/validate/validators-recurrence.d.ts +15 -0
- package/dist/validate/validators-recurrence.js +115 -0
- package/dist/validate/validators.d.ts +1 -0
- package/dist/validate/validators.js +1 -0
- package/dist/validate.d.ts +2 -6
- package/dist/validate.js +2 -745
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Task } from "../types.js";
|
|
2
|
+
import type { CreateOptions, TaskInput } from "./types.js";
|
|
3
|
+
import { Base } from "./base.js";
|
|
4
|
+
export declare class TaskObject extends Base<Task> {
|
|
5
|
+
/**
|
|
6
|
+
* Create a task with normalized date fields and RFC defaults applied.
|
|
7
|
+
* @param input Task input values to normalize.
|
|
8
|
+
* @param options Creation options (validation, clock).
|
|
9
|
+
* @return TaskObject instance.
|
|
10
|
+
*/
|
|
11
|
+
constructor(input?: TaskInput, options?: CreateOptions);
|
|
12
|
+
/**
|
|
13
|
+
* Clone the task as a new TaskObject instance.
|
|
14
|
+
* @return Cloned TaskObject.
|
|
15
|
+
*/
|
|
16
|
+
clone(): TaskObject;
|
|
17
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { resolveTimeZone } from "../timezones.js";
|
|
2
|
+
import { deepClone, nowUtc } from "../utils.js";
|
|
3
|
+
import { validateJsCalendarObject } from "../validate.js";
|
|
4
|
+
import { applyCommonDefaults, applyTaskDefaults } from "./defaults.js";
|
|
5
|
+
import { createUid } from "./ids.js";
|
|
6
|
+
import { toLocalDateTime, toUtcDateTime } from "./datetime.js";
|
|
7
|
+
import { Base } from "./base.js";
|
|
8
|
+
export class TaskObject extends Base {
|
|
9
|
+
/**
|
|
10
|
+
* Create a task with normalized date fields and RFC defaults applied.
|
|
11
|
+
* @param input Task input values to normalize.
|
|
12
|
+
* @param options Creation options (validation, clock).
|
|
13
|
+
* @return TaskObject instance.
|
|
14
|
+
*/
|
|
15
|
+
constructor(input = {}, options = {}) {
|
|
16
|
+
const now = options.now ?? nowUtc;
|
|
17
|
+
const { start: rawStart, due: rawDue, updated: rawUpdated, created: rawCreated, timeZone: rawTimeZone, ...rest } = input;
|
|
18
|
+
const updated = rawUpdated ? toUtcDateTime(rawUpdated) : now();
|
|
19
|
+
let timeZone;
|
|
20
|
+
if (rawTimeZone === null) {
|
|
21
|
+
timeZone = null;
|
|
22
|
+
}
|
|
23
|
+
else if (rawTimeZone) {
|
|
24
|
+
timeZone = resolveTimeZone(rawTimeZone);
|
|
25
|
+
}
|
|
26
|
+
const data = {
|
|
27
|
+
...rest,
|
|
28
|
+
"@type": "Task",
|
|
29
|
+
uid: input.uid ?? createUid(),
|
|
30
|
+
updated,
|
|
31
|
+
};
|
|
32
|
+
if (rawStart)
|
|
33
|
+
data.start = toLocalDateTime(rawStart);
|
|
34
|
+
if (rawDue)
|
|
35
|
+
data.due = toLocalDateTime(rawDue);
|
|
36
|
+
if (timeZone !== undefined)
|
|
37
|
+
data.timeZone = timeZone;
|
|
38
|
+
if (rawCreated) {
|
|
39
|
+
data.created = toUtcDateTime(rawCreated);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
data.created = updated;
|
|
43
|
+
}
|
|
44
|
+
applyCommonDefaults(data);
|
|
45
|
+
applyTaskDefaults(data);
|
|
46
|
+
if (options.validate !== false) {
|
|
47
|
+
validateJsCalendarObject(data);
|
|
48
|
+
}
|
|
49
|
+
super(data);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Clone the task as a new TaskObject instance.
|
|
53
|
+
* @return Cloned TaskObject.
|
|
54
|
+
*/
|
|
55
|
+
clone() {
|
|
56
|
+
const cloneData = deepClone(this.data);
|
|
57
|
+
const { "@type": _type, ...rest } = cloneData;
|
|
58
|
+
return new TaskObject(rest);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Event, Group, Task, TimeZoneInput, UTCDateTime } from "../types.js";
|
|
2
|
+
export type CreateOptions = {
|
|
3
|
+
now?: () => UTCDateTime;
|
|
4
|
+
validate?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type UpdateOptions = {
|
|
7
|
+
touch?: boolean;
|
|
8
|
+
sequence?: boolean;
|
|
9
|
+
now?: () => UTCDateTime;
|
|
10
|
+
validate?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type DateInput = string | Date;
|
|
13
|
+
export type DurationInput = string | number;
|
|
14
|
+
export type EntryInput = Event | Task | {
|
|
15
|
+
data: Event | Task;
|
|
16
|
+
};
|
|
17
|
+
export type EventInput = Omit<Event, "@type" | "uid" | "updated" | "created" | "start" | "duration" | "timeZone"> & {
|
|
18
|
+
start: DateInput;
|
|
19
|
+
duration?: DurationInput;
|
|
20
|
+
timeZone?: TimeZoneInput | null;
|
|
21
|
+
uid?: string;
|
|
22
|
+
updated?: DateInput;
|
|
23
|
+
created?: DateInput;
|
|
24
|
+
};
|
|
25
|
+
export type TaskInput = Omit<Task, "@type" | "uid" | "updated" | "created" | "start" | "due" | "timeZone"> & {
|
|
26
|
+
uid?: string;
|
|
27
|
+
updated?: DateInput;
|
|
28
|
+
created?: DateInput;
|
|
29
|
+
start?: DateInput;
|
|
30
|
+
due?: DateInput;
|
|
31
|
+
timeZone?: TimeZoneInput | null;
|
|
32
|
+
};
|
|
33
|
+
export type GroupInput = Omit<Group, "@type" | "uid" | "updated" | "created" | "entries"> & {
|
|
34
|
+
entries: EntryInput[];
|
|
35
|
+
uid?: string;
|
|
36
|
+
updated?: DateInput;
|
|
37
|
+
created?: DateInput;
|
|
38
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/jscal.d.ts
CHANGED
|
@@ -1,73 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { applyPatch } from "./patch.js";
|
|
1
|
+
import type { JSCalendarObject } from "./types.js";
|
|
3
2
|
import { resolveTimeZone } from "./timezones.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
type DateInput = string | Date;
|
|
15
|
-
type DurationInput = string | number;
|
|
16
|
-
type EventInput = Omit<Event, "@type" | "uid" | "updated" | "created" | "start" | "duration" | "timeZone"> & {
|
|
17
|
-
start: DateInput;
|
|
18
|
-
duration?: DurationInput;
|
|
19
|
-
timeZone?: TimeZoneInput | null;
|
|
20
|
-
uid?: string;
|
|
21
|
-
updated?: DateInput;
|
|
22
|
-
created?: DateInput;
|
|
23
|
-
};
|
|
24
|
-
type TaskInput = Omit<Task, "@type" | "uid" | "updated" | "created" | "start" | "due" | "timeZone"> & {
|
|
25
|
-
uid?: string;
|
|
26
|
-
updated?: DateInput;
|
|
27
|
-
created?: DateInput;
|
|
28
|
-
start?: DateInput;
|
|
29
|
-
due?: DateInput;
|
|
30
|
-
timeZone?: TimeZoneInput | null;
|
|
31
|
-
};
|
|
32
|
-
type GroupInput = Omit<Group, "@type" | "uid" | "updated" | "created"> & {
|
|
33
|
-
uid?: string;
|
|
34
|
-
updated?: DateInput;
|
|
35
|
-
created?: DateInput;
|
|
36
|
-
};
|
|
37
|
-
export declare function createUid(): string;
|
|
38
|
-
export declare function createId(): Id;
|
|
39
|
-
export declare function isEvent(obj: JSCalendarObject): obj is Event;
|
|
40
|
-
export declare function isTask(obj: JSCalendarObject): obj is Task;
|
|
41
|
-
export declare function isGroup(obj: JSCalendarObject): obj is Group;
|
|
42
|
-
declare class Base<T extends JSCalendarObject> {
|
|
43
|
-
data: T;
|
|
44
|
-
constructor(data: T);
|
|
45
|
-
eject(): T;
|
|
46
|
-
clone(): Base<T>;
|
|
47
|
-
get<K extends keyof T>(key: K): T[K];
|
|
48
|
-
set<K extends keyof T>(key: K, value: T[K]): this;
|
|
49
|
-
update(values: Partial<T>, options?: UpdateOptions): this;
|
|
50
|
-
patch(patch: PatchObject, options?: UpdateOptions): this;
|
|
51
|
-
addLocation(location: Omit<Location, "@type"> & Partial<Pick<Location, "@type">>, id?: Id): Id;
|
|
52
|
-
addVirtualLocation(location: Omit<VirtualLocation, "@type"> & Partial<Pick<VirtualLocation, "@type">>, id?: Id): Id;
|
|
53
|
-
addParticipant(participant: Omit<Participant, "@type"> & Partial<Pick<Participant, "@type">>, id?: Id): Id;
|
|
54
|
-
addAlert(alert: Omit<Alert, "@type"> & Partial<Pick<Alert, "@type">>, id?: Id): Id;
|
|
55
|
-
protected touchKeys(keys: string[], options?: UpdateOptions): this;
|
|
56
|
-
protected touchFromPatch(patch: PatchObject, options?: UpdateOptions): this;
|
|
57
|
-
}
|
|
58
|
-
declare class EventObject extends Base<Event> {
|
|
59
|
-
constructor(input: EventInput, options?: CreateOptions);
|
|
60
|
-
clone(): EventObject;
|
|
61
|
-
}
|
|
62
|
-
declare class TaskObject extends Base<Task> {
|
|
63
|
-
constructor(input?: TaskInput, options?: CreateOptions);
|
|
64
|
-
clone(): TaskObject;
|
|
65
|
-
}
|
|
66
|
-
declare class GroupObject extends Base<Group> {
|
|
67
|
-
constructor(input: GroupInput, options?: CreateOptions);
|
|
68
|
-
addEntry(entry: Event | Task): this;
|
|
69
|
-
clone(): GroupObject;
|
|
70
|
-
}
|
|
3
|
+
import { applyPatch } from "./patch.js";
|
|
4
|
+
import { EventObject } from "./jscal/event.js";
|
|
5
|
+
import { TaskObject } from "./jscal/task.js";
|
|
6
|
+
import { GroupObject } from "./jscal/group.js";
|
|
7
|
+
import { createId, createUid } from "./jscal/ids.js";
|
|
8
|
+
import { isEvent, isGroup, isTask } from "./jscal/guards.js";
|
|
9
|
+
import { buildAlert, buildLink, buildLocation, buildNDay, buildParticipants, buildRecurrenceRule, buildRelation, buildRelatedTo, buildTimeZone, buildTimeZoneMap, buildTimeZoneRule, buildVirtualLocation, buildVirtualLocations, buildLocations, buildLinks, buildParticipant, buildAlerts } from "./jscal/builders.js";
|
|
10
|
+
export type { CreateOptions, UpdateOptions } from "./jscal/types.js";
|
|
11
|
+
export type { AlertInput, LinkInput, LocationInput, NDayInput, ParticipantInput, RecurrenceRuleInput, RelationInput, TimeZoneInput, TimeZoneRuleInput, VirtualLocationInput, } from "./jscal/builders.js";
|
|
12
|
+
export { createId, createUid, isEvent, isGroup, isTask };
|
|
71
13
|
export declare const JsCal: {
|
|
72
14
|
Event: typeof EventObject;
|
|
73
15
|
Task: typeof TaskObject;
|
|
@@ -89,27 +31,87 @@ export declare const JsCal: {
|
|
|
89
31
|
timeZone: typeof resolveTimeZone;
|
|
90
32
|
timeZones: import("./timezones.js").TimeZoneId[];
|
|
91
33
|
applyPatch: typeof applyPatch;
|
|
34
|
+
Participant: typeof buildParticipant;
|
|
35
|
+
Location: typeof buildLocation;
|
|
36
|
+
VirtualLocation: typeof buildVirtualLocation;
|
|
37
|
+
Alert: typeof buildAlert;
|
|
38
|
+
Relation: typeof buildRelation;
|
|
39
|
+
Link: typeof buildLink;
|
|
40
|
+
TimeZone: typeof buildTimeZone;
|
|
41
|
+
TimeZoneRule: typeof buildTimeZoneRule;
|
|
42
|
+
RecurrenceRule: typeof buildRecurrenceRule;
|
|
43
|
+
NDay: typeof buildNDay;
|
|
44
|
+
participants: typeof buildParticipants;
|
|
45
|
+
locations: typeof buildLocations;
|
|
46
|
+
virtualLocations: typeof buildVirtualLocations;
|
|
47
|
+
alerts: typeof buildAlerts;
|
|
48
|
+
links: typeof buildLinks;
|
|
49
|
+
relatedTo: typeof buildRelatedTo;
|
|
50
|
+
timeZonesMap: typeof buildTimeZoneMap;
|
|
51
|
+
/**
|
|
52
|
+
* Find a JSCalendar object by UID.
|
|
53
|
+
* @param items JSCalendar objects or JsCal instances.
|
|
54
|
+
* @param uid UID to match.
|
|
55
|
+
* @return Matching object, if found.
|
|
56
|
+
*/
|
|
92
57
|
findByUid(items: Array<JSCalendarObject | {
|
|
93
58
|
data: JSCalendarObject;
|
|
94
59
|
}>, uid: string): JSCalendarObject | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Filter JSCalendar objects by @type.
|
|
62
|
+
* @param items JSCalendar objects or JsCal instances.
|
|
63
|
+
* @param type JSCalendar @type to match.
|
|
64
|
+
* @return Matching objects.
|
|
65
|
+
*/
|
|
95
66
|
filterByType(items: Array<JSCalendarObject | {
|
|
96
67
|
data: JSCalendarObject;
|
|
97
68
|
}>, type: JSCalendarObject["@type"]): JSCalendarObject[];
|
|
69
|
+
/**
|
|
70
|
+
* Group JSCalendar objects by @type.
|
|
71
|
+
* @param items JSCalendar objects or JsCal instances.
|
|
72
|
+
* @return Record keyed by @type.
|
|
73
|
+
*/
|
|
98
74
|
groupByType(items: Array<JSCalendarObject | {
|
|
99
75
|
data: JSCalendarObject;
|
|
100
76
|
}>): Record<string, JSCalendarObject[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Filter JSCalendar objects whose text fields match a query.
|
|
79
|
+
* @param items JSCalendar objects or JsCal instances.
|
|
80
|
+
* @param query Text query to match.
|
|
81
|
+
* @return Matching objects.
|
|
82
|
+
*/
|
|
101
83
|
filterByText(items: Array<JSCalendarObject | {
|
|
102
84
|
data: JSCalendarObject;
|
|
103
85
|
}>, query: string): JSCalendarObject[];
|
|
86
|
+
/**
|
|
87
|
+
* Filter JSCalendar objects that overlap a date range.
|
|
88
|
+
* @param items JSCalendar objects or JsCal instances.
|
|
89
|
+
* @param range Date range bounds.
|
|
90
|
+
* @param options Range comparison options.
|
|
91
|
+
* @return Matching objects.
|
|
92
|
+
*/
|
|
104
93
|
filterByDateRange(items: Array<JSCalendarObject | {
|
|
105
94
|
data: JSCalendarObject;
|
|
106
95
|
}>, range: import("./search.js").DateRange, options?: import("./search.js").DateRangeOptions): JSCalendarObject[];
|
|
96
|
+
/**
|
|
97
|
+
* Expand recurrence rules into concrete occurrences.
|
|
98
|
+
* @param items JSCalendar objects or JsCal instances.
|
|
99
|
+
* @param range Date range bounds.
|
|
100
|
+
* @return Generator of expanded JSCalendar objects.
|
|
101
|
+
*/
|
|
107
102
|
expandRecurrence(items: Array<JSCalendarObject | {
|
|
108
103
|
data: JSCalendarObject;
|
|
109
104
|
}>, range: {
|
|
110
105
|
from: Date;
|
|
111
106
|
to: Date;
|
|
112
107
|
}): Generator<JSCalendarObject>;
|
|
108
|
+
/**
|
|
109
|
+
* Expand recurrence rules with pagination support.
|
|
110
|
+
* @param items JSCalendar objects or JsCal instances.
|
|
111
|
+
* @param range Date range bounds.
|
|
112
|
+
* @param options Pagination options.
|
|
113
|
+
* @return Page of expanded items plus an optional next cursor.
|
|
114
|
+
*/
|
|
113
115
|
expandRecurrencePaged(items: Array<JSCalendarObject | {
|
|
114
116
|
data: JSCalendarObject;
|
|
115
117
|
}>, range: {
|
|
@@ -122,8 +124,13 @@ export declare const JsCal: {
|
|
|
122
124
|
items: JSCalendarObject[];
|
|
123
125
|
nextCursor?: string;
|
|
124
126
|
};
|
|
127
|
+
/**
|
|
128
|
+
* Convert JSCalendar objects to iCalendar text.
|
|
129
|
+
* @param value JSCalendar objects or JsCal instances.
|
|
130
|
+
* @param options iCalendar export options.
|
|
131
|
+
* @return iCalendar text.
|
|
132
|
+
*/
|
|
125
133
|
toICal(value: Array<JSCalendarObject | {
|
|
126
134
|
data: JSCalendarObject;
|
|
127
135
|
}>, options?: import("./ical.js").ICalOptions): string;
|
|
128
136
|
};
|
|
129
|
-
export {};
|