waku 1.0.0-beta.7 → 1.0.0-beta.9

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 (137) hide show
  1. package/README.md +3 -2
  2. package/dist/adapters/cloudflare.js +3 -2
  3. package/dist/adapters/cloudflare.js.map +1 -1
  4. package/dist/client.d.ts +0 -6
  5. package/dist/client.js +4 -6
  6. package/dist/client.js.map +1 -1
  7. package/dist/lib/constants.d.ts +1 -0
  8. package/dist/lib/constants.js +1 -0
  9. package/dist/lib/constants.js.map +1 -1
  10. package/dist/lib/env.d.ts +1 -4
  11. package/dist/lib/env.js +1 -3
  12. package/dist/lib/env.js.map +1 -1
  13. package/dist/lib/global-types.d.ts +0 -1
  14. package/dist/lib/types.d.ts +12 -10
  15. package/dist/lib/types.js.map +1 -1
  16. package/dist/lib/utils/custom-errors.d.ts +2 -0
  17. package/dist/lib/utils/custom-errors.js +6 -0
  18. package/dist/lib/utils/custom-errors.js.map +1 -1
  19. package/dist/lib/utils/fs-router.js +1 -0
  20. package/dist/lib/utils/fs-router.js.map +1 -1
  21. package/dist/lib/utils/react-debug-channel.js +7 -0
  22. package/dist/lib/utils/react-debug-channel.js.map +1 -1
  23. package/dist/lib/utils/redirect.d.ts +1 -0
  24. package/dist/lib/utils/redirect.js +45 -0
  25. package/dist/lib/utils/redirect.js.map +1 -0
  26. package/dist/lib/utils/render.d.ts +2 -3
  27. package/dist/lib/utils/render.js +4 -4
  28. package/dist/lib/utils/render.js.map +1 -1
  29. package/dist/lib/utils/request.d.ts +10 -6
  30. package/dist/lib/utils/request.js +24 -19
  31. package/dist/lib/utils/request.js.map +1 -1
  32. package/dist/lib/utils/ssr.d.ts +2 -0
  33. package/dist/lib/utils/ssr.js +62 -1
  34. package/dist/lib/utils/ssr.js.map +1 -1
  35. package/dist/lib/vite-entries/entry.browser.js +0 -5
  36. package/dist/lib/vite-entries/entry.browser.js.map +1 -1
  37. package/dist/lib/vite-entries/entry.build.js +2 -2
  38. package/dist/lib/vite-entries/entry.build.js.map +1 -1
  39. package/dist/lib/vite-entries/entry.server.js +2 -2
  40. package/dist/lib/vite-entries/entry.server.js.map +1 -1
  41. package/dist/lib/vite-plugins/build-id.js +2 -1
  42. package/dist/lib/vite-plugins/build-id.js.map +1 -1
  43. package/dist/lib/vite-plugins/patch-rsdw.js +10 -10
  44. package/dist/lib/vite-plugins/patch-rsdw.js.map +1 -1
  45. package/dist/lib/vite-rsc/cmd-dev.js +11 -8
  46. package/dist/lib/vite-rsc/cmd-dev.js.map +1 -1
  47. package/dist/lib/vite-rsc/cmd-start.js +2 -1
  48. package/dist/lib/vite-rsc/cmd-start.js.map +1 -1
  49. package/dist/lib/vite-rsc/handler.js +28 -12
  50. package/dist/lib/vite-rsc/handler.js.map +1 -1
  51. package/dist/lib/vite-rsc/ssr.js +11 -9
  52. package/dist/lib/vite-rsc/ssr.js.map +1 -1
  53. package/dist/minimal/client-utils/fetch-store.d.ts +5 -3
  54. package/dist/minimal/client-utils/fetch-store.js.map +1 -1
  55. package/dist/minimal/client.d.ts +56 -40
  56. package/dist/minimal/client.js +195 -109
  57. package/dist/minimal/client.js.map +1 -1
  58. package/dist/router/base-types.d.ts +2 -1
  59. package/dist/router/base-types.js.map +1 -1
  60. package/dist/router/client-utils/error-route.d.ts +16 -0
  61. package/dist/router/client-utils/error-route.js +66 -0
  62. package/dist/router/client-utils/error-route.js.map +1 -0
  63. package/dist/router/client-utils/prefetch-cache.d.ts +23 -0
  64. package/dist/router/client-utils/prefetch-cache.js +119 -0
  65. package/dist/router/client-utils/prefetch-cache.js.map +1 -0
  66. package/dist/router/client-utils/route-url.d.ts +11 -0
  67. package/dist/router/client-utils/route-url.js +43 -0
  68. package/dist/router/client-utils/route-url.js.map +1 -0
  69. package/dist/router/client-utils/router-state.d.ts +37 -0
  70. package/dist/router/client-utils/router-state.js +70 -0
  71. package/dist/router/client-utils/router-state.js.map +1 -0
  72. package/dist/router/client-utils/scroll.d.ts +5 -0
  73. package/dist/router/client-utils/scroll.js +61 -0
  74. package/dist/router/client-utils/scroll.js.map +1 -0
  75. package/dist/router/client.d.ts +73 -24
  76. package/dist/router/client.js +657 -543
  77. package/dist/router/client.js.map +1 -1
  78. package/dist/router/create-pages-utils/inferred-path-types.d.ts +1 -14
  79. package/dist/router/create-pages-utils/inferred-path-types.js.map +1 -1
  80. package/dist/router/create-pages.d.ts +4 -67
  81. package/dist/router/create-pages.js +8 -14
  82. package/dist/router/create-pages.js.map +1 -1
  83. package/dist/router/define-router-utils/build-handler.d.ts +11 -0
  84. package/dist/router/define-router-utils/build-handler.js +258 -0
  85. package/dist/router/define-router-utils/build-handler.js.map +1 -0
  86. package/dist/router/define-router-utils/client-code.d.ts +3 -0
  87. package/dist/router/define-router-utils/client-code.js +51 -0
  88. package/dist/router/define-router-utils/client-code.js.map +1 -0
  89. package/dist/router/define-router-utils/config-registry.d.ts +18 -0
  90. package/dist/router/define-router-utils/config-registry.js +99 -0
  91. package/dist/router/define-router-utils/config-registry.js.map +1 -0
  92. package/dist/router/define-router-utils/config.d.ts +73 -0
  93. package/dist/router/define-router-utils/config.js +145 -0
  94. package/dist/router/define-router-utils/config.js.map +1 -0
  95. package/dist/router/define-router-utils/element-cache.d.ts +14 -0
  96. package/dist/router/define-router-utils/element-cache.js +42 -0
  97. package/dist/router/define-router-utils/element-cache.js.map +1 -0
  98. package/dist/router/define-router-utils/request-handler.d.ts +10 -0
  99. package/dist/router/define-router-utils/request-handler.js +267 -0
  100. package/dist/router/define-router-utils/request-handler.js.map +1 -0
  101. package/dist/router/define-router-utils/request-store.d.ts +32 -0
  102. package/dist/router/define-router-utils/request-store.js +62 -0
  103. package/dist/router/define-router-utils/request-store.js.map +1 -0
  104. package/dist/router/define-router-utils/route-entries.d.ts +15 -0
  105. package/dist/router/define-router-utils/route-entries.js +130 -0
  106. package/dist/router/define-router-utils/route-entries.js.map +1 -0
  107. package/dist/router/define-router.d.ts +14 -78
  108. package/dist/router/define-router.js +46 -885
  109. package/dist/router/define-router.js.map +1 -1
  110. package/dist/router/fs-router.d.ts +1 -60
  111. package/dist/router/fs-router.js.map +1 -1
  112. package/dist/router/isomorphic-utils/build-route-href.d.ts +2 -1
  113. package/dist/router/isomorphic-utils/build-route-href.js.map +1 -1
  114. package/dist/router/isomorphic-utils/path-spec.d.ts +1 -16
  115. package/dist/router/isomorphic-utils/path-spec.js +17 -16
  116. package/dist/router/isomorphic-utils/path-spec.js.map +1 -1
  117. package/dist/router/isomorphic-utils/route-path.d.ts +4 -0
  118. package/dist/router/isomorphic-utils/route-path.js +6 -0
  119. package/dist/router/isomorphic-utils/route-path.js.map +1 -1
  120. package/dist/router/isomorphic-utils/search-codec-registry.d.ts +14 -1
  121. package/dist/router/isomorphic-utils/search-codec-registry.js +9 -1
  122. package/dist/router/isomorphic-utils/search-codec-registry.js.map +1 -1
  123. package/dist/server.js +2 -1
  124. package/dist/server.js.map +1 -1
  125. package/package.json +9 -9
  126. package/dist/router/client-utils/navigate.d.ts +0 -39
  127. package/dist/router/client-utils/navigate.js +0 -95
  128. package/dist/router/client-utils/navigate.js.map +0 -1
  129. package/dist/router/define-router-utils/path-spec.d.ts +0 -5
  130. package/dist/router/define-router-utils/path-spec.js +0 -19
  131. package/dist/router/define-router-utils/path-spec.js.map +0 -1
  132. package/dist/router/define-router-utils/task-runner.d.ts +0 -4
  133. package/dist/router/define-router-utils/task-runner.js +0 -29
  134. package/dist/router/define-router-utils/task-runner.js.map +0 -1
  135. package/dist/router/prefetch-cache.d.ts +0 -22
  136. package/dist/router/prefetch-cache.js +0 -79
  137. package/dist/router/prefetch-cache.js.map +0 -1
package/README.md CHANGED
@@ -39,7 +39,7 @@ While there's a bit of a learning curve to modern React rendering, it introduces
39
39
 
40
40
  So please don't be intimidated by the `'use client'` directive! Once you get the hang of it, you'll appreciate how awesome it is to flexibly move server-client boundaries with a single line of code as your full-stack React codebase evolves over time. It's way simpler than maintaining separate codebases for your backend and frontend.
41
41
 
42
- And please don't fret about client components! Even if you only lightly optimize towards server components, your client bundle size will be smaller than traditional React frameworks, which are always 100% client components.
42
+ And please don't fret about client components! Even if you only lightly optimize towards server components, your client bundle size will be smaller than that of a fully client-rendered React app.
43
43
 
44
44
  > Future versions of Waku may provide additional opt-in APIs to abstract some of the complexity away for an improved developer experience.
45
45
 
@@ -524,6 +524,7 @@ Group routes are especially powerful for organizing complex applications where d
524
524
 
525
525
  The following directories are ignored by the router:
526
526
 
527
+ - `_actions`
527
528
  - `_components`
528
529
  - `_hooks`
529
530
 
