From 4195ab2fd36cda2329769c40e638d9cd84edbd93 Mon Sep 17 00:00:00 2001 From: Michael Schramm Date: Tue, 8 Jun 2021 17:53:05 +0200 Subject: [PATCH] add method to vevent (#125) * add method to vevent --- ical.js | 11 ++++++++++- node-ical.d.ts | 2 ++ test/test.js | 33 +++++++++++++++++++++++++++++++++ test/test18.ics | 2 +- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/ical.js b/ical.js index 609102d..c908ce7 100644 --- a/ical.js +++ b/ical.js @@ -407,6 +407,10 @@ module.exports = { // If this is the first time we run into this UID, just save it. if (par[curr.uid] === undefined) { par[curr.uid] = curr; + + if (par.method) { // RFC5545, 3.2 + par[curr.uid].method = par.method; + } } else if (curr.recurrenceid === undefined) { // If we have multiple ical entries with the same UID, it's either going to be a // modification to a recurrence (RECURRENCE-ID), and/or a significant modification @@ -475,7 +479,12 @@ module.exports = { delete par[curr.uid].recurrenceid; } } else { - par[uuid()] = curr; + const id = uuid(); + par[id] = curr; + + if (par.method) { // RFC5545, 3.2 + par[id].method = par.method; + } } return par; diff --git a/node-ical.d.ts b/node-ical.d.ts index d8ba6e4..44cda1b 100644 --- a/node-ical.d.ts +++ b/node-ical.d.ts @@ -64,6 +64,7 @@ declare module 'node-ical' { export interface VEvent extends BaseComponent { type: 'VEVENT'; + method: Method; dtstamp: DateWithTimeZone; uid: string; sequence: string; @@ -108,4 +109,5 @@ declare module 'node-ical' { export type DateType = 'date-time' | 'date'; export type Transparency = 'TRANSPARENT' | 'OPAQUE'; export type Class = 'PUBLIC' | 'PRIVATE' | 'CONFIDENTIAL'; + export type Method = 'PUBLISH' | 'REQUEST' | 'REPLY' | 'ADD' | 'CANCEL' | 'REFRESH' | 'COUNTER' | 'DECLINECOUNTER'; } diff --git a/test/test.js b/test/test.js index f1227b8..c1ac504 100644 --- a/test/test.js +++ b/test/test.js @@ -40,6 +40,9 @@ vows }, 'datetype is date'(topic) { assert.equal(topic.datetype, 'date'); + }, + 'method is PUBLISH'(topic) { + assert.equal(topic.method, 'PUBLISH'); } }, 'event 480a': { @@ -56,6 +59,9 @@ vows }, 'has a date only end datetime'(topic) { assert.equal(topic.end.dateOnly, true); + }, + 'method is PUBLISH'(topic) { + assert.equal(topic.method, 'PUBLISH'); } }, 'event d4c8': { @@ -69,6 +75,9 @@ vows }, 'datetype is date-time'(topic) { assert.equal(topic.datetype, 'date-time'); + }, + 'method is PUBLISH'(topic) { + assert.equal(topic.method, 'PUBLISH'); } }, @@ -80,6 +89,9 @@ vows }, 'has a start datetime'(topic) { assert.equal(topic.start, 'Next Year'); + }, + 'method is PUBLISH'(topic) { + assert.equal(topic.method, 'PUBLISH'); } } }, @@ -163,6 +175,9 @@ vows }, 'datetype is date-time'(topic) { assert.equal(topic.datetype, 'date-time'); + }, + 'method is PUBLISH'(topic) { + assert.equal(topic.method, 'PUBLISH'); } } }, @@ -222,6 +237,9 @@ vows 'has a start'(topic) { assert.equal(topic.start.tz, 'America/Phoenix'); assert.equal(topic.start.toISOString(), new Date(Date.UTC(2011, 10, 10, 2, 0, 0)).toISOString()); + }, + 'method is PUBLISH'(topic) { + assert.equal(topic.method, 'PUBLISH'); } } }, @@ -604,6 +622,9 @@ vows }, 'starts 28 Oct 2002 @ 01:20:30 (Local Time)'(topic) { assert.equal(topic.start.toISOString(), new Date(2002, 9, 28, 1, 20, 30).toISOString()); + }, + 'method is REQUEST'(topic) { + assert.equal(topic.method, 'REQUEST'); } }, @@ -621,6 +642,9 @@ vows }, 'starts 28 Oct 2002 @ 01:20:30 (UTC)'(topic) { assert.equal(topic.start.toISOString(), '2002-10-28T01:20:30.000Z'); + }, + 'method is REQUEST'(topic) { + assert.equal(topic.method, 'REQUEST'); } }, @@ -638,6 +662,9 @@ vows }, 'starts 28 Oct 2002 @ 06:20:30 (UTC)'(topic) { assert.equal(topic.start.toISOString(), '2002-10-28T06:20:30.000Z'); + }, + 'method is REQUEST'(topic) { + assert.equal(topic.method, 'REQUEST'); } }, @@ -655,6 +682,9 @@ vows }, 'starts 28 Oct 2002 @ 00:00:00 (Local Time)'(topic) { assert.equal(topic.start.toISOString(), new Date(2002, 9, 28).toISOString()); + }, + 'method is REQUEST'(topic) { + assert.equal(topic.method, 'REQUEST'); } }, @@ -672,6 +702,9 @@ vows }, 'starts 28 Oct 2002 @ 00:00:00 (Local Time)'(topic) { assert.equal(topic.start.toISOString(), new Date(2002, 9, 28).toISOString()); + }, + 'method is REQUEST'(topic) { + assert.equal(topic.method, 'REQUEST'); } } }, diff --git a/test/test18.ics b/test/test18.ics index 26e5021..760ecbe 100644 --- a/test/test18.ics +++ b/test/test18.ics @@ -1,7 +1,7 @@ BEGIN:VCALENDAR CALSCALE:GREGORIAN X-WR-TIMEZONE;VALUE=TEXT:US/Pacific -METHOD:PUBLISH +METHOD:REQUEST PRODID:-//Apple Computer\, Inc//iCal 1.0//EN X-WR-CALNAME;VALUE=TEXT:Example VERSION:2.0