UNPKG

typed-ocpp

Version:

A library for type-aware parsing, serialization and validation of OCPP 1.6, OCPP 2.0 and OCPP 2.1 messages

54 lines (53 loc) 2.25 kB
/** * A period is defined by its start date (inclusive), * its end date (exclusive) and related data. */ export interface Period<T> { /** Beginning of this period, inclusive */ start: Date; /** End of this period, exclusive */ end: Date; /** Data related to this period */ data: T; } /** * A Schedule is a temporally-ordered collection of discrete, * non-overlapping periods. A schedule contains at least one * period. */ export type Schedule<T> = [first: Period<T>, ...rest: Period<T>[]]; /** * A MaybeSchdule is a temporally-ordered collection of discrete, * non-overlapping periods. Contrary to a Schedule, a MaybeSchedule * can be empty, i.e. it can contain zero periods. */ export type MaybeSchedule<T> = Period<T>[]; /** * Data cloning functions are used by other functions in this module to create * identical copies of period's data. A data cloning function **must** return a * deep copy of the provided value. */ export type CloneDataFn<T> = (data: T) => T; /** * Data merging functions are used by other functions in this module to merge * the data of two different periods into a new data value for a new period. */ export type MergeDataFn<T> = (left: T, right: T) => T; /** * Returns the first (and only) period in the schedule which covers the time * instant represented by the provided date. Returns undefined if the schedule * does not contain one such period. */ export declare const getPeriodForDate: <T>(schedule: MaybeSchedule<T>, value: Date) => Period<T> | undefined; /** * Merges two schedules together. Overlapping periods will be broken down into * shorter periods. The cloning and merging functions will be called to create * the resulting periods and may be used to customize the merging logic in the * case of partially or completely overlapping periods. */ export declare const merge: <T>(left: MaybeSchedule<T>, right: MaybeSchedule<T>, cloner: CloneDataFn<T>, merger: MergeDataFn<T>) => MaybeSchedule<T>; /** * Fills empty gaps in a schedule with new periods built upon the provided * `defaults` data object. */ export declare const fillGaps: <T>(schedule: MaybeSchedule<T>, start: Date, end: Date, getPeriodData: (start: Date, end: Date) => T) => Schedule<T>;