Skip to content

Types

All TypeScript interfaces for the Alap configuration and engine.

AlapConfig

Root configuration object. Passed to registerConfig(), AlapUI, AlapEngine, and framework providers.

typescript
interface AlapConfig {
  allLinks: Record<string, AlapLink>;                          // required
  settings?: AlapSettings;
  macros?: Record<string, AlapMacro>;
  searchPatterns?: Record<string, AlapSearchPattern | string>;
  protocols?: Record<string, AlapProtocol>;
}

Only allLinks is required. Everything else is optional.

A single link entry in config.allLinks.

typescript
interface AlapLink {
  url: string;                         // required
  label?: string;                      // required unless image is set
  tags?: string[];
  cssClass?: string;
  image?: string;
  altText?: string;
  targetWindow?: string;               // '_self', '_blank', etc. Default: 'fromAlap'
  description?: string;
  thumbnail?: string;
  hooks?: string[];
  guid?: string;
  createdAt?: string | number;         // ISO 8601 or Unix ms
  meta?: Record<string, unknown>;
}
FieldTypeRequiredDescription
urlstringYesDestination URL
labelstringNoDisplay text (required unless image is set)
tagsstring[]NoTags for .tag queries
cssClassstringNoCSS class applied to the menu item
imagestringNoImage URL rendered instead of text
altTextstringNoAlt text for image
targetWindowstringNo_self, _blank, _parent, _top, or any string
descriptionstringNoUsed by search patterns and hooks
thumbnailstringNoPreview image for hover/context events (not rendered in menu)
hooksstring[]NoEvent hooks this item participates in (overrides settings.hooks)
guidstringNoPermanent UUID that survives renames
createdAtstring | numberNoISO 8601 or Unix ms. Used by age filters
metaRecord<string, unknown>NoArbitrary metadata for protocol queries

AlapSettings

Global settings in config.settings.

typescript
interface AlapSettings {
  listType?: 'ul' | 'ol';
  menuTimeout?: number;
  maxVisibleItems?: number;
  hooks?: string[];
  existingUrl?: 'prepend' | 'append' | 'ignore';
  placement?: 'N' | 'NE' | 'E' | 'SE' | 'S' | 'SW' | 'W' | 'NW' | 'C';
  placementGap?: number;
  viewportPadding?: number;
  viewportAdjust?: boolean;
  targetWindow?: string;
}
FieldTypeDefaultDescription
listType'ul' | 'ol''ul'Menu list element type
menuTimeoutnumber5000Auto-dismiss timeout (ms) after mouse leaves
maxVisibleItemsnumber10Items before the menu scrolls. 0 = no limit
hooksstring[]Default hooks for all items
existingUrl'prepend' | 'append' | 'ignore''prepend'How to handle an existing href on the trigger
placementPlacement'SE'Preferred menu position: N, NE, E, SE, S, SW, W, NW, C
placementGapnumber4Pixel gap between trigger edge and menu edge
viewportPaddingnumber8Minimum distance the menu keeps from viewport edges
viewportAdjustbooleantrueEnable smart placement with viewport containment and fallback
targetWindowstringGlobal default for link targets

Placement type

typescript
type Placement = 'N' | 'NE' | 'E' | 'SE' | 'S' | 'SW' | 'W' | 'NW' | 'C';
ValuePositionAlignment
NAbove triggerCentered horizontally
NEAbove triggerLeft edge aligned with trigger left
ERight of triggerVertically centered
SEBelow triggerLeft edge aligned with trigger left
SBelow triggerCentered horizontally
SWBelow triggerRight edge aligned with trigger right
WLeft of triggerVertically centered
NWAbove triggerRight edge aligned with trigger right
CCentered over triggerBoth axes

When the preferred placement doesn't fit in the viewport, Alap tries the opposite side first, then adjacent positions, then picks the best available fit — clamping height and enabling scroll if needed. The menu never causes the page to scroll.

AlapMacro

A named macro in config.macros.

typescript
interface AlapMacro {
  linkItems: string;
  config?: Record<string, unknown>;    // reserved for future use
}

AlapSearchPattern

A named regex pattern in config.searchPatterns. Can also be a plain string (shorthand for { pattern: "..." }).

typescript
interface AlapSearchPattern {
  pattern: string;
  options?: AlapSearchOptions;
}

interface AlapSearchOptions {
  fields?: string;                     // Field codes: l, u, t, d, k, a
  limit?: number;
  age?: string;                        // '30d', '24h', '2w'
  sort?: 'alpha' | 'newest' | 'oldest';
}

AlapProtocol

A registered protocol in config.protocols. Protocols come in two kinds: filter (predicate over existing links) and generate (fetch external data and return new links). A protocol can have one or both.

typescript
interface AlapProtocol {
  filter?: ProtocolHandler;            // Predicate: does this link match?
  generate?: GenerateHandler;          // Async: fetch and return new links
  cache?: number;                      // TTL in minutes for generate results (0 = no cache, default: 5)
  keys?: Record<string, WebKeyConfig>; // Key configs for external protocols
  allowedOrigins?: string[];           // Restrict :web: fetch to these origins
  sources?: string[];                  // Default: ['config']
  [key: string]: unknown;
}

type ProtocolHandler = (segments: string[], link: AlapLink, id: string) => boolean;
type GenerateHandler = (segments: string[], config: AlapConfig) => Promise<AlapLink[]>;

If allowedOrigins is set, any :web: fetch whose URL origin is not in the list is rejected before the request is made. Omit or pass an empty array to allow all origins.

WebKeyConfig

Configuration for a single key in an external protocol like :web:.

typescript
interface WebKeyConfig {
  url: string;                                    // Base URL for the API endpoint
  linkBase?: string;                              // Prepended to relative link URLs (e.g. "https://openlibrary.org")
  searches?: Record<string, Record<string, string | number>>;  // Predefined search aliases
  map?: {                                         // Field mapping: API field → AlapLink field
    label?: string;
    url?: string;
    meta?: Record<string, string>;
  };
  cache?: number;                                 // Per-key cache TTL override (minutes)
  credentials?: boolean;                           // Send browser credentials (cookies, auth) — default: false
}

Returned by engine.resolve().

typescript
type ResolvedLink = { id: string } & AlapLink;

ResolveResult

Full result with metadata (used internally by refiners).

typescript
interface ResolveResult {
  links: ResolvedLink[];
  totalMatches: number;                // Count before refiners applied
}

ConfigStore

Interface for persistence backends. See Storage.

typescript
interface ConfigStore {
  save(name: string, config: AlapConfig): Promise<void>;
  load(name: string): Promise<AlapConfig | null>;
  loadEntry(name: string): Promise<ConfigEntry | null>;
  list(): Promise<string[]>;
  remove(name: string): Promise<void>;
}

interface ConfigEntry {
  config: AlapConfig;
  meta: ConfigMeta;
}

interface ConfigMeta {
  updatedAt: string;                   // ISO 8601
  createdAt: string;                   // ISO 8601
}

Constants

Safety limits enforced by the parser:

ConstantValueDescription
MAX_DEPTH32Maximum parentheses nesting
MAX_TOKENS1024Maximum tokens per expression
MAX_MACROS10Maximum macro expansion rounds
MAX_REGEX5Maximum regex searches per expression
MAX_REFINERS10Maximum refiners per expression
MAX_GENERATED_LINKS200Maximum links a generate handler can return per call
WEB_FETCH_TIMEOUT_MS10,000Timeout for :web: protocol fetch requests (10 seconds)
MAX_WEB_RESPONSE_BYTES1,048,576Maximum response body size for :web: fetch (1 MB)