All files / src/fastify coherent-fastify.d.ts

0% Statements 0/1
100% Branches 1/1
100% Functions 1/1
0% Lines 0/1

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123                                                                                                                                                                                                                                                     
// Type definitions for Coherent.js Fastify Integration
 
import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
import { CoherentNode } from '../coherent';
 
export interface CoherentFastifyOptions {
  /**
   * Enable performance monitoring for rendered components
   * @default false
   */
  enablePerformanceMonitoring?: boolean;
  
  /**
   * HTML template to wrap rendered components
   * @default '<!DOCTYPE html><html><body>{{content}}</body></html>'
   */
  template?: string;
  
  /**
   * Enable server-side rendering
   * @default true
   */
  enableSSR?: boolean;
  
  /**
   * Static file directory for client-side assets
   * @default 'public'
   */
  staticDir?: string;
}
 
export interface CoherentFastifyHandlerOptions {
  /**
   * Enable performance monitoring for rendered components
   * @default false
   */
  enablePerformanceMonitoring?: boolean;
  
  /**
   * HTML template to wrap rendered components
   * @default '<!DOCTYPE html><html><body>{{content}}</body></html>'
   */
  template?: string;
  
  /**
   * Enable streaming rendering for large components
   * @default false
   */
  enableStreaming?: boolean;
}
 
/**
 * Fastify plugin for Coherent.js
 * Adds Coherent.js rendering capabilities to Fastify
 * @param fastify Fastify instance
 * @param options Configuration options
 * @param done Callback to signal plugin registration completion
 */
export function coherentFastify(
  fastify: FastifyInstance,
  options: CoherentFastifyOptions,
  done: () => void
): void;
 
/**
 * Create a Fastify route handler for Coherent.js components
 * @param componentFactory Function that returns a Coherent component
 * @param options Configuration options
 * @returns Fastify route handler
 */
export function createCoherentFastifyHandler(
  componentFactory: (request: FastifyRequest, reply: FastifyReply) => CoherentNode | Promise<CoherentNode>,
  options?: CoherentFastifyHandlerOptions
): (request: FastifyRequest, reply: FastifyReply) => Promise<any>;
 
/**
 * Setup Coherent.js with Fastify instance
 * Configures plugin, static files, and reply extensions
 * @param fastify Fastify instance
 * @param options Configuration options
 */
export function setupCoherentFastify(
  fastify: FastifyInstance,
  options?: CoherentFastifyOptions
): void;
 
/**
 * Render a Coherent component to HTML string
 * @param component Coherent component to render
 * @param options Rendering options
 * @returns Rendered HTML string
 */
export function renderComponent(
  component: CoherentNode,
  options?: CoherentFastifyHandlerOptions
): string;
 
/**
 * Fastify reply extensions
 */
declare module 'fastify' {
  interface FastifyReply {
    /**
     * Check if an object is a valid Coherent component
     * @param obj Object to check
     * @returns True if object is a valid Coherent component
     */
    isCoherentObject(obj: any): boolean;
    
    /**
     * Render and send a Coherent component as HTML response
     * @param component Coherent component to render
     * @param options Rendering options
     */
    coherent(component: CoherentNode, options?: CoherentFastifyHandlerOptions): void;
  }
}
 
/**
 * Default export as Fastify plugin
 */
export default coherentFastify;