@bgub/fig-server 0.0.1 → 0.1.0-alpha.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/dist/payload.d.ts CHANGED
@@ -1,18 +1,26 @@
1
- import { a as ServerErrorPayload, i as ServerErrorInfo } from "./types-4X0JT0wt.js";
2
- import { DataResourceKeyInput, ElementType, FigAssetResource, FigAssetResourceList, FigDataHydrationEntry, FigDataStoreHandle, FigNode, FontResource, Key, ModulePreloadResource, PreconnectResource, PreloadResource, ScriptResource, StylesheetResource } from "@bgub/fig";
1
+ import { n as ServerErrorInfo, r as ServerErrorPayload } from "./types-CimwEFsf.js";
2
+ import { DataResourceKeyInput, FigAssetResourceList, FigNode, Props } from "@bgub/fig";
3
3
  //#region src/payload.d.ts
4
4
  interface PayloadRenderResult {
5
- abort(reason?: unknown): void;
6
5
  allReady: Promise<void>;
7
6
  contentType: string;
8
7
  stream: ReadableStream<Uint8Array>;
9
8
  }
9
+ type PayloadComponent = (props: Props & {
10
+ children?: FigNode;
11
+ }) => FigNode;
10
12
  interface PayloadRenderOptions {
11
13
  clientReferenceAssets?: (metadata: {
12
14
  id: string;
13
15
  }) => FigAssetResourceList;
14
- codec?: PayloadCodec;
16
+ componentAssets?: (type: PayloadComponent) => FigAssetResourceList | undefined;
15
17
  dataPartition?: DataResourceKeyInput;
18
+ /**
19
+ * Encoded bytes the result stream buffers before row flushing pauses until
20
+ * the consumer reads (rendering itself never pauses; encoded rows wait
21
+ * queued). Defaults to 65536; values below 1 are clamped to 1.
22
+ */
23
+ highWaterMark?: number;
16
24
  signal?: AbortSignal;
17
25
  /**
18
26
  * Decides what crosses the wire when a server render throws, mirroring the
@@ -21,238 +29,7 @@ interface PayloadRenderOptions {
21
29
  * an empty payload.
22
30
  */
23
31
  onError?: (error: unknown, info: ServerErrorInfo) => ServerErrorPayload | undefined;
24
- refreshBoundary?: string;
25
- }
26
- interface PayloadRootLike {
27
- data?: FigDataStoreHandle;
28
- render(node: FigNode): void;
29
- }
30
- type SerializedAssetResource = {
31
- crossOrigin?: StylesheetResource["crossOrigin"];
32
- href: string;
33
- kind: "stylesheet";
34
- media?: string;
35
- precedence?: string;
36
- } | {
37
- as: string;
38
- crossOrigin?: PreloadResource["crossOrigin"];
39
- fetchPriority?: PreloadResource["fetchPriority"];
40
- href: string;
41
- kind: "preload";
42
- type?: string;
43
- } | {
44
- crossOrigin?: ModulePreloadResource["crossOrigin"];
45
- fetchPriority?: ModulePreloadResource["fetchPriority"];
46
- href: string;
47
- kind: "modulepreload";
48
- } | {
49
- async?: boolean;
50
- crossOrigin?: ScriptResource["crossOrigin"];
51
- defer?: boolean;
52
- kind: "script";
53
- module?: boolean;
54
- src: string;
55
- } | {
56
- crossOrigin?: FontResource["crossOrigin"];
57
- fetchPriority?: FontResource["fetchPriority"];
58
- href: string;
59
- kind: "font";
60
- type: string;
61
- } | {
62
- crossOrigin?: PreconnectResource["crossOrigin"];
63
- href: string;
64
- kind: "preconnect";
65
- };
66
- /**
67
- * Semantic payload row before a PayloadCodec turns it into bytes. This row
68
- * model is the stable contract; a codec's byte layout is intentionally opaque.
69
- */
70
- type PayloadRow = {
71
- tag: "assets";
72
- value: SerializedAssetResource[];
73
- } | {
74
- id: number;
75
- tag: "client";
76
- value: {
77
- id: string;
78
- assets?: SerializedAssetResource[];
79
- exportName?: string;
80
- ssr?: true;
81
- };
82
- } | {
83
- tag: "data";
84
- value: PayloadDataHydrationEntry[];
85
- } | {
86
- id: number;
87
- tag: "error";
88
- value: ServerErrorPayload;
89
- } | {
90
- id: number;
91
- tag: "model";
92
- value: PayloadModel;
93
- } | {
94
- boundary: string;
95
- tag: "refresh-error";
96
- value: ServerErrorPayload;
97
- } | {
98
- boundary: string;
99
- tag: "refresh";
100
- value: PayloadModel;
101
- };
102
- /**
103
- * Transport-safe model value used inside payload rows. The shape is public so
104
- * custom codecs and framework integrations can encode/decode rows, but callers
105
- * should not treat the exact tagged representation as an app data format.
106
- */
107
- type PayloadModel = null | boolean | number | string | PayloadModel[] | {
108
- [key: string]: PayloadModel;
109
- } | PayloadElementModel | PayloadSpecialModel;
110
- type PayloadElementModel = {
111
- $fig: "element";
112
- id?: number;
113
- key: Key | null;
114
- props: PayloadModel;
115
- type: string | PayloadSpecialModel;
116
- };
117
- type PayloadSpecialModel = {
118
- $fig: "array";
119
- id: number;
120
- value: PayloadModel[];
121
- } | {
122
- $fig: "boundary";
123
- child: PayloadModel;
124
- id: string;
125
- } | {
126
- $fig: "bigint";
127
- value: string;
128
- } | {
129
- $fig: "client";
130
- id: number;
131
- } | {
132
- $fig: "date";
133
- value: string;
134
- } | {
135
- $fig: "fragment";
136
- } | {
137
- $fig: "lazy";
138
- id: number;
139
- } | {
140
- $fig: "map";
141
- entries: Array<[PayloadModel, PayloadModel]>;
142
- id: number;
143
- } | {
144
- $fig: "number";
145
- value: "Infinity" | "-Infinity" | "-0" | "NaN";
146
- } | {
147
- $fig: "object";
148
- id?: number;
149
- value: Record<string, PayloadModel>;
150
- } | {
151
- $fig: "promise";
152
- id: number;
153
- } | {
154
- $fig: "ref";
155
- id: number;
156
- } | {
157
- $fig: "set";
158
- id: number;
159
- values: PayloadModel[];
160
- } | {
161
- $fig: "symbol";
162
- key: string;
163
- } | {
164
- $fig: "suspense";
165
- } | {
166
- $fig: "undefined";
167
- } | {
168
- $fig: "view-transition";
169
- };
170
- type PayloadDataHydrationEntry = Omit<FigDataHydrationEntry, "value"> & {
171
- value: PayloadModel;
172
- };
173
- interface PayloadClientReferenceMetadata {
174
- id: string;
175
- exportName?: string;
176
- ssr?: boolean;
177
- }
178
- interface PayloadClientReferenceRecord extends PayloadClientReferenceMetadata {
179
- assets?: readonly FigAssetResource[];
180
- }
181
- interface PayloadResponseOptions {
182
- codec?: PayloadCodec;
183
- loadClientReference?: (metadata: PayloadClientReferenceMetadata) => Promise<unknown>;
184
- resolveClientReference?: (metadata: PayloadClientReferenceMetadata) => ElementType<any> | undefined;
185
- }
186
- interface PayloadResponse {
187
- bindRoot(root: PayloadRootLike): () => void;
188
- readonly codec: PayloadCodec;
189
- getAssetResources(): readonly FigAssetResource[];
190
- getClientReferences(): readonly PayloadClientReferenceRecord[];
191
- getRoot(): FigNode;
192
- preloadClientReferences(): Promise<void>;
193
- processBytesChunk(chunk: Uint8Array): void;
194
- processStream(stream: ReadableStream<Uint8Array>, signal?: AbortSignal | null): Promise<void>;
195
- processStringChunk(chunk: string): void;
196
- readonly rootReady: Promise<void>;
197
- subscribe(listener: () => void): () => void;
198
32
  }
