@coherent.js/express 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.
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@coherent.js/express",
3
+ "version": "1.0.0-beta.2",
4
+ "description": "Express adapter for Coherent.js",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
+ "types": "./types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "types/",
17
+ "dist/",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "engines": {
22
+ "node": ">=20.0.0"
23
+ },
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/Tomdrouv1/coherent.js.git"
28
+ },
29
+ "peerDependencies": {
30
+ "express": ">=4.18.0 < 6.0.0",
31
+ "@coherent.js/core": "1.0.0-beta.2"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "scripts": {
37
+ "build": "node build.mjs",
38
+ "clean": "rm -rf dist/",
39
+ "test": "vitest run",
40
+ "test:watch": "vitest",
41
+ "typecheck": "tsc --noEmit",
42
+ "test:coverage": "vitest run --coverage",
43
+ "test:vitest": "vitest run",
44
+ "test:node": "node --test test/*.test.js"
45
+ }
46
+ }
@@ -0,0 +1,247 @@
1
+ /**
2
+ * Coherent.js Express Integration Types
3
+ * TypeScript definitions for Express.js framework integration
4
+ *
5
+ * @version 1.0.0-beta.1
6
+ */
7
+
8
+ import { Application, RequestHandler, Request, Response, NextFunction } from 'express';
9
+ import { CoherentNode } from '@coherent/core';
10
+
11
+ // ============================================================================
12
+ // Express Engine Types
13
+ // ============================================================================
14
+
15
+ /** Express view engine callback */
16
+ export type ExpressEngineCallback = (err: Error | null, html?: string) => void;
17
+
18
+ /** Express view engine options */
19
+ export interface ExpressEngineOptions {
20
+ [key: string]: any;
21
+ settings?: {
22
+ 'view cache'?: boolean;
23
+ 'view engine'?: string;
24
+ views?: string | string[];
25
+ };
26
+ cache?: boolean;
27
+ filename?: string;
28
+ _locals?: any;
29
+ }
30
+
31
+ /** Express view engine function */
32
+ export type ExpressEngine = (
33
+ filePath: string,
34
+ options: ExpressEngineOptions,
35
+ callback: ExpressEngineCallback
36
+ ) => void;
37
+
38
+ // ============================================================================
39
+ // Coherent Express Integration
40
+ // ============================================================================
41
+
42
+ /** Coherent Express middleware options */
43
+ export interface CoherentExpressOptions {
44
+ viewEngine?: string;
45
+ viewsDirectory?: string;
46
+ cache?: boolean;
47
+ development?: boolean;
48
+ renderOptions?: {
49
+ pretty?: boolean;
50
+ doctype?: string;
51
+ compileDebug?: boolean;
52
+ };
53
+ errorHandler?: (error: Error, req: Request, res: Response, next: NextFunction) => void;
54
+ }
55
+
56
+ /** Express application with Coherent.js support */
57
+ export interface CoherentExpressApplication extends Application {
58
+ renderCoherent(view: CoherentNode, options?: any): void;
59
+ }
60
+
61
+ /** Enhanced Express request with Coherent.js utilities */
62
+ export interface CoherentRequest extends Request {
63
+ renderComponent<P = any>(component: (props: P) => CoherentNode, props?: P): string;
64
+ getComponent<P = any>(name: string, props?: P): CoherentNode | undefined;
65
+ }
66
+
67
+ /** Enhanced Express response with Coherent.js utilities */
68
+ export interface CoherentResponse extends Response {
69
+ renderCoherent(component: CoherentNode, options?: any): void;
70
+ sendComponent<P = any>(component: (props: P) => CoherentNode, props?: P): void;
71
+ streamComponent<P = any>(component: (props: P) => CoherentNode, props?: P): void;
72
+ }
73
+
74
+ // ============================================================================
75
+ // Middleware Types
76
+ // ============================================================================
77
+
78
+ /** Coherent middleware factory */
79
+ export type CoherentMiddleware = (options?: CoherentExpressOptions) => RequestHandler;
80
+
81
+ /** Component rendering middleware options */
82
+ export interface ComponentMiddlewareOptions {
83
+ componentDirectory?: string;
84
+ autoRegister?: boolean;
85
+ cache?: boolean;
86
+ development?: boolean;
87
+ }
88
+
89
+ /** Static asset serving options for Coherent.js */
90
+ export interface CoherentStaticOptions {
91
+ clientScript?: boolean;
92
+ hydrationScript?: boolean;
93
+ cssFiles?: string[];
94
+ jsFiles?: string[];
95
+ publicPath?: string;
96
+ }
97
+
98
+ // ============================================================================
99
+ // Routing Enhancement Types
100
+ // ============================================================================
101
+
102
+ /** Route handler with Coherent.js component rendering */
103
+ export interface CoherentRouteHandler {
104
+ (req: CoherentRequest, res: CoherentResponse, next: NextFunction): void | Promise<void>;
105
+ }
106
+
107
+ /** Route configuration for component-based routing */
108
+ export interface ComponentRoute {
109
+ path: string;
110
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'ALL';
111
+ component: (props: any) => CoherentNode;
112
+ middleware?: RequestHandler[];
113
+ props?: (req: Request, res: Response) => any | Promise<any>;
114
+ layout?: (props: any) => CoherentNode;
115
+ meta?: {
116
+ title?: string;
117
+ description?: string;
118
+ keywords?: string[];
119
+ };
120
+ }
121
+
122
+ // ============================================================================
123
+ // Server-Side Rendering Types
124
+ // ============================================================================
125
+
126
+ /** SSR configuration for Express */
127
+ export interface SSRConfig {
128
+ enabled?: boolean;
129
+ cache?: boolean;
130
+ cacheMaxAge?: number;
131
+ bundlePath?: string;
132
+ templatePath?: string;
133
+ clientManifest?: any;
134
+ serverBundle?: any;
135
+ renderToStream?: boolean;
136
+ }
137
+
138
+ /** SSR context passed to components */
139
+ export interface SSRContext {
140
+ req: Request;
141
+ res: Response;
142
+ url: string;
143
+ state: any;
144
+ meta: {
145
+ title?: string;
146
+ description?: string;
147
+ keywords?: string[];
148
+ og?: Record<string, string>;
149
+ twitter?: Record<string, string>;
150
+ };
151
+ assets: {
152
+ css: string[];
153
+ js: string[];
154
+ };
155
+ }
156
+
157
+ // ============================================================================
158
+ // Development Features
159
+ // ============================================================================
160
+
161
+ /** Development server options */
162
+ export interface DevServerOptions {
163
+ port?: number;
164
+ host?: string;
165
+ hot?: boolean;
166
+ open?: boolean;
167
+ proxy?: Record<string, string>;
168
+ watchOptions?: {
169
+ ignored?: string | RegExp | (string | RegExp)[];
170
+ aggregateTimeout?: number;
171
+ poll?: boolean | number;
172
+ };
173
+ }
174
+
175
+ /** Hot module replacement configuration */
176
+ export interface HMRConfig {
177
+ enabled?: boolean;
178
+ port?: number;
179
+ path?: string;
180
+ clientEntry?: string;
181
+ }
182
+
183
+ // ============================================================================
184
+ // Main Functions
185
+ // ============================================================================
186
+
187
+ /** Create Express view engine for Coherent.js */
188
+ export function expressEngine(options?: Partial<CoherentExpressOptions>): ExpressEngine;
189
+
190
+ /** Setup Coherent.js with Express application */
191
+ export function setupCoherent(
192
+ app: Application,
193
+ options?: CoherentExpressOptions
194
+ ): CoherentExpressApplication;
195
+
196
+ /** Create component-based route */
197
+ export function createComponentRoute(config: ComponentRoute): RequestHandler;
198
+
199
+ /** Middleware for serving Coherent.js client assets */
200
+ export function coherentStatic(options?: CoherentStaticOptions): RequestHandler;
201
+
202
+ /** Middleware for component rendering */
203
+ export function componentMiddleware(options?: ComponentMiddlewareOptions): RequestHandler;
204
+
205
+ /** SSR middleware */
206
+ export function ssrMiddleware(config?: SSRConfig): RequestHandler;
207
+
208
+ /** Development middleware with HMR */
209
+ export function devMiddleware(options?: DevServerOptions & HMRConfig): RequestHandler;
210
+
211
+ // ============================================================================
212
+ // Utility Functions
213
+ // ============================================================================
214
+
215
+ /** Create enhanced Express app with Coherent.js */
216
+ export function createCoherentApp(options?: CoherentExpressOptions): CoherentExpressApplication;
217
+
218
+ /** Register component routes */
219
+ export function registerRoutes(
220
+ app: Application,
221
+ routes: ComponentRoute[]
222
+ ): void;
223
+
224
+ /** Create error handler for Coherent.js */
225
+ export function createErrorHandler(options?: {
226
+ showStack?: boolean;
227
+ logErrors?: boolean;
228
+ }): (error: Error, req: Request, res: Response, next: NextFunction) => void;
229
+
230
+ // ============================================================================
231
+ // Default Export
232
+ // ============================================================================
233
+
234
+ declare const coherentExpress: {
235
+ expressEngine: typeof expressEngine;
236
+ setupCoherent: typeof setupCoherent;
237
+ createComponentRoute: typeof createComponentRoute;
238
+ coherentStatic: typeof coherentStatic;
239
+ componentMiddleware: typeof componentMiddleware;
240
+ ssrMiddleware: typeof ssrMiddleware;
241
+ devMiddleware: typeof devMiddleware;
242
+ createCoherentApp: typeof createCoherentApp;
243
+ registerRoutes: typeof registerRoutes;
244
+ createErrorHandler: typeof createErrorHandler;
245
+ };
246
+
247
+ export default coherentExpress;