Skip to content

PatternRule

A count of rests by class inside a window: “at least 4 weekly rests in any 4 weeks, at least 2 of them regular”.

import type { PatternRule } from "@northguild/gmt";
MemberTypeDescription
labelstringThe caller’s name for the rule. The report is keyed by it; labels must be unique.
severity?"violation" | "advisory" (DutySeverity)Whether a failure is a violation or an advisory.
kind"pattern"Selects this rule kind.
periodPeriodThe unit the window is counted in.
lookbacknumberHow many periods the window covers, an integer from 1 to 10,000. Times a count period, it is 10,000 at most.
classesobject[]The classes of rest, each named for require.
classes[].labelstringThe class’s name, unique within the rule.
classes[].statusesS[]The statuses a run of this class is made of.
classes[].minimumstringThe shortest run of this class, a positive ISO 8601 duration of exact time.
requireobject[]The count each class needs.
require[].labelstringThe class, one of the labels in classes.
require[].atLeastnumberThe fewest runs of that class the window must hold, a non-negative integer.
type PatternRule<S extends string = string> = {
/** The caller's name for the rule. The report is keyed by it; labels must be unique. */
label: string;
/**
* Whether a failure is a violation or an advisory.
*
* @defaultValue `"violation"`.
*/
severity?: DutySeverity;
/** Selects this rule kind. */
kind: "pattern";
/** The unit the window is counted in. */
period: Period;
/**
* How many periods the window covers, an integer from 1 to 10,000. Times a count `period`, it is
* 10,000 at most.
*/
lookback: number;
/** The classes of rest, each named for `require`. */
classes: {
/** The class's name, unique within the rule. */
label: string;
/** The statuses a run of this class is made of. */
statuses: S[];
/** The shortest run of this class, a positive ISO 8601 duration of exact time. */
minimum: string;
}[];
/** The count each class needs. */
require: {
/** The class, one of the labels in `classes`. */
label: string;
/** The fewest runs of that class the window must hold, a non-negative integer. */
atLeast: number;
}[];
};

types/duty.ts