@nestjs-ssr/react 0.1.5 → 0.1.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.
@@ -295,7 +295,7 @@ declare class TemplateParserService {
295
295
  * This library handles all edge cases including escaping dangerous characters,
296
296
  * functions, dates, regexes, and prevents prototype pollution.
297
297
  */
298
- buildInlineScripts(data: any, context: any, componentPath: string): string;
298
+ buildInlineScripts(data: any, context: any, componentName: string): string;
299
299
  /**
300
300
  * Get client script tag for hydration
301
301
  *
@@ -367,12 +367,14 @@ declare class RenderService {
367
367
  private serverManifest;
368
368
  private isDevelopment;
369
369
  private ssrMode;
370
+ private readonly entryServerPath;
371
+ private readonly entryClientPath;
370
372
  constructor(templateParser: TemplateParserService, streamingErrorHandler: StreamingErrorHandler, ssrMode?: SSRMode, defaultHead?: HeadData | undefined);
371
373
  setViteServer(vite: ViteDevServer): void;
372
374
  /**
373
375
  * Main render method that routes to string or stream mode
374
376
  */
375
- render(viewPath: string, data?: any, res?: Response, head?: HeadData): Promise<string | void>;
377
+ render(viewComponent: any, data?: any, res?: Response, head?: HeadData): Promise<string | void>;
376
378
  /**
377
379
  * Merge default head with page-specific head
378
380
  * Page-specific head values override defaults
@@ -295,7 +295,7 @@ declare class TemplateParserService {
295
295
  * This library handles all edge cases including escaping dangerous characters,
296
296
  * functions, dates, regexes, and prevents prototype pollution.
297
297
  */
298
- buildInlineScripts(data: any, context: any, componentPath: string): string;
298
+ buildInlineScripts(data: any, context: any, componentName: string): string;
299
299
  /**
300
300
  * Get client script tag for hydration
301
301
  *
@@ -367,12 +367,14 @@ declare class RenderService {
367
367
  private serverManifest;
368
368
  private isDevelopment;
369
369
  private ssrMode;
370
+ private readonly entryServerPath;
371
+ private readonly entryClientPath;
370
372
  constructor(templateParser: TemplateParserService, streamingErrorHandler: StreamingErrorHandler, ssrMode?: SSRMode, defaultHead?: HeadData | undefined);
371
373
  setViteServer(vite: ViteDevServer): void;
372
374
  /**
373
375
  * Main render method that routes to string or stream mode
374
376
  */
375
- render(viewPath: string, data?: any, res?: Response, head?: HeadData): Promise<string | void>;
377
+ render(viewComponent: any, data?: any, res?: Response, head?: HeadData): Promise<string | void>;
376
378
  /**
377
379
  * Merge default head with page-specific head
378
380
  * Page-specific head values override defaults
package/dist/index.d.mts CHANGED
@@ -1,8 +1,7 @@
1
- import { H as HeadData } from './index-Bptct1Q3.mjs';
2
- export { E as ErrorPageDevelopment, f as ErrorPageProduction, c as RenderConfig, b as RenderInterceptor, R as RenderModule, e as RenderResponse, a as RenderService, d as SSRMode, S as StreamingErrorHandler, T as TemplateParserService } from './index-Bptct1Q3.mjs';
3
- import * as _nestjs_common from '@nestjs/common';
4
- export { viewRegistryPlugin } from './vite/index.mjs';
5
- import 'react';
1
+ import { H as HeadData } from './index-Bpzo1KfR.mjs';
2
+ export { E as ErrorPageDevelopment, f as ErrorPageProduction, c as RenderConfig, b as RenderInterceptor, R as RenderModule, e as RenderResponse, a as RenderService, d as SSRMode, S as StreamingErrorHandler, T as TemplateParserService } from './index-Bpzo1KfR.mjs';
3
+ import React from 'react';
4
+ import '@nestjs/common';
6
5
  import 'vite';
7
6
  import 'express';
8
7
  import '@nestjs/core';
@@ -122,39 +121,49 @@ type PageProps<TProps = {}> = TProps & {
122
121
  };
123
122
 
124
123
  /**
125
- * Interface for view paths - augmented by the generated view registry.
126
- * This enables type-safe path validation in Render decorator.
124
+ * Extract the data type T from PageProps<T>.
125
+ * PageProps<T> = T & { head?, context }, so we extract T by removing those keys.
127
126
  */
128
- interface ViewPaths {
129
- }
127
+ type ExtractPagePropsData<P> = P extends PageProps<infer T> ? T : P extends {
128
+ head?: any;
129
+ context: any;
130
+ } ? Omit<P, 'head' | 'context'> : P;
130
131
  /**
131
- * Type-safe view path - union of all registered view paths.
132
- * This is populated via module augmentation from the generated view registry.
132
+ * Extract controller return type from a React component's props.
133
133
  */
134
- type ViewPath = keyof ViewPaths extends never ? string : keyof ViewPaths;
134
+ type ExtractComponentData<T> = T extends React.ComponentType<infer P> ? ExtractPagePropsData<P> : never;
135
135
  /**
136
136
  * Decorator to render a React component as the response.
137
- * Provides IDE autocomplete and type checking for view paths.
138
137
  *
139
- * Works the same as NestJS's @Render() decorator for template engines,
140
- * but renders React components with SSR instead.
138
+ * Import the component directly for Cmd+Click navigation in your IDE.
139
+ * TypeScript automatically validates your controller returns the correct props.
141
140
  *
142
- * @param viewPath - Path to the React component (e.g., 'users/views/user-list')
141
+ * @param component - The React component to render
143
142
  *
144
143
  * @example
145
144
  * ```typescript
145
+ * // Your view component (views/home.tsx)
146
+ * export interface HomeProps {
147
+ * message: string;
148
+ * }
149
+ * export default function Home(props: PageProps<HomeProps>) { ... }
150
+ *
151
+ * // Your controller - Cmd+Click on Home navigates to the view file!
152
+ * import Home from './views/home';
153
+ *
146
154
  * @Get()
147
- * @Render('users/views/user-list')
148
- * getUsers() {
149
- * return { users: [...] };
155
+ * @Render(Home) // Type-safe! Wrong props = build error
156
+ * getHome() {
157
+ * return { message: 'Hello' }; // ✅ Correct
158
+ * // return { wrong: 'prop' }; // ❌ Type error!
150
159
  * }
151
160
  * ```
152
161
  */
153
- declare const Render: (viewPath: ViewPath) => _nestjs_common.CustomDecorator<string>;
162
+ declare function Render<T extends React.ComponentType<any>>(component: T): <TMethod extends (...args: any[]) => ExtractComponentData<T> | Promise<ExtractComponentData<T>>>(target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<TMethod>) => TypedPropertyDescriptor<TMethod> | void;
154
163
  /**
155
164
  * @deprecated Use `Render` instead. This alias will be removed in a future version.
156
165
  */
157
- declare const ReactRender: (viewPath: ViewPath) => _nestjs_common.CustomDecorator<string>;
166
+ declare const ReactRender: typeof Render;
158
167
 
159
168
  /**
160
169
  * Hook to access the full page context.
@@ -217,4 +226,4 @@ declare function useQuery(): Record<string, string | string[]>;
217
226
  */
218
227
  declare function useUserAgent(): string | undefined;
219
228
 
220
- export { HeadData, type PageProps, ReactRender, Render, type RenderContext, type ViewPath, type ViewPaths, usePageContext, useParams, useQuery, useUserAgent };
229
+ export { HeadData, type PageProps, ReactRender, Render, type RenderContext, usePageContext, useParams, useQuery, useUserAgent };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { H as HeadData } from './index-Bptct1Q3.js';
2
- export { E as ErrorPageDevelopment, f as ErrorPageProduction, c as RenderConfig, b as RenderInterceptor, R as RenderModule, e as RenderResponse, a as RenderService, d as SSRMode, S as StreamingErrorHandler, T as TemplateParserService } from './index-Bptct1Q3.js';
3
- import * as _nestjs_common from '@nestjs/common';
4
- export { viewRegistryPlugin } from './vite/index.js';
5
- import 'react';
1
+ import { H as HeadData } from './index-Bpzo1KfR.js';
2
+ export { E as ErrorPageDevelopment, f as ErrorPageProduction, c as RenderConfig, b as RenderInterceptor, R as RenderModule, e as RenderResponse, a as RenderService, d as SSRMode, S as StreamingErrorHandler, T as TemplateParserService } from './index-Bpzo1KfR.js';
3
+ import React from 'react';
4
+ import '@nestjs/common';
6
5
  import 'vite';
7
6
  import 'express';
8
7
  import '@nestjs/core';
@@ -122,39 +121,49 @@ type PageProps<TProps = {}> = TProps & {
122
121
  };
123
122
 
124
123
  /**
125
- * Interface for view paths - augmented by the generated view registry.
126
- * This enables type-safe path validation in Render decorator.
124
+ * Extract the data type T from PageProps<T>.
125
+ * PageProps<T> = T & { head?, context }, so we extract T by removing those keys.
127
126
  */
128
- interface ViewPaths {
129
- }
127
+ type ExtractPagePropsData<P> = P extends PageProps<infer T> ? T : P extends {
128
+ head?: any;
129
+ context: any;
130
+ } ? Omit<P, 'head' | 'context'> : P;
130
131
  /**
131
- * Type-safe view path - union of all registered view paths.
132
- * This is populated via module augmentation from the generated view registry.
132
+ * Extract controller return type from a React component's props.
133
133
  */
134
- type ViewPath = keyof ViewPaths extends never ? string : keyof ViewPaths;
134
+ type ExtractComponentData<T> = T extends React.ComponentType<infer P> ? ExtractPagePropsData<P> : never;
135
135
  /**
136
136
  * Decorator to render a React component as the response.
137
- * Provides IDE autocomplete and type checking for view paths.
138
137
  *
139
- * Works the same as NestJS's @Render() decorator for template engines,
140
- * but renders React components with SSR instead.
138
+ * Import the component directly for Cmd+Click navigation in your IDE.
139
+ * TypeScript automatically validates your controller returns the correct props.
141
140
  *
142
- * @param viewPath - Path to the React component (e.g., 'users/views/user-list')
141
+ * @param component - The React component to render
143
142
  *
144
143
  * @example
145
144
  * ```typescript
145
+ * // Your view component (views/home.tsx)
146
+ * export interface HomeProps {
147
+ * message: string;
148
+ * }
149
+ * export default function Home(props: PageProps<HomeProps>) { ... }
150
+ *
151
+ * // Your controller - Cmd+Click on Home navigates to the view file!
152
+ * import Home from './views/home';
153
+ *
146
154
  * @Get()
147
- * @Render('users/views/user-list')
148
- * getUsers() {
149
- * return { users: [...] };
155
+ * @Render(Home) // Type-safe! Wrong props = build error
156
+ * getHome() {
157
+ * return { message: 'Hello' }; // ✅ Correct
158
+ * // return { wrong: 'prop' }; // ❌ Type error!
150
159
  * }
151
160
  * ```
152
161
  */
153
- declare const Render: (viewPath: ViewPath) => _nestjs_common.CustomDecorator<string>;
162
+ declare function Render<T extends React.ComponentType<any>>(component: T): <TMethod extends (...args: any[]) => ExtractComponentData<T> | Promise<ExtractComponentData<T>>>(target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<TMethod>) => TypedPropertyDescriptor<TMethod> | void;
154
163
  /**
155
164
  * @deprecated Use `Render` instead. This alias will be removed in a future version.
156
165
  */
157
- declare const ReactRender: (viewPath: ViewPath) => _nestjs_common.CustomDecorator<string>;
166
+ declare const ReactRender: typeof Render;
158
167
 
159
168
  /**
160
169
  * Hook to access the full page context.
@@ -217,4 +226,4 @@ declare function useQuery(): Record<string, string | string[]>;
217
226
  */
218
227
  declare function useUserAgent(): string | undefined;
219
228
 
220
- export { HeadData, type PageProps, ReactRender, Render, type RenderContext, type ViewPath, type ViewPaths, usePageContext, useParams, useQuery, useUserAgent };
229
+ export { HeadData, type PageProps, ReactRender, Render, type RenderContext, usePageContext, useParams, useQuery, useUserAgent };