@@ -1117,7 +1118,7 @@ Data mutations can be performed via [server actions](https://react.dev/reference
1117
1118
 
1118
1119
  ### API endpoints
1119
1120
 
1120
- Create API routes by making a new file in the special `./src/pages/_api` directory and exporting one or more functions named after the HTTP methods that you want it to support: `GET`, `HEAD`, `POST`, `PUT`, `DELETE`, `CONNECT`, `OPTIONS`, `TRACE`, or `PATCH`. The name of the file determines the route it will be served from. Each function receives a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object and returns a standard [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) object.
1121
+ Create API routes by making a new file in the special `./src/pages/_api` directory and exporting one or more functions named after the HTTP methods that you want it to support: `GET`, `HEAD`, `POST`, `PUT`, `DELETE`, `CONNECT`, `OPTIONS`, `TRACE`, `PATCH`, or `QUERY`. The name of the file determines the route it will be served from. Each function receives a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object and returns a standard [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) object.
1121
1122
 
1122
1123
  ```ts
1123
1124
  // ./src/pages/_api/contact.ts
@@ -33,7 +33,7 @@ function removeGzipEncoding(res) {
33
33
  }
34
34
  return res;
35
35
  }
36
- export default createServerEntryAdapter(({ processRequest, processBuild, setAllEnv, config, notFoundHtml }, options)=>{
36
+ export default createServerEntryAdapter(({ processRequest, processBuild, unstable_setAllEnv, config, notFoundHtml }, options)=>{
37
37
  const { bodyLimit: bodyLimitOptions, middlewareFns = [], middlewareModules = {}, internalPathToBuildStaticFiles = '__waku_internal_build_static_files' } = options || {};
38
38
  const app = new Hono();
39
39
  app.notFound((c)=>{
@@ -102,6 +102,7 @@ export default createServerEntryAdapter(({ processRequest, processBuild, setAllE
102
102
  return res;
103
103
  };
104
104
  return {
105
+ ...options?.handlers,
105
106
  fetch: fetchFn,
106
107
  build: async (utils)=>{
107
108
  const server = await startPreviewServer();
@@ -137,7 +138,7 @@ export default createServerEntryAdapter(({ processRequest, processBuild, setAllE
137
138
  defaultExport: {
138
139
  ...options?.handlers,
139
140
  fetch (req, env) {
140
- setAllEnv(env);
141
+ unstable_setAllEnv(env);
141
142
  return fetchFn(req);
142
143
  }
143
144
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/adapters/cloudflare.ts"],"sourcesContent":["import type { MiddlewareHandler } from 'hono';\nimport { bodyLimit } from 'hono/body-limit';\nimport { Hono } from 'hono/tiny';\nimport {\n unstable_createServerEntryAdapter as createServerEntryAdapter,\n unstable_startPreviewServer as startPreviewServer,\n} from 'waku/adapter-builders';\nimport {\n unstable_constants as constants,\n unstable_consumeMultiplexedStream as consumeMultiplexedStream,\n unstable_honoMiddleware as honoMiddleware,\n unstable_produceMultiplexedStream as produceMultiplexedStream,\n} from 'waku/internals';\nimport type { BuildOptions } from './cloudflare-build-enhancer.js';\n\nconst { DIST_PUBLIC } = constants;\nconst { rscMiddleware, middlewareRunner } = honoMiddleware;\n\nconst DEFAULT_BODY_LIMIT_MAX_SIZE = 100 * 1024 * 1024;\n\nconst DO_NOT_BUNDLE = '';\n\nconst PRUNABLE_KEY_PREFIX = '\\0__prunable__/';\n\nconst emptyStream = () =>\n new ReadableStream<Uint8Array>({\n start(controller) {\n controller.close();\n },\n });\n\nfunction isProductionWorker(req: Request): boolean {\n // This header seems to only be set for production cloudflare workers\n return !!req.headers.get('cf-visitor');\n}\n\nfunction isLoopbackRequest(req: Request): boolean {\n const { hostname } = new URL(req.url);\n return (\n hostname === 'localhost' ||\n hostname === '127.0.0.1' ||\n hostname === '::1' ||\n hostname === '[::1]'\n );\n}\n\nfunction removeGzipEncoding(res: Response): Response {\n const contentType = res.headers.get('content-type');\n if (\n !contentType ||\n contentType.includes('text/html') ||\n contentType.includes('text/plain')\n ) {\n const headers = new Headers(res.headers);\n headers.set('content-encoding', 'Identity');\n return new Response(res.body, {\n status: res.status,\n statusText: res.statusText,\n headers,\n });\n }\n return res;\n}\n\nexport default createServerEntryAdapter(\n (\n { processRequest, processBuild, setAllEnv, config, notFoundHtml },\n options?: {\n static?: boolean;\n handlers?: Record<string, unknown>;\n assetsDir?: string;\n bodyLimit?: Parameters<typeof bodyLimit>[0] | false;\n middlewareFns?: ((opts: { app: Hono }) => MiddlewareHandler)[];\n middlewareModules?: Record<string, () => Promise<unknown>>;\n internalPathToBuildStaticFiles?: string;\n },\n ) => {\n const {\n bodyLimit: bodyLimitOptions,\n middlewareFns = [],\n middlewareModules = {},\n internalPathToBuildStaticFiles = '__waku_internal_build_static_files',\n } = options || {};\n const app = new Hono();\n app.notFound((c) => {\n if (notFoundHtml) {\n return c.html(notFoundHtml, 404);\n }\n return c.text('404 Not Found', 404);\n });\n if (bodyLimitOptions !== false) {\n app.use(\n bodyLimit(bodyLimitOptions ?? { maxSize: DEFAULT_BODY_LIMIT_MAX_SIZE }),\n );\n }\n for (const middlewareFn of middlewareFns) {\n app.use(middlewareFn({ app }));\n }\n app.use(middlewareRunner(middlewareModules as never, { app }));\n app.use(rscMiddleware({ processRequest }));\n const buildOptions: BuildOptions = {\n srcDir: config.srcDir,\n distDir: config.distDir,\n DIST_PUBLIC,\n serverless: !options?.static,\n };\n\n const buildBody = () =>\n produceMultiplexedStream(async (emitFile) => {\n await processBuild({\n emitFile,\n unstable_registerPrunableFile: (srcPath) =>\n emitFile(PRUNABLE_KEY_PREFIX + srcPath, emptyStream()),\n });\n });\n\n const fetchFn = async (req: Request) => {\n if (\n new URL(req.url).pathname === `/${internalPathToBuildStaticFiles}` &&\n isLoopbackRequest(req) &&\n !isProductionWorker(req)\n ) {\n return new Response(buildBody());\n }\n let cloudflareContext;\n try {\n cloudflareContext = await import(\n /* @vite-ignore */ DO_NOT_BUNDLE + 'cloudflare:workers'\n );\n } catch {\n // Not in a Cloudflare environment\n }\n let res: Response | Promise<Response>;\n if (cloudflareContext) {\n const { env, waitUntil, passThroughOnException } = cloudflareContext;\n res = app.fetch(req, env, {\n waitUntil,\n passThroughOnException,\n props: undefined,\n });\n } else {\n res = app.fetch(req);\n }\n // Workaround https://github.com/cloudflare/workers-sdk/issues/6577\n if (import.meta.env?.PROD && !isProductionWorker(req)) {\n if ('then' in res) {\n res = res.then((res) => removeGzipEncoding(res));\n } else {\n res = removeGzipEncoding(res);\n }\n }\n return res;\n };\n\n return {\n fetch: fetchFn,\n build: async (utils) => {\n const server = await startPreviewServer();\n // Fallback middleware for the case without @cloudflare/vite-plugin\n server.middlewares.use(async (_req, res, next) => {\n try {\n const { Readable } = await import(\n /* @vite-ignore */ DO_NOT_BUNDLE + 'node:stream'\n );\n Readable.fromWeb(buildBody() as never).pipe(res);\n } catch (err) {\n next(err);\n }\n });\n const response = await fetch(\n server.baseUrl + internalPathToBuildStaticFiles,\n { headers: { connection: 'close' } },\n );\n await consumeMultiplexedStream(response.body!, async (key, stream) => {\n if (key.startsWith(PRUNABLE_KEY_PREFIX)) {\n utils.unstable_registerPrunableFile(\n key.slice(PRUNABLE_KEY_PREFIX.length),\n );\n return;\n }\n await utils.emitFile(key, stream);\n });\n // https://github.com/nodejs/node/issues/56645\n await new Promise((resolve) => setTimeout(resolve, 100));\n await server.close();\n },\n buildOptions,\n buildEnhancers: ['waku/adapters/cloudflare-build-enhancer'],\n defaultExport: {\n ...options?.handlers,\n fetch(req: Request, env: Record<string, unknown>) {\n setAllEnv(env);\n return fetchFn(req);\n },\n },\n };\n },\n);\n"],"names":["bodyLimit","Hono","unstable_createServerEntryAdapter","createServerEntryAdapter","unstable_startPreviewServer","startPreviewServer","unstable_constants","constants","unstable_consumeMultiplexedStream","consumeMultiplexedStream","unstable_honoMiddleware","honoMiddleware","unstable_produceMultiplexedStream","produceMultiplexedStream","DIST_PUBLIC","rscMiddleware","middlewareRunner","DEFAULT_BODY_LIMIT_MAX_SIZE","DO_NOT_BUNDLE","PRUNABLE_KEY_PREFIX","emptyStream","ReadableStream","start","controller","close","isProductionWorker","req","headers","get","isLoopbackRequest","hostname","URL","url","removeGzipEncoding","res","contentType","includes","Headers","set","Response","body","status","statusText","processRequest","processBuild","setAllEnv","config","notFoundHtml","options","bodyLimitOptions","middlewareFns","middlewareModules","internalPathToBuildStaticFiles","app","notFound","c","html","text","use","maxSize","middlewareFn","buildOptions","srcDir","distDir","serverless","static","buildBody","emitFile","unstable_registerPrunableFile","srcPath","fetchFn","pathname","cloudflareContext","env","waitUntil","passThroughOnException","fetch","props","undefined","PROD","then","build","utils","server","middlewares","_req","next","Readable","fromWeb","pipe","err","response","baseUrl","connection","key","stream","startsWith","slice","length","Promise","resolve","setTimeout","buildEnhancers","defaultExport","handlers"],"mappings":"AACA,SAASA,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,IAAI,QAAQ,YAAY;AACjC,SACEC,qCAAqCC,wBAAwB,EAC7DC,+BAA+BC,kBAAkB,QAC5C,wBAAwB;AAC/B,SACEC,sBAAsBC,SAAS,EAC/BC,qCAAqCC,wBAAwB,EAC7DC,2BAA2BC,cAAc,EACzCC,qCAAqCC,wBAAwB,QACxD,iBAAiB;AAGxB,MAAM,EAAEC,WAAW,EAAE,GAAGP;AACxB,MAAM,EAAEQ,aAAa,EAAEC,gBAAgB,EAAE,GAAGL;AAE5C,MAAMM,8BAA8B,MAAM,OAAO;AAEjD,MAAMC,gBAAgB;AAEtB,MAAMC,sBAAsB;AAE5B,MAAMC,cAAc,IAClB,IAAIC,eAA2B;QAC7BC,OAAMC,UAAU;YACdA,WAAWC,KAAK;QAClB;IACF;AAEF,SAASC,mBAAmBC,GAAY;IACtC,qEAAqE;IACrE,OAAO,CAAC,CAACA,IAAIC,OAA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AC,OAAO2B,MAAMnD,KAAKoD;gBACvC,IAAI;oBACF,MAAM,EAAEC,QAAQ,EAAE,GAAG,MAAM,MAAM,CAC/B,gBAAgB,GAAGrE,gBAAgB;oBAErCqE,SAASC,OAAO,CAACtB,aAAsBuB,IAAI,CAACvD;gBAC9C,EAAE,OAAOwD,KAAK;oBACZJ,KAAKI;gBACP;YACF;YACA,MAAMC,WAAW,MAAMf,MACrBO,OAAOS,OAAO,GAAGxC,gCACjB;gBAAEzB,SAAS;oBAAEkE,YAAY;gBAAQ;YAAE;YAErC,MAAMpF,yBAAyBkF,SAASnD,IAAI,EAAG,OAAOsD,KAAKC;gBACzD,IAAID,IAAIE,UAAU,CAAC7E,sBAAsB;oBACvC+D,MAAMd,6BAA6B,CACjC0B,IAAIG,KAAK,CAAC9E,oBAAoB+E,MAAM;oBAEtC;gBACF;gBACA,MAAMhB,MAAMf,QAAQ,CAAC2B,KAAKC;YAC5B;YACA,8CAA8C;YAC9C,MAAM,IAAII,QAAQ,CAACC,UAAYC,WAAWD,SAAS;YACnD,MAAMjB,OAAO3D,KAAK;QACpB;QACAqC;QACAyC,gBAAgB;YAAC;SAA0C;QAC3DC,eAAe;YACb,GAAGvD,SAASwD,QAAQ;YACpB5B,OAAMlD,GAAY,EAAE+C,GAA4B;gBAC9C5B,UAAU4B;gBACV,OAAOH,QAAQ5C;YACjB;QACF;IACF;AACF,GACA"}
1
+ {"version":3,"sources":["../../src/adapters/cloudflare.ts"],"sourcesContent":["import type { MiddlewareHandler } from 'hono';\nimport { bodyLimit } from 'hono/body-limit';\nimport { Hono } from 'hono/tiny';\nimport {\n unstable_createServerEntryAdapter as createServerEntryAdapter,\n unstable_startPreviewServer as startPreviewServer,\n} from 'waku/adapter-builders';\nimport {\n unstable_constants as constants,\n unstable_consumeMultiplexedStream as consumeMultiplexedStream,\n unstable_honoMiddleware as honoMiddleware,\n unstable_produceMultiplexedStream as produceMultiplexedStream,\n} from 'waku/internals';\nimport type { BuildOptions } from './cloudflare-build-enhancer.js';\n\nconst { DIST_PUBLIC } = constants;\nconst { rscMiddleware, middlewareRunner } = honoMiddleware;\n\nconst DEFAULT_BODY_LIMIT_MAX_SIZE = 100 * 1024 * 1024;\n\nconst DO_NOT_BUNDLE = '';\n\nconst PRUNABLE_KEY_PREFIX = '\\0__prunable__/';\n\nconst emptyStream = () =>\n new ReadableStream<Uint8Array>({\n start(controller) {\n controller.close();\n },\n });\n\nfunction isProductionWorker(req: Request): boolean {\n // This header seems to only be set for production cloudflare workers\n return !!req.headers.get('cf-visitor');\n}\n\nfunction isLoopbackRequest(req: Request): boolean {\n const { hostname } = new URL(req.url);\n return (\n hostname === 'localhost' ||\n hostname === '127.0.0.1' ||\n hostname === '::1' ||\n hostname === '[::1]'\n );\n}\n\nfunction removeGzipEncoding(res: Response): Response {\n const contentType = res.headers.get('content-type');\n if (\n !contentType ||\n contentType.includes('text/html') ||\n contentType.includes('text/plain')\n ) {\n const headers = new Headers(res.headers);\n headers.set('content-encoding', 'Identity');\n return new Response(res.body, {\n status: res.status,\n statusText: res.statusText,\n headers,\n });\n }\n return res;\n}\n\nexport default createServerEntryAdapter(\n (\n { processRequest, processBuild, unstable_setAllEnv, config, notFoundHtml },\n options?: {\n static?: boolean;\n handlers?: Record<string, unknown>;\n assetsDir?: string;\n bodyLimit?: Parameters<typeof bodyLimit>[0] | false;\n middlewareFns?: ((opts: { app: Hono }) => MiddlewareHandler)[];\n middlewareModules?: Record<string, () => Promise<unknown>>;\n internalPathToBuildStaticFiles?: string;\n },\n ) => {\n const {\n bodyLimit: bodyLimitOptions,\n middlewareFns = [],\n middlewareModules = {},\n internalPathToBuildStaticFiles = '__waku_internal_build_static_files',\n } = options || {};\n const app = new Hono();\n app.notFound((c) => {\n if (notFoundHtml) {\n return c.html(notFoundHtml, 404);\n }\n return c.text('404 Not Found', 404);\n });\n if (bodyLimitOptions !== false) {\n app.use(\n bodyLimit(bodyLimitOptions ?? { maxSize: DEFAULT_BODY_LIMIT_MAX_SIZE }),\n );\n }\n for (const middlewareFn of middlewareFns) {\n app.use(middlewareFn({ app }));\n }\n app.use(middlewareRunner(middlewareModules as never, { app }));\n app.use(rscMiddleware({ processRequest }));\n const buildOptions: BuildOptions = {\n srcDir: config.srcDir,\n distDir: config.distDir,\n DIST_PUBLIC,\n serverless: !options?.static,\n };\n\n const buildBody = () =>\n produceMultiplexedStream(async (emitFile) => {\n await processBuild({\n emitFile,\n unstable_registerPrunableFile: (srcPath) =>\n emitFile(PRUNABLE_KEY_PREFIX + srcPath, emptyStream()),\n });\n });\n\n const fetchFn = async (req: Request) => {\n if (\n new URL(req.url).pathname === `/${internalPathToBuildStaticFiles}` &&\n isLoopbackRequest(req) &&\n !isProductionWorker(req)\n ) {\n return new Response(buildBody());\n }\n let cloudflareContext;\n try {\n cloudflareContext = await import(\n /* @vite-ignore */ DO_NOT_BUNDLE + 'cloudflare:workers'\n );\n } catch {\n // Not in a Cloudflare environment\n }\n let res: Response | Promise<Response>;\n if (cloudflareContext) {\n const { env, waitUntil, passThroughOnException } = cloudflareContext;\n res = app.fetch(req, env, {\n waitUntil,\n passThroughOnException,\n props: undefined,\n });\n } else {\n res = app.fetch(req);\n }\n // Workaround https://github.com/cloudflare/workers-sdk/issues/6577\n if (import.meta.env?.PROD && !isProductionWorker(req)) {\n if ('then' in res) {\n res = res.then((res) => removeGzipEncoding(res));\n } else {\n res = removeGzipEncoding(res);\n }\n }\n return res;\n };\n\n return {\n ...options?.handlers,\n fetch: fetchFn,\n build: async (utils) => {\n const server = await startPreviewServer();\n // Fallback middleware for the case without @cloudflare/vite-plugin\n server.middlewares.use(async (_req, res, next) => {\n try {\n const { Readable } = await import(\n /* @vite-ignore */ DO_NOT_BUNDLE + 'node:stream'\n );\n Readable.fromWeb(buildBody() as never).pipe(res);\n } catch (err) {\n next(err);\n }\n });\n const response = await fetch(\n server.baseUrl + internalPathToBuildStaticFiles,\n { headers: { connection: 'close' } },\n );\n await consumeMultiplexedStream(response.body!, async (key, stream) => {\n if (key.startsWith(PRUNABLE_KEY_PREFIX)) {\n utils.unstable_registerPrunableFile(\n key.slice(PRUNABLE_KEY_PREFIX.length),\n );\n return;\n }\n await utils.emitFile(key, stream);\n });\n // https://github.com/nodejs/node/issues/56645\n await new Promise((resolve) => setTimeout(resolve, 100));\n await server.close();\n },\n buildOptions,\n buildEnhancers: ['waku/adapters/cloudflare-build-enhancer'],\n defaultExport: {\n ...options?.handlers,\n fetch(req: Request, env: Record<string, unknown>) {\n unstable_setAllEnv(env);\n return fetchFn(req);\n },\n },\n };\n },\n);\n"],"names":["bodyLimit","Hono","unstable_createServerEntryAdapter","createServerEntryAdapter","unstable_startPreviewServer","startPreviewServer","unstable_constants","constants","unstable_consumeMultiplexedStream","consumeMultiplexedStream","unstable_honoMiddleware","honoMiddleware","unstable_produceMultiplexedStream","produceMultiplexedStream","DIST_PUBLIC","rscMiddleware","middlewareRunner","DEFAULT_BODY_LIMIT_MAX_SIZE","DO_NOT_BUNDLE","PRUNABLE_KEY_PREFIX","emptyStream","ReadableStream","start","controller","close","isProductionWorker","req","headers","get","isLoopbackRequest","hostname","URL","url","removeGzipEncoding","res","contentType","includes","Headers","set","Response","body","status","statusText","processRequest","processBuild","unstable_setAllEnv","config","notFoundHtml","options","bodyLimitOptions","middlewareFns","middlewareModules","internalPathToBuildStaticFiles","app","notFound","c","html","text","use","maxSize","middlewareFn","buildOptions","srcDir","distDir","serverless","static","buildBody","emitFile","unstable_registerPrunableFile","srcPath","fetchFn","pathname","cloudflareContext","env","waitUntil","passThroughOnException","fetch","props","undefined","PROD","then","handlers","build","utils","server","middlewares","_req","next","Readable","fromWeb","pipe","err","response","baseUrl","connection","key","stream","startsWith","slice","length","Promise","resolve","setTimeout","buildEnhancers","defaultExport"],"mappings":"AACA,SAASA,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,IAAI,QAAQ,YAAY;AACjC,SACEC,qCAAqCC,wBAAwB,EAC7DC,+BAA+BC,kBAAkB,QAC5C,wBAAwB;AAC/B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AGxD,SAASiC,QAAQ;YACpBL,OAAMlD,GAAY,EAAE+C,GAA4B;gBAC9C5B,mBAAmB4B;gBACnB,OAAOH,QAAQ5C;YACjB;QACF;IACF;AACF,GACA"}
package/dist/client.d.ts CHANGED
@@ -1,10 +1,4 @@
1
- /**
2
- * Experimental, the name and the behavior might change.
3
- */
4
1
  export declare const unstable_allowServer: <T>(x: T) => T;
5
- /**
6
- * Unsure if this is going to be a public API in the future.
7
- */
8
2
  export declare const unstable_defaultRootOptions: {
9
3
  onCaughtError(error: unknown): void;
10
4
  };
package/dist/client.js CHANGED
@@ -1,10 +1,8 @@
1
1
  import { getErrorInfo } from './lib/utils/custom-errors.js';
2
- /**
3
- * Experimental, the name and the behavior might change.
4
- */ export const unstable_allowServer = (x)=>x;
5
- /**
6
- * Unsure if this is going to be a public API in the future.
7
- */ export const unstable_defaultRootOptions = {
2
+ // Experimental, the name and the behavior might change.
3
+ export const unstable_allowServer = (x)=>x;
4
+ // Unsure if this is going to be a public API in the future.
5
+ export const unstable_defaultRootOptions = {
8
6
  onCaughtError (error) {
9
7
  if (getErrorInfo(error)) {
10
8
  return;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts"],"sourcesContent":["import { getErrorInfo } from './lib/utils/custom-errors.js';\n\n/**\n * Experimental, the name and the behavior might change.\n */\nexport const unstable_allowServer = <T>(x: T) => x;\n\n/**\n * Unsure if this is going to be a public API in the future.\n */\nexport const unstable_defaultRootOptions = {\n onCaughtError(error: unknown) {\n if (getErrorInfo(error)) {\n return;\n }\n console.error(error);\n },\n};\n"],"names":["getErrorInfo","unstable_allowServer","x","unstable_defaultRootOptions","onCaughtError","error","console"],"mappings":"AAAA,SAASA,YAAY,QAAQ,+BAA+B;AAE5D;;CAEC,GACD,OAAO,MAAMC,uBAAuB,CAAIC,IAASA,EAAE;AAEnD;;CAEC,GACD,OAAO,MAAMC,8BAA8B;IACzCC,eAAcC,KAAc;QAC1B,IAAIL,aAAaK,QAAQ;YACvB;QACF;QACAC,QAAQD,KAAK,CAACA;IAChB;AACF,EAAE"}
1
+ {"version":3,"sources":["../src/client.ts"],"sourcesContent":["import { getErrorInfo } from './lib/utils/custom-errors.js';\n\n// Experimental, the name and the behavior might change.\nexport const unstable_allowServer = <T>(x: T) => x;\n\n// Unsure if this is going to be a public API in the future.\nexport const unstable_defaultRootOptions = {\n onCaughtError(error: unknown) {\n if (getErrorInfo(error)) {\n return;\n }\n console.error(error);\n },\n};\n"],"names":["getErrorInfo","unstable_allowServer","x","unstable_defaultRootOptions","onCaughtError","error","console"],"mappings":"AAAA,SAASA,YAAY,QAAQ,+BAA+B;AAE5D,wDAAwD;AACxD,OAAO,MAAMC,uBAAuB,CAAIC,IAASA,EAAE;AAEnD,4DAA4D;AAC5D,OAAO,MAAMC,8BAA8B;IACzCC,eAAcC,KAAc;QAC1B,IAAIL,aAAaK,QAAQ;YACvB;QACF;QACAC,QAAQD,KAAK,CAACA;IAChB;AACF,EAAE"}
@@ -1,4 +1,5 @@
1
1
  export declare const EXTENSIONS: string[];
2
+ export declare const DEV_BUILD_ID = "dev";
2
3
  export declare const SRC_CLIENT_ENTRY = "waku.client";
3
4
  export declare const SRC_SERVER_ENTRY = "waku.server";
4
5
  export declare const SRC_PAGES = "pages";
@@ -6,6 +6,7 @@ export const EXTENSIONS = [
6
6
  '.mjs',
7
7
  '.cjs'
8
8
  ];
9
+ export const DEV_BUILD_ID = 'dev'; // truthy on purpose
9
10
  export const SRC_CLIENT_ENTRY = 'waku.client';
10
11
  export const SRC_SERVER_ENTRY = 'waku.server';
11
12
  export const SRC_PAGES = 'pages'; // only for managed mode
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/constants.ts"],"sourcesContent":["export const EXTENSIONS = ['.js', '.ts', '.tsx', '.jsx', '.mjs', '.cjs'];\nexport const SRC_CLIENT_ENTRY = 'waku.client';\nexport const SRC_SERVER_ENTRY = 'waku.server';\nexport const SRC_PAGES = 'pages'; // only for managed mode\nexport const SRC_MIDDLEWARE = 'middleware'; // only for managed mode\n\n// Some file and dir names for dist\n// We may change this in the future\nexport const DIST_PUBLIC = 'public';\nexport const DIST_SERVER = 'server';\nexport const BUILD_METADATA_FILE = '__waku_build_metadata.js';\n"],"names":["EXTENSIONS","SRC_CLIENT_ENTRY","SRC_SERVER_ENTRY","SRC_PAGES","SRC_MIDDLEWARE","DIST_PUBLIC","DIST_SERVER","BUILD_METADATA_FILE"],"mappings":"AAAA,OAAO,MAAMA,aAAa;IAAC;IAAO;IAAO;IAAQ;IAAQ;IAAQ;CAAO,CAAC;AACzE,OAAO,MAAMC,mBAAmB,cAAc;AAC9C,OAAO,MAAMC,mBAAmB,cAAc;AAC9C,OAAO,MAAMC,YAAY,QAAQ,CAAC,wBAAwB;AAC1D,OAAO,MAAMC,iBAAiB,aAAa,CAAC,wBAAwB;AAEpE,mCAAmC;AACnC,mCAAmC;AACnC,OAAO,MAAMC,cAAc,SAAS;AACpC,OAAO,MAAMC,cAAc,SAAS;AACpC,OAAO,MAAMC,sBAAsB,2BAA2B"}
1
+ {"version":3,"sources":["../../src/lib/constants.ts"],"sourcesContent":["export const EXTENSIONS = ['.js', '.ts', '.tsx', '.jsx', '.mjs', '.cjs'];\n\nexport const DEV_BUILD_ID = 'dev'; // truthy on purpose\nexport const SRC_CLIENT_ENTRY = 'waku.client';\nexport const SRC_SERVER_ENTRY = 'waku.server';\nexport const SRC_PAGES = 'pages'; // only for managed mode\nexport const SRC_MIDDLEWARE = 'middleware'; // only for managed mode\n\n// Some file and dir names for dist\n// We may change this in the future\nexport const DIST_PUBLIC = 'public';\nexport const DIST_SERVER = 'server';\nexport const BUILD_METADATA_FILE = '__waku_build_metadata.js';\n"],"names":["EXTENSIONS","DEV_BUILD_ID","SRC_CLIENT_ENTRY","SRC_SERVER_ENTRY","SRC_PAGES","SRC_MIDDLEWARE","DIST_PUBLIC","DIST_SERVER","BUILD_METADATA_FILE"],"mappings":"AAAA,OAAO,MAAMA,aAAa;IAAC;IAAO;IAAO;IAAQ;IAAQ;IAAQ;CAAO,CAAC;AAEzE,OAAO,MAAMC,eAAe,MAAM,CAAC,oBAAoB;AACvD,OAAO,MAAMC,mBAAmB,cAAc;AAC9C,OAAO,MAAMC,mBAAmB,cAAc;AAC9C,OAAO,MAAMC,YAAY,QAAQ,CAAC,wBAAwB;AAC1D,OAAO,MAAMC,iBAAiB,aAAa,CAAC,wBAAwB;AAEpE,mCAAmC;AACnC,mCAAmC;AACnC,OAAO,MAAMC,cAAc,SAAS;AACpC,OAAO,MAAMC,cAAc,SAAS;AACpC,OAAO,MAAMC,sBAAsB,2BAA2B"}
package/dist/lib/env.d.ts CHANGED
@@ -1,5 +1,2 @@
1
- /**
2
- * This is an internal function and not for public use.
3
- */
4
- export declare function setAllEnv(newEnv: Readonly<Record<string, unknown>>): void;
1
+ export declare function unstable_setAllEnv(newEnv: Readonly<Record<string, unknown>>): void;
5
2
  export declare function getEnv(key: string): string | undefined;
package/dist/lib/env.js CHANGED
@@ -1,8 +1,6 @@
1
1
  // The use of `globalThis` in this file is more or less a hack.
2
2
  // It should be revisited with a better solution.
3
- /**
4
- * This is an internal function and not for public use.
5
- */ export function setAllEnv(newEnv) {
3
+ export function unstable_setAllEnv(newEnv) {
6
4
  const env = {};
7
5
  for (const [key, value] of Object.entries(newEnv)){
8
6
  if (typeof value === 'string') {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/env.ts"],"sourcesContent":["// The use of `globalThis` in this file is more or less a hack.\n// It should be revisited with a better solution.\n\n/**\n * This is an internal function and not for public use.\n */\nexport function setAllEnv(newEnv: Readonly<Record<string, unknown>>) {\n const env: Record<string, string> = {};\n for (const [key, value] of Object.entries(newEnv)) {\n if (typeof value === 'string') {\n env[key] = value;\n }\n }\n globalThis.__WAKU_SERVER_ENV__ = env;\n}\n\nexport function getEnv(key: string): string | undefined {\n return globalThis.__WAKU_SERVER_ENV__?.[key];\n}\n"],"names":["setAllEnv","newEnv","env","key","value","Object","entries","globalThis","__WAKU_SERVER_ENV__","getEnv"],"mappings":"AAAA,+DAA+D;AAC/D,iDAAiD;AAEjD;;CAEC,GACD,OAAO,SAASA,UAAUC,MAAyC;IACjE,MAAMC,MAA8B,CAAC;IACrC,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIC,OAAOC,OAAO,CAACL,QAAS;QACjD,IAAI,OAAOG,UAAU,UAAU;YAC7BF,GAAG,CAACC,IAAI,GAAGC;QACb;IACF;IACAG,WAAWC,mBAAmB,GAAGN;AACnC;AAEA,OAAO,SAASO,OAAON,GAAW;IAChC,OAAOI,WAAWC,mBAAmB,EAAE,CAACL,IAAI;AAC9C"}
1
+ {"version":3,"sources":["../../src/lib/env.ts"],"sourcesContent":["// The use of `globalThis` in this file is more or less a hack.\n// It should be revisited with a better solution.\n\nexport function unstable_setAllEnv(newEnv: Readonly<Record<string, unknown>>) {\n const env: Record<string, string> = {};\n for (const [key, value] of Object.entries(newEnv)) {\n if (typeof value === 'string') {\n env[key] = value;\n }\n }\n globalThis.__WAKU_SERVER_ENV__ = env;\n}\n\nexport function getEnv(key: string): string | undefined {\n return globalThis.__WAKU_SERVER_ENV__?.[key];\n}\n"],"names":["unstable_setAllEnv","newEnv","env","key","value","Object","entries","globalThis","__WAKU_SERVER_ENV__","getEnv"],"mappings":"AAAA,+DAA+D;AAC/D,iDAAiD;AAEjD,OAAO,SAASA,mBAAmBC,MAAyC;IAC1E,MAAMC,MAA8B,CAAC;IACrC,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIC,OAAOC,OAAO,CAACL,QAAS;QACjD,IAAI,OAAOG,UAAU,UAAU;YAC7BF,GAAG,CAACC,IAAI,GAAGC;QACb;IACF;IACAG,WAAWC,mBAAmB,GAAGN;AACnC;AAEA,OAAO,SAASO,OAAON,GAAW;IAChC,OAAOI,WAAWC,mBAAmB,EAAE,CAACL,IAAI;AAC9C"}
@@ -1,7 +1,6 @@
1
1
  declare global {
2
2
  var __WAKU_RSC_RELOAD_LISTENERS__: (() => void)[] | undefined;
3
3
  var __WAKU_REFETCH_RSC__: (() => void) | undefined;
4
- var __WAKU_REFETCH_ROUTE__: (() => void) | undefined;
5
4
  var __WAKU_START_PREVIEW_SERVER__: (() => Promise<import('./vite-rsc/preview.js').PreviewServer>) | undefined;
6
5
  var __WAKU_SERVER_ENV__: Readonly<Record<string, string>> | undefined;
7
6
  var __WAKU_INITIAL_RSC__: import('./utils/initial-rsc.js').InitialRscEntry | undefined;
@@ -5,9 +5,9 @@ type Elements = Record<string, unknown>;
5
5
  export type Unstable_RenderRsc = (elements: Elements, options?: {
6
6
  value?: unknown;
7
7
  etags?: Etags;
8
+ documentLocation?: string;
8
9
  unstable_clientModuleCallback?: (ids: string[]) => void;
9
10
  }) => Promise<ReadableStream>;
10
- export type Unstable_ParseRsc = (rscStream: ReadableStream) => Promise<Elements>;
11
11
  export type Unstable_RenderHtml = (elementsStream: ReadableStream, html: ReactNode, options: {
12
12
  rscPath: string;
13
13
  formState?: unknown;
@@ -17,31 +17,33 @@ export type Unstable_RenderHtml = (elementsStream: ReadableStream, html: ReactNo
17
17
  }) => Promise<Response>;
18
18
  export type Unstable_EmitFile = (filePath: string, body: ReadableStream) => Promise<void>;
19
19
  export type Unstable_HandleRequest = (input: ({
20
- type: 'component';
20
+ type: 'rsc';
21
21
  rscPath: string;
22
22
  rscParams: unknown;
23
23
  } | {
24
- type: 'function';
24
+ type: 'call';
25
25
  fn: (...args: unknown[]) => Promise<unknown>;
26
26
  args: unknown[];
27
27
  } | {
28
- type: 'action';
29
- fn: () => Promise<unknown>;
30
- } | {
31
- type: 'custom';
28
+ type: 'http';
29
+ tryAction?: () => Promise<{
30
+ action: true;
31
+ formState: unknown;
32
+ } | {
33
+ action: false;
34
+ formData: FormData;
35
+ }>;
32
36
  }) & {
33
37
  pathname: string;
34
38
  req: Request;
35
39
  etags?: Etags;
36
40
  }, utils: {
37
41
  renderRsc: Unstable_RenderRsc;
38
- parseRsc: Unstable_ParseRsc;
39
42
  renderHtml: Unstable_RenderHtml;
40
43
  loadBuildMetadata: (key: string) => Promise<string | undefined>;
41
44
  }) => Promise<ReadableStream | Response | 'fallback' | null | undefined>;
42
45
  export type Unstable_HandleBuild = (utils: {
43
46
  renderRsc: Unstable_RenderRsc;
44
- parseRsc: Unstable_ParseRsc;
45
47
  renderHtml: Unstable_RenderHtml;
46
48
  rscPath2pathname: (rscPath: string) => string;
47
49
  saveBuildMetadata: (key: string, value: string) => Promise<void>;
@@ -71,7 +73,7 @@ export type Unstable_CreateServerEntryAdapter = <Options>(fn: (args: {
71
73
  handlers: Unstable_Handlers;
72
74
  processRequest: Unstable_ProcessRequest;
73
75
  processBuild: Unstable_ProcessBuild;
74
- setAllEnv: (newEnv: Readonly<Record<string, unknown>>) => void;
76
+ unstable_setAllEnv: (newEnv: Readonly<Record<string, unknown>>) => void;
75
77
  config: Omit<Required<Config>, 'vite'>;
76
78
  isBuild: boolean;
77
79
  notFoundHtml: string;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/types.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport type { Config } from '../config.js';\nimport type { Etags } from './utils/etags.js';\n\ntype Elements = Record<string, unknown>;\n\nexport type Unstable_RenderRsc = (\n elements: Elements,\n options?: {\n value?: unknown;\n etags?: Etags;\n unstable_clientModuleCallback?: (ids: string[]) => void;\n },\n) => Promise<ReadableStream>;\n\nexport type Unstable_ParseRsc = (\n rscStream: ReadableStream,\n) => Promise<Elements>;\n\nexport type Unstable_RenderHtml = (\n elementsStream: ReadableStream,\n html: ReactNode,\n options: {\n rscPath: string;\n formState?: unknown;\n status?: number;\n nonce?: string;\n unstable_extraScriptContent?: string;\n },\n) => Promise<Response>;\n\nexport type Unstable_EmitFile = (\n filePath: string,\n body: ReadableStream,\n) => Promise<void>;\n\nexport type Unstable_HandleRequest = (\n input: (\n | { type: 'component'; rscPath: string; rscParams: unknown }\n | {\n type: 'function';\n fn: (...args: unknown[]) => Promise<unknown>;\n args: unknown[];\n }\n | {\n type: 'action';\n fn: () => Promise<unknown>;\n }\n | { type: 'custom' }\n ) & {\n pathname: string;\n req: Request;\n etags?: Etags;\n },\n utils: {\n renderRsc: Unstable_RenderRsc;\n parseRsc: Unstable_ParseRsc;\n renderHtml: Unstable_RenderHtml;\n loadBuildMetadata: (key: string) => Promise<string | undefined>;\n },\n) => Promise<ReadableStream | Response | 'fallback' | null | undefined>;\n\nexport type Unstable_HandleBuild = (utils: {\n renderRsc: Unstable_RenderRsc;\n parseRsc: Unstable_ParseRsc;\n renderHtml: Unstable_RenderHtml;\n rscPath2pathname: (rscPath: string) => string;\n saveBuildMetadata: (key: string, value: string) => Promise<void>;\n generateFile: (\n fileName: string,\n body: ReadableStream | string,\n ) => Promise<void>;\n generateDefaultHtml: (fileName: string) => Promise<void>;\n unstable_registerPrunableFile: (srcPath: string) => void;\n}) => Promise<void>;\n\nexport type Unstable_Handlers = {\n handleRequest: Unstable_HandleRequest;\n handleBuild: Unstable_HandleBuild;\n [someOtherProperty: string]: unknown;\n};\n\nexport type Unstable_ServerEntry = {\n fetch: (req: Request, ...args: any[]) => Response | Promise<Response>;\n build: (\n utils: {\n emitFile: Unstable_EmitFile;\n unstable_registerPrunableFile: (srcPath: string) => void;\n },\n ...args: any[]\n ) => Promise<void>;\n buildOptions?: Record<string, unknown>;\n buildEnhancers?: string[]; // enhancer module ids\n defaultExport?: unknown;\n [someOtherProperty: string]: unknown;\n};\n\nexport type Unstable_ProcessRequest = (\n arg: Parameters<Unstable_ServerEntry['fetch']>[0],\n) => Promise<Response | null>;\n\nexport type Unstable_ProcessBuild = (\n arg: Parameters<Unstable_ServerEntry['build']>[0],\n) => Promise<void>;\n\nexport type Unstable_CreateServerEntryAdapter = <Options>(\n fn: (\n args: {\n handlers: Unstable_Handlers;\n processRequest: Unstable_ProcessRequest;\n processBuild: Unstable_ProcessBuild;\n setAllEnv: (newEnv: Readonly<Record<string, unknown>>) => void;\n config: Omit<Required<Config>, 'vite'>;\n isBuild: boolean;\n notFoundHtml: string;\n },\n options?: Options,\n ) => Unstable_ServerEntry,\n) => (handlers: Unstable_Handlers, options?: Options) => Unstable_ServerEntry;\n"],"names":[],"mappings":"AAyGA,WAa8E"}
1
+ {"version":3,"sources":["../../src/lib/types.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport type { Config } from '../config.js';\nimport type { Etags } from './utils/etags.js';\n\ntype Elements = Record<string, unknown>;\n\nexport type Unstable_RenderRsc = (\n elements: Elements,\n options?: {\n value?: unknown;\n etags?: Etags;\n documentLocation?: string;\n unstable_clientModuleCallback?: (ids: string[]) => void;\n },\n) => Promise<ReadableStream>;\n\nexport type Unstable_RenderHtml = (\n elementsStream: ReadableStream,\n html: ReactNode,\n options: {\n rscPath: string;\n formState?: unknown;\n status?: number;\n nonce?: string;\n unstable_extraScriptContent?: string;\n },\n) => Promise<Response>;\n\nexport type Unstable_EmitFile = (\n filePath: string,\n body: ReadableStream,\n) => Promise<void>;\n\nexport type Unstable_HandleRequest = (\n input: (\n | { type: 'rsc'; rscPath: string; rscParams: unknown }\n | {\n type: 'call';\n fn: (...args: unknown[]) => Promise<unknown>;\n args: unknown[];\n }\n | {\n type: 'http';\n tryAction?: () => Promise<\n | { action: true; formState: unknown }\n | { action: false; formData: FormData }\n >;\n }\n ) & {\n pathname: string;\n req: Request;\n etags?: Etags;\n },\n utils: {\n renderRsc: Unstable_RenderRsc;\n renderHtml: Unstable_RenderHtml;\n loadBuildMetadata: (key: string) => Promise<string | undefined>;\n },\n) => Promise<ReadableStream | Response | 'fallback' | null | undefined>;\n\nexport type Unstable_HandleBuild = (utils: {\n renderRsc: Unstable_RenderRsc;\n renderHtml: Unstable_RenderHtml;\n rscPath2pathname: (rscPath: string) => string;\n saveBuildMetadata: (key: string, value: string) => Promise<void>;\n generateFile: (\n fileName: string,\n body: ReadableStream | string,\n ) => Promise<void>;\n generateDefaultHtml: (fileName: string) => Promise<void>;\n unstable_registerPrunableFile: (srcPath: string) => void;\n}) => Promise<void>;\n\nexport type Unstable_Handlers = {\n handleRequest: Unstable_HandleRequest;\n handleBuild: Unstable_HandleBuild;\n [someOtherProperty: string]: unknown;\n};\n\nexport type Unstable_ServerEntry = {\n fetch: (req: Request, ...args: any[]) => Response | Promise<Response>;\n build: (\n utils: {\n emitFile: Unstable_EmitFile;\n unstable_registerPrunableFile: (srcPath: string) => void;\n },\n ...args: any[]\n ) => Promise<void>;\n buildOptions?: Record<string, unknown>;\n buildEnhancers?: string[]; // enhancer module ids\n defaultExport?: unknown;\n [someOtherProperty: string]: unknown;\n};\n\nexport type Unstable_ProcessRequest = (\n arg: Parameters<Unstable_ServerEntry['fetch']>[0],\n) => Promise<Response | null>;\n\nexport type Unstable_ProcessBuild = (\n arg: Parameters<Unstable_ServerEntry['build']>[0],\n) => Promise<void>;\n\nexport type Unstable_CreateServerEntryAdapter = <Options>(\n fn: (\n args: {\n handlers: Unstable_Handlers;\n processRequest: Unstable_ProcessRequest;\n processBuild: Unstable_ProcessBuild;\n unstable_setAllEnv: (newEnv: Readonly<Record<string, unknown>>) => void;\n config: Omit<Required<Config>, 'vite'>;\n isBuild: boolean;\n notFoundHtml: string;\n },\n options?: Options,\n ) => Unstable_ServerEntry,\n) => (handlers: Unstable_Handlers, options?: Options) => Unstable_ServerEntry;\n"],"names":[],"mappings":"AAsGA,WAa8E"}
@@ -1,6 +1,8 @@
1
1
  type ErrorInfo = {
2
2
  status?: number;
3
3
  location?: string;
4
+ unstable_leave?: boolean;
5
+ unstable_networkError?: boolean;
4
6
  };
5
7
  export declare const createCustomError: (message: string, errorInfo: ErrorInfo) => Error;
6
8
  export declare const getErrorInfo: (err: unknown) => ErrorInfo | null;
@@ -8,6 +8,12 @@ const isErrorInfo = (x)=>{
8
8
  if ('location' in x && typeof x.location !== 'string') {
9
9
  return false;
10
10
  }
11
+ if ('unstable_leave' in x && typeof x.unstable_leave !== 'boolean') {
12
+ return false;
13
+ }
14
+ if ('unstable_networkError' in x && typeof x.unstable_networkError !== 'boolean') {
15
+ return false;
16
+ }
11
17
  return true;
12
18
  };
13
19
  const prefix = '__WAKU_CUSTOM_ERROR__;';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/utils/custom-errors.ts"],"sourcesContent":["type ErrorInfo = {\n status?: number;\n location?: string;\n};\n\nconst isErrorInfo = (x: unknown): x is ErrorInfo => {\n if (typeof x !== 'object' || x === null) {\n return false;\n }\n if ('status' in x && typeof (x as ErrorInfo).status !== 'number') {\n return false;\n }\n if ('location' in x && typeof (x as ErrorInfo).location !== 'string') {\n return false;\n }\n return true;\n};\n\nconst prefix = '__WAKU_CUSTOM_ERROR__;';\n\n// This is an internal API and not for public use\nexport const createCustomError = (message: string, errorInfo: ErrorInfo) => {\n const err = new Error(message);\n (err as { digest?: string }).digest = prefix + JSON.stringify(errorInfo);\n return err;\n};\n\nexport const getErrorInfo = (err: unknown) => {\n const digest = (err as { digest?: string } | undefined)?.digest;\n if (typeof digest !== 'string' || !digest.startsWith(prefix)) {\n return null;\n }\n try {\n const info = JSON.parse(digest.slice(prefix.length));\n if (isErrorInfo(info)) {\n return info;\n }\n } catch {\n // ignore\n }\n return null;\n};\n"],"names":["isErrorInfo","x","status","location","prefix","createCustomError","message","errorInfo","err","Error","digest","JSON","stringify","getErrorInfo","startsWith","info","parse","slice","length"],"mappings":"AAKA,MAAMA,cAAc,CAACC;IACnB,IAAI,OAAOA,MAAM,YAAYA,MAAM,MAAM;QACvC,OAAO;IACT;IACA,IAAI,YAAYA,KAAK,OAAO,AAACA,EAAgBC,MAAM,KAAK,UAAU;QAChE,OAAO;IACT;IACA,IAAI,cAAcD,KAAK,OAAO,AAACA,EAAgBE,QAAQ,KAAK,UAAU;QACpE,OAAO;IACT;IACA,OAAO;AACT;AAEA,MAAMC,SAAS;AAEf,iDAAiD;AACjD,OAAO,MAAMC,oBAAoB,CAACC,SAAiBC;IACjD,MAAMC,MAAM,IAAIC,MAAMH;IACrBE,IAA4BE,MAAM,GAAGN,SAASO,KAAKC,SAAS,CAACL;IAC9D,OAAOC;AACT,EAAE;AAEF,OAAO,MAAMK,eAAe,CAACL;IAC3B,MAAME,SAAUF,KAAyCE;IACzD,IAAI,OAAOA,WAAW,YAAY,CAACA,OAAOI,UAAU,CAACV,SAAS;QAC5D,OAAO;IACT;IACA,IAAI;QACF,MAAMW,OAAOJ,KAAKK,KAAK,CAACN,OAAOO,KAAK,CAACb,OAAOc,MAAM;QAClD,IAAIlB,YAAYe,OAAO;YACrB,OAAOA;QACT;IACF,EAAE,OAAM;IACN,SAAS;IACX;IACA,OAAO;AACT,EAAE"}
1
+ {"version":3,"sources":["../../../src/lib/utils/custom-errors.ts"],"sourcesContent":["type ErrorInfo = {\n status?: number;\n location?: string;\n unstable_leave?: boolean;\n // set by the client, read by no one in waku: an app decides its own recovery\n unstable_networkError?: boolean;\n};\n\nconst isErrorInfo = (x: unknown): x is ErrorInfo => {\n if (typeof x !== 'object' || x === null) {\n return false;\n }\n if ('status' in x && typeof (x as ErrorInfo).status !== 'number') {\n return false;\n }\n if ('location' in x && typeof (x as ErrorInfo).location !== 'string') {\n return false;\n }\n if (\n 'unstable_leave' in x &&\n typeof (x as ErrorInfo).unstable_leave !== 'boolean'\n ) {\n return false;\n }\n if (\n 'unstable_networkError' in x &&\n typeof (x as ErrorInfo).unstable_networkError !== 'boolean'\n ) {\n return false;\n }\n return true;\n};\n\nconst prefix = '__WAKU_CUSTOM_ERROR__;';\n\n// This is an internal API and not for public use\nexport const createCustomError = (message: string, errorInfo: ErrorInfo) => {\n const err = new Error(message);\n (err as { digest?: string }).digest = prefix + JSON.stringify(errorInfo);\n return err;\n};\n\nexport const getErrorInfo = (err: unknown) => {\n const digest = (err as { digest?: string } | undefined)?.digest;\n if (typeof digest !== 'string' || !digest.startsWith(prefix)) {\n return null;\n }\n try {\n const info = JSON.parse(digest.slice(prefix.length));\n if (isErrorInfo(info)) {\n return info;\n }\n } catch {\n // ignore\n }\n return null;\n};\n"],"names":["isErrorInfo","x","status","location","unstable_leave","unstable_networkError","prefix","createCustomError","message","errorInfo","err","Error","digest","JSON","stringify","getErrorInfo","startsWith","info","parse","slice","length"],"mappings":"AAQA,MAAMA,cAAc,CAACC;IACnB,IAAI,OAAOA,MAAM,YAAYA,MAAM,MAAM;QACvC,OAAO;IACT;IACA,IAAI,YAAYA,KAAK,OAAO,AAACA,EAAgBC,MAAM,KAAK,UAAU;QAChE,OAAO;IACT;IACA,IAAI,cAAcD,KAAK,OAAO,AAACA,EAAgBE,QAAQ,KAAK,UAAU;QACpE,OAAO;IACT;IACA,IACE,oBAAoBF,KACpB,OAAO,AAACA,EAAgBG,cAAc,KAAK,WAC3C;QACA,OAAO;IACT;IACA,IACE,2BAA2BH,KAC3B,OAAO,AAACA,EAAgBI,qBAAqB,KAAK,WAClD;QACA,OAAO;IACT;IACA,OAAO;AACT;AAEA,MAAMC,SAAS;AAEf,iDAAiD;AACjD,OAAO,MAAMC,oBAAoB,CAACC,SAAiBC;IACjD,MAAMC,MAAM,IAAIC,MAAMH;IACrBE,IAA4BE,MAAM,GAAGN,SAASO,KAAKC,SAAS,CAACL;IAC9D,OAAOC;AACT,EAAE;AAEF,OAAO,MAAMK,eAAe,CAACL;IAC3B,MAAME,SAAUF,KAAyCE;IACzD,IAAI,OAAOA,WAAW,YAAY,CAACA,OAAOI,UAAU,CAACV,SAAS;QAC5D,OAAO;IACT;IACA,IAAI;QACF,MAAMW,OAAOJ,KAAKK,KAAK,CAACN,OAAOO,KAAK,CAACb,OAAOc,MAAM;QAClD,IAAIpB,YAAYiB,OAAO;YACrB,OAAOA;QACT;IACF,EAAE,OAAM;IACN,SAAS;IACX;IACA,OAAO;AACT,EAAE"}
@@ -1,4 +1,5 @@
1
1
  const IGNORED_PATH_PARTS = new Set([
2
+ '_actions',
2
3
  '_components',
3
4
  '_hooks'
4
5
  ]);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/utils/fs-router.ts"],"sourcesContent":["const IGNORED_PATH_PARTS = new Set(['_components', '_hooks']);\n\n/** Ignore paths like `_components` and `_hooks` in pages dir */\nexport const isIgnoredPath = (paths: string[]) =>\n paths.some((p) => IGNORED_PATH_PARTS.has(p));\n"],"names":["IGNORED_PATH_PARTS","Set","isIgnoredPath","paths","some","p","has"],"mappings":"AAAA,MAAMA,qBAAqB,IAAIC,IAAI;IAAC;IAAe;CAAS;AAE5D,8DAA8D,GAC9D,OAAO,MAAMC,gBAAgB,CAACC,QAC5BA,MAAMC,IAAI,CAAC,CAACC,IAAML,mBAAmBM,GAAG,CAACD,IAAI"}
1
+ {"version":3,"sources":["../../../src/lib/utils/fs-router.ts"],"sourcesContent":["const IGNORED_PATH_PARTS = new Set(['_actions', '_components', '_hooks']);\n\n/** Ignore paths like `_components` and `_hooks` in pages dir */\nexport const isIgnoredPath = (paths: string[]) =>\n paths.some((p) => IGNORED_PATH_PARTS.has(p));\n"],"names":["IGNORED_PATH_PARTS","Set","isIgnoredPath","paths","some","p","has"],"mappings":"AAAA,MAAMA,qBAAqB,IAAIC,IAAI;IAAC;IAAY;IAAe;CAAS;AAExE,8DAA8D,GAC9D,OAAO,MAAMC,gBAAgB,CAACC,QAC5BA,MAAMC,IAAI,CAAC,CAACC,IAAML,mBAAmBM,GAAG,CAACD,IAAI"}
@@ -1,4 +1,11 @@
1
1
  // This file should not include Node specific code.
2
+ // TODO: this WS debug channel keeps dev payloads lean by offloading React's
3
+ // Server Components debug info (component stacks, timing, console, async
4
+ // metadata) out of the main Flight stream. Our transport is bespoke: paired
5
+ // HMR events here plus the debug-id header hack in rsc-devtools.ts. Waku is
6
+ // cited as prior art for a shared @vitejs/plugin-rsc debug-channel example
7
+ // (https://github.com/vitejs/vite-plugin-react/issues/1306). Once that lands,
8
+ // consider adopting it so we can delete our own transport and rsc-devtools.ts.
2
9
  import { base64ToBytes, bytesToBase64 } from './base64-web.js';
3
10
  export const DEBUG_ID_HEADER = 'X-Waku-Debug-Id';
4
11
  export const DEBUG_CMD_EVENT = 'waku:debug-cmd';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/utils/react-debug-channel.ts"],"sourcesContent":["// This file should not include Node specific code.\n\nimport { base64ToBytes, bytesToBase64 } from './base64-web.js';\n\nexport const DEBUG_ID_HEADER = 'X-Waku-Debug-Id';\nexport const DEBUG_CMD_EVENT = 'waku:debug-cmd';\nexport const DEBUG_DATA_EVENT = 'waku:debug-data';\n\ntype DebugCmdEventReadyPayload = {\n i: string; // debugId\n};\ntype DebugCmdEventChunkPayload = {\n i: string; // debugId\n b: string; // base64 encoded chunk\n};\ntype DebugCmdEventDonePayload = {\n i: string; // debugId\n d: true; // done flag\n};\ntype DebugDataEventChunkPayload = {\n i: string; // debugId\n b: string; // base64 encoded chunk\n};\ntype DebugDataEventDonePayload = {\n i: string; // debugId\n d: true; // done flag\n};\nexport type DebugEventPayload =\n | DebugCmdEventReadyPayload\n | DebugCmdEventChunkPayload\n | DebugCmdEventDonePayload\n | DebugDataEventChunkPayload\n | DebugDataEventDonePayload;\n\nexport function assertIsDebugEventPayload(\n payload: unknown,\n): asserts payload is DebugEventPayload {\n if (\n !payload ||\n typeof payload !== 'object' ||\n typeof (payload as { i?: unknown }).i !== 'string' ||\n ('b' in payload && typeof (payload as { b?: unknown }).b !== 'string') ||\n ('d' in payload && (payload as { d?: unknown }).d !== true)\n ) {\n throw new Error('Invalid debug event payload');\n }\n}\n\nconst createWsDebugChannel = (debugId: string) => {\n const hot = import.meta.hot!;\n let closed = false;\n let onDataEvent: ((payload: unknown) => void) | undefined;\n\n const cleanup = (notify?: boolean) => {\n if (closed) {\n return;\n }\n closed = true;\n if (onDataEvent) {\n hot.off(DEBUG_DATA_EVENT, onDataEvent);\n }\n if (notify) {\n hot.send(DEBUG_CMD_EVENT, {\n i: debugId,\n d: true,\n } satisfies DebugEventPayload);\n }\n };\n\n const readable = new ReadableStream<Uint8Array>({\n start(controller) {\n onDataEvent = (payload: unknown) => {\n assertIsDebugEventPayload(payload);\n if (closed || payload.i !== debugId) {\n return;\n }\n if ('b' in payload) {\n // chunk\n controller.enqueue(base64ToBytes(payload.b));\n }\n if ('d' in payload) {\n // done\n cleanup();\n controller.close();\n }\n };\n hot.on(DEBUG_DATA_EVENT, onDataEvent);\n hot.send(DEBUG_CMD_EVENT, { i: debugId } satisfies DebugEventPayload);\n },\n cancel() {\n cleanup(true);\n },\n });\n\n const writable = new WritableStream<Uint8Array>({\n write(chunk) {\n if (closed) {\n throw new Error('Channel is closed');\n }\n hot.send(DEBUG_CMD_EVENT, {\n i: debugId,\n b: bytesToBase64(chunk),\n } satisfies DebugEventPayload);\n },\n close() {\n cleanup(true);\n },\n abort() {\n cleanup(true);\n },\n });\n\n return { readable, writable };\n};\n\nexport const setupDebugChannel = (\n baseFetchFn: typeof fetch,\n prefetched: boolean,\n debugId?: string,\n) => {\n if (prefetched) {\n if (debugId) {\n const debugChannel = createWsDebugChannel(debugId);\n return { debugChannel };\n }\n return {};\n }\n\n const newDebugId = crypto.randomUUID();\n const debugChannel = createWsDebugChannel(newDebugId);\n const fetchFn = ((input: RequestInfo | URL, init?: RequestInit) => {\n const headers = new Headers(init?.headers);\n headers.set(DEBUG_ID_HEADER, newDebugId);\n return baseFetchFn(input, {\n ...init,\n headers,\n });\n }) as typeof fetch;\n return { fetchFn, debugChannel };\n};\n"],"names":["base64ToBytes","bytesToBase64","DEBUG_ID_HEADER","DEBUG_CMD_EVENT","DEBUG_DATA_EVENT","assertIsDebugEventPayload","payload","i","b","d","Error","createWsDebugChannel","debugId","hot","closed","onDataEvent","cleanup","notify","off","send","readable","ReadableStream","start","controller","enqueue","close","on","cancel","writable","WritableStream","write","chunk","abort","setupDebugChannel","baseFetchFn","prefetched","debugChannel","newDebugId","crypto","randomUUID","fetchFn","input","init","headers","Headers","set"],"mappings":"AAAA,mDAAmD;AAEnD,SAASA,aAAa,EAAEC,aAAa,QAAQ,kBAAkB;AAE/D,OAAO,MAAMC,kBAAkB,kBAAkB;AACjD,OAAO,MAAMC,kBAAkB,iBAAiB;AAChD,OAAO,MAAMC,mBAAmB,kBAAkB;AA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AAQ;QACV;QACAgB;YACEhB,QAAQ;QACV;IACF;IAEA,OAAO;QAAEI;QAAUQ;IAAS;AAC9B;AAEA,OAAO,MAAMK,oBAAoB,CAC/BC,aACAC,YACAvB;IAEA,IAAIuB,YAAY;QACd,IAAIvB,SAAS;YACX,MAAMwB,eAAezB,qBAAqBC;YAC1C,OAAO;gBAAEwB;YAAa;QACxB;QACA,OAAO,CAAC;IACV;IAEA,MAAMC,aAAaC,OAAOC,UAAU;IACpC,MAAMH,eAAezB,qBAAqB0B;IAC1C,MAAMG,UAAW,CAACC,OAA0BC;QAC1C,MAAMC,UAAU,IAAIC,QAAQF,MAAMC;QAClCA,QAAQE,GAAG,CAAC3C,iBAAiBmC;QAC7B,OAAOH,YAAYO,OAAO;YACxB,GAAGC,IAAI;YACPC;QACF;IACF;IACA,OAAO;QAAEH;QAASJ;IAAa;AACjC,EAAE"}
1
+ {"version":3,"sources":["../../../src/lib/utils/react-debug-channel.ts"],"sourcesContent":["// This file should not include Node specific code.\n\n// TODO: this WS debug channel keeps dev payloads lean by offloading React's\n// Server Components debug info (component stacks, timing, console, async\n// metadata) out of the main Flight stream. Our transport is bespoke: paired\n// HMR events here plus the debug-id header hack in rsc-devtools.ts. Waku is\n// cited as prior art for a shared @vitejs/plugin-rsc debug-channel example\n// (https://github.com/vitejs/vite-plugin-react/issues/1306). Once that lands,\n// consider adopting it so we can delete our own transport and rsc-devtools.ts.\n\nimport { base64ToBytes, bytesToBase64 } from './base64-web.js';\n\nexport const DEBUG_ID_HEADER = 'X-Waku-Debug-Id';\nexport const DEBUG_CMD_EVENT = 'waku:debug-cmd';\nexport const DEBUG_DATA_EVENT = 'waku:debug-data';\n\ntype DebugCmdEventReadyPayload = {\n i: string; // debugId\n};\ntype DebugCmdEventChunkPayload = {\n i: string; // debugId\n b: string; // base64 encoded chunk\n};\ntype DebugCmdEventDonePayload = {\n i: string; // debugId\n d: true; // done flag\n};\ntype DebugDataEventChunkPayload = {\n i: string; // debugId\n b: string; // base64 encoded chunk\n};\ntype DebugDataEventDonePayload = {\n i: string; // debugId\n d: true; // done flag\n};\nexport type DebugEventPayload =\n | DebugCmdEventReadyPayload\n | DebugCmdEventChunkPayload\n | DebugCmdEventDonePayload\n | DebugDataEventChunkPayload\n | DebugDataEventDonePayload;\n\nexport function assertIsDebugEventPayload(\n payload: unknown,\n): asserts payload is DebugEventPayload {\n if (\n !payload ||\n typeof payload !== 'object' ||\n typeof (payload as { i?: unknown }).i !== 'string' ||\n ('b' in payload && typeof (payload as { b?: unknown }).b !== 'string') ||\n ('d' in payload && (payload as { d?: unknown }).d !== true)\n ) {\n throw new Error('Invalid debug event payload');\n }\n}\n\nconst createWsDebugChannel = (debugId: string) => {\n const hot = import.meta.hot!;\n let closed = false;\n let onDataEvent: ((payload: unknown) => void) | undefined;\n\n const cleanup = (notify?: boolean) => {\n if (closed) {\n return;\n }\n closed = true;\n if (onDataEvent) {\n hot.off(DEBUG_DATA_EVENT, onDataEvent);\n }\n if (notify) {\n hot.send(DEBUG_CMD_EVENT, {\n i: debugId,\n d: true,\n } satisfies DebugEventPayload);\n }\n };\n\n const readable = new ReadableStream<Uint8Array>({\n start(controller) {\n onDataEvent = (payload: unknown) => {\n assertIsDebugEventPayload(payload);\n if (closed || payload.i !== debugId) {\n return;\n }\n if ('b' in payload) {\n // chunk\n controller.enqueue(base64ToBytes(payload.b));\n }\n if ('d' in payload) {\n // done\n cleanup();\n controller.close();\n }\n };\n hot.on(DEBUG_DATA_EVENT, onDataEvent);\n hot.send(DEBUG_CMD_EVENT, { i: debugId } satisfies DebugEventPayload);\n },\n cancel() {\n cleanup(true);\n },\n });\n\n const writable = new WritableStream<Uint8Array>({\n write(chunk) {\n if (closed) {\n throw new Error('Channel is closed');\n }\n hot.send(DEBUG_CMD_EVENT, {\n i: debugId,\n b: bytesToBase64(chunk),\n } satisfies DebugEventPayload);\n },\n close() {\n cleanup(true);\n },\n abort() {\n cleanup(true);\n },\n });\n\n return { readable, writable };\n};\n\nexport const setupDebugChannel = (\n baseFetchFn: typeof fetch,\n prefetched: boolean,\n debugId?: string,\n) => {\n if (prefetched) {\n if (debugId) {\n const debugChannel = createWsDebugChannel(debugId);\n return { debugChannel };\n }\n return {};\n }\n\n const newDebugId = crypto.randomUUID();\n const debugChannel = createWsDebugChannel(newDebugId);\n const fetchFn = ((input: RequestInfo | URL, init?: RequestInit) => {\n const headers = new Headers(init?.headers);\n headers.set(DEBUG_ID_HEADER, newDebugId);\n return baseFetchFn(input, {\n ...init,\n headers,\n });\n }) as typeof fetch;\n return { fetchFn, debugChannel };\n};\n"],"names":["base64ToBytes","bytesToBase64","DEBUG_ID_HEADER","DEBUG_CMD_EVENT","DEBUG_DATA_EVENT","assertIsDebugEventPayload","payload","i","b","d","Error","createWsDebugChannel","debugId","hot","closed","onDataEvent","cleanup","notify","off","send","readable","ReadableStream","start","controller","enqueue","close","on","cancel","writable","WritableStream","write","chunk","abort","setupDebugChannel","baseFetchFn","prefetched","debugChannel","newDebugId","crypto","randomUUID","fetchFn","input","init","headers","Headers","set"],"mappings":"AAAA,mDAAmD;AAEnD,4EAA4E;AAC5E,yEAAyE;AACzE,4EAA4E;AAC5E,4EAA4E;AAC5E,2EAA2E;AAC3E,8EAA8E;AAC9E,+EAA+E;AAE/E,SAASA,aAAa,EAAEC,aAAa,QAAQ,kBAAkB;AAE/D,OAAO,MAAMC,kBAAkB,kBAAkB;AACjD,OAAO,MAAMC,kBAAkB,iBAAiB;AAChD,OAAO,MAAMC,mBAAmB,kBAAkB;AA4BlD,OAAO,SAASC,0BACdC,OAAgB;IAEhB,IACE,CAACA,WACD,OAAOA,YAAY,YACnB,OAAO,AAACA,QAA4BC,CAAC,KAAK,YACzC,OAAOD,WAAW,OAAO,AAACA,QAA4BE,CAAC,KAAK,YAC5D,OAAOF,WAAW,AAACA,QAA4BG,CAAC,KAAK,MACtD;QACA,MAAM,IAAIC,MAAM;IAClB;AACF;AAEA,MAAMC,uBAAuB,CAACC;IAC5B,MAAMC,MAAM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ACpC,MAAMH,eAAezB,qBAAqB0B;IAC1C,MAAMG,UAAW,CAACC,OAA0BC;QAC1C,MAAMC,UAAU,IAAIC,QAAQF,MAAMC;QAClCA,QAAQE,GAAG,CAAC3C,iBAAiBmC;QAC7B,OAAOH,YAAYO,OAAO;YACxB,GAAGC,IAAI;YACPC;QACF;IACF;IACA,OAAO;QAAEH;QAASJ;IAAa;AACjC,EAAE"}
@@ -0,0 +1 @@
1
+ export declare const resolveRedirectLocation: (location: string, requestUrl: string, basePath: string) => string | undefined;
@@ -0,0 +1,45 @@
1
+ import { addBase } from './path.js';
2
+ const hasControlCharacter = (value)=>[
3
+ ...value
4
+ ].some((char)=>char < ' ' || char === '\u007f');
5
+ const getLocationType = (location)=>{
6
+ if (/^[a-z][a-z\d+.-]*:/i.test(location)) {
7
+ return 'absolute';
8
+ }
9
+ if (location.startsWith('//')) {
10
+ return 'authority';
11
+ }
12
+ return location.startsWith('/') ? 'appPath' : 'relative';
13
+ };
14
+ export const resolveRedirectLocation = (location, requestUrl, basePath)=>{
15
+ // a header strips these, so classify what will actually be sent
16
+ location = location.trim();
17
+ const locationType = getLocationType(location);
18
+ if (locationType === 'relative') {
19
+ return hasControlCharacter(location) ? undefined : location;
20
+ }
21
+ const request = new URL(requestUrl);
22
+ let target;
23
+ try {
24
+ target = new URL(location, request);
25
+ } catch {
26
+ return undefined;
27
+ }
28
+ if (target.protocol !== 'http:' && target.protocol !== 'https:') {
29
+ return undefined;
30
+ }
31
+ target.username = '';
32
+ target.password = '';
33
+ const path = target.pathname + target.search + target.hash;
34
+ if (target.host !== request.host) {
35
+ return locationType === 'absolute' ? target.href : '//' + target.host + path;
36
+ }
37
+ // requestUrl takes its scheme from the socket, so http from there is no
38
+ // evidence that the browser is on http
39
+ if (locationType === 'absolute' && target.protocol === 'https:') {
40
+ return target.href;
41
+ }
42
+ return locationType === 'appPath' ? addBase(path, basePath) : path;
43
+ };
44
+
45
+ //# sourceMappingURL=redirect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/utils/redirect.ts"],"sourcesContent":["import { addBase } from './path.js';\n\nconst hasControlCharacter = (value: string) =>\n [...value].some((char) => char < ' ' || char === '\\u007f');\n\nconst getLocationType = (location: string) => {\n if (/^[a-z][a-z\\d+.-]*:/i.test(location)) {\n return 'absolute' as const;\n }\n if (location.startsWith('//')) {\n return 'authority' as const;\n }\n return location.startsWith('/')\n ? ('appPath' as const)\n : ('relative' as const);\n};\n\nexport const resolveRedirectLocation = (\n location: string,\n requestUrl: string,\n basePath: string,\n): string | undefined => {\n // a header strips these, so classify what will actually be sent\n location = location.trim();\n const locationType = getLocationType(location);\n if (locationType === 'relative') {\n return hasControlCharacter(location) ? undefined : location;\n }\n const request = new URL(requestUrl);\n let target: URL;\n try {\n target = new URL(location, request);\n } catch {\n return undefined;\n }\n if (target.protocol !== 'http:' && target.protocol !== 'https:') {\n return undefined;\n }\n target.username = '';\n target.password = '';\n const path = target.pathname + target.search + target.hash;\n if (target.host !== request.host) {\n return locationType === 'absolute'\n ? target.href\n : '//' + target.host + path;\n }\n // requestUrl takes its scheme from the socket, so http from there is no\n // evidence that the browser is on http\n if (locationType === 'absolute' && target.protocol === 'https:') {\n return target.href;\n }\n return locationType === 'appPath' ? addBase(path, basePath) : path;\n};\n"],"names":["addBase","hasControlCharacter","value","some","char","getLocationType","location","test","startsWith","resolveRedirectLocation","requestUrl","basePath","trim","locationType","undefined","request","URL","target","protocol","username","password","path","pathname","search","hash","host","href"],"mappings":"AAAA,SAASA,OAAO,QAAQ,YAAY;AAEpC,MAAMC,sBAAsB,CAACC,QAC3B;WAAIA;KAAM,CAACC,IAAI,CAAC,CAACC,OAASA,OAAO,OAAOA,SAAS;AAEnD,MAAMC,kBAAkB,CAACC;IACvB,IAAI,sBAAsBC,IAAI,CAACD,WAAW;QACxC,OAAO;IACT;IACA,IAAIA,SAASE,UAAU,CAAC,OAAO;QAC7B,OAAO;IACT;IACA,OAAOF,SAASE,UAAU,CAAC,OACtB,YACA;AACP;AAEA,OAAO,MAAMC,0BAA0B,CACrCH,UACAI,YACAC;IAEA,gEAAgE;IAChEL,WAAWA,SAASM,IAAI;IACxB,MAAMC,eAAeR,gBAAgBC;IACrC,IAAIO,iBAAiB,YAAY;QAC/B,OAAOZ,oBAAoBK,YAAYQ,YAAYR;IACrD;IACA,MAAMS,UAAU,IAAIC,IAAIN;IACxB,IAAIO;IACJ,IAAI;QACFA,SAAS,IAAID,IAAIV,UAAUS;IAC7B,EAAE,OAAM;QACN,OAAOD;IACT;IACA,IAAIG,OAAOC,QAAQ,KAAK,WAAWD,OAAOC,QAAQ,KAAK,UAAU;QAC/D,OAAOJ;IACT;IACAG,OAAOE,QAAQ,GAAG;IAClBF,OAAOG,QAAQ,GAAG;IAClB,MAAMC,OAAOJ,OAAOK,QAAQ,GAAGL,OAAOM,MAAM,GAAGN,OAAOO,IAAI;IAC1D,IAAIP,OAAOQ,IAAI,KAAKV,QAAQU,IAAI,EAAE;QAChC,OAAOZ,iBAAiB,aACpBI,OAAOS,IAAI,GACX,OAAOT,OAAOQ,IAAI,GAAGJ;IAC3B;IACA,wEAAwE;IACxE,uCAAuC;IACvC,IAAIR,iBAAiB,cAAcI,OAAOC,QAAQ,KAAK,UAAU;QAC/D,OAAOD,OAAOS,IAAI;IACpB;IACA,OAAOb,iBAAiB,YAAYb,QAAQqB,MAAMV,YAAYU;AAChE,EAAE"}
@@ -1,9 +1,8 @@
1
- import type { Unstable_ParseRsc, Unstable_RenderHtml, Unstable_RenderRsc } from '../types.js';
2
- export declare function createRenderUtils(temporaryReferences: unknown, renderToReadableStream: (data: unknown, options?: object, extraOptions?: object) => ReadableStream, createFromReadableStream: (stream: ReadableStream, options?: object) => Promise<unknown>, loadSsrEntryModule: () => Promise<typeof import('../vite-entries/entry.ssr.js')>, buildId: string, debugChannel?: {
1
+ import type { Unstable_RenderHtml, Unstable_RenderRsc } from '../types.js';
2
+ export declare function createRenderUtils(temporaryReferences: unknown, renderToReadableStream: (data: unknown, options?: object, extraOptions?: object) => ReadableStream, loadSsrEntryModule: () => Promise<typeof import('../vite-entries/entry.ssr.js')>, buildId: string, debugChannel?: {
3
3
  readable?: ReadableStream;
4
4
  writable?: WritableStream;
5
5
  }, debugId?: string): {
6
6
  renderRsc: Unstable_RenderRsc;
7
- parseRsc: Unstable_ParseRsc;
8
7
  renderHtml: Unstable_RenderHtml;
9
8
  };
@@ -7,7 +7,7 @@ const validateRscElementIds = (elements)=>{
7
7
  }
8
8
  }
9
9
  };
10
- export function createRenderUtils(temporaryReferences, renderToReadableStream, createFromReadableStream, loadSsrEntryModule, buildId, debugChannel, debugId) {
10
+ export function createRenderUtils(temporaryReferences, renderToReadableStream, loadSsrEntryModule, buildId, debugChannel, debugId) {
11
11
  const onError = (e)=>{
12
12
  if (e && typeof e === 'object' && 'digest' in e && typeof e.digest === 'string') {
13
13
  return e.digest;
@@ -26,6 +26,9 @@ export function createRenderUtils(temporaryReferences, renderToReadableStream, c
26
26
  if (options && 'value' in options) {
27
27
  data._value = options.value;
28
28
  }
29
+ if (options?.documentLocation) {
30
+ data._location = options.documentLocation;
31
+ }
29
32
  if (options?.etags) {
30
33
  for (const [slotId, etag] of Object.entries(options.etags)){
31
34
  data[ETAG_ID_PREFIX + slotId] = etag;
@@ -41,9 +44,6 @@ export function createRenderUtils(temporaryReferences, renderToReadableStream, c
41
44
  }
42
45
  });
43
46
  },
44
- async parseRsc (stream) {
45
- return createFromReadableStream(stream, {});
46
- },
47
47
  async renderHtml (elementsStream, html, options) {
48
48
  const { INTERNAL_renderHtmlStream: renderHtmlStream } = await loadSsrEntryModule();
49
49
  const rscHtmlStream = renderToReadableStream(html, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/utils/render.ts"],"sourcesContent":["import type {\n Unstable_ParseRsc,\n Unstable_RenderHtml,\n Unstable_RenderRsc,\n} from '../types.js';\nimport { ETAG_ID_PREFIX } from './etags.js';\nimport { sanitizeLog } from './log.js';\n\nconst validateRscElementIds = (elements: Record<string, unknown>) => {\n for (const id of Object.keys(elements)) {\n if (id.startsWith('_')) {\n throw new Error(\n `RSC element IDs starting with \"_\" are reserved for Waku internals: ${id}`,\n );\n }\n }\n};\n\nexport function createRenderUtils(\n temporaryReferences: unknown,\n renderToReadableStream: (\n data: unknown,\n options?: object,\n extraOptions?: object,\n ) => ReadableStream,\n createFromReadableStream: (\n stream: ReadableStream,\n options?: object,\n ) => Promise<unknown>,\n loadSsrEntryModule: () => Promise<\n typeof import('../vite-entries/entry.ssr.js')\n >,\n buildId: string,\n debugChannel?: { readable?: ReadableStream; writable?: WritableStream },\n debugId?: string,\n): {\n renderRsc: Unstable_RenderRsc;\n parseRsc: Unstable_ParseRsc;\n renderHtml: Unstable_RenderHtml;\n} {\n const onError = (e: unknown) => {\n if (\n e &&\n typeof e === 'object' &&\n 'digest' in e &&\n typeof e.digest === 'string'\n ) {\n return e.digest;\n }\n console.error('Error during rendering:', sanitizeLog(e));\n };\n\n return {\n async renderRsc(elements, options) {\n validateRscElementIds(elements);\n const data: Record<string, unknown> = buildId\n ? { ...elements, _buildId: buildId }\n : { ...elements };\n if (options && 'value' in options) {\n data._value = options.value;\n }\n if (options?.etags) {\n for (const [slotId, etag] of Object.entries(options.etags)) {\n data[ETAG_ID_PREFIX + slotId] = etag;\n }\n }\n return renderToReadableStream(\n data,\n {\n temporaryReferences,\n onError,\n debugChannel,\n },\n {\n onClientReference(metadata: {\n id: string;\n name: string;\n deps: { js: string[]; css: string[] };\n }) {\n options?.unstable_clientModuleCallback?.(metadata.deps.js);\n },\n },\n );\n },\n async parseRsc(stream) {\n return createFromReadableStream(stream, {}) as Promise<\n Record<string, unknown>\n >;\n },\n async renderHtml(elementsStream, html, options) {\n const { INTERNAL_renderHtmlStream: renderHtmlStream } =\n await loadSsrEntryModule();\n\n const rscHtmlStream = renderToReadableStream(html, {\n onError,\n });\n const htmlResult = await renderHtmlStream(elementsStream, rscHtmlStream, {\n rscPath: options.rscPath,\n formState: options.formState as never,\n nonce: options.nonce,\n extraScriptContent: options.unstable_extraScriptContent,\n debugId,\n });\n return new Response(htmlResult.stream, {\n status: htmlResult.status || options.status || 200,\n headers: { 'content-type': 'text/html; charset=utf-8' },\n });\n },\n };\n}\n"],"names":["ETAG_ID_PREFIX","sanitizeLog","validateRscElementIds","elements","id","Object","keys","startsWith","Error","createRenderUtils","temporaryReferences","renderToReadableStream","createFromReadableStream","loadSsrEntryModule","buildId","debugChannel","debugId","onError","e","digest","console","error","renderRsc","options","data","_buildId","_value","value","etags","slotId","etag","entries","onClientReference","metadata","unstable_clientModuleCallback","deps","js","parseRsc","stream","renderHtml","elementsStream","html","INTERNAL_renderHtmlStream","renderHtmlStream","rscHtmlStream","htmlResult","rscPath","formState","nonce","extraScriptContent","unstable_extraScriptContent","Response","status","headers"],"mappings":"AAKA,SAASA,cAAc,QAAQ,aAAa;AAC5C,SAASC,WAAW,QAAQ,WAAW;AAEvC,MAAMC,wBAAwB,CAACC;IAC7B,KAAK,MAAMC,MAAMC,OAAOC,IAAI,CAACH,UAAW;QACtC,IAAIC,GAAGG,UAAU,CAAC,MAAM;YACtB,MAAM,IAAIC,MACR,CAAC,mEAAmE,EAAEJ,IAAI;QAE9E;IACF;AACF;AAEA,OAAO,SAASK,kBACdC,mBAA4B,EAC5BC,sBAImB,EACnBC,wBAGqB,EACrBC,kBAEC,EACDC,OAAe,EACfC,YAAuE,EACvEC,OAAgB;IAMhB,MAAMC,UAAU,CAACC;QACf,IACEA,KACA,OAAOA,MAAM,YACb,YAAYA,KACZ,OAAOA,EAAEC,MAAM,KAAK,UACpB;YACA,OAAOD,EAAEC,MAAM;QACjB;QACAC,QAAQC,KAAK,CAAC,2BAA2BpB,YAAYiB;IACvD;IAEA,OAAO;QACL,MAAMI,WAAUnB,QAAQ,EAAEoB,OAAO;YAC/BrB,sBAAsBC;YACtB,MAAMqB,OAAgCV,UAClC;gBAAE,GAAGX,QAAQ;gBAAEsB,UAAUX;YAAQ,IACjC;gBAAE,GAAGX,QAAQ;YAAC;YAClB,IAAIoB,WAAW,WAAWA,SAAS;gBACjCC,KAAKE,MAAM,GAAGH,QAAQI,KAAK;YAC7B;YACA,IAAIJ,SAASK,OAAO;gBAClB,KAAK,MAAM,CAACC,QAAQC,KAAK,IAAIzB,OAAO0B,OAAO,CAACR,QAAQK,KAAK,EAAG;oBAC1DJ,IAAI,CAACxB,iBAAiB6B,OAAO,GAAGC;gBAClC;YACF;YACA,OAAOnB,uBACLa,MACA;gBACEd;gBACAO;gBACAF;YACF,GACA;gBACEiB,mBAAkBC,QAIjB;oBACCV,SAASW,gCAAgCD,SAASE,IAAI,CAACC,EAAE;gBAC3D;YACF;QAEJ;QACA,MAAMC,UAASC,MAAM;YACnB,OAAO1B,yBAAyB0B,QAAQ,CAAC;QAG3C;QACA,MAAMC,YAAWC,cAAc,EAAEC,IAAI,EAAElB,OAAO;YAC5C,MAAM,EAAEmB,2BAA2BC,gBAAgB,EAAE,GACnD,MAAM9B;YAER,MAAM+B,gBAAgBjC,uBAAuB8B,MAAM;gBACjDxB;YACF;YACA,MAAM4B,aAAa,MAAMF,iBAAiBH,gBAAgBI,eAAe;gBACvEE,SAASvB,QAAQuB,OAAO;gBACxBC,WAAWxB,QAAQwB,SAAS;gBAC5BC,OAAOzB,QAAQyB,KAAK;gBACpBC,oBAAoB1B,QAAQ2B,2BAA2B;gBACvDlC;YACF;YACA,OAAO,IAAImC,SAASN,WAAWP,MAAM,EAAE;gBACrCc,QAAQP,WAAWO,MAAM,IAAI7B,QAAQ6B,MAAM,IAAI;gBAC/CC,SAAS;oBAAE,gBAAgB;gBAA2B;YACxD;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/lib/utils/render.ts"],"sourcesContent":["import type { Unstable_RenderHtml, Unstable_RenderRsc } from '../types.js';\nimport { ETAG_ID_PREFIX } from './etags.js';\nimport { sanitizeLog } from './log.js';\n\nconst validateRscElementIds = (elements: Record<string, unknown>) => {\n for (const id of Object.keys(elements)) {\n if (id.startsWith('_')) {\n throw new Error(\n `RSC element IDs starting with \"_\" are reserved for Waku internals: ${id}`,\n );\n }\n }\n};\n\nexport function createRenderUtils(\n temporaryReferences: unknown,\n renderToReadableStream: (\n data: unknown,\n options?: object,\n extraOptions?: object,\n ) => ReadableStream,\n loadSsrEntryModule: () => Promise<\n typeof import('../vite-entries/entry.ssr.js')\n >,\n buildId: string,\n debugChannel?: { readable?: ReadableStream; writable?: WritableStream },\n debugId?: string,\n): {\n renderRsc: Unstable_RenderRsc;\n renderHtml: Unstable_RenderHtml;\n} {\n const onError = (e: unknown) => {\n if (\n e &&\n typeof e === 'object' &&\n 'digest' in e &&\n typeof e.digest === 'string'\n ) {\n return e.digest;\n }\n console.error('Error during rendering:', sanitizeLog(e));\n };\n\n return {\n async renderRsc(elements, options) {\n validateRscElementIds(elements);\n const data: Record<string, unknown> = buildId\n ? { ...elements, _buildId: buildId }\n : { ...elements };\n if (options && 'value' in options) {\n data._value = options.value;\n }\n if (options?.documentLocation) {\n data._location = options.documentLocation;\n }\n if (options?.etags) {\n for (const [slotId, etag] of Object.entries(options.etags)) {\n data[ETAG_ID_PREFIX + slotId] = etag;\n }\n }\n return renderToReadableStream(\n data,\n {\n temporaryReferences,\n onError,\n debugChannel,\n },\n {\n onClientReference(metadata: {\n id: string;\n name: string;\n deps: { js: string[]; css: string[] };\n }) {\n options?.unstable_clientModuleCallback?.(metadata.deps.js);\n },\n },\n );\n },\n async renderHtml(elementsStream, html, options) {\n const { INTERNAL_renderHtmlStream: renderHtmlStream } =\n await loadSsrEntryModule();\n\n const rscHtmlStream = renderToReadableStream(html, {\n onError,\n });\n const htmlResult = await renderHtmlStream(elementsStream, rscHtmlStream, {\n rscPath: options.rscPath,\n formState: options.formState as never,\n nonce: options.nonce,\n extraScriptContent: options.unstable_extraScriptContent,\n debugId,\n });\n return new Response(htmlResult.stream, {\n status: htmlResult.status || options.status || 200,\n headers: { 'content-type': 'text/html; charset=utf-8' },\n });\n },\n };\n}\n"],"names":["ETAG_ID_PREFIX","sanitizeLog","validateRscElementIds","elements","id","Object","keys","startsWith","Error","createRenderUtils","temporaryReferences","renderToReadableStream","loadSsrEntryModule","buildId","debugChannel","debugId","onError","e","digest","console","error","renderRsc","options","data","_buildId","_value","value","documentLocation","_location","etags","slotId","etag","entries","onClientReference","metadata","unstable_clientModuleCallback","deps","js","renderHtml","elementsStream","html","INTERNAL_renderHtmlStream","renderHtmlStream","rscHtmlStream","htmlResult","rscPath","formState","nonce","extraScriptContent","unstable_extraScriptContent","Response","stream","status","headers"],"mappings":"AACA,SAASA,cAAc,QAAQ,aAAa;AAC5C,SAASC,WAAW,QAAQ,WAAW;AAEvC,MAAMC,wBAAwB,CAACC;IAC7B,KAAK,MAAMC,MAAMC,OAAOC,IAAI,CAACH,UAAW;QACtC,IAAIC,GAAGG,UAAU,CAAC,MAAM;YACtB,MAAM,IAAIC,MACR,CAAC,mEAAmE,EAAEJ,IAAI;QAE9E;IACF;AACF;AAEA,OAAO,SAASK,kBACdC,mBAA4B,EAC5BC,sBAImB,EACnBC,kBAEC,EACDC,OAAe,EACfC,YAAuE,EACvEC,OAAgB;IAKhB,MAAMC,UAAU,CAACC;QACf,IACEA,KACA,OAAOA,MAAM,YACb,YAAYA,KACZ,OAAOA,EAAEC,MAAM,KAAK,UACpB;YACA,OAAOD,EAAEC,MAAM;QACjB;QACAC,QAAQC,KAAK,CAAC,2BAA2BnB,YAAYgB;IACvD;IAEA,OAAO;QACL,MAAMI,WAAUlB,QAAQ,EAAEmB,OAAO;YAC/BpB,sBAAsBC;YACtB,MAAMoB,OAAgCV,UAClC;gBAAE,GAAGV,QAAQ;gBAAEqB,UAAUX;YAAQ,IACjC;gBAAE,GAAGV,QAAQ;YAAC;YAClB,IAAImB,WAAW,WAAWA,SAAS;gBACjCC,KAAKE,MAAM,GAAGH,QAAQI,KAAK;YAC7B;YACA,IAAIJ,SAASK,kBAAkB;gBAC7BJ,KAAKK,SAAS,GAAGN,QAAQK,gBAAgB;YAC3C;YACA,IAAIL,SAASO,OAAO;gBAClB,KAAK,MAAM,CAACC,QAAQC,KAAK,IAAI1B,OAAO2B,OAAO,CAACV,QAAQO,KAAK,EAAG;oBAC1DN,IAAI,CAACvB,iBAAiB8B,OAAO,GAAGC;gBAClC;YACF;YACA,OAAOpB,uBACLY,MACA;gBACEb;gBACAM;gBACAF;YACF,GACA;gBACEmB,mBAAkBC,QAIjB;oBACCZ,SAASa,gCAAgCD,SAASE,IAAI,CAACC,EAAE;gBAC3D;YACF;QAEJ;QACA,MAAMC,YAAWC,cAAc,EAAEC,IAAI,EAAElB,OAAO;YAC5C,MAAM,EAAEmB,2BAA2BC,gBAAgB,EAAE,GACnD,MAAM9B;YAER,MAAM+B,gBAAgBhC,uBAAuB6B,MAAM;gBACjDxB;YACF;YACA,MAAM4B,aAAa,MAAMF,iBAAiBH,gBAAgBI,eAAe;gBACvEE,SAASvB,QAAQuB,OAAO;gBACxBC,WAAWxB,QAAQwB,SAAS;gBAC5BC,OAAOzB,QAAQyB,KAAK;gBACpBC,oBAAoB1B,QAAQ2B,2BAA2B;gBACvDlC;YACF;YACA,OAAO,IAAImC,SAASN,WAAWO,MAAM,EAAE;gBACrCC,QAAQR,WAAWQ,MAAM,IAAI9B,QAAQ8B,MAAM,IAAI;gBAC/CC,SAAS;oBAAE,gBAAgB;gBAA2B;YACxD;QACF;IACF;AACF"}