199
- type PayloadFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
200
- interface PayloadFetchOptions extends RequestInit {
201
- fetch?: PayloadFetch;
202
- refreshBoundary?: string;
203
- }
204
- interface PayloadCodec {
205
- /**
206
- * Opaque implementation id, e.g. "json" or "binary". Fig checks this id at
207
- * transport boundaries; the encoded byte layout is not a public contract.
208
- */
209
- readonly id: string;
210
- readonly contentType: string;
211
- /**
212
- * Creates a streaming row decoder. The decoder calls `onRow` for each
213
- * complete semantic row. If `onRow` throws, the decoder must propagate that
214
- * error; when it can already see more complete sibling rows in the same
215
- * input chunk, it should process those siblings before rethrowing so
216
- * notifications already implied by earlier rows are not lost.
217
- */
218
- createDecoder(onRow: (row: PayloadRow) => void): PayloadDecoder;
219
- encodeRow(row: PayloadRow): Uint8Array;
220
- }
221
- interface PayloadDecoder {
222
- decode(chunk: Uint8Array): void;
223
- flush(): void;
224
- }
225
- declare const PAYLOAD_BOUNDARY_HEADER = "x-fig-payload-boundary";
226
- declare class PayloadFetchError extends Error {
227
- readonly response: Response;
228
- readonly status: number;
229
- constructor(response: Response);
230
- }
231
- /**
232
- * Readable development-oriented codec: one JSON payload row per newline.
233
- */
234
- declare const jsonPayloadCodec: PayloadCodec;
235
- type PayloadBoundaryProps = {
236
- children?: FigNode;
237
- id: string;
238
- };
239
- declare const PayloadBoundary: {
240
- (props: PayloadBoundaryProps): FigNode;
241
- readonly $$typeof: symbol;
242
- };
243
33
  declare function renderToPayloadStream(node: FigNode, options?: PayloadRenderOptions): PayloadRenderResult;
