@coherent.js/nextjs 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,329 @@
1
+ /**
2
+ * Coherent.js Next.js Integration Types
3
+ * TypeScript definitions for Next.js framework integration
4
+ *
5
+ * @version 1.0.0-beta.1
6
+ */
7
+
8
+ import { NextApiRequest, NextApiResponse, NextPage, GetServerSideProps, GetStaticProps } from 'next';
9
+ import { CoherentNode } from '@coherent/core';
10
+
11
+ // ============================================================================
12
+ // Next.js Integration Types
13
+ // ============================================================================
14
+
15
+ /** Coherent Next.js page props */
16
+ export interface CoherentPageProps {
17
+ [key: string]: any;
18
+ coherentState?: any;
19
+ coherentMeta?: {
20
+ title?: string;
21
+ description?: string;
22
+ keywords?: string[];
23
+ og?: Record<string, string>;
24
+ twitter?: Record<string, string>;
25
+ };
26
+ }
27
+
28
+ /** Coherent Next.js page component */
29
+ export interface CoherentNextPage<P = CoherentPageProps> extends NextPage<P> {
30
+ renderCoherent?: (props: P) => CoherentNode;
31
+ getLayout?: (page: CoherentNode) => CoherentNode;
32
+ coherentConfig?: {
33
+ ssr?: boolean;
34
+ hydrate?: boolean;
35
+ cache?: boolean;
36
+ };
37
+ }
38
+
39
+ /** Enhanced Next.js API request */
40
+ export interface CoherentApiRequest extends NextApiRequest {
41
+ renderComponent<P = any>(component: (props: P) => CoherentNode, props?: P): string;
42
+ }
43
+
44
+ /** Enhanced Next.js API response */
45
+ export interface CoherentApiResponse extends NextApiResponse {
46
+ sendComponent<P = any>(component: (props: P) => CoherentNode, props?: P): void;
47
+ renderCoherent(component: CoherentNode, options?: any): void;
48
+ }
49
+
50
+ // ============================================================================
51
+ // Configuration Types
52
+ // ============================================================================
53
+
54
+ /** Next.js configuration with Coherent.js support */
55
+ export interface CoherentNextConfig {
56
+ // Standard Next.js config
57
+ reactStrictMode?: boolean;
58
+ swcMinify?: boolean;
59
+ experimental?: any;
60
+
61
+ // Coherent.js specific
62
+ coherent?: {
63
+ ssr?: boolean;
64
+ hydration?: boolean;
65
+ componentDirectory?: string;
66
+ staticGeneration?: boolean;
67
+ cache?: {
68
+ enabled?: boolean;
69
+ maxAge?: number;
70
+ staleWhileRevalidate?: number;
71
+ };
72
+ build?: {
73
+ analyze?: boolean;
74
+ bundleAnalyzer?: boolean;
75
+ };
76
+ dev?: {
77
+ hmr?: boolean;
78
+ overlay?: boolean;
79
+ };
80
+ };
81
+
82
+ // Webpack configuration
83
+ webpack?: (config: any, options: any) => any;
84
+ }
85
+
86
+ /** Build configuration for Coherent.js */
87
+ export interface CoherentBuildConfig {
88
+ outputDirectory?: string;
89
+ staticGeneration?: boolean;
90
+ optimization?: {
91
+ minimize?: boolean;
92
+ splitChunks?: boolean;
93
+ treeshaking?: boolean;
94
+ };
95
+ bundleAnalysis?: boolean;
96
+ }
97
+
98
+ // ============================================================================
99
+ // SSR and Static Generation Types
100
+ // ============================================================================
101
+
102
+ /** Server-side rendering context for Next.js */
103
+ export interface NextSSRContext {
104
+ req: NextApiRequest;
105
+ res: NextApiResponse;
106
+ params?: { [key: string]: string | string[] };
107
+ query: { [key: string]: string | string[] };
108
+ preview?: boolean;
109
+ previewData?: any;
110
+ resolvedUrl: string;
111
+ locale?: string;
112
+ locales?: string[];
113
+ defaultLocale?: string;
114
+ }
115
+
116
+ /** Enhanced GetServerSideProps with Coherent.js support */
117
+ export type CoherentGetServerSideProps<P = CoherentPageProps> = (
118
+ context: NextSSRContext & {
119
+ renderComponent: <CP = any>(component: (props: CP) => CoherentNode, props?: CP) => string;
120
+ coherentState: any;
121
+ setCoherentState: (state: any) => void;
122
+ }
123
+ ) => Promise<{
124
+ props: P;
125
+ redirect?: any;
126
+ notFound?: boolean;
127
+ }>;
128
+
129
+ /** Enhanced GetStaticProps with Coherent.js support */
130
+ export type CoherentGetStaticProps<P = CoherentPageProps> = (
131
+ context: {
132
+ params?: { [key: string]: string | string[] };
133
+ preview?: boolean;
134
+ previewData?: any;
135
+ locale?: string;
136
+ locales?: string[];
137
+ defaultLocale?: string;
138
+ } & {
139
+ renderComponent: <CP = any>(component: (props: CP) => CoherentNode, props?: CP) => string;
140
+ }
141
+ ) => Promise<{
142
+ props: P;
143
+ revalidate?: number | boolean;
144
+ redirect?: any;
145
+ notFound?: boolean;
146
+ }>;
147
+
148
+ // ============================================================================
149
+ // Plugin and Middleware Types
150
+ // ============================================================================
151
+
152
+ /** Next.js plugin for Coherent.js */
153
+ export interface CoherentNextPlugin {
154
+ (nextConfig?: any): any;
155
+ }
156
+
157
+ /** Middleware options for API routes */
158
+ export interface ApiMiddlewareOptions {
159
+ cors?: {
160
+ origin?: string | string[] | boolean;
161
+ methods?: string[];
162
+ allowedHeaders?: string[];
163
+ credentials?: boolean;
164
+ };
165
+ rateLimit?: {
166
+ windowMs?: number;
167
+ max?: number;
168
+ };
169
+ auth?: {
170
+ required?: boolean;
171
+ roles?: string[];
172
+ };
173
+ }
174
+
175
+ /** API route handler with Coherent.js support */
176
+ export type CoherentApiHandler = (
177
+ req: CoherentApiRequest,
178
+ res: CoherentApiResponse
179
+ ) => void | Promise<void>;
180
+
181
+ // ============================================================================
182
+ // Layout and App Types
183
+ // ============================================================================
184
+
185
+ /** Custom App component with Coherent.js support */
186
+ export interface CoherentAppProps {
187
+ Component: CoherentNextPage;
188
+ pageProps: CoherentPageProps;
189
+ coherentState?: any;
190
+ coherentMeta?: any;
191
+ }
192
+
193
+ /** Custom App component type */
194
+ export type CoherentApp = (props: CoherentAppProps) => CoherentNode;
195
+
196
+ /** Layout component props */
197
+ export interface LayoutProps {
198
+ children: CoherentNode;
199
+ meta?: {
200
+ title?: string;
201
+ description?: string;
202
+ keywords?: string[];
203
+ };
204
+ coherentState?: any;
205
+ }
206
+
207
+ /** Layout component type */
208
+ export type CoherentLayout = (props: LayoutProps) => CoherentNode;
209
+
210
+ // ============================================================================
211
+ // Development and Build Types
212
+ // ============================================================================
213
+
214
+ /** Development server configuration */
215
+ export interface DevServerConfig {
216
+ port?: number;
217
+ hostname?: string;
218
+ hmr?: boolean;
219
+ turbo?: boolean;
220
+ experimental?: {
221
+ turbo?: boolean;
222
+ serverComponents?: boolean;
223
+ };
224
+ }
225
+
226
+ /** Build statistics */
227
+ export interface BuildStats {
228
+ pages: Array<{
229
+ path: string;
230
+ size: number;
231
+ firstLoad: number;
232
+ }>;
233
+ assets: Array<{
234
+ name: string;
235
+ size: number;
236
+ type: string;
237
+ }>;
238
+ bundles: Array<{
239
+ name: string;
240
+ size: number;
241
+ modules: number;
242
+ }>;
243
+ }
244
+
245
+ // ============================================================================
246
+ // Main Functions
247
+ // ============================================================================
248
+
249
+ /** Create Coherent.js Next.js configuration */
250
+ export function withCoherent(nextConfig?: any): CoherentNextConfig;
251
+
252
+ /** Create page component with Coherent.js support */
253
+ export function createPage<P = CoherentPageProps>(
254
+ component: (props: P) => CoherentNode,
255
+ options?: {
256
+ layout?: CoherentLayout;
257
+ ssr?: boolean;
258
+ hydrate?: boolean;
259
+ }
260
+ ): CoherentNextPage<P>;
261
+
262
+ /** Create API route with Coherent.js support */
263
+ export function createApiRoute(
264
+ handler: CoherentApiHandler,
265
+ options?: ApiMiddlewareOptions
266
+ ): CoherentApiHandler;
267
+
268
+ /** Create layout component */
269
+ export function createLayout(
270
+ component: (props: LayoutProps) => CoherentNode
271
+ ): CoherentLayout;
272
+
273
+ /** Create custom App component */
274
+ export function createApp(
275
+ component: (props: CoherentAppProps) => CoherentNode
276
+ ): CoherentApp;
277
+
278
+ /** Middleware for API routes */
279
+ export function withMiddleware(
280
+ handler: CoherentApiHandler,
281
+ options?: ApiMiddlewareOptions
282
+ ): CoherentApiHandler;
283
+
284
+ /** Enhanced GetServerSideProps */
285
+ export function withServerSideProps<P = CoherentPageProps>(
286
+ getProps: CoherentGetServerSideProps<P>
287
+ ): GetServerSideProps<P>;
288
+
289
+ /** Enhanced GetStaticProps */
290
+ export function withStaticProps<P = CoherentPageProps>(
291
+ getProps: CoherentGetStaticProps<P>
292
+ ): GetStaticProps<P>;
293
+
294
+ // ============================================================================
295
+ // Utility Functions
296
+ // ============================================================================
297
+
298
+ /** Get build configuration */
299
+ export function getBuildConfig(): CoherentBuildConfig;
300
+
301
+ /** Get runtime configuration */
302
+ export function getRuntimeConfig(): any;
303
+
304
+ /** Create webpack configuration */
305
+ export function createWebpackConfig(baseConfig: any, options: any): any;
306
+
307
+ /** Analyze bundle */
308
+ export function analyzeBundle(): Promise<BuildStats>;
309
+
310
+ // ============================================================================
311
+ // Default Export
312
+ // ============================================================================
313
+
314
+ declare const coherentNext: {
315
+ withCoherent: typeof withCoherent;
316
+ createPage: typeof createPage;
317
+ createApiRoute: typeof createApiRoute;
318
+ createLayout: typeof createLayout;
319
+ createApp: typeof createApp;
320
+ withMiddleware: typeof withMiddleware;
321
+ withServerSideProps: typeof withServerSideProps;
322
+ withStaticProps: typeof withStaticProps;
323
+ getBuildConfig: typeof getBuildConfig;
324
+ getRuntimeConfig: typeof getRuntimeConfig;
325
+ createWebpackConfig: typeof createWebpackConfig;
326
+ analyzeBundle: typeof analyzeBundle;
327
+ };
328
+
329
+ export default coherentNext;