@stacksjs/stx
Version:
A performant UI Framework. Powered by Bun.
52 lines • 2.29 kB
TypeScript
import type { StxOptions } from './types';
/**
* Process middleware registered in the application.
*
* Executes all middleware handlers that match the specified timing in sequence.
* Each middleware receives the current template and can modify it.
*
* @param template - The template string to process
* @param context - Template context with variables (can be modified by middleware)
* @param filePath - Path to the template file (for error messages)
* @param options - STX processing options containing middleware configuration
* @param timing - When to run: 'before' or 'after' directive processing
* @returns The processed template string
*
* @example
* ```typescript
* const processed = await processMiddleware(
* '<div>{{ content }}</div>',
* { content: 'Hello' },
* '/path/to/template.stx',
* { middleware: myMiddleware },
* 'before'
* )
* ```
*/
export declare function processMiddleware(template: string, context: Record<string, any>, filePath: string, options: StxOptions, timing: 'before' | 'after'): Promise<string>;
/**
* Run pre-processing middleware (timing: 'before').
*
* This is a convenience wrapper for `processMiddleware` with timing='before'.
* Pre-processing middleware runs before any directives are processed.
*
* @param template - The raw template string
* @param context - Template context with variables
* @param filePath - Path to the template file
* @param options - STX processing options
* @returns The pre-processed template string
*/
export declare function runPreProcessingMiddleware(template: string, context: Record<string, any>, filePath: string, options: StxOptions): Promise<string>;
/**
* Run post-processing middleware (timing: 'after').
*
* This is a convenience wrapper for `processMiddleware` with timing='after'.
* Post-processing middleware runs after all directives have been processed.
*
* @param template - The processed template string
* @param context - Template context with variables
* @param filePath - Path to the template file
* @param options - STX processing options
* @returns The post-processed template string
*/
export declare function runPostProcessingMiddleware(template: string, context: Record<string, any>, filePath: string, options: StxOptions): Promise<string>;