244
- declare function createPayloadResponse(options?: PayloadResponseOptions): PayloadResponse;
245
- declare function isPayloadRequestCancelled(error: unknown): boolean;
246
- declare function fetchPayload(response: PayloadResponse, input: RequestInfo | URL, options?: PayloadFetchOptions): Promise<Response>;
247
- /**
248
- * Encode ordinary data values into PayloadModel. Server component references
249
- * such as Fig elements, promises, and client references are handled by the
250
- * payload renderer before ordinary values reach this helper.
251
- */
252
- declare function encodePayloadValue(value: unknown): PayloadModel;
253
- /** Decode values produced by encodePayloadValue. */
254
- declare function decodePayloadValue(model: PayloadModel): unknown;
255
- declare function encodePayloadDataEntries(entries: readonly FigDataHydrationEntry[]): PayloadDataHydrationEntry[];
256
- declare function decodePayloadDataEntries(entries: readonly PayloadDataHydrationEntry[]): FigDataHydrationEntry[];
257
34
  //#endregion
258
- export { PAYLOAD_BOUNDARY_HEADER, PayloadBoundary, PayloadClientReferenceMetadata, PayloadClientReferenceRecord, PayloadCodec, PayloadDataHydrationEntry, PayloadDecoder, PayloadFetch, PayloadFetchError, PayloadFetchOptions, PayloadModel, PayloadRenderOptions, PayloadRenderResult, PayloadResponse, PayloadResponseOptions, PayloadRootLike, PayloadRow, SerializedAssetResource, createPayloadResponse, decodePayloadDataEntries, decodePayloadValue, encodePayloadDataEntries, encodePayloadValue, fetchPayload, isPayloadRequestCancelled, jsonPayloadCodec, renderToPayloadStream };
35
+ export { PayloadComponent, PayloadRenderOptions, PayloadRenderResult, renderToPayloadStream };