@timber-js/app 0.2.0-alpha.219 → 0.2.0-alpha.220

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.
Files changed (164) hide show
  1. package/dist/_chunks/chains-CDK1AWZQ.js +1 -0
  2. package/dist/_chunks/{chains-YKZ8WpIW.js → chains-e_Buf9vg.js} +2 -7
  3. package/dist/_chunks/{chains-YKZ8WpIW.js.map → chains-e_Buf9vg.js.map} +1 -1
  4. package/dist/_chunks/{cli-check-D2WtbNqo.js → cli-check-DDwCkeDY.js} +2 -2
  5. package/dist/_chunks/{cli-check-D2WtbNqo.js.map → cli-check-DDwCkeDY.js.map} +1 -1
  6. package/dist/_chunks/cli-context-BJQB6rtF.js +1 -0
  7. package/dist/_chunks/{cli-context-By7k2xVo.js → cli-context-_mPttGGY.js} +3 -3
  8. package/dist/_chunks/{cli-context-By7k2xVo.js.map → cli-context-_mPttGGY.js.map} +1 -1
  9. package/dist/_chunks/{cli-schema-sync-CySLKrO3.js → cli-schema-sync-BdIebmk3.js} +3 -12
  10. package/dist/_chunks/{cli-schema-sync-CySLKrO3.js.map → cli-schema-sync-BdIebmk3.js.map} +1 -1
  11. package/dist/_chunks/cli-schema-sync-CLNfXQDK.js +1 -0
  12. package/dist/_chunks/dev-server-DkytOEG2.js +1 -0
  13. package/dist/_chunks/{dev-server-B8zsT-ee.js → dev-server-DnODXuNM.js} +31 -14
  14. package/dist/_chunks/{dev-server-B8zsT-ee.js.map → dev-server-DnODXuNM.js.map} +1 -1
  15. package/dist/_chunks/flight-source-node-0dE-t3kq.js +519 -0
  16. package/dist/_chunks/flight-source-node-0dE-t3kq.js.map +1 -0
  17. package/dist/_chunks/{live-graph-BhtrZpRd.js → live-graph-tSWrv8eH.js} +2 -2
  18. package/dist/_chunks/{live-graph-BhtrZpRd.js.map → live-graph-tSWrv8eH.js.map} +1 -1
  19. package/dist/_chunks/node-response-Dibufw_b.js +187 -0
  20. package/dist/_chunks/node-response-Dibufw_b.js.map +1 -0
  21. package/dist/_chunks/{plugin-context-BPBPc3lL.js → plugin-context-DxMMvjUt.js} +2 -18
  22. package/dist/_chunks/{plugin-context-BPBPc3lL.js.map → plugin-context-DxMMvjUt.js.map} +1 -1
  23. package/dist/_chunks/plugin-context-uDHFqHHJ.js +1 -0
  24. package/dist/_chunks/{walkers-Ber9bamD.js → walkers-qu8TpiLh.js} +2 -2
  25. package/dist/_chunks/{walkers-Ber9bamD.js.map → walkers-qu8TpiLh.js.map} +1 -1
  26. package/dist/adapters/nitro-preview.d.ts.map +1 -1
  27. package/dist/adapters/nitro.js +40 -1
  28. package/dist/adapters/nitro.js.map +1 -1
  29. package/dist/analyze/crawl-entry.js +2 -2
  30. package/dist/analyze/graph-command.js +3 -3
  31. package/dist/analyze/graph-command.js.map +1 -1
  32. package/dist/cli.js +5 -5
  33. package/dist/cli.js.map +1 -1
  34. package/dist/client/browser-entry/form-state.d.ts.map +1 -1
  35. package/dist/client/browser-entry/index.d.ts +1 -1
  36. package/dist/client/browser-entry/rsc-stream.d.ts +4 -1
  37. package/dist/client/browser-entry/rsc-stream.d.ts.map +1 -1
  38. package/dist/client/react-root.d.ts +6 -0
  39. package/dist/client/react-root.d.ts.map +1 -1
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +36 -5
  42. package/dist/index.js.map +1 -1
  43. package/dist/plugins/encryption-runtime.d.ts +13 -0
  44. package/dist/plugins/encryption-runtime.d.ts.map +1 -0
  45. package/dist/plugins/entries.d.ts +1 -0
  46. package/dist/plugins/entries.d.ts.map +1 -1
  47. package/dist/plugins/server-bundle.d.ts +1 -1
  48. package/dist/plugins/server-bundle.d.ts.map +1 -1
  49. package/dist/routing/index.js +1 -1
  50. package/dist/rsc-runtime/encryption-runtime.d.ts +25 -0
  51. package/dist/rsc-runtime/encryption-runtime.d.ts.map +1 -0
  52. package/dist/rsc-runtime/render-flight.d.ts +14 -0
  53. package/dist/rsc-runtime/render-flight.d.ts.map +1 -0
  54. package/dist/rsc-runtime/rsc.d.ts +6 -2
  55. package/dist/rsc-runtime/rsc.d.ts.map +1 -1
  56. package/dist/rsc-runtime/ssr.d.ts +6 -12
  57. package/dist/rsc-runtime/ssr.d.ts.map +1 -1
  58. package/dist/server/action-handler.d.ts.map +1 -1
  59. package/dist/server/compress.d.ts +2 -0
  60. package/dist/server/compress.d.ts.map +1 -1
  61. package/dist/server/deny-renderer.d.ts +2 -1
  62. package/dist/server/deny-renderer.d.ts.map +1 -1
  63. package/dist/server/flight-injector-core.d.ts +125 -0
  64. package/dist/server/flight-injector-core.d.ts.map +1 -0
  65. package/dist/server/flight-scripts.d.ts +9 -0
  66. package/dist/server/flight-scripts.d.ts.map +1 -1
  67. package/dist/server/flight-source-node.d.ts +105 -0
  68. package/dist/server/flight-source-node.d.ts.map +1 -0
  69. package/dist/server/flight-source.d.ts +136 -0
  70. package/dist/server/flight-source.d.ts.map +1 -0
  71. package/dist/server/head-response.d.ts.map +1 -1
  72. package/dist/server/html-injector-core.d.ts +3 -91
  73. package/dist/server/html-injector-core.d.ts.map +1 -1
  74. package/dist/server/html-injectors.d.ts +5 -17
  75. package/dist/server/html-injectors.d.ts.map +1 -1
  76. package/dist/server/internal.js +78 -138
  77. package/dist/server/internal.js.map +1 -1
  78. package/dist/server/node-body-response.d.ts +55 -0
  79. package/dist/server/node-body-response.d.ts.map +1 -0
  80. package/dist/server/node-response.d.ts +62 -0
  81. package/dist/server/node-response.d.ts.map +1 -0
  82. package/dist/server/node-stream-transforms.d.ts +24 -21
  83. package/dist/server/node-stream-transforms.d.ts.map +1 -1
  84. package/dist/server/node-streams-platform.d.ts +21 -0
  85. package/dist/server/node-streams-platform.d.ts.map +1 -0
  86. package/dist/server/pipeline-helpers.d.ts.map +1 -1
  87. package/dist/server/pipeline.d.ts.map +1 -1
  88. package/dist/server/prebuilt-runtime.d.ts +2 -3
  89. package/dist/server/prebuilt-runtime.d.ts.map +1 -1
  90. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  91. package/dist/server/rsc-entry/render-route.d.ts +4 -1
  92. package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
  93. package/dist/server/rsc-entry/rsc-payload.d.ts +9 -6
  94. package/dist/server/rsc-entry/rsc-payload.d.ts.map +1 -1
  95. package/dist/server/rsc-entry/rsc-stream.d.ts +9 -4
  96. package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
  97. package/dist/server/rsc-entry/ssr-bridge.d.ts +2 -1
  98. package/dist/server/rsc-entry/ssr-bridge.d.ts.map +1 -1
  99. package/dist/server/rsc-entry/ssr-renderer.d.ts +2 -1
  100. package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
  101. package/dist/server/ssr-bridge-types.d.ts +9 -4
  102. package/dist/server/ssr-bridge-types.d.ts.map +1 -1
  103. package/dist/server/ssr-entry.d.ts +8 -5
  104. package/dist/server/ssr-entry.d.ts.map +1 -1
  105. package/dist/server/ssr-render.d.ts +7 -16
  106. package/dist/server/ssr-render.d.ts.map +1 -1
  107. package/dist/server/stream-utils.d.ts +44 -10
  108. package/dist/server/stream-utils.d.ts.map +1 -1
  109. package/dist/shared/flight-base64.d.ts +13 -0
  110. package/dist/shared/flight-base64.d.ts.map +1 -0
  111. package/dist/shared/flight-segment.d.ts +18 -0
  112. package/dist/shared/flight-segment.d.ts.map +1 -0
  113. package/dist/shared/form-state-flight.d.ts +0 -4
  114. package/dist/shared/form-state-flight.d.ts.map +1 -1
  115. package/docs/learn/12-error-handling.mdx +1 -1
  116. package/package.json +1 -1
  117. package/src/adapters/nitro-preview.ts +39 -0
  118. package/src/client/browser-entry/form-state.ts +3 -2
  119. package/src/client/browser-entry/index.ts +14 -8
  120. package/src/client/browser-entry/rsc-stream.ts +14 -14
  121. package/src/client/react-root.ts +25 -2
  122. package/src/index.ts +2 -0
  123. package/src/plugins/encryption-runtime.ts +31 -0
  124. package/src/plugins/entries.ts +1 -1
  125. package/src/plugins/server-bundle.ts +17 -2
  126. package/src/rsc-runtime/encryption-runtime.ts +78 -0
  127. package/src/rsc-runtime/render-flight.ts +26 -0
  128. package/src/rsc-runtime/rsc.ts +7 -4
  129. package/src/rsc-runtime/ssr.ts +10 -48
  130. package/src/rsc-runtime/vendor-types.d.ts +31 -2
  131. package/src/server/action-handler.ts +43 -44
  132. package/src/server/compress.ts +49 -12
  133. package/src/server/deny-renderer.ts +14 -7
  134. package/src/server/flight-injector-core.ts +328 -0
  135. package/src/server/flight-scripts.ts +14 -2
  136. package/src/server/flight-source-node.ts +430 -0
  137. package/src/server/flight-source.ts +288 -0
  138. package/src/server/form-state-flight.ts +4 -4
  139. package/src/server/head-response.ts +6 -10
  140. package/src/server/html-injector-core.ts +24 -216
  141. package/src/server/html-injectors.ts +12 -71
  142. package/src/server/node-body-response.ts +236 -0
  143. package/src/server/node-response.ts +93 -0
  144. package/src/server/node-stream-transforms.ts +70 -53
  145. package/src/server/node-streams-platform.ts +23 -0
  146. package/src/server/pipeline-helpers.ts +3 -1
  147. package/src/server/pipeline.ts +14 -6
  148. package/src/server/prebuilt/capture-render.ts +5 -5
  149. package/src/server/prebuilt-runtime.ts +7 -10
  150. package/src/server/rsc-entry/error-renderer.ts +8 -4
  151. package/src/server/rsc-entry/index.ts +4 -2
  152. package/src/server/rsc-entry/render-route.ts +5 -2
  153. package/src/server/rsc-entry/rsc-payload.ts +52 -73
  154. package/src/server/rsc-entry/rsc-stream.ts +102 -106
  155. package/src/server/rsc-entry/ssr-bridge.ts +32 -10
  156. package/src/server/rsc-entry/ssr-renderer.ts +15 -18
  157. package/src/server/ssr-bridge-types.ts +10 -4
  158. package/src/server/ssr-entry.ts +56 -52
  159. package/src/server/ssr-render.ts +41 -76
  160. package/src/server/stream-utils.ts +125 -70
  161. package/src/shared/flight-base64.ts +23 -0
  162. package/src/shared/flight-segment.ts +35 -0
  163. package/src/shared/form-state-flight.ts +0 -15
  164. package/dist/_chunks/rolldown-runtime-D7D4PA-g.js +0 -13
