Skip to main content

Gate Functions Overview

A gate function is a TypeScript function that runs in an isolated JavaScript sandbox and decides what happens to each event as it flows from a source calendar to a target calendar.

Every sync rule has one. As CalendarPipe syncs events, each one passes through the gate function, which can:

  • Pass the event through unchanged.
  • Block the event from syncing.
  • Transform the event — its title, description, visibility, or free/busy status.

Minimum function

The simplest gate function passes every event through without modification:

function gate(event: GateEvent): GateResult {
return { pass: true };
}

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 gate function 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 author a gate function:

ModeBest forDescription
TemplatesQuick setupFive built-in presets (Copy All, Busy as Commitment, Weekends, Weekdays, Evenings).
Visual BuilderNo codePoint-and-click condition editor.
Code EditorCustom logicTypeScript editor with full type definitions and a test-before-save workflow.
AI GeneratorPlain EnglishDescribe 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.