Function: dispatchCondition()
function dispatchCondition<TContext>(config:
| {
condition_type: "PRICING_SCHEDULE";
date_range?: {
end: string;
exclude?: boolean;
start: string;
};
day_of_week?: {
days: number[];
exclude?: boolean;
};
duration?: {
max?: number;
max_exclusive?: boolean;
min?: number;
min_exclusive?: boolean;
unit?: "days" | "minutes" | "hours";
};
end_field: string;
holidays?: {
exclude?: boolean;
include_observed?: boolean;
names: (
| "NEW_YEARS_DAY"
| "MLK_DAY"
| "PRESIDENTS_DAY"
| "MEMORIAL_DAY"
| "JUNETEENTH"
| "INDEPENDENCE_DAY"
| "LABOR_DAY"
| "COLUMBUS_DAY"
| "VETERANS_DAY"
| "THANKSGIVING"
| "CHRISTMAS_DAY")[];
};
offered_until?: string;
start_field: string;
time_range?: {
end_min: number;
exclude?: boolean;
start_min: number;
};
zone?: string;
}
| {
condition_type: "FIELD_COMPARISON";
field: string;
operator: "eq";
value: string | number | boolean;
}
| {
condition_type: "FIELD_COMPARISON";
field: string;
operator: "neq";
value: string | number | boolean;
}
| {
condition_type: "FIELD_COMPARISON";
field: string;
operator: "gt";
value: number;
}
| {
condition_type: "FIELD_COMPARISON";
field: string;
operator: "lt";
value: number;
}
| {
condition_type: "FIELD_COMPARISON";
field: string;
operator: "gte";
value: number;
}
| {
condition_type: "FIELD_COMPARISON";
field: string;
operator: "lte";
value: number;
}
| {
condition_type: "FIELD_COMPARISON";
field: string;
operator: "contains";
value: string;
}
| {
condition_type: "FIELD_COMPARISON";
field: string;
operator: "in";
value: (string | number | boolean)[];
}
| {
condition_type: "FIELD_COMPARISON";
field: string;
operator: "exists";
}
| {
condition_type: "AGE_CHECK";
evaluation_date_field?: string;
field: string;
max_age?: number;
min_age: number;
}
| {
condition_type: "AGE_CHECK";
evaluation_date_field?: string;
field: string;
max_age: number;
min_age?: number;
}
| {
condition_type: "DATE_WINDOW";
end: string;
field: string;
start: string;
}
| {
condition_type: "DATE_INCLUDES";
days: number[];
end_field: string;
start_field: string;
}
| {
codes: string[];
condition_type: "DISCOUNT_CODE";
field?: string;
}
| {
condition_type: "DURATION_CHECK";
end_field: string;
max?: number;
min?: number;
start_field: string;
unit?: string;
}
| {
condition_type: "GROUP_SIZE";
field: string;
max?: number;
min?: number;
}
| {
condition_type: "PRICE_THRESHOLD";
operator: "gt" | "lt" | "gte" | "lte" | "eq" | "neq";
price_field: string;
value: number;
}
| {
condition_type: "TIME_OF_DAY";
end: string;
field: string;
start: string;
zone?: string;
}
| {
condition_type: "RELATIVE_DATE_CHECK";
evaluation_date_field?: string;
field: string;
max?: number;
min: number;
unit?: "days" | "hours";
}
| {
condition_type: "RELATIVE_DATE_CHECK";
evaluation_date_field?: string;
field: string;
max: number;
min?: number;
unit?: "days" | "hours";
}
| {
adults_min_age: number;
condition_type: "HOUSEHOLD";
dob_field?: string;
id_field?: string;
members_field?: string;
num_adults_max?: number;
num_adults_min?: number;
num_youth_max?: number;
num_youth_min?: number;
youth_max_age: number;
}
| {
condition_type: "HOLIDAY";
field: string;
holidays: (
| "NEW_YEARS_DAY"
| "MLK_DAY"
| "PRESIDENTS_DAY"
| "MEMORIAL_DAY"
| "JUNETEENTH"
| "INDEPENDENCE_DAY"
| "LABOR_DAY"
| "COLUMBUS_DAY"
| "VETERANS_DAY"
| "THANKSGIVING"
| "CHRISTMAS_DAY")[];
include_observed?: boolean;
zone?: string;
}, resolve: Resolve<TContext>): boolean;Defined in: shared/rules/condition-handlers.ts:535
Dispatch a built-in condition to its handler using exhaustive ts-pattern
matching on condition_type. Each branch receives a fully-typed config
and a typed resolver — no unknown casts. Adding a new variant to
BuiltInConditionConfig is a compile error until handled here.
Time-aware handlers each manage their own evaluation date, defaulting
to DateTime.now(). The engine no longer threads now through —
tests should pin the clock via vi.setSystemTime(...).
Type Parameters
| Type Parameter |
|---|
TContext |
Parameters
| Parameter | Type |
|---|---|
config | | { condition_type: "PRICING_SCHEDULE"; date_range?: { end: string; exclude?: boolean; start: string; }; day_of_week?: { days: number[]; exclude?: boolean; }; duration?: { max?: number; max_exclusive?: boolean; min?: number; min_exclusive?: boolean; unit?: "days" | "minutes" | "hours"; }; end_field: string; holidays?: { exclude?: boolean; include_observed?: boolean; names: ( | "NEW_YEARS_DAY" | "MLK_DAY" | "PRESIDENTS_DAY" | "MEMORIAL_DAY" | "JUNETEENTH" | "INDEPENDENCE_DAY" | "LABOR_DAY" | "COLUMBUS_DAY" | "VETERANS_DAY" | "THANKSGIVING" | "CHRISTMAS_DAY")[]; }; offered_until?: string; start_field: string; time_range?: { end_min: number; exclude?: boolean; start_min: number; }; zone?: string; } | { condition_type: "FIELD_COMPARISON"; field: string; operator: "eq"; value: string | number | boolean; } | { condition_type: "FIELD_COMPARISON"; field: string; operator: "neq"; value: string | number | boolean; } | { condition_type: "FIELD_COMPARISON"; field: string; operator: "gt"; value: number; } | { condition_type: "FIELD_COMPARISON"; field: string; operator: "lt"; value: number; } | { condition_type: "FIELD_COMPARISON"; field: string; operator: "gte"; value: number; } | { condition_type: "FIELD_COMPARISON"; field: string; operator: "lte"; value: number; } | { condition_type: "FIELD_COMPARISON"; field: string; operator: "contains"; value: string; } | { condition_type: "FIELD_COMPARISON"; field: string; operator: "in"; value: (string | number | boolean)[]; } | { condition_type: "FIELD_COMPARISON"; field: string; operator: "exists"; } | { condition_type: "AGE_CHECK"; evaluation_date_field?: string; field: string; max_age?: number; min_age: number; } | { condition_type: "AGE_CHECK"; evaluation_date_field?: string; field: string; max_age: number; min_age?: number; } | { condition_type: "DATE_WINDOW"; end: string; field: string; start: string; } | { condition_type: "DATE_INCLUDES"; days: number[]; end_field: string; start_field: string; } | { codes: string[]; condition_type: "DISCOUNT_CODE"; field?: string; } | { condition_type: "DURATION_CHECK"; end_field: string; max?: number; min?: number; start_field: string; unit?: string; } | { condition_type: "GROUP_SIZE"; field: string; max?: number; min?: number; } | { condition_type: "PRICE_THRESHOLD"; operator: "gt" | "lt" | "gte" | "lte" | "eq" | "neq"; price_field: string; value: number; } | { condition_type: "TIME_OF_DAY"; end: string; field: string; start: string; zone?: string; } | { condition_type: "RELATIVE_DATE_CHECK"; evaluation_date_field?: string; field: string; max?: number; min: number; unit?: "days" | "hours"; } | { condition_type: "RELATIVE_DATE_CHECK"; evaluation_date_field?: string; field: string; max: number; min?: number; unit?: "days" | "hours"; } | { adults_min_age: number; condition_type: "HOUSEHOLD"; dob_field?: string; id_field?: string; members_field?: string; num_adults_max?: number; num_adults_min?: number; num_youth_max?: number; num_youth_min?: number; youth_max_age: number; } | { condition_type: "HOLIDAY"; field: string; holidays: ( | "NEW_YEARS_DAY" | "MLK_DAY" | "PRESIDENTS_DAY" | "MEMORIAL_DAY" | "JUNETEENTH" | "INDEPENDENCE_DAY" | "LABOR_DAY" | "COLUMBUS_DAY" | "VETERANS_DAY" | "THANKSGIVING" | "CHRISTMAS_DAY")[]; include_observed?: boolean; zone?: string; } |
resolve | Resolve<TContext> |
Returns
boolean