@nestjs-ssr/react 0.1.1
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/LICENSE +22 -0
- package/README.md +587 -0
- package/dist/index-Bptct1Q3.d.mts +419 -0
- package/dist/index-Bptct1Q3.d.ts +419 -0
- package/dist/index.d.mts +220 -0
- package/dist/index.d.ts +220 -0
- package/dist/index.js +8148 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +8113 -0
- package/dist/index.mjs.map +1 -0
- package/dist/render/index.d.mts +8 -0
- package/dist/render/index.d.ts +8 -0
- package/dist/render/index.js +1110 -0
- package/dist/render/index.js.map +1 -0
- package/dist/render/index.mjs +1102 -0
- package/dist/render/index.mjs.map +1 -0
- package/dist/templates/entry-client.tsx +20 -0
- package/dist/templates/entry-server.tsx +13 -0
- package/dist/templates/index.html +17 -0
- package/dist/vite/index.d.mts +11 -0
- package/dist/vite/index.d.ts +11 -0
- package/dist/vite/index.js +7022 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/vite/index.mjs +6997 -0
- package/dist/vite/index.mjs.map +1 -0
- package/package.json +135 -0
- package/src/global.d.ts +32 -0
- package/src/templates/entry-client.tsx +20 -0
- package/src/templates/entry-server.tsx +13 -0
- package/src/templates/index.html +17 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
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';
|
|
6
|
+
import 'vite';
|
|
7
|
+
import 'express';
|
|
8
|
+
import '@nestjs/core';
|
|
9
|
+
import 'rxjs';
|
|
10
|
+
import 'react/jsx-runtime';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Request context available to all React components.
|
|
14
|
+
* Contains safe request metadata that can be exposed to the client.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Basic usage - use as-is
|
|
18
|
+
* const context: RenderContext = {
|
|
19
|
+
* url: '/users/123',
|
|
20
|
+
* path: '/users/123',
|
|
21
|
+
* query: { tab: 'profile' },
|
|
22
|
+
* params: { id: '123' },
|
|
23
|
+
* };
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Extended usage - add custom properties for your app
|
|
27
|
+
* interface AppRenderContext extends RenderContext {
|
|
28
|
+
* user?: {
|
|
29
|
+
* id: string;
|
|
30
|
+
* name: string;
|
|
31
|
+
* email: string;
|
|
32
|
+
* roles: string[];
|
|
33
|
+
* };
|
|
34
|
+
* tenant?: {
|
|
35
|
+
* id: string;
|
|
36
|
+
* name: string;
|
|
37
|
+
* };
|
|
38
|
+
* locale?: string;
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* // Use in interceptor
|
|
42
|
+
* const context: AppRenderContext = {
|
|
43
|
+
* ...baseContext,
|
|
44
|
+
* user: req.user,
|
|
45
|
+
* tenant: req.tenant,
|
|
46
|
+
* locale: req.locale,
|
|
47
|
+
* };
|
|
48
|
+
*/
|
|
49
|
+
interface RenderContext {
|
|
50
|
+
url: string;
|
|
51
|
+
path: string;
|
|
52
|
+
query: Record<string, string | string[]>;
|
|
53
|
+
params: Record<string, string>;
|
|
54
|
+
userAgent?: string;
|
|
55
|
+
acceptLanguage?: string;
|
|
56
|
+
referer?: string;
|
|
57
|
+
[key: string]: any;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Generic type for React page component props.
|
|
62
|
+
* Spreads controller data directly as props (React-standard pattern).
|
|
63
|
+
*
|
|
64
|
+
* @template TProps - The shape of props returned by the controller
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* interface ProductPageProps {
|
|
69
|
+
* product: Product;
|
|
70
|
+
* relatedProducts: Product[];
|
|
71
|
+
* }
|
|
72
|
+
*
|
|
73
|
+
* export default function ProductDetail(props: PageProps<ProductPageProps>) {
|
|
74
|
+
* const { product, relatedProducts, head, context } = props;
|
|
75
|
+
* return (
|
|
76
|
+
* <html>
|
|
77
|
+
* <head>
|
|
78
|
+
* <title>{head?.title || product.name}</title>
|
|
79
|
+
* </head>
|
|
80
|
+
* <body>
|
|
81
|
+
* <h1>{product.name}</h1>
|
|
82
|
+
* </body>
|
|
83
|
+
* </html>
|
|
84
|
+
* );
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
type PageProps<TProps = {}> = TProps & {
|
|
89
|
+
/**
|
|
90
|
+
* Optional head metadata for SEO (title, description, og tags, etc.)
|
|
91
|
+
* Pass from controller to populate meta tags, Open Graph, etc.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* // In controller:
|
|
96
|
+
* return {
|
|
97
|
+
* product,
|
|
98
|
+
* head: {
|
|
99
|
+
* title: product.name,
|
|
100
|
+
* description: product.description,
|
|
101
|
+
* }
|
|
102
|
+
* };
|
|
103
|
+
*
|
|
104
|
+
* // In component:
|
|
105
|
+
* <head>
|
|
106
|
+
* <title>{props.head?.title}</title>
|
|
107
|
+
* <meta name="description" content={props.head?.description} />
|
|
108
|
+
* </head>
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
head?: HeadData;
|
|
112
|
+
/**
|
|
113
|
+
* Request context containing URL metadata and safe headers.
|
|
114
|
+
* Always available on every page component.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const { path, query, method } = props.context;
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
context: RenderContext;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Interface for view paths - augmented by the generated view registry.
|
|
126
|
+
* This enables type-safe path validation in Render decorator.
|
|
127
|
+
*/
|
|
128
|
+
interface ViewPaths {
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Type-safe view path - union of all registered view paths.
|
|
132
|
+
* This is populated via module augmentation from the generated view registry.
|
|
133
|
+
*/
|
|
134
|
+
type ViewPath = keyof ViewPaths extends never ? string : keyof ViewPaths;
|
|
135
|
+
/**
|
|
136
|
+
* Decorator to render a React component as the response.
|
|
137
|
+
* Provides IDE autocomplete and type checking for view paths.
|
|
138
|
+
*
|
|
139
|
+
* Works the same as NestJS's @Render() decorator for template engines,
|
|
140
|
+
* but renders React components with SSR instead.
|
|
141
|
+
*
|
|
142
|
+
* @param viewPath - Path to the React component (e.g., 'users/views/user-list')
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* @Get()
|
|
147
|
+
* @Render('users/views/user-list')
|
|
148
|
+
* getUsers() {
|
|
149
|
+
* return { users: [...] };
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
declare const Render: (viewPath: ViewPath) => _nestjs_common.CustomDecorator<string>;
|
|
154
|
+
/**
|
|
155
|
+
* @deprecated Use `Render` instead. This alias will be removed in a future version.
|
|
156
|
+
*/
|
|
157
|
+
declare const ReactRender: (viewPath: ViewPath) => _nestjs_common.CustomDecorator<string>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Hook to access the full page context.
|
|
161
|
+
* Contains URL metadata and request headers.
|
|
162
|
+
*
|
|
163
|
+
* For apps with authentication, extend RenderContext and create custom hooks.
|
|
164
|
+
*
|
|
165
|
+
* @throws Error if used outside PageContextProvider
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```tsx
|
|
169
|
+
* const context = usePageContext();
|
|
170
|
+
* console.log(context.path); // '/users/123'
|
|
171
|
+
* console.log(context.query); // { search: 'foo' }
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* // Custom hook for extended context
|
|
176
|
+
* interface AppRenderContext extends RenderContext {
|
|
177
|
+
* user?: { id: string; name: string };
|
|
178
|
+
* }
|
|
179
|
+
*
|
|
180
|
+
* export function useUser() {
|
|
181
|
+
* return (usePageContext() as AppRenderContext).user;
|
|
182
|
+
* }
|
|
183
|
+
*/
|
|
184
|
+
declare function usePageContext(): RenderContext;
|
|
185
|
+
/**
|
|
186
|
+
* Hook to access route parameters.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```tsx
|
|
190
|
+
* // Route: /users/:id
|
|
191
|
+
* const params = useParams();
|
|
192
|
+
* console.log(params.id); // '123'
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
declare function useParams(): Record<string, string>;
|
|
196
|
+
/**
|
|
197
|
+
* Hook to access query string parameters.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```tsx
|
|
201
|
+
* // URL: /search?q=react&sort=date
|
|
202
|
+
* const query = useQuery();
|
|
203
|
+
* console.log(query.q); // 'react'
|
|
204
|
+
* console.log(query.sort); // 'date'
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
declare function useQuery(): Record<string, string | string[]>;
|
|
208
|
+
/**
|
|
209
|
+
* Hook to access the User-Agent header.
|
|
210
|
+
* Useful for device detection or analytics.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```tsx
|
|
214
|
+
* const userAgent = useUserAgent();
|
|
215
|
+
* const isMobile = /Mobile/.test(userAgent || '');
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
declare function useUserAgent(): string | undefined;
|
|
219
|
+
|
|
220
|
+
export { HeadData, type PageProps, ReactRender, Render, type RenderContext, type ViewPath, type ViewPaths, usePageContext, useParams, useQuery, useUserAgent };
|