@@ -1,18 +1,22 @@
1
1
  import type { ReactFormState } from 'react-dom/client';
2
2
  import type { Config } from '../../config.js';
3
3
  export declare function getInput(req: Request, config: Omit<Required<Config>, 'vite'>, temporaryReferences: unknown, decodeReply: (body: string | FormData, options?: object) => Promise<unknown[]>, decodeAction: (body: FormData) => Promise<() => Promise<void>> | null, decodeFormState: (actionResult: unknown, body: FormData) => Promise<ReactFormState | undefined>, loadServerAction: (id: string) => Promise<unknown>): Promise<({
4
- type: "component";
4
+ type: "rsc";
5
5
  rscPath: string;
6
6
  rscParams: unknown;
7
7
  } | {
8
- type: "function";
8
+ type: "call";
9
9
  fn: (...args: unknown[]) => Promise<unknown>;
10
10
  args: unknown[];
11
11
  } | {
12
- type: "action";
13
- fn: () => Promise<unknown>;
14
- } | {
15
- type: "custom";
12
+ type: "http";
13
+ tryAction?: () => Promise<{
14
+ action: true;
15
+ formState: unknown;
16
+ } | {
17
+ action: false;
18
+ formData: FormData;
19
+ }>;
16
20
  }) & {
17
21
  pathname: string;
18
22
  req: Request;