@@ -15,7 +15,7 @@
15
15
  import { getLogger } from './logger.ts';
16
16
 
17
17
  /** Default maximum buffer divergence before cancellation (5MB). */
18
- const DEFAULT_MAX_BUFFER_BYTES = 5 * 1024 * 1024;
18
+ export const DEFAULT_MAX_BUFFER_BYTES = 5 * 1024 * 1024;
19
19
 
20
20
  export interface TeeOptions {
21
21
  /**
@@ -138,14 +138,7 @@ export function teeWithErrorPropagation(
138
138
  // approximates the tee's internal buffer size.
139
139
  const divergence = getSelfConsumed() - getOtherConsumed();
140
140
  if (divergence > maxBuffer) {
141
- const error = new Error(
142
- `RSC stream tee buffer exceeded ${formatBytes(maxBuffer)} ` +
143
- `(divergence: ${formatBytes(divergence)}). ` +
144
- `This usually means SSR is much slower than the inline stream consumer. ` +
145
- `Consider reducing RSC payload size or increasing the tee buffer limit.`
146
- );
147
- console.warn(`[timber] ${error.message}`);
148
- cancelBoth(error);
141
+ cancelBoth(teeBufferExceeded(maxBuffer, divergence));
149
142
  return;
150
143
  }
151
144
 
@@ -208,40 +201,71 @@ export function teeWithErrorPropagation(
208
201
  }
209
202
 
210
203
  /**
211
- * Wrap a response body with stream-lifecycle timing instrumentation.
212
- *
213
- * Logs firstChunk, lastChunk, close, maxGap (largest inter-chunk gap),
214
- * chunk count, and byte count on stream termination (clean close OR
215
- * cancellation/disconnect). Gated behind `serverTiming: 'detailed'`.
216
- *
217
- * Uses a manual reader pump to guarantee logging on all termination
218
- * paths — TransformStream.flush() is not called on cancellation.
204
+ * Stream-lifecycle timing for one response body: firstChunk, lastChunk,
205
+ * close, maxGap (largest inter-chunk gap), chunk count, and byte count,
206
+ * logged once when the stream terminates (clean close OR
207
+ * cancellation/disconnect). Gated behind `serverTiming: 'detailed'`. The
208
+ * Web body wrapper below and the Node body (`node-body-response.ts`) feed
209
+ * the same recorder, so the two report identically.
219
210
  */
220
- export function wrapResponseWithStreamTiming(
221
- body: ReadableStream<Uint8Array>,
222
- startTime: number
223
- ): ReadableStream<Uint8Array> {
211
+ export interface StreamTimingRecorder {
212
+ chunk(byteLength: number): void;
213
+ end(cancelled: boolean): void;
214
+ }
215
+
216
+ export function createStreamTimingRecorder(startTime: number): StreamTimingRecorder {
224
217
  let firstChunkMs = 0;
225
218
  let lastChunkMs = 0;
226
219
  let maxGapMs = 0;
227
220
  let prevChunkTime = 0;
228
221
  let chunks = 0;
229
222
  let bytes = 0;
230
- let cancelled = false;
223
+ let ended = false;
231
224
 
232
- function emitLog(): void {
233
- const closeMs = Math.round(performance.now() - startTime);
234
- getLogger().debug('stream-lifecycle', {
235
- firstChunkMs,
236
- lastChunkMs,
237
- closeMs,
238
- maxGapMs,
239
- chunks,
240
- bytes,
241
- ...(cancelled ? { cancelled: true } : {}),
242
- });
243
- }
225
+ return {
226
+ chunk(byteLength) {
227
+ const now = performance.now();
228
+ const relativeMs = Math.round(now - startTime);
229
+ if (chunks === 0) {
230
+ firstChunkMs = relativeMs;
231
+ } else {
232
+ const gap = Math.round(now - prevChunkTime);
233
+ if (gap > maxGapMs) maxGapMs = gap;
234
+ }
235
+ prevChunkTime = now;
236
+ lastChunkMs = relativeMs;
237
+ chunks++;
238
+ bytes += byteLength;
239
+ },
240
+ end(cancelled) {
241
+ if (ended) return;
242
+ ended = true;
243
+ const closeMs = Math.round(performance.now() - startTime);
244
+ getLogger().debug('stream-lifecycle', {
245
+ firstChunkMs,
246
+ lastChunkMs,
247
+ closeMs,
248
+ maxGapMs,
249
+ chunks,
250
+ bytes,
251
+ ...(cancelled ? { cancelled: true } : {}),
252
+ });
253
+ },
254
+ };
255
+ }
244
256
 
257
+ /**
258
+ * Wrap a Web response body with stream-lifecycle timing instrumentation
259
+ * ({@link createStreamTimingRecorder}).
260
+ *
261
+ * Uses a manual reader pump to guarantee logging on all termination
262
+ * paths — TransformStream.flush() is not called on cancellation.
263
+ */
264
+ export function wrapResponseWithStreamTiming(
265
+ body: ReadableStream<Uint8Array>,
266
+ startTime: number
267
+ ): ReadableStream<Uint8Array> {
268
+ const timing = createStreamTimingRecorder(startTime);
245
269
  const reader = body.getReader();
246
270
 
247
271
  return new ReadableStream<Uint8Array>({
@@ -249,36 +273,20 @@ export function wrapResponseWithStreamTiming(
249
273
  try {
250
274
  const { done, value } = await reader.read();
251
275
  if (done) {
252
- emitLog();
276
+ timing.end(false);
253
277
  controller.close();
254
278
  return;
255
279
  }
256
-
257
- const now = performance.now();
258
- const relativeMs = Math.round(now - startTime);
259
-
260
- if (chunks === 0) {
261
- firstChunkMs = relativeMs;
262
- } else {
263
- const gap = Math.round(now - prevChunkTime);
264
- if (gap > maxGapMs) maxGapMs = gap;
265
- }
266
-
267
- prevChunkTime = now;
268
- lastChunkMs = relativeMs;
269
- chunks++;
270
- bytes += value.byteLength;
271
-
280
+ timing.chunk(value.byteLength);
272
281
  controller.enqueue(value);
273
282
  } catch (err) {
274
- emitLog();
283
+ timing.end(false);
275
284
  controller.error(err);
276
285
  }
277
286
  },
278
287
 
279
288
  cancel(reason) {
280
- cancelled = true;
281
- emitLog();
289
+ timing.end(true);
282
290
  reader.cancel(reason).catch(() => {});
283
291
  },
284
292
  });
@@ -292,24 +300,46 @@ function formatBytes(bytes: number): string {
292
300
  }
293
301
 
294
302
  /**
295
- * Read a byte stream to completion under one overall deadline and return
296
- * the concatenated bytes. Every read is raced against the time remaining,
297
- * and the reader is cancelled on every exit, so a stalled upstream never
298
- * outlives the deadline. See design/02-rendering-pipeline.md §"Always
299
- * Timeout-Guard Stream Reads".
303
+ * The error both tee implementations (this Web one and the Node one in
304
+ * `flight-source-node.ts`) cancel with when one branch lags the other by more
305
+ * than `maxBuffer` bytes. Warns once, here, so the two cannot drift.
306
+ */
307
+ export function teeBufferExceeded(maxBuffer: number, divergence: number): Error {
308
+ const error = new Error(
309
+ `RSC stream tee buffer exceeded ${formatBytes(maxBuffer)} ` +
310
+ `(divergence: ${formatBytes(divergence)}). ` +
311
+ `This usually means SSR is much slower than the inline stream consumer. ` +
312
+ `Consider reducing RSC payload size or increasing the tee buffer limit.`
313
+ );
314
+ console.warn(`[timber] ${error.message}`);
315
+ return error;
316
+ }
317
+
318
+ /**
319
+ * A pull reader over any chunk stream: a Web reader, or the Flight reader in
320
+ * `flight-source.ts`, which reads a Node or Web Flight source.
321
+ */
322
+ export interface ChunkReader<T> {
323
+ read(): Promise<ReadableStreamReadResult<T>>;
324
+ cancel(reason?: unknown): void;
325
+ }
326
+
327
+ /**
328
+ * Read a chunk stream to completion under one overall deadline. Every read
329
+ * is raced against the time remaining, and the reader is cancelled on every
330
+ * exit, so a stalled upstream never outlives the deadline. See
331
+ * design/02-rendering-pipeline.md §"Always Timeout-Guard Stream Reads".
300
332
  *
301
333
  * @param label - Prefix for the timeout error message. Both ways the deadline
302
334
  * can pass (between reads, or while a read is pending) reject with the same
303
335
  * `${label} did not complete within ${timeoutMs}ms`.
304
336
  */
305
- export async function readAllBytesWithDeadline(
306
- stream: ReadableStream<Uint8Array>,
337
+ export async function drainWithDeadline<T>(
338
+ reader: ChunkReader<T>,
307
339
  timeoutMs: number,
308
340
  label: string
309
- ): Promise<Uint8Array> {
310
- const reader = stream.getReader();
311
- const chunks: Uint8Array[] = [];
312
- let totalLength = 0;
341
+ ): Promise<T[]> {
342
+ const chunks: T[] = [];
313
343
  const deadline = Date.now() + timeoutMs;
314
344
  const deadlineError = () => new Error(`${label} did not complete within ${timeoutMs}ms`);
315
345
  try {
@@ -320,20 +350,25 @@ export async function readAllBytesWithDeadline(
320
350
  const timeout = new Promise<never>((_, reject) => {
321
351
  timer = setTimeout(() => reject(deadlineError()), remaining);
322
352
  });
323
- let result: ReadableStreamReadResult<Uint8Array>;
353
+ let result: Awaited<ReturnType<ChunkReader<T>['read']>>;
324
354
  try {
325
355
  result = await Promise.race([reader.read(), timeout]);
326
356
  } finally {
327
357
  clearTimeout(timer);
328
358
  }
329
- if (result.done) break;
359
+ if (result.done) return chunks;
330
360
  chunks.push(result.value);
331
- totalLength += result.value.byteLength;
332
361
  }
333
362
  } finally {
334
- reader.cancel().catch(() => {});
363
+ reader.cancel();
335
364
  }
336
- const bytes = new Uint8Array(totalLength);
365
+ }
366
+
367
+ /** Concatenate byte chunks into one array. */
368
+ export function concatBytes(chunks: readonly Uint8Array[]): Uint8Array<ArrayBuffer> {
369
+ let total = 0;
370
+ for (const chunk of chunks) total += chunk.byteLength;
371
+ const bytes = new Uint8Array(total);
337
372
  let offset = 0;
338
373
  for (const chunk of chunks) {
339
374
  bytes.set(chunk, offset);
@@ -341,3 +376,23 @@ export async function readAllBytesWithDeadline(
341
376
  }
342
377
  return bytes;
343
378
  }
379
+
380
+ /**
381
+ * Read a byte stream to completion under one overall deadline and return
382
+ * the concatenated bytes ({@link drainWithDeadline}). The static generator's
383
+ * body drain uses it; Flight renders use `collectFlightBytes`
384
+ * (`flight-source.ts`), which reads either source kind the same way.
385
+ */
386
+ export async function readAllBytesWithDeadline(
387
+ stream: ReadableStream<Uint8Array>,
388
+ timeoutMs: number,
389
+ label: string
390
+ ): Promise<Uint8Array> {
391
+ const reader = stream.getReader();
392
+ const chunks = await drainWithDeadline(
393
+ { read: () => reader.read(), cancel: (reason) => void reader.cancel(reason).catch(() => {}) },
394
+ timeoutMs,
395
+ label
396
+ );
397
+ return concatBytes(chunks);
398
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Flight bytes as base64, for the two places a page embeds Flight that a
3
+ * text chunk cannot carry: a no-JS action's form state
4
+ * (server/form-state-flight.ts) and an inlined Flight chunk that is not valid
5
+ * UTF-8, the binary row of a typed array or ArrayBuffer (the `[3, base64]`
6
+ * tuple, server/flight-injector-core.ts). Base64 has no character that can end
7
+ * a `<script>` element or a JS string, so it embeds without escaping.
8
+ */
9
+
10
+ /** Flight bytes as base64. */
11
+ export function flightBytesToBase64(bytes: Uint8Array): string {
12
+ let binary = '';
13
+ for (const byte of bytes) binary += String.fromCharCode(byte);
14
+ return btoa(binary);
15
+ }
16
+
17
+ /** Embedded base64 back to the Flight bytes. */
18
+ export function flightBytesFromBase64(text: string): Uint8Array<ArrayBuffer> {
19
+ const binary = atob(text);
20
+ const bytes = new Uint8Array(binary.length);
21
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
22
+ return bytes;
23
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The inline Flight tuples a page pushes onto `self.__timber_f`, and how the
3
+ * browser turns each back into Flight bytes. The server writes them
4
+ * (server/flight-scripts.ts, server/flight-injector-core.ts); the browser
5
+ * reads them (client/browser-entry/rsc-stream.ts).
6
+ *
7
+ * - `[0]` — bootstrap signal: Flight data is active for this page.
8
+ * - `[1, text]` — Flight text, UTF-8 encoded back to bytes.
9
+ * - `[3, base64]` — Flight bytes that are not valid UTF-8 (a typed array's
10
+ * binary row), base64-decoded back to the same bytes.
11
+ *
12
+ * Both data tuples become bytes, enqueued in order, so the decoder sees the
13
+ * byte stream the server rendered whichever tuple carried each run.
14
+ */
15
+
16
+ import { flightBytesFromBase64 } from './flight-base64.ts';
17
+
18
+ export type FlightSegment =
19
+ | [isBootstrap: 0]
20
+ | [isData: 1, data: string]
21
+ | [isBinaryData: 3, base64: string];
22
+
23
+ const encoder = new TextEncoder();
24
+
25
+ /** A data tuple's Flight bytes; `null` for the bootstrap signal. */
26
+ export function flightSegmentBytes(segment: FlightSegment): Uint8Array | null {
27
+ switch (segment[0]) {
28
+ case 0:
29
+ return null;
30
+ case 1:
31
+ return encoder.encode(segment[1]);
32
+ case 3:
33
+ return flightBytesFromBase64(segment[1]);
34
+ }
35
+ }
@@ -57,18 +57,3 @@ export async function decodeFormState(
57
57
  clearTimeout(timer);
58
58
  }
59
59
  }
60
-
61
- /** The form state's Flight bytes as the base64 the page embeds. */
62
- export function formStateToBase64(bytes: Uint8Array): string {
63
- let binary = '';
64
- for (const byte of bytes) binary += String.fromCharCode(byte);
65
- return btoa(binary);
66
- }
67
-
68
- /** The embedded base64 back to the Flight bytes. */
69
- export function formStateFromBase64(text: string): Uint8Array {
70
- const binary = atob(text);
71
- const bytes = new Uint8Array(binary.length);
72
- for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
73
- return bytes;
74
- }
@@ -1,13 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __defProp = Object.defineProperty;
3
- var __exportAll = (all, no_symbols) => {
4
- let target = {};
5
- for (var name in all) __defProp(target, name, {
6
- get: all[name],
7
- enumerable: true
8
- });
9
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
- return target;
11
- };
12
- //#endregion
13
- export { __exportAll as t };