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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | /**
* Coherent.js Express Integration Types
* TypeScript definitions for Express.js framework integration
*
* @version 1.1.1
*/
import { Application, RequestHandler, Request, Response, NextFunction } from 'express';
import { CoherentNode } from '@coherent/core';
// ============================================================================
// Express Engine Types
// ============================================================================
/** Express view engine callback */
export type ExpressEngineCallback = (err: Error | null, html?: string) => void;
/** Express view engine options */
export interface ExpressEngineOptions {
[key: string]: any;
settings?: {
'view cache'?: boolean;
'view engine'?: string;
views?: string | string[];
};
cache?: boolean;
filename?: string;
_locals?: any;
}
/** Express view engine function */
export type ExpressEngine = (
filePath: string,
options: ExpressEngineOptions,
callback: ExpressEngineCallback
) => void;
// ============================================================================
// Coherent Express Integration
// ============================================================================
/** Coherent Express middleware options */
export interface CoherentExpressOptions {
viewEngine?: string;
viewsDirectory?: string;
cache?: boolean;
development?: boolean;
renderOptions?: {
pretty?: boolean;
doctype?: string;
compileDebug?: boolean;
};
errorHandler?: (error: Error, req: Request, res: Response, next: NextFunction) => void;
}
/** Express application with Coherent.js support */
export interface CoherentExpressApplication extends Application {
renderCoherent(view: CoherentNode, options?: any): void;
}
/** Enhanced Express request with Coherent.js utilities */
export interface CoherentRequest extends Request {
renderComponent<P = any>(component: (props: P) => CoherentNode, props?: P): string;
getComponent<P = any>(name: string, props?: P): CoherentNode | undefined;
}
/** Enhanced Express response with Coherent.js utilities */
export interface CoherentResponse extends Response {
renderCoherent(component: CoherentNode, options?: any): void;
sendComponent<P = any>(component: (props: P) => CoherentNode, props?: P): void;
streamComponent<P = any>(component: (props: P) => CoherentNode, props?: P): void;
}
// ============================================================================
// Middleware Types
// ============================================================================
/** Coherent middleware factory */
export type CoherentMiddleware = (options?: CoherentExpressOptions) => RequestHandler;
/** Component rendering middleware options */
export interface ComponentMiddlewareOptions {
componentDirectory?: string;
autoRegister?: boolean;
cache?: boolean;
development?: boolean;
}
/** Static asset serving options for Coherent.js */
export interface CoherentStaticOptions {
clientScript?: boolean;
hydrationScript?: boolean;
cssFiles?: string[];
jsFiles?: string[];
publicPath?: string;
}
// ============================================================================
// Routing Enhancement Types
// ============================================================================
/** Route handler with Coherent.js component rendering */
export interface CoherentRouteHandler {
(req: CoherentRequest, res: CoherentResponse, next: NextFunction): void | Promise<void>;
}
/** Route configuration for component-based routing */
export interface ComponentRoute {
path: string;
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'ALL';
component: (props: any) => CoherentNode;
middleware?: RequestHandler[];
props?: (req: Request, res: Response) => any | Promise<any>;
layout?: (props: any) => CoherentNode;
meta?: {
title?: string;
description?: string;
keywords?: string[];
};
}
// ============================================================================
// Server-Side Rendering Types
// ============================================================================
/** SSR configuration for Express */
export interface SSRConfig {
enabled?: boolean;
cache?: boolean;
cacheMaxAge?: number;
bundlePath?: string;
templatePath?: string;
clientManifest?: any;
serverBundle?: any;
renderToStream?: boolean;
}
/** SSR context passed to components */
export interface SSRContext {
req: Request;
res: Response;
url: string;
state: any;
meta: {
title?: string;
description?: string;
keywords?: string[];
og?: Record<string, string>;
twitter?: Record<string, string>;
};
assets: {
css: string[];
js: string[];
};
}
// ============================================================================
// Development Features
// ============================================================================
/** Development server options */
export interface DevServerOptions {
port?: number;
host?: string;
hot?: boolean;
open?: boolean;
proxy?: Record<string, string>;
watchOptions?: {
ignored?: string | RegExp | (string | RegExp)[];
aggregateTimeout?: number;
poll?: boolean | number;
};
}
/** Hot module replacement configuration */
export interface HMRConfig {
enabled?: boolean;
port?: number;
path?: string;
clientEntry?: string;
}
// ============================================================================
// Main Functions
// ============================================================================
/** Create Express view engine for Coherent.js */
export function expressEngine(options?: Partial<CoherentExpressOptions>): ExpressEngine;
/** Setup Coherent.js with Express application */
export function setupCoherent(
app: Application,
options?: CoherentExpressOptions
): CoherentExpressApplication;
/** Create component-based route */
export function createComponentRoute(config: ComponentRoute): RequestHandler;
/** Middleware for serving Coherent.js client assets */
export function coherentStatic(options?: CoherentStaticOptions): RequestHandler;
/** Middleware for component rendering */
export function componentMiddleware(options?: ComponentMiddlewareOptions): RequestHandler;
/** SSR middleware */
export function ssrMiddleware(config?: SSRConfig): RequestHandler;
/** Development middleware with HMR */
export function devMiddleware(options?: DevServerOptions & HMRConfig): RequestHandler;
// ============================================================================
// Utility Functions
// ============================================================================
/** Create enhanced Express app with Coherent.js */
export function createCoherentApp(options?: CoherentExpressOptions): CoherentExpressApplication;
/** Register component routes */
export function registerRoutes(
app: Application,
routes: ComponentRoute[]
): void;
/** Create error handler for Coherent.js */
export function createErrorHandler(options?: {
showStack?: boolean;
logErrors?: boolean;
}): (error: Error, req: Request, res: Response, next: NextFunction) => void;
// ============================================================================
// Default Export
// ============================================================================
declare const coherentExpress: {
expressEngine: typeof expressEngine;
setupCoherent: typeof setupCoherent;
createComponentRoute: typeof createComponentRoute;
coherentStatic: typeof coherentStatic;
componentMiddleware: typeof componentMiddleware;
ssrMiddleware: typeof ssrMiddleware;
devMiddleware: typeof devMiddleware;
createCoherentApp: typeof createCoherentApp;
registerRoutes: typeof registerRoutes;
createErrorHandler: typeof createErrorHandler;
};
export default coherentExpress; |