Skip to content

Commit

Permalink
Schedule Service Type Updates (#29)
Browse files Browse the repository at this point in the history
* Initial implementation of endpoints from updated schedules API design

* Adding updated types from new API schemas

* Finished importing updated schemas into schedule types, added schedule service return types to api calls

* Fixed service method args, updated types, most of the tests updated

* Fixed tests, updated incorrect endpoint url

* 3.0.35

* Updated api calls to allow partial updates, updated types per pr comments, updated tests with updates

* Added AtLeastOne to new types utilities file, exported, updated Schedule types per API specification

* Added mock schedule object

* Removed AtLeastOne type mplementation as does not play nicely when extending HCore types. Added comments on Schedule type implementation

---------

Co-authored-by: Christopher Marshall <chrism@j2inn.com>
  • Loading branch information
thoughtpalette and Christopher Marshall committed May 15, 2023
1 parent 28afc0e commit 93ebf4c
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 26 deletions.
57 changes: 51 additions & 6 deletions spec/client/schedules/ScheduleService.spec.ts
Expand Up @@ -25,16 +25,61 @@ import {
getHaystackServiceUrl,
} from '../../../src'

const mockSchedule = (): Schedule => {
const mockSchedule = () => {
return new HDict({
schedule: HMarker.make(),
id: HRef.make('123'),
dis: HStr.make('sample'),
kind: HStr.make(Kind.Number),
point: HMarker.make(),
dis: 'Schedule record',
tz: 'Mexico_City',
// Kind name starts with uppercase as in defs.
kind: 'Str',
effectivePeriod: new HDict({
lowBound: HDate.make(new Date()),
upBound: HDate.make(new Date()),
effectivePeriod: HMarker.make(),
entryType: 'Range',
lowBound: HDate.make('1998-12-01'),
upBound: HDate.make('1998-12-15'),
}),
weeklySchedule: new HList(
new HDict({
dayToSchedule: HMarker.make(),
dayOfWeek: 4,
dailySchedule: new HList(
new HDict({
timeToVal: HMarker.make(),
bacnetTime: new HDict({
bacnetTime: HMarker.make(),
hour: 2,
minute: 28,
second: 41,
}),
scheduledVal: 'boo',
})
),
})
),
exceptionSchedule: new HList(
new HDict({
specialEvent: HMarker.make(),
priority: 15,
dailySchedule: new HList(
new HDict({
timeToVal: HMarker.make(),
bacnetTime: new HDict({
bacnetTime: HMarker.make(),
hour: 14,
second: 0,
}),
scheduledVal: 'bar',
})
),
calendarEntry: new HDict({
calendarEntry: HMarker.make(),
entryType: 'Date',
dayOfMonth: 21,
dayOfWeek: 4,
}),
})
),
}) as Schedule
}

Expand Down
65 changes: 45 additions & 20 deletions src/client/schedules/types.ts
Expand Up @@ -104,6 +104,7 @@ export interface SchedulePointUpdate {

/**
* Schedule object.
* Must have at least one property: 'exceptionSchedule' | 'weeklySchedule'.
*/
export interface Schedule extends HDict {
/**
Expand All @@ -126,15 +127,26 @@ export interface Schedule extends HDict {
*/
tz: HStr

/**
* The required schedule marker tag
*/
schedule: HMarker

/**
* The required point marker tag
*/
point: HMarker

/**
* Is the current value of the schedule.
*/
curVal?: OptionalHVal

/**
* Is the schedule kind (bool, number, str).
* Must be capitalized. e.g. 'Str', 'Bool'
*/
kind: Kind
kind: Capitalize<Kind>

/**
* Is the list of calendar(s) the schedule subscribes to.
Expand All @@ -157,17 +169,17 @@ export interface Schedule extends HDict {
nextTime?: HDateTime

/**
* Is the range of dates (if any) that the schedule is active.
* Is the range of dates that the schedule is active.
*/
effectivePeriod: CalendarRange
effectivePeriod: { effectivePeriod: HMarker } & CalendarRange

/**
* One week of schedules per day.
* The list of one week of schedules.
*/
weeklySchedule?: HList<WeekDaySchedule>

/**
* The scheduled exceptions.
* The list of scheduled exceptions.
*/
exceptionSchedule?: ExceptionSchedule
}
Expand All @@ -176,6 +188,7 @@ export interface Schedule extends HDict {
* Defines the day of week and schedule for that day.
*/
export interface WeekDaySchedule extends HDict {
dayToSchedule: HMarker
dayOfWeek: HNum
dailySchedule: HList<DailySchedule>
}
Expand All @@ -189,22 +202,30 @@ export type ExceptionSchedule = HList<SpecialEvent>
* Defines data for a special event.
*/
export interface SpecialEvent extends HDict {
specialEvent: HMarker
calendarEntry?: CalendarEntry
calendarRef?: HRef
priority: number
dailySchedule: HList<DailySchedule>
}

/**
* Defines data for the bacnet time object.
*/
export interface BacnetTime extends HDict {
bacnetTime: HMarker
hour?: number
minute?: number
second?: number
hundredths?: number
}

/**
* Defines the schedule for a day.
*/
export interface DailySchedule extends HDict {
bacnetTime: {
hour?: number
minute?: number
second?: number
hundredths?: number
}
timeToVal: HMarker
bacnetTime: BacnetTime
scheduledVal: OptionalHVal
}

Expand All @@ -220,7 +241,7 @@ export interface Calendar extends HDict {
/**
* Specifies the name of the calendar.
*/
dis?: HStr
dis: HStr

/**
* Is the date-time when the calendar was last modified
Expand All @@ -240,21 +261,23 @@ export interface Calendar extends HDict {
/**
* The calendar entries
*/
entries?: CalendarEntry[]
entries?: HList<CalendarEntry>
}

/**
* A Calendar Entry.
*/
export type CalendarEntry =
| ({ entryType: 'Date' } & CalendarDate)
| ({ entryType: 'Range' } & CalendarRange)
| ({ entryType: 'WeekNDay' } & CalendarWeekNDay)
export type CalendarEntry = { calendarEntry: HMarker } & (
| CalendarDate
| CalendarRange
| CalendarWeekNDay
)

/**
* A Date for a Calendar.
*/
export interface CalendarDate {
export interface CalendarDate extends HDict {
entryType: 'Date'
year?: number
month?: number
dayOfMonth?: number
Expand All @@ -264,15 +287,17 @@ export interface CalendarDate {
/**
* The Date range of a Calendar.
*/
export interface CalendarRange {
export interface CalendarRange extends HDict {
entryType: 'Range'
lowBound?: HDate
upBound?: HDate
}

/**
* Define the week and day of a Calendar.
*/
export interface CalendarWeekNDay {
export interface CalendarWeekNDay extends HDict {
entryType: 'WeekNDay'
weekOfMonth?: number
month?: number
dayOfWeek?: number
Expand Down

0 comments on commit 93ebf4c

Please sign in to comment.