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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | /**
* Coherent.js Next.js Integration Types
* TypeScript definitions for Next.js framework integration
*
* @version 1.1.1
*/
import { NextApiRequest, NextApiResponse, NextPage, GetServerSideProps, GetStaticProps } from 'next';
import { CoherentNode } from '@coherent/core';
// ============================================================================
// Next.js Integration Types
// ============================================================================
/** Coherent Next.js page props */
export interface CoherentPageProps {
[key: string]: any;
coherentState?: any;
coherentMeta?: {
title?: string;
description?: string;
keywords?: string[];
og?: Record<string, string>;
twitter?: Record<string, string>;
};
}
/** Coherent Next.js page component */
export interface CoherentNextPage<P = CoherentPageProps> extends NextPage<P> {
renderCoherent?: (props: P) => CoherentNode;
getLayout?: (page: CoherentNode) => CoherentNode;
coherentConfig?: {
ssr?: boolean;
hydrate?: boolean;
cache?: boolean;
};
}
/** Enhanced Next.js API request */
export interface CoherentApiRequest extends NextApiRequest {
renderComponent<P = any>(component: (props: P) => CoherentNode, props?: P): string;
}
/** Enhanced Next.js API response */
export interface CoherentApiResponse extends NextApiResponse {
sendComponent<P = any>(component: (props: P) => CoherentNode, props?: P): void;
renderCoherent(component: CoherentNode, options?: any): void;
}
// ============================================================================
// Configuration Types
// ============================================================================
/** Next.js configuration with Coherent.js support */
export interface CoherentNextConfig {
// Standard Next.js config
reactStrictMode?: boolean;
swcMinify?: boolean;
experimental?: any;
// Coherent.js specific
coherent?: {
ssr?: boolean;
hydration?: boolean;
componentDirectory?: string;
staticGeneration?: boolean;
cache?: {
enabled?: boolean;
maxAge?: number;
staleWhileRevalidate?: number;
};
build?: {
analyze?: boolean;
bundleAnalyzer?: boolean;
};
dev?: {
hmr?: boolean;
overlay?: boolean;
};
};
// Webpack configuration
webpack?: (config: any, options: any) => any;
}
/** Build configuration for Coherent.js */
export interface CoherentBuildConfig {
outputDirectory?: string;
staticGeneration?: boolean;
optimization?: {
minimize?: boolean;
splitChunks?: boolean;
treeshaking?: boolean;
};
bundleAnalysis?: boolean;
}
// ============================================================================
// SSR and Static Generation Types
// ============================================================================
/** Server-side rendering context for Next.js */
export interface NextSSRContext {
req: NextApiRequest;
res: NextApiResponse;
params?: { [key: string]: string | string[] };
query: { [key: string]: string | string[] };
preview?: boolean;
previewData?: any;
resolvedUrl: string;
locale?: string;
locales?: string[];
defaultLocale?: string;
}
/** Enhanced GetServerSideProps with Coherent.js support */
export type CoherentGetServerSideProps<P = CoherentPageProps> = (
context: NextSSRContext & {
renderComponent: <CP = any>(component: (props: CP) => CoherentNode, props?: CP) => string;
coherentState: any;
setCoherentState: (state: any) => void;
}
) => Promise<{
props: P;
redirect?: any;
notFound?: boolean;
}>;
/** Enhanced GetStaticProps with Coherent.js support */
export type CoherentGetStaticProps<P = CoherentPageProps> = (
context: {
params?: { [key: string]: string | string[] };
preview?: boolean;
previewData?: any;
locale?: string;
locales?: string[];
defaultLocale?: string;
} & {
renderComponent: <CP = any>(component: (props: CP) => CoherentNode, props?: CP) => string;
}
) => Promise<{
props: P;
revalidate?: number | boolean;
redirect?: any;
notFound?: boolean;
}>;
// ============================================================================
// Plugin and Middleware Types
// ============================================================================
/** Next.js plugin for Coherent.js */
export interface CoherentNextPlugin {
(nextConfig?: any): any;
}
/** Middleware options for API routes */
export interface ApiMiddlewareOptions {
cors?: {
origin?: string | string[] | boolean;
methods?: string[];
allowedHeaders?: string[];
credentials?: boolean;
};
rateLimit?: {
windowMs?: number;
max?: number;
};
auth?: {
required?: boolean;
roles?: string[];
};
}
/** API route handler with Coherent.js support */
export type CoherentApiHandler = (
req: CoherentApiRequest,
res: CoherentApiResponse
) => void | Promise<void>;
// ============================================================================
// Layout and App Types
// ============================================================================
/** Custom App component with Coherent.js support */
export interface CoherentAppProps {
Component: CoherentNextPage;
pageProps: CoherentPageProps;
coherentState?: any;
coherentMeta?: any;
}
/** Custom App component type */
export type CoherentApp = (props: CoherentAppProps) => CoherentNode;
/** Layout component props */
export interface LayoutProps {
children: CoherentNode;
meta?: {
title?: string;
description?: string;
keywords?: string[];
};
coherentState?: any;
}
/** Layout component type */
export type CoherentLayout = (props: LayoutProps) => CoherentNode;
// ============================================================================
// Development and Build Types
// ============================================================================
/** Development server configuration */
export interface DevServerConfig {
port?: number;
hostname?: string;
hmr?: boolean;
turbo?: boolean;
experimental?: {
turbo?: boolean;
serverComponents?: boolean;
};
}
/** Build statistics */
export interface BuildStats {
pages: Array<{
path: string;
size: number;
firstLoad: number;
}>;
assets: Array<{
name: string;
size: number;
type: string;
}>;
bundles: Array<{
name: string;
size: number;
modules: number;
}>;
}
// ============================================================================
// Main Functions
// ============================================================================
/** Create Coherent.js Next.js configuration */
export function withCoherent(nextConfig?: any): CoherentNextConfig;
/** Create page component with Coherent.js support */
export function createPage<P = CoherentPageProps>(
component: (props: P) => CoherentNode,
options?: {
layout?: CoherentLayout;
ssr?: boolean;
hydrate?: boolean;
}
): CoherentNextPage<P>;
/** Create API route with Coherent.js support */
export function createApiRoute(
handler: CoherentApiHandler,
options?: ApiMiddlewareOptions
): CoherentApiHandler;
/** Create layout component */
export function createLayout(
component: (props: LayoutProps) => CoherentNode
): CoherentLayout;
/** Create custom App component */
export function createApp(
component: (props: CoherentAppProps) => CoherentNode
): CoherentApp;
/** Middleware for API routes */
export function withMiddleware(
handler: CoherentApiHandler,
options?: ApiMiddlewareOptions
): CoherentApiHandler;
/** Enhanced GetServerSideProps */
export function withServerSideProps<P = CoherentPageProps>(
getProps: CoherentGetServerSideProps<P>
): GetServerSideProps<P>;
/** Enhanced GetStaticProps */
export function withStaticProps<P = CoherentPageProps>(
getProps: CoherentGetStaticProps<P>
): GetStaticProps<P>;
// ============================================================================
// Utility Functions
// ============================================================================
/** Get build configuration */
export function getBuildConfig(): CoherentBuildConfig;
/** Get runtime configuration */
export function getRuntimeConfig(): any;
/** Create webpack configuration */
export function createWebpackConfig(baseConfig: any, options: any): any;
/** Analyze bundle */
export function analyzeBundle(): Promise<BuildStats>;
// ============================================================================
// Default Export
// ============================================================================
declare const coherentNext: {
withCoherent: typeof withCoherent;
createPage: typeof createPage;
createApiRoute: typeof createApiRoute;
createLayout: typeof createLayout;
createApp: typeof createApp;
withMiddleware: typeof withMiddleware;
withServerSideProps: typeof withServerSideProps;
withStaticProps: typeof withStaticProps;
getBuildConfig: typeof getBuildConfig;
getRuntimeConfig: typeof getRuntimeConfig;
createWebpackConfig: typeof createWebpackConfig;
analyzeBundle: typeof analyzeBundle;
};
export default coherentNext; |