@coherent.js/koa 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,156 @@
1
+ /**
2
+ * Coherent.js Koa Integration Types
3
+ * TypeScript definitions for Koa.js framework integration
4
+ *
5
+ * @version 1.0.0-beta.1
6
+ */
7
+
8
+ import Koa, { Context, Middleware, Next } from 'koa';
9
+ import { CoherentNode } from '@coherent/core';
10
+
11
+ // ============================================================================
12
+ // Koa Integration Types
13
+ // ============================================================================
14
+
15
+ /** Coherent Koa options */
16
+ export interface CoherentKoaOptions {
17
+ viewEngine?: string;
18
+ viewsDirectory?: string;
19
+ cache?: boolean;
20
+ development?: boolean;
21
+ renderOptions?: {
22
+ pretty?: boolean;
23
+ doctype?: string;
24
+ };
25
+ errorHandler?: (error: Error, ctx: Context, next: Next) => Promise<void>;
26
+ }
27
+
28
+ /** Enhanced Koa context with Coherent.js utilities */
29
+ export interface CoherentContext extends Context {
30
+ renderComponent<P = any>(component: (props: P) => CoherentNode, props?: P): string;
31
+ renderCoherent(component: CoherentNode, options?: any): void;
32
+ sendComponent<P = any>(component: (props: P) => CoherentNode, props?: P): void;
33
+ getComponent<P = any>(name: string, props?: P): CoherentNode | undefined;
34
+
35
+ // State management
36
+ coherentState: any;
37
+ setCoherentState(state: any): void;
38
+ getCoherentState(): any;
39
+ }
40
+
41
+ /** Koa application with Coherent.js support */
42
+ export interface CoherentKoaApplication extends Koa {
43
+ context: CoherentContext;
44
+ renderCoherent(component: CoherentNode, options?: any): void;
45
+ }
46
+
47
+ // ============================================================================
48
+ // Middleware Types
49
+ // ============================================================================
50
+
51
+ /** Component rendering middleware options */
52
+ export interface KoaComponentMiddlewareOptions {
53
+ componentDirectory?: string;
54
+ autoRegister?: boolean;
55
+ cache?: boolean;
56
+ development?: boolean;
57
+ }
58
+
59
+ /** Route configuration for component-based routing */
60
+ export interface KoaComponentRoute {
61
+ path: string | RegExp;
62
+ method?: string | string[];
63
+ component: (props: any) => CoherentNode;
64
+ middleware?: Middleware[];
65
+ props?: (ctx: Context) => any | Promise<any>;
66
+ layout?: (props: any) => CoherentNode;
67
+ meta?: {
68
+ title?: string;
69
+ description?: string;
70
+ keywords?: string[];
71
+ };
72
+ }
73
+
74
+ /** SSR configuration for Koa */
75
+ export interface KoaSSRConfig {
76
+ enabled?: boolean;
77
+ cache?: boolean;
78
+ cacheMaxAge?: number;
79
+ bundlePath?: string;
80
+ templatePath?: string;
81
+ clientManifest?: any;
82
+ serverBundle?: any;
83
+ renderToStream?: boolean;
84
+ }
85
+
86
+ /** SSR context for Koa */
87
+ export interface KoaSSRContext {
88
+ ctx: Context;
89
+ url: string;
90
+ state: any;
91
+ meta: {
92
+ title?: string;
93
+ description?: string;
94
+ keywords?: string[];
95
+ og?: Record<string, string>;
96
+ twitter?: Record<string, string>;
97
+ };
98
+ assets: {
99
+ css: string[];
100
+ js: string[];
101
+ };
102
+ }
103
+
104
+ // ============================================================================
105
+ // Main Functions
106
+ // ============================================================================
107
+
108
+ /** Setup Coherent.js with Koa application */
109
+ export function setupCoherent(
110
+ app: Koa,
111
+ options?: CoherentKoaOptions
112
+ ): CoherentKoaApplication;
113
+
114
+ /** Create component-based route middleware */
115
+ export function createComponentRoute(config: KoaComponentRoute): Middleware;
116
+
117
+ /** Middleware for component rendering */
118
+ export function componentMiddleware(options?: KoaComponentMiddlewareOptions): Middleware;
119
+
120
+ /** SSR middleware for Koa */
121
+ export function ssrMiddleware(config?: KoaSSRConfig): Middleware;
122
+
123
+ /** Error handling middleware for Coherent.js */
124
+ export function errorMiddleware(options?: {
125
+ showStack?: boolean;
126
+ logErrors?: boolean;
127
+ }): Middleware;
128
+
129
+ // ============================================================================
130
+ // Utility Functions
131
+ // ============================================================================
132
+
133
+ /** Create enhanced Koa app with Coherent.js */
134
+ export function createCoherentApp(options?: CoherentKoaOptions): CoherentKoaApplication;
135
+
136
+ /** Register component routes */
137
+ export function registerRoutes(
138
+ app: Koa,
139
+ routes: KoaComponentRoute[]
140
+ ): void;
141
+
142
+ // ============================================================================
143
+ // Default Export
144
+ // ============================================================================
145
+
146
+ declare const coherentKoa: {
147
+ setupCoherent: typeof setupCoherent;
148
+ createComponentRoute: typeof createComponentRoute;
149
+ componentMiddleware: typeof componentMiddleware;
150
+ ssrMiddleware: typeof ssrMiddleware;
151
+ errorMiddleware: typeof errorMiddleware;
152
+ createCoherentApp: typeof createCoherentApp;
153
+ registerRoutes: typeof registerRoutes;
154
+ };
155
+
156
+ export default coherentKoa;