Rules Overview
A rule decides what happens to each event as it flows through a pipe, from a source calendar to a target calendar.
Every pipe has one rule. As CalendarPipe syncs events, each one passes through the rule, which can:
- Pass the event through unchanged.
- Block the event from syncing.
- Transform the event — its title, description, visibility, or free/busy status.
However you write a rule, it runs as a TypeScript function — function rule(event) — in an isolated JavaScript sandbox. The sections below describe that function; the Visual Builder, Templates, and AI Generator write it for you.
Minimum function
The simplest rule passes every event through without modification:
function rule(event: GateEvent): GateResult {
return { pass: true };
}
New rules use function rule(event). Legacy function gate(event) still works — the sandbox prefers gate when both names are defined.
When pass is true, the event syncs to the target calendar. When pass is false, the event is blocked.
GateEvent
Each event that reaches your rule is a GateEvent object containing the event's properties -- title, description, start/end times, attendees, and more. CalendarPipe also enriches events with computed convenience properties like durationMinutes, isWeekday, and dayOfWeek.
For a full list of all available properties, see the Property Reference.
GateResult
Your gate function returns a GateResult that tells CalendarPipe what to do with the event:
interface GateResult {
pass: boolean; // true = sync, false = block
reason?: string; // Human-readable reason (max 200 chars, only for pass: false)
transform?: {
title?: string; // Override title (max 500 chars)
description?: string; // Override description (max 5000 chars)
visibility?: 'default' | 'public' | 'private';
showAs?: 'free' | 'busy';
};
}
Authoring modes
There are four ways to write a rule:
| Mode | Best for | Description |
|---|---|---|
| Templates | Quick setup | Five built-in presets (Copy All, Busy as Commitment, Weekends, Weekdays, Evenings). |
| Visual Builder | No code | Point-and-click condition editor. |
| Code Editor | Custom logic | TypeScript editor with full type definitions and a test-before-save workflow. |
| AI Generator | Plain English | Describe the behavior you want; the editor generates the function. |
You can switch between modes at any time — for example, start from a template and refine it in the Code Editor.