@fictjs/ssr 0.20.0 → 0.22.0
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/README.md +15 -4
- package/dist/chunk-LW7ALN63.js +1129 -0
- package/dist/experimental.cjs +780 -0
- package/dist/experimental.d.cts +164 -0
- package/dist/experimental.d.ts +164 -0
- package/dist/experimental.js +7 -0
- package/dist/index.cjs +76 -165
- package/dist/index.d.cts +2 -154
- package/dist/index.d.ts +2 -154
- package/dist/index.js +8 -1082
- package/package.json +11 -5
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { FictNode } from '@fictjs/runtime';
|
|
2
|
+
|
|
3
|
+
interface SSRDom {
|
|
4
|
+
window: Window;
|
|
5
|
+
document: Document;
|
|
6
|
+
}
|
|
7
|
+
interface RenderToStringOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Provide a pre-created DOM (document + window). If omitted, a new DOM is
|
|
10
|
+
* created per render using `html`.
|
|
11
|
+
*/
|
|
12
|
+
dom?: SSRDom;
|
|
13
|
+
/**
|
|
14
|
+
* Provide a document directly. If `window` is omitted, `document.defaultView`
|
|
15
|
+
* will be used when available.
|
|
16
|
+
*/
|
|
17
|
+
document?: Document;
|
|
18
|
+
/**
|
|
19
|
+
* Provide a window directly. If `document` is omitted, `window.document` is used.
|
|
20
|
+
*/
|
|
21
|
+
window?: Window;
|
|
22
|
+
/**
|
|
23
|
+
* HTML template used when creating a new DOM.
|
|
24
|
+
*/
|
|
25
|
+
html?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Provide a container element to render into.
|
|
28
|
+
*/
|
|
29
|
+
container?: HTMLElement;
|
|
30
|
+
/**
|
|
31
|
+
* Tag name for the auto-created container.
|
|
32
|
+
*/
|
|
33
|
+
containerTag?: string;
|
|
34
|
+
/**
|
|
35
|
+
* id applied to the auto-created container.
|
|
36
|
+
*/
|
|
37
|
+
containerId?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Additional attributes applied to the auto-created container.
|
|
40
|
+
*/
|
|
41
|
+
containerAttributes?: Record<string, string | number | boolean | null | undefined>;
|
|
42
|
+
/**
|
|
43
|
+
* Return the container element including its outer tag.
|
|
44
|
+
*/
|
|
45
|
+
includeContainer?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Return a full HTML document string (doctype + documentElement.outerHTML).
|
|
48
|
+
*/
|
|
49
|
+
fullDocument?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Override doctype when `fullDocument` is true. Use `null` to omit.
|
|
52
|
+
*/
|
|
53
|
+
doctype?: string | null;
|
|
54
|
+
/**
|
|
55
|
+
* Expose DOM globals (window/document/Node/Element/etc) during render.
|
|
56
|
+
* Defaults to false. Set to true only for compatibility with components
|
|
57
|
+
* that still read process-global DOM objects during server rendering.
|
|
58
|
+
*/
|
|
59
|
+
exposeGlobals?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Manifest mapping module URLs to built client chunk URLs.
|
|
62
|
+
* Can be an object or a path to a JSON file.
|
|
63
|
+
* File path mode requires Deno sync filesystem access or a CommonJS
|
|
64
|
+
* environment where `require('node:fs')` is available. Pass an object when
|
|
65
|
+
* rendering from Node ESM or edge runtimes.
|
|
66
|
+
*/
|
|
67
|
+
manifest?: Record<string, string> | string;
|
|
68
|
+
/**
|
|
69
|
+
* Include the SSR snapshot script for resumability.
|
|
70
|
+
* Defaults to true.
|
|
71
|
+
*/
|
|
72
|
+
includeSnapshot?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Script element id for the snapshot.
|
|
75
|
+
*/
|
|
76
|
+
snapshotScriptId?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Where to append the snapshot script when not returning full document.
|
|
79
|
+
* Defaults to 'container'.
|
|
80
|
+
*/
|
|
81
|
+
snapshotTarget?: 'container' | 'body' | 'head';
|
|
82
|
+
/**
|
|
83
|
+
* Nonce applied to generated <script> tags for CSP compatibility.
|
|
84
|
+
*/
|
|
85
|
+
scriptNonce?: string;
|
|
86
|
+
}
|
|
87
|
+
interface RenderToStreamOptions extends RenderToStringOptions {
|
|
88
|
+
/**
|
|
89
|
+
* Streaming mode:
|
|
90
|
+
* - 'shell': send fallback shell first, then patch resolved boundaries
|
|
91
|
+
* - 'all': wait for all suspense boundaries, then send full HTML
|
|
92
|
+
*/
|
|
93
|
+
mode?: 'shell' | 'all';
|
|
94
|
+
/**
|
|
95
|
+
* Called once the initial shell has been written.
|
|
96
|
+
*/
|
|
97
|
+
onShellReady?: () => void;
|
|
98
|
+
/**
|
|
99
|
+
* Called once all pending boundaries resolve and the stream completes.
|
|
100
|
+
*/
|
|
101
|
+
onAllReady?: () => void;
|
|
102
|
+
/**
|
|
103
|
+
* Called when an error occurs during streaming.
|
|
104
|
+
*/
|
|
105
|
+
onError?: (err: unknown) => void;
|
|
106
|
+
/**
|
|
107
|
+
* Abort signal to cancel the stream.
|
|
108
|
+
*/
|
|
109
|
+
signal?: AbortSignal;
|
|
110
|
+
/**
|
|
111
|
+
* How to load the streaming patch runtime.
|
|
112
|
+
* Defaults to 'inline'. Use 'external' with streamRuntimeSrc for strict CSP.
|
|
113
|
+
*/
|
|
114
|
+
streamRuntime?: 'inline' | 'external';
|
|
115
|
+
/**
|
|
116
|
+
* External streaming patch runtime URL when streamRuntime is 'external'.
|
|
117
|
+
*/
|
|
118
|
+
streamRuntimeSrc?: string;
|
|
119
|
+
/**
|
|
120
|
+
* How resolved Suspense patch chunks are applied.
|
|
121
|
+
* Defaults to 'inline' for inline runtimes and 'observer' for external runtimes.
|
|
122
|
+
*/
|
|
123
|
+
streamPatchMode?: 'inline' | 'observer';
|
|
124
|
+
}
|
|
125
|
+
interface PipeableStream {
|
|
126
|
+
pipe: (writable: NodeJS.WritableStream) => void;
|
|
127
|
+
abort: (reason?: unknown) => void;
|
|
128
|
+
shellReady: Promise<void>;
|
|
129
|
+
allReady: Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
interface PartialPrerenderResult {
|
|
132
|
+
/**
|
|
133
|
+
* Complete shell HTML (fallbacks + markers + initial snapshot scripts).
|
|
134
|
+
*
|
|
135
|
+
* @experimental Preview API for v1.0; the access pattern may change before
|
|
136
|
+
* this becomes stable.
|
|
137
|
+
*/
|
|
138
|
+
shell: string;
|
|
139
|
+
/**
|
|
140
|
+
* Stream of deferred patch chunks and incremental snapshots.
|
|
141
|
+
*/
|
|
142
|
+
stream: ReadableStream<Uint8Array>;
|
|
143
|
+
shellReady: Promise<void>;
|
|
144
|
+
allReady: Promise<void>;
|
|
145
|
+
abort: (reason?: unknown) => void;
|
|
146
|
+
}
|
|
147
|
+
interface RenderToDocumentResult extends SSRDom {
|
|
148
|
+
html: string;
|
|
149
|
+
container: HTMLElement;
|
|
150
|
+
dispose: () => void;
|
|
151
|
+
}
|
|
152
|
+
declare function createSSRDocument(html?: string): SSRDom;
|
|
153
|
+
declare function renderToDocument(view: () => FictNode, options?: RenderToStringOptions): RenderToDocumentResult;
|
|
154
|
+
declare function renderToString(view: () => FictNode, options?: RenderToStringOptions): string;
|
|
155
|
+
declare function renderToStringAsync(view: () => FictNode, options?: RenderToStringOptions): Promise<string>;
|
|
156
|
+
declare function renderToStream(view: () => FictNode, options?: RenderToStreamOptions): ReadableStream<Uint8Array>;
|
|
157
|
+
declare function renderToPipeableStream(view: () => FictNode, options?: RenderToStreamOptions): PipeableStream;
|
|
158
|
+
/**
|
|
159
|
+
* @experimental Preview API for v1.0; the return shape may change before this
|
|
160
|
+
* becomes stable.
|
|
161
|
+
*/
|
|
162
|
+
declare function renderToPartial(view: () => FictNode, options?: RenderToStreamOptions): PartialPrerenderResult;
|
|
163
|
+
|
|
164
|
+
export { type PipeableStream as P, type PartialPrerenderResult, type RenderToStringOptions as R, type SSRDom as S, renderToString as a, renderToStringAsync as b, createSSRDocument as c, renderToStream as d, renderToPipeableStream as e, type RenderToStreamOptions as f, type RenderToDocumentResult as g, renderToDocument as r, renderToPartial };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { FictNode } from '@fictjs/runtime';
|
|
2
|
+
|
|
3
|
+
interface SSRDom {
|
|
4
|
+
window: Window;
|
|
5
|
+
document: Document;
|
|
6
|
+
}
|
|
7
|
+
interface RenderToStringOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Provide a pre-created DOM (document + window). If omitted, a new DOM is
|
|
10
|
+
* created per render using `html`.
|
|
11
|
+
*/
|
|
12
|
+
dom?: SSRDom;
|
|
13
|
+
/**
|
|
14
|
+
* Provide a document directly. If `window` is omitted, `document.defaultView`
|
|
15
|
+
* will be used when available.
|
|
16
|
+
*/
|
|
17
|
+
document?: Document;
|
|
18
|
+
/**
|
|
19
|
+
* Provide a window directly. If `document` is omitted, `window.document` is used.
|
|
20
|
+
*/
|
|
21
|
+
window?: Window;
|
|
22
|
+
/**
|
|
23
|
+
* HTML template used when creating a new DOM.
|
|
24
|
+
*/
|
|
25
|
+
html?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Provide a container element to render into.
|
|
28
|
+
*/
|
|
29
|
+
container?: HTMLElement;
|
|
30
|
+
/**
|
|
31
|
+
* Tag name for the auto-created container.
|
|
32
|
+
*/
|
|
33
|
+
containerTag?: string;
|
|
34
|
+
/**
|
|
35
|
+
* id applied to the auto-created container.
|
|
36
|
+
*/
|
|
37
|
+
containerId?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Additional attributes applied to the auto-created container.
|
|
40
|
+
*/
|
|
41
|
+
containerAttributes?: Record<string, string | number | boolean | null | undefined>;
|
|
42
|
+
/**
|
|
43
|
+
* Return the container element including its outer tag.
|
|
44
|
+
*/
|
|
45
|
+
includeContainer?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Return a full HTML document string (doctype + documentElement.outerHTML).
|
|
48
|
+
*/
|
|
49
|
+
fullDocument?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Override doctype when `fullDocument` is true. Use `null` to omit.
|
|
52
|
+
*/
|
|
53
|
+
doctype?: string | null;
|
|
54
|
+
/**
|
|
55
|
+
* Expose DOM globals (window/document/Node/Element/etc) during render.
|
|
56
|
+
* Defaults to false. Set to true only for compatibility with components
|
|
57
|
+
* that still read process-global DOM objects during server rendering.
|
|
58
|
+
*/
|
|
59
|
+
exposeGlobals?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Manifest mapping module URLs to built client chunk URLs.
|
|
62
|
+
* Can be an object or a path to a JSON file.
|
|
63
|
+
* File path mode requires Deno sync filesystem access or a CommonJS
|
|
64
|
+
* environment where `require('node:fs')` is available. Pass an object when
|
|
65
|
+
* rendering from Node ESM or edge runtimes.
|
|
66
|
+
*/
|
|
67
|
+
manifest?: Record<string, string> | string;
|
|
68
|
+
/**
|
|
69
|
+
* Include the SSR snapshot script for resumability.
|
|
70
|
+
* Defaults to true.
|
|
71
|
+
*/
|
|
72
|
+
includeSnapshot?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Script element id for the snapshot.
|
|
75
|
+
*/
|
|
76
|
+
snapshotScriptId?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Where to append the snapshot script when not returning full document.
|
|
79
|
+
* Defaults to 'container'.
|
|
80
|
+
*/
|
|
81
|
+
snapshotTarget?: 'container' | 'body' | 'head';
|
|
82
|
+
/**
|
|
83
|
+
* Nonce applied to generated <script> tags for CSP compatibility.
|
|
84
|
+
*/
|
|
85
|
+
scriptNonce?: string;
|
|
86
|
+
}
|
|
87
|
+
interface RenderToStreamOptions extends RenderToStringOptions {
|
|
88
|
+
/**
|
|
89
|
+
* Streaming mode:
|
|
90
|
+
* - 'shell': send fallback shell first, then patch resolved boundaries
|
|
91
|
+
* - 'all': wait for all suspense boundaries, then send full HTML
|
|
92
|
+
*/
|
|
93
|
+
mode?: 'shell' | 'all';
|
|
94
|
+
/**
|
|
95
|
+
* Called once the initial shell has been written.
|
|
96
|
+
*/
|
|
97
|
+
onShellReady?: () => void;
|
|
98
|
+
/**
|
|
99
|
+
* Called once all pending boundaries resolve and the stream completes.
|
|
100
|
+
*/
|
|
101
|
+
onAllReady?: () => void;
|
|
102
|
+
/**
|
|
103
|
+
* Called when an error occurs during streaming.
|
|
104
|
+
*/
|
|
105
|
+
onError?: (err: unknown) => void;
|
|
106
|
+
/**
|
|
107
|
+
* Abort signal to cancel the stream.
|
|
108
|
+
*/
|
|
109
|
+
signal?: AbortSignal;
|
|
110
|
+
/**
|
|
111
|
+
* How to load the streaming patch runtime.
|
|
112
|
+
* Defaults to 'inline'. Use 'external' with streamRuntimeSrc for strict CSP.
|
|
113
|
+
*/
|
|
114
|
+
streamRuntime?: 'inline' | 'external';
|
|
115
|
+
/**
|
|
116
|
+
* External streaming patch runtime URL when streamRuntime is 'external'.
|
|
117
|
+
*/
|
|
118
|
+
streamRuntimeSrc?: string;
|
|
119
|
+
/**
|
|
120
|
+
* How resolved Suspense patch chunks are applied.
|
|
121
|
+
* Defaults to 'inline' for inline runtimes and 'observer' for external runtimes.
|
|
122
|
+
*/
|
|
123
|
+
streamPatchMode?: 'inline' | 'observer';
|
|
124
|
+
}
|
|
125
|
+
interface PipeableStream {
|
|
126
|
+
pipe: (writable: NodeJS.WritableStream) => void;
|
|
127
|
+
abort: (reason?: unknown) => void;
|
|
128
|
+
shellReady: Promise<void>;
|
|
129
|
+
allReady: Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
interface PartialPrerenderResult {
|
|
132
|
+
/**
|
|
133
|
+
* Complete shell HTML (fallbacks + markers + initial snapshot scripts).
|
|
134
|
+
*
|
|
135
|
+
* @experimental Preview API for v1.0; the access pattern may change before
|
|
136
|
+
* this becomes stable.
|
|
137
|
+
*/
|
|
138
|
+
shell: string;
|
|
139
|
+
/**
|
|
140
|
+
* Stream of deferred patch chunks and incremental snapshots.
|
|
141
|
+
*/
|
|
142
|
+
stream: ReadableStream<Uint8Array>;
|
|
143
|
+
shellReady: Promise<void>;
|
|
144
|
+
allReady: Promise<void>;
|
|
145
|
+
abort: (reason?: unknown) => void;
|
|
146
|
+
}
|
|
147
|
+
interface RenderToDocumentResult extends SSRDom {
|
|
148
|
+
html: string;
|
|
149
|
+
container: HTMLElement;
|
|
150
|
+
dispose: () => void;
|
|
151
|
+
}
|
|
152
|
+
declare function createSSRDocument(html?: string): SSRDom;
|
|
153
|
+
declare function renderToDocument(view: () => FictNode, options?: RenderToStringOptions): RenderToDocumentResult;
|
|
154
|
+
declare function renderToString(view: () => FictNode, options?: RenderToStringOptions): string;
|
|
155
|
+
declare function renderToStringAsync(view: () => FictNode, options?: RenderToStringOptions): Promise<string>;
|
|
156
|
+
declare function renderToStream(view: () => FictNode, options?: RenderToStreamOptions): ReadableStream<Uint8Array>;
|
|
157
|
+
declare function renderToPipeableStream(view: () => FictNode, options?: RenderToStreamOptions): PipeableStream;
|
|
158
|
+
/**
|
|
159
|
+
* @experimental Preview API for v1.0; the return shape may change before this
|
|
160
|
+
* becomes stable.
|
|
161
|
+
*/
|
|
162
|
+
declare function renderToPartial(view: () => FictNode, options?: RenderToStreamOptions): PartialPrerenderResult;
|
|
163
|
+
|
|
164
|
+
export { type PipeableStream as P, type PartialPrerenderResult, type RenderToStringOptions as R, type SSRDom as S, renderToString as a, renderToStringAsync as b, createSSRDocument as c, renderToStream as d, renderToPipeableStream as e, type RenderToStreamOptions as f, type RenderToDocumentResult as g, renderToDocument as r, renderToPartial };
|