@coherent.js/express 1.0.0-beta.3 → 1.0.0-beta.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coherent.js/express",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.6",
4
4
  "description": "Express adapter for Coherent.js",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -28,11 +28,12 @@
28
28
  },
29
29
  "peerDependencies": {
30
30
  "express": ">=4.18.0 < 6.0.0",
31
- "@coherent.js/core": "1.0.0-beta.3"
31
+ "@coherent.js/core": "1.0.0-beta.6"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
+ "sideEffects": false,
36
37
  "scripts": {
37
38
  "build": "node build.mjs",
38
39
  "clean": "rm -rf dist/",
package/types/index.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import { Application, RequestHandler, Request, Response, NextFunction } from 'express';
9
- import { CoherentNode } from '@coherent/core';
9
+ import { CoherentNode, RenderOptions } from '@coherent.js/core';
10
10
 
11
11
  // ============================================================================
12
12
  // Express Engine Types
@@ -45,7 +45,7 @@ export interface CoherentExpressOptions {
45
45
  viewsDirectory?: string;
46
46
  cache?: boolean;
47
47
  development?: boolean;
48
- renderOptions?: {
48
+ renderOptions?: RenderOptions & {
49
49
  pretty?: boolean;
50
50
  doctype?: string;
51
51
  compileDebug?: boolean;
@@ -55,7 +55,7 @@ export interface CoherentExpressOptions {
55
55
 
56
56
  /** Express application with Coherent.js support */
57
57
  export interface CoherentExpressApplication extends Application {
58
- renderCoherent(view: CoherentNode, options?: any): void;
58
+ renderCoherent(view: CoherentNode, options?: RenderOptions): void;
59
59
  }
60
60
 
61
61
  /** Enhanced Express request with Coherent.js utilities */
@@ -66,7 +66,7 @@ export interface CoherentRequest extends Request {
66
66
 
67
67
  /** Enhanced Express response with Coherent.js utilities */
68
68
  export interface CoherentResponse extends Response {
69
- renderCoherent(component: CoherentNode, options?: any): void;
69
+ renderCoherent(component: CoherentNode, options?: RenderOptions): void;
70
70
  sendComponent<P = any>(component: (props: P) => CoherentNode, props?: P): void;
71
71
  streamComponent<P = any>(component: (props: P) => CoherentNode, props?: P): void;
72
72
  }
@@ -78,6 +78,24 @@ export interface CoherentResponse extends Response {
78
78
  /** Coherent middleware factory */
79
79
  export type CoherentMiddleware = (options?: CoherentExpressOptions) => RequestHandler;
80
80
 
81
+ /**
82
+ * Create middleware that enables Coherent.js rendering on Express responses.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * import express from 'express';
87
+ * import { coherentMiddleware } from '@coherent.js/express';
88
+ *
89
+ * const app = express();
90
+ * app.use(coherentMiddleware({ development: true }));
91
+ *
92
+ * app.get('/', (req, res) => {
93
+ * res.renderCoherent({ div: { text: 'Hello World' } });
94
+ * });
95
+ * ```
96
+ */
97
+ export function coherentMiddleware(options?: CoherentExpressOptions): RequestHandler;
98
+
81
99
  /** Component rendering middleware options */
82
100
  export interface ComponentMiddlewareOptions {
83
101
  componentDirectory?: string;
@@ -208,6 +226,18 @@ export function ssrMiddleware(config?: SSRConfig): RequestHandler;
208
226
  /** Development middleware with HMR */
209
227
  export function devMiddleware(options?: DevServerOptions & HMRConfig): RequestHandler;
210
228
 
229
+ /**
230
+ * Render a CoherentNode to HTML string.
231
+ *
232
+ * @example
233
+ * ```typescript
234
+ * import { renderComponent } from '@coherent.js/express';
235
+ *
236
+ * const html = renderComponent({ div: { text: 'Hello' } });
237
+ * ```
238
+ */
239
+ export function renderComponent(component: CoherentNode, options?: RenderOptions): string;
240
+
211
241
  // ============================================================================
212
242
  // Utility Functions
213
243
  // ============================================================================
@@ -236,12 +266,14 @@ declare const coherentExpress: {
236
266
  setupCoherent: typeof setupCoherent;
237
267
  createComponentRoute: typeof createComponentRoute;
238
268
  coherentStatic: typeof coherentStatic;
269
+ coherentMiddleware: typeof coherentMiddleware;
239
270
  componentMiddleware: typeof componentMiddleware;
240
271
  ssrMiddleware: typeof ssrMiddleware;
241
272
  devMiddleware: typeof devMiddleware;
242
273
  createCoherentApp: typeof createCoherentApp;
243
274
  registerRoutes: typeof registerRoutes;
244
275
  createErrorHandler: typeof createErrorHandler;
276
+ renderComponent: typeof renderComponent;
245
277
  };
246
278
 
247
279
  export default coherentExpress;