rwsdk 0.1.16 → 0.1.17-test.20250715200658

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 (298) hide show
  1. package/dist/lib/$.d.mts +8 -0
  2. package/dist/lib/$.mjs +5 -0
  3. package/dist/lib/constants.d.mts +4 -0
  4. package/dist/lib/constants.mjs +6 -0
  5. package/dist/lib/findWranglerConfig.d.mts +1 -0
  6. package/dist/lib/findWranglerConfig.mjs +12 -0
  7. package/dist/lib/getShortName.d.mts +1 -0
  8. package/dist/lib/getShortName.mjs +2 -0
  9. package/dist/lib/getSrcPaths.d.ts +15 -0
  10. package/dist/lib/getSrcPaths.js +80 -0
  11. package/dist/lib/hasPkgScript.d.mts +1 -0
  12. package/dist/lib/hasPkgScript.mjs +9 -0
  13. package/dist/lib/jsonUtils.d.mts +28 -0
  14. package/dist/lib/jsonUtils.mjs +167 -0
  15. package/dist/lib/setupEnvFiles.d.mts +4 -0
  16. package/dist/lib/setupEnvFiles.mjs +31 -0
  17. package/dist/lib/smokeTests/artifacts.d.mts +10 -0
  18. package/dist/lib/smokeTests/artifacts.mjs +164 -0
  19. package/dist/lib/smokeTests/browser.d.mts +48 -0
  20. package/dist/lib/smokeTests/browser.mjs +1041 -0
  21. package/dist/lib/smokeTests/cleanup.d.mts +5 -0
  22. package/dist/lib/smokeTests/cleanup.mjs +214 -0
  23. package/dist/lib/smokeTests/codeUpdates.d.mts +8 -0
  24. package/dist/lib/smokeTests/codeUpdates.mjs +229 -0
  25. package/dist/lib/smokeTests/constants.d.mts +5 -0
  26. package/dist/lib/smokeTests/constants.mjs +10 -0
  27. package/dist/lib/smokeTests/development.d.mts +11 -0
  28. package/dist/lib/smokeTests/development.mjs +209 -0
  29. package/dist/lib/smokeTests/environment.d.mts +14 -0
  30. package/dist/lib/smokeTests/environment.mjs +163 -0
  31. package/dist/lib/smokeTests/release.d.mts +61 -0
  32. package/dist/lib/smokeTests/release.mjs +526 -0
  33. package/dist/lib/smokeTests/reporting.d.mts +13 -0
  34. package/dist/lib/smokeTests/reporting.mjs +355 -0
  35. package/dist/lib/smokeTests/runSmokeTests.d.mts +5 -0
  36. package/dist/lib/smokeTests/runSmokeTests.mjs +144 -0
  37. package/dist/lib/smokeTests/state.d.mts +48 -0
  38. package/dist/lib/smokeTests/state.mjs +57 -0
  39. package/dist/lib/smokeTests/templates/SmokeTest.template.d.ts +1 -0
  40. package/dist/lib/smokeTests/templates/SmokeTest.template.js +81 -0
  41. package/dist/lib/smokeTests/templates/SmokeTestClient.template.d.ts +1 -0
  42. package/dist/lib/smokeTests/templates/SmokeTestClient.template.js +159 -0
  43. package/dist/lib/smokeTests/templates/smokeTestFunctions.template.d.ts +1 -0
  44. package/dist/lib/smokeTests/templates/smokeTestFunctions.template.js +19 -0
  45. package/dist/lib/smokeTests/types.d.mts +75 -0
  46. package/dist/lib/smokeTests/utils.d.mts +15 -0
  47. package/dist/lib/smokeTests/utils.mjs +147 -0
  48. package/dist/llms/index.d.ts +3 -0
  49. package/dist/llms/index.js +35 -0
  50. package/dist/llms/rules/interruptors.d.ts +1 -0
  51. package/dist/llms/rules/interruptors.js +243 -0
  52. package/dist/llms/rules/middleware.d.ts +1 -0
  53. package/dist/llms/rules/middleware.js +71 -0
  54. package/dist/llms/rules/react.d.ts +1 -0
  55. package/dist/llms/rules/react.js +106 -0
  56. package/dist/llms/rules/request-response.d.ts +1 -0
  57. package/dist/llms/rules/request-response.js +209 -0
  58. package/dist/runtime/client.d.ts +17 -0
  59. package/dist/runtime/client.js +74 -0
  60. package/dist/runtime/clientNavigation.d.ts +4 -0
  61. package/dist/runtime/clientNavigation.js +53 -0
  62. package/dist/runtime/clientNavigation.test.d.ts +1 -0
  63. package/dist/runtime/clientNavigation.test.js +55 -0
  64. package/dist/runtime/constants.d.ts +1 -0
  65. package/dist/runtime/constants.js +1 -0
  66. package/dist/runtime/entries/auth.d.ts +1 -0
  67. package/dist/runtime/entries/auth.js +1 -0
  68. package/dist/runtime/entries/client.d.ts +4 -0
  69. package/dist/runtime/entries/client.js +4 -0
  70. package/dist/runtime/entries/clientSSR.d.ts +1 -0
  71. package/dist/runtime/entries/clientSSR.js +1 -0
  72. package/dist/runtime/entries/no-react-server.d.ts +0 -0
  73. package/dist/runtime/entries/no-react-server.js +2 -0
  74. package/dist/runtime/entries/react-server-only.d.ts +0 -0
  75. package/dist/runtime/entries/react-server-only.js +2 -0
  76. package/dist/runtime/entries/router.d.ts +2 -0
  77. package/dist/runtime/entries/router.js +2 -0
  78. package/dist/runtime/entries/ssr.d.ts +1 -0
  79. package/dist/runtime/entries/ssr.js +1 -0
  80. package/dist/runtime/entries/worker.d.ts +9 -0
  81. package/dist/runtime/entries/worker.js +9 -0
  82. package/dist/runtime/error.d.ts +6 -0
  83. package/dist/runtime/error.js +8 -0
  84. package/dist/runtime/imports/ClientOnly.d.ts +3 -0
  85. package/dist/runtime/imports/ClientOnly.js +8 -0
  86. package/dist/runtime/imports/client.d.ts +4 -0
  87. package/dist/runtime/imports/client.js +33 -0
  88. package/dist/runtime/imports/ssr.d.ts +5 -0
  89. package/dist/runtime/imports/ssr.js +20 -0
  90. package/dist/runtime/imports/worker.d.ts +5 -0
  91. package/dist/runtime/imports/worker.js +22 -0
  92. package/dist/runtime/lib/auth/index.d.ts +1 -0
  93. package/dist/runtime/lib/auth/index.js +1 -0
  94. package/dist/runtime/lib/auth/session.d.ts +50 -0
  95. package/dist/runtime/lib/auth/session.js +148 -0
  96. package/dist/runtime/lib/db/DOWorkerDialect.d.ts +29 -0
  97. package/dist/runtime/lib/db/DOWorkerDialect.js +66 -0
  98. package/dist/runtime/lib/db/SqliteDurableObject.d.ts +14 -0
  99. package/dist/runtime/lib/db/SqliteDurableObject.js +42 -0
  100. package/dist/runtime/lib/db/createDb.d.ts +2 -0
  101. package/dist/runtime/lib/db/createDb.js +33 -0
  102. package/dist/runtime/lib/db/index.d.ts +4 -0
  103. package/dist/runtime/lib/db/index.js +3 -0
  104. package/dist/runtime/lib/db/migrations.d.ts +23 -0
  105. package/dist/runtime/lib/db/migrations.js +34 -0
  106. package/dist/runtime/lib/db/typeInference/assert.d.ts +2 -0
  107. package/dist/runtime/lib/db/typeInference/assert.js +1 -0
  108. package/dist/runtime/lib/db/typeInference/builders/alterColumn.d.ts +27 -0
  109. package/dist/runtime/lib/db/typeInference/builders/alterColumn.js +1 -0
  110. package/dist/runtime/lib/db/typeInference/builders/alterTable.d.ts +53 -0
  111. package/dist/runtime/lib/db/typeInference/builders/alterTable.js +1 -0
  112. package/dist/runtime/lib/db/typeInference/builders/columnDefinition.d.ts +26 -0
  113. package/dist/runtime/lib/db/typeInference/builders/columnDefinition.js +1 -0
  114. package/dist/runtime/lib/db/typeInference/builders/createTable.d.ts +49 -0
  115. package/dist/runtime/lib/db/typeInference/builders/createTable.js +1 -0
  116. package/dist/runtime/lib/db/typeInference/builders/createView.d.ts +17 -0
  117. package/dist/runtime/lib/db/typeInference/builders/createView.js +1 -0
  118. package/dist/runtime/lib/db/typeInference/builders/dropTable.d.ts +11 -0
  119. package/dist/runtime/lib/db/typeInference/builders/dropTable.js +1 -0
  120. package/dist/runtime/lib/db/typeInference/builders/dropView.d.ts +12 -0
  121. package/dist/runtime/lib/db/typeInference/builders/dropView.js +1 -0
  122. package/dist/runtime/lib/db/typeInference/builders/schema.d.ts +24 -0
  123. package/dist/runtime/lib/db/typeInference/builders/schema.js +1 -0
  124. package/dist/runtime/lib/db/typeInference/database.d.ts +27 -0
  125. package/dist/runtime/lib/db/typeInference/database.js +1 -0
  126. package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.d.ts +1 -0
  127. package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.js +360 -0
  128. package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.d.ts +1 -0
  129. package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.js +33 -0
  130. package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.d.ts +1 -0
  131. package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.js +143 -0
  132. package/dist/runtime/lib/db/typeInference/typetests/print.d.ts +3 -0
  133. package/dist/runtime/lib/db/typeInference/typetests/print.js +1 -0
  134. package/dist/runtime/lib/db/typeInference/typetests/testUtils.d.ts +2 -0
  135. package/dist/runtime/lib/db/typeInference/typetests/testUtils.js +1 -0
  136. package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.d.ts +1 -0
  137. package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.js +17 -0
  138. package/dist/runtime/lib/db/typeInference/utils.d.ts +82 -0
  139. package/dist/runtime/lib/db/typeInference/utils.js +2 -0
  140. package/dist/runtime/lib/debug.d.ts +2 -0
  141. package/dist/runtime/lib/debug.js +36 -0
  142. package/dist/runtime/lib/links.d.ts +14 -0
  143. package/dist/runtime/lib/links.js +38 -0
  144. package/dist/runtime/lib/realtime/client.d.ts +7 -0
  145. package/dist/runtime/lib/realtime/client.js +166 -0
  146. package/dist/runtime/lib/realtime/constants.d.ts +1 -0
  147. package/dist/runtime/lib/realtime/constants.js +1 -0
  148. package/dist/runtime/lib/realtime/durableObject.d.ts +29 -0
  149. package/dist/runtime/lib/realtime/durableObject.js +187 -0
  150. package/dist/runtime/lib/realtime/renderRealtimeClients.d.ts +7 -0
  151. package/dist/runtime/lib/realtime/renderRealtimeClients.js +6 -0
  152. package/dist/runtime/lib/realtime/shared.d.ts +10 -0
  153. package/dist/runtime/lib/realtime/shared.js +10 -0
  154. package/dist/runtime/lib/realtime/validateUpgradeRequest.d.ts +6 -0
  155. package/dist/runtime/lib/realtime/validateUpgradeRequest.js +29 -0
  156. package/dist/runtime/lib/realtime/worker.d.ts +3 -0
  157. package/dist/runtime/lib/realtime/worker.js +16 -0
  158. package/dist/runtime/lib/router.d.ts +56 -0
  159. package/dist/runtime/lib/router.js +210 -0
  160. package/dist/runtime/lib/router.test.d.ts +1 -0
  161. package/dist/runtime/lib/router.test.js +58 -0
  162. package/dist/runtime/lib/streams/consumeEventStream.d.ts +4 -0
  163. package/dist/runtime/lib/streams/consumeEventStream.js +13 -0
  164. package/dist/runtime/lib/turnstile/TurnstileScript.d.ts +1 -0
  165. package/dist/runtime/lib/turnstile/TurnstileScript.js +2 -0
  166. package/dist/runtime/lib/turnstile/turnstile.d.ts +3 -0
  167. package/dist/runtime/lib/turnstile/turnstile.js +3 -0
  168. package/dist/runtime/lib/turnstile/useTurnstile.d.ts +4 -0
  169. package/dist/runtime/lib/turnstile/useTurnstile.js +23 -0
  170. package/dist/runtime/lib/turnstile/verifyTurnstileToken.d.ts +4 -0
  171. package/dist/runtime/lib/turnstile/verifyTurnstileToken.js +15 -0
  172. package/dist/runtime/lib/utils.d.ts +1 -0
  173. package/dist/runtime/lib/utils.js +1 -0
  174. package/dist/runtime/register/client.d.ts +1 -0
  175. package/dist/runtime/register/client.js +5 -0
  176. package/dist/runtime/register/ssr.d.ts +3 -0
  177. package/dist/runtime/register/ssr.js +26 -0
  178. package/dist/runtime/register/worker.d.ts +4 -0
  179. package/dist/runtime/register/worker.js +42 -0
  180. package/dist/runtime/render/createClientManifest.d.ts +1 -0
  181. package/dist/runtime/render/createClientManifest.js +7 -0
  182. package/dist/runtime/render/createModuleMap.d.ts +1 -0
  183. package/dist/runtime/render/createModuleMap.js +13 -0
  184. package/dist/runtime/render/renderRscThenableToHtmlStream.d.ts +9 -0
  185. package/dist/runtime/render/renderRscThenableToHtmlStream.js +49 -0
  186. package/dist/runtime/render/renderToRscStream.d.ts +5 -0
  187. package/dist/runtime/render/renderToRscStream.js +46 -0
  188. package/dist/runtime/render/renderToStream.d.ts +9 -0
  189. package/dist/runtime/render/renderToStream.js +27 -0
  190. package/dist/runtime/render/renderToString.d.ts +7 -0
  191. package/dist/runtime/render/renderToString.js +26 -0
  192. package/dist/runtime/render/transformRscToHtmlStream.d.ts +8 -0
  193. package/dist/runtime/render/transformRscToHtmlStream.js +19 -0
  194. package/dist/runtime/requestInfo/types.d.ts +11 -0
  195. package/dist/runtime/requestInfo/types.js +1 -0
  196. package/dist/runtime/requestInfo/worker.d.ts +5 -0
  197. package/dist/runtime/requestInfo/worker.js +33 -0
  198. package/dist/runtime/script.d.ts +5 -0
  199. package/dist/runtime/script.js +8 -0
  200. package/dist/runtime/ssrBridge.d.ts +2 -0
  201. package/dist/runtime/ssrBridge.js +11 -0
  202. package/dist/runtime/worker.d.ts +18 -0
  203. package/dist/runtime/worker.js +173 -0
  204. package/dist/scripts/__sdk.d.mts +1 -0
  205. package/dist/scripts/__sdk.mjs +14 -0
  206. package/dist/scripts/debug-sync.d.mts +6 -0
  207. package/dist/scripts/debug-sync.mjs +224 -0
  208. package/dist/scripts/dev-init.d.mts +1 -0
  209. package/dist/scripts/dev-init.mjs +25 -0
  210. package/dist/scripts/ensure-deploy-env.d.mts +1 -0
  211. package/dist/scripts/ensure-deploy-env.mjs +271 -0
  212. package/dist/scripts/ensure-env.d.mts +1 -0
  213. package/dist/scripts/ensure-env.mjs +9 -0
  214. package/dist/scripts/migrate-new.d.mts +1 -0
  215. package/dist/scripts/migrate-new.mjs +51 -0
  216. package/dist/scripts/smoke-test.d.mts +1 -0
  217. package/dist/scripts/smoke-test.mjs +166 -0
  218. package/dist/scripts/worker-run.d.mts +1 -0
  219. package/dist/scripts/worker-run.mjs +82 -0
  220. package/dist/vite/checkIsUsingPrisma.d.mts +6 -0
  221. package/dist/vite/checkIsUsingPrisma.mjs +18 -0
  222. package/dist/vite/configPlugin.d.mts +9 -0
  223. package/dist/vite/configPlugin.mjs +169 -0
  224. package/dist/vite/createDirectiveLookupPlugin.d.mts +21 -0
  225. package/dist/vite/createDirectiveLookupPlugin.mjs +231 -0
  226. package/dist/vite/devServerTimingPlugin.d.mts +2 -0
  227. package/dist/vite/devServerTimingPlugin.mjs +24 -0
  228. package/dist/vite/directivesPlugin.d.mts +6 -0
  229. package/dist/vite/directivesPlugin.mjs +200 -0
  230. package/dist/vite/ensureAliasArray.d.mts +2 -0
  231. package/dist/vite/ensureAliasArray.mjs +17 -0
  232. package/dist/vite/findSpecifiers.d.mts +31 -0
  233. package/dist/vite/findSpecifiers.mjs +230 -0
  234. package/dist/vite/findSsrSpecifiers.d.mts +11 -0
  235. package/dist/vite/findSsrSpecifiers.mjs +67 -0
  236. package/dist/vite/hasDirective.d.mts +7 -0
  237. package/dist/vite/hasDirective.mjs +54 -0
  238. package/dist/vite/hasOwnCloudflareVitePlugin.d.mts +3 -0
  239. package/dist/vite/hasOwnCloudflareVitePlugin.mjs +14 -0
  240. package/dist/vite/index.d.mts +1 -0
  241. package/dist/vite/index.mjs +1 -0
  242. package/dist/vite/injectVitePreamblePlugin.d.mts +4 -0
  243. package/dist/vite/injectVitePreamblePlugin.mjs +23 -0
  244. package/dist/vite/invalidateCacheIfPrismaClientChanged.d.mts +3 -0
  245. package/dist/vite/invalidateCacheIfPrismaClientChanged.mjs +27 -0
  246. package/dist/vite/invalidateModule.d.mts +6 -0
  247. package/dist/vite/invalidateModule.mjs +30 -0
  248. package/dist/vite/miniflareHMRPlugin.d.mts +10 -0
  249. package/dist/vite/miniflareHMRPlugin.mjs +209 -0
  250. package/dist/vite/moveStaticAssetsPlugin.d.mts +4 -0
  251. package/dist/vite/moveStaticAssetsPlugin.mjs +12 -0
  252. package/dist/vite/normalizeModulePath.d.mts +1 -0
  253. package/dist/vite/normalizeModulePath.mjs +13 -0
  254. package/dist/vite/prismaPlugin.d.mts +4 -0
  255. package/dist/vite/prismaPlugin.mjs +43 -0
  256. package/dist/vite/reactConditionsResolverPlugin.d.mts +16 -0
  257. package/dist/vite/reactConditionsResolverPlugin.mjs +179 -0
  258. package/dist/vite/redwoodPlugin.d.mts +12 -0
  259. package/dist/vite/redwoodPlugin.mjs +105 -0
  260. package/dist/vite/ssrBridgePlugin.d.mts +7 -0
  261. package/dist/vite/ssrBridgePlugin.mjs +137 -0
  262. package/dist/vite/transformClientComponents.d.mts +12 -0
  263. package/dist/vite/transformClientComponents.mjs +116 -0
  264. package/dist/vite/transformClientComponents.test.d.mts +1 -0
  265. package/dist/vite/transformClientComponents.test.mjs +264 -0
  266. package/dist/vite/transformJsxScriptTagsPlugin.d.mts +8 -0
  267. package/dist/vite/transformJsxScriptTagsPlugin.mjs +315 -0
  268. package/dist/vite/transformJsxScriptTagsPlugin.test.d.mts +1 -0
  269. package/dist/vite/transformJsxScriptTagsPlugin.test.mjs +334 -0
  270. package/dist/vite/transformServerFunctions.d.mts +16 -0
  271. package/dist/vite/transformServerFunctions.mjs +296 -0
  272. package/dist/vite/transformServerFunctions.test.d.mts +1 -0
  273. package/dist/vite/transformServerFunctions.test.mjs +124 -0
  274. package/dist/vite/useClientLookupPlugin.d.mts +5 -0
  275. package/dist/vite/useClientLookupPlugin.mjs +15 -0
  276. package/dist/vite/useServerLookupPlugin.d.mts +5 -0
  277. package/dist/vite/useServerLookupPlugin.mjs +15 -0
  278. package/dist/vite/useServerPlugin.d.mts +1 -0
  279. package/dist/vite/useServerPlugin.mjs +1 -0
  280. package/dist/vite/virtualPlugin.d.mts +2 -0
  281. package/dist/vite/virtualPlugin.mjs +18 -0
  282. package/dist/vite/vitePreamblePlugin.d.mts +1 -0
  283. package/dist/vite/vitePreamblePlugin.mjs +11 -0
  284. package/package.json +1 -1
  285. package/dist/runtime/lib/db/typeInference/builders/table.d.ts +0 -10
  286. package/dist/vite/invalidateClientModule.d.mts +0 -2
  287. package/dist/vite/invalidateClientModule.mjs +0 -8
  288. package/dist/vite/invalidateModule copy.d.mts +0 -2
  289. package/dist/vite/invalidateModule copy.mjs +0 -14
  290. package/dist/vite/invalidateSSRModule.d.mts +0 -2
  291. package/dist/vite/invalidateSSRModule.mjs +0 -7
  292. package/dist/vite/mode.d.mts +0 -5
  293. package/dist/vite/mode.mjs +0 -25
  294. package/dist/vite/modePlugin.d.mts +0 -2
  295. package/dist/vite/modePlugin.mjs +0 -10
  296. /package/dist/{runtime/lib/db/typeInference/builders/table.js → lib/smokeTests/types.mjs} +0 -0
  297. /package/dist/vite/{isJsFile.d.ts → isJsFile.d.mts} +0 -0
  298. /package/dist/vite/{isJsFile.js → isJsFile.mjs} +0 -0
@@ -0,0 +1,26 @@
1
+ import { renderToStream } from "./renderToStream";
2
+ export const renderToString = async (element, options) => {
3
+ const stream = await new Promise((resolve, reject) => renderToStream(element, {
4
+ ...options,
5
+ onError: reject,
6
+ })
7
+ .then(resolve)
8
+ .catch(reject));
9
+ const reader = stream.getReader();
10
+ const decoder = new TextDecoder();
11
+ let result = "";
12
+ try {
13
+ while (true) {
14
+ const { done, value } = await reader.read();
15
+ if (done)
16
+ break;
17
+ result += decoder.decode(value, { stream: true });
18
+ }
19
+ // Flush any remaining bytes
20
+ result += decoder.decode();
21
+ return result;
22
+ }
23
+ finally {
24
+ reader.releaseLock();
25
+ }
26
+ };
@@ -0,0 +1,8 @@
1
+ import { DocumentProps } from "../lib/router";
2
+ import { RequestInfo } from "../requestInfo/types";
3
+ export declare const transformRscToHtmlStream: ({ stream, Document, requestInfo, onError, }: {
4
+ stream: ReadableStream;
5
+ Document: React.FC<DocumentProps>;
6
+ requestInfo: RequestInfo;
7
+ onError: (error: unknown) => void;
8
+ }) => Promise<import("react-dom/server.js").ReactDOMServerReadableStream>;
@@ -0,0 +1,19 @@
1
+ import { createModuleMap } from "./createModuleMap.js";
2
+ import ReactServerDom from "react-server-dom-webpack/client.edge";
3
+ import { renderRscThenableToHtmlStream } from "rwsdk/__ssr_bridge";
4
+ const { createFromReadableStream } = ReactServerDom;
5
+ export const transformRscToHtmlStream = ({ stream, Document, requestInfo, onError, }) => {
6
+ const thenable = createFromReadableStream(stream, {
7
+ serverConsumerManifest: {
8
+ moduleMap: createModuleMap(),
9
+ moduleLoading: null,
10
+ },
11
+ });
12
+ return renderRscThenableToHtmlStream({
13
+ thenable,
14
+ Document,
15
+ requestInfo,
16
+ shouldSSR: requestInfo.rw.ssr,
17
+ onError,
18
+ });
19
+ };
@@ -0,0 +1,11 @@
1
+ import { RwContext } from "../lib/router";
2
+ export interface DefaultAppContext {
3
+ }
4
+ export interface RequestInfo<Params = any, AppContext = DefaultAppContext> {
5
+ request: Request;
6
+ params: Params;
7
+ ctx: AppContext;
8
+ headers: Headers;
9
+ rw: RwContext;
10
+ cf: ExecutionContext;
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { RequestInfo, DefaultAppContext } from "./types";
2
+ export declare const requestInfo: RequestInfo<DefaultAppContext>;
3
+ export declare function getRequestInfo(): RequestInfo;
4
+ export declare function runWithRequestInfo<Result>(context: Record<string, any>, fn: () => Result): Result;
5
+ export declare function runWithRequestInfoOverrides<Result>(overrides: Record<string, any>, fn: () => Result): Result;
@@ -0,0 +1,33 @@
1
+ import { AsyncLocalStorage } from "async_hooks";
2
+ const requestInfoStore = new AsyncLocalStorage();
3
+ const requestInfoBase = {};
4
+ const REQUEST_INFO_KEYS = ["request", "params", "ctx", "headers", "rw", "cf"];
5
+ REQUEST_INFO_KEYS.forEach((key) => {
6
+ Object.defineProperty(requestInfoBase, key, {
7
+ enumerable: true,
8
+ configurable: false,
9
+ get: function () {
10
+ const store = requestInfoStore.getStore();
11
+ return store ? store[key] : undefined;
12
+ },
13
+ });
14
+ });
15
+ export const requestInfo = Object.freeze(requestInfoBase);
16
+ export function getRequestInfo() {
17
+ const store = requestInfoStore.getStore();
18
+ if (!store) {
19
+ throw new Error("Request context not found");
20
+ }
21
+ return store;
22
+ }
23
+ export function runWithRequestInfo(context, fn) {
24
+ return requestInfoStore.run(context, fn);
25
+ }
26
+ export function runWithRequestInfoOverrides(overrides, fn) {
27
+ const requestInfo = requestInfoStore.getStore();
28
+ const newRequestInfo = {
29
+ ...requestInfo,
30
+ ...overrides,
31
+ };
32
+ return requestInfoStore.run(newRequestInfo, fn);
33
+ }
@@ -0,0 +1,5 @@
1
+ export declare const defineScript: (fn: ({ env }: {
2
+ env: Env;
3
+ }) => Promise<unknown>) => {
4
+ fetch(request: Request, env: Env): Promise<Response>;
5
+ };
@@ -0,0 +1,8 @@
1
+ export const defineScript = (fn) => {
2
+ return {
3
+ async fetch(request, env) {
4
+ await fn({ env });
5
+ return new Response("Done!");
6
+ },
7
+ };
8
+ };
@@ -0,0 +1,2 @@
1
+ export { renderRscThenableToHtmlStream } from "./render/renderRscThenableToHtmlStream";
2
+ export { ssrLoadModule, ssrGetModuleExport, ssrWebpackRequire, } from "./imports/ssr";
@@ -0,0 +1,11 @@
1
+ // context(justinvdm, 28 May 2025): This is the "bridge" between the RSC side
2
+ // and the SSR side, both run inside the same runtime environment. We have this
3
+ // separation so that they can each be processed with their own respective
4
+ // import conditions and bundling logic
5
+ //
6
+ // **NOTE:** Any time we need to import from SSR side in RSC side, we need to
7
+ // import it through this bridge module, using the bare import path
8
+ // `rwsdk/__ssr_bridge`. We have bundler logic (ssrBridgePlugin) that looks out
9
+ // for imports to it.
10
+ export { renderRscThenableToHtmlStream } from "./render/renderRscThenableToHtmlStream";
11
+ export { ssrLoadModule, ssrGetModuleExport, ssrWebpackRequire, } from "./imports/ssr";
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ import { RequestInfo, DefaultAppContext } from "./requestInfo/types";
3
+ import { Route } from "./lib/router";
4
+ declare global {
5
+ type Env = {
6
+ ASSETS: Fetcher;
7
+ DB: D1Database;
8
+ };
9
+ }
10
+ export declare const defineApp: <T extends RequestInfo = RequestInfo<any, DefaultAppContext>>(routes: Route<T>[]) => {
11
+ fetch: (request: Request, env: Env, cf: ExecutionContext) => Promise<Response>;
12
+ };
13
+ export declare const SmokeTestWrapper: React.FC<{
14
+ children: React.ReactNode;
15
+ }>;
16
+ export declare const DefaultDocument: React.FC<{
17
+ children: React.ReactNode;
18
+ }>;
@@ -0,0 +1,173 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { transformRscToHtmlStream } from "./render/transformRscToHtmlStream";
3
+ import { renderToRscStream } from "./render/renderToRscStream";
4
+ import { rscActionHandler } from "./register/worker";
5
+ import { injectRSCPayload } from "rsc-html-stream/server";
6
+ import { ErrorResponse } from "./error";
7
+ import { getRequestInfo, runWithRequestInfo, runWithRequestInfoOverrides, } from "./requestInfo/worker";
8
+ import { defineRoutes } from "./lib/router";
9
+ import { generateNonce } from "./lib/utils";
10
+ import { IS_DEV } from "./constants";
11
+ import { ssrWebpackRequire } from "./imports/worker";
12
+ export const defineApp = (routes) => {
13
+ return {
14
+ fetch: async (request, env, cf) => {
15
+ globalThis.__webpack_require__ = ssrWebpackRequire;
16
+ const router = defineRoutes(routes);
17
+ // context(justinvdm, 5 Feb 2025): Serve assets requests using the assets service binding
18
+ // todo(justinvdm, 5 Feb 2025): Find a way to avoid this so asset requests are served directly
19
+ // rather than first needing to go through the worker
20
+ if (request.url.includes("/assets/")) {
21
+ const url = new URL(request.url);
22
+ url.pathname = url.pathname.slice("/assets/".length);
23
+ return env.ASSETS.fetch(new Request(url.toString(), request));
24
+ }
25
+ else if (IS_DEV && request.url.includes("/__vite_preamble__")) {
26
+ return new Response('import RefreshRuntime from "/@react-refresh"; RefreshRuntime.injectIntoGlobalHook(window); window.$RefreshReg$ = () => {}; window.$RefreshSig$ = () => (type) => type; window.__vite_plugin_react_preamble_installed__ = true;', {
27
+ headers: {
28
+ "content-type": "text/javascript",
29
+ },
30
+ });
31
+ }
32
+ try {
33
+ const url = new URL(request.url);
34
+ const isRSCRequest = url.searchParams.has("__rsc") ||
35
+ request.headers.get("accept")?.includes("text/x-component");
36
+ const isSmokeTest = url.searchParams.has("__smoke_test");
37
+ const userHeaders = new Headers();
38
+ const rw = {
39
+ Document: DefaultDocument,
40
+ nonce: generateNonce(),
41
+ rscPayload: true,
42
+ ssr: true,
43
+ databases: new Map(),
44
+ };
45
+ const outerRequestInfo = {
46
+ request,
47
+ headers: userHeaders,
48
+ cf,
49
+ params: {},
50
+ ctx: {},
51
+ rw,
52
+ };
53
+ const createPageElement = (requestInfo, Page) => {
54
+ let pageElement;
55
+ if (isClientReference(Page)) {
56
+ const { ctx, params } = requestInfo; // context(justinvdm, 25 Feb 2025): If the page is a client reference, we need to avoid passing
57
+ // down props the client shouldn't get (e.g. env). For safety, we pick the allowed props explicitly.
58
+ pageElement = _jsx(Page, { ctx: ctx, params: params });
59
+ }
60
+ else {
61
+ // context(justinvdm, 24 Apr 2025): We need to wrap the page in a component that throws the response to bubble it up and break out of react rendering context
62
+ // This way, we're able to return a response from the page component while still staying within react rendering context
63
+ const PageWrapper = async () => {
64
+ const result = await Page(requestInfo);
65
+ if (result instanceof Response) {
66
+ throw result;
67
+ }
68
+ return result;
69
+ };
70
+ pageElement = _jsx(PageWrapper, {});
71
+ }
72
+ if (isSmokeTest) {
73
+ pageElement = _jsx(SmokeTestWrapper, { children: pageElement });
74
+ }
75
+ return pageElement;
76
+ };
77
+ const renderPage = async (requestInfo, Page, onError) => {
78
+ if (isClientReference(requestInfo.rw.Document)) {
79
+ if (IS_DEV) {
80
+ console.error("Document cannot be a client component");
81
+ }
82
+ return new Response(null, {
83
+ status: 500,
84
+ });
85
+ }
86
+ let actionResult = undefined;
87
+ const isRSCActionHandler = url.searchParams.has("__rsc_action_id");
88
+ if (isRSCActionHandler) {
89
+ actionResult = await rscActionHandler(request);
90
+ }
91
+ const pageElement = createPageElement(requestInfo, Page);
92
+ const { rscPayload: shouldInjectRSCPayload } = rw;
93
+ let rscPayloadStream = renderToRscStream({
94
+ node: pageElement,
95
+ actionResult: actionResult instanceof Response ? null : actionResult,
96
+ onError,
97
+ });
98
+ if (isRSCRequest) {
99
+ return new Response(rscPayloadStream, {
100
+ headers: {
101
+ "content-type": "text/x-component; charset=utf-8",
102
+ },
103
+ });
104
+ }
105
+ let injectRSCPayloadStream;
106
+ if (shouldInjectRSCPayload) {
107
+ const [rscPayloadStream1, rscPayloadStream2] = rscPayloadStream.tee();
108
+ rscPayloadStream = rscPayloadStream1;
109
+ injectRSCPayloadStream = injectRSCPayload(rscPayloadStream2, {
110
+ nonce: rw.nonce,
111
+ });
112
+ }
113
+ let html = await transformRscToHtmlStream({
114
+ stream: rscPayloadStream,
115
+ Document: rw.Document,
116
+ requestInfo: requestInfo,
117
+ onError,
118
+ });
119
+ if (injectRSCPayloadStream) {
120
+ html = html.pipeThrough(injectRSCPayloadStream);
121
+ }
122
+ return new Response(html, {
123
+ headers: {
124
+ "content-type": "text/html; charset=utf-8",
125
+ },
126
+ });
127
+ };
128
+ const response = await runWithRequestInfo(outerRequestInfo, async () => new Promise(async (resolve, reject) => {
129
+ try {
130
+ resolve(await router.handle({
131
+ request,
132
+ renderPage,
133
+ getRequestInfo: getRequestInfo,
134
+ runWithRequestInfoOverrides,
135
+ onError: reject,
136
+ }));
137
+ }
138
+ catch (e) {
139
+ reject(e);
140
+ }
141
+ }));
142
+ // context(justinvdm, 18 Mar 2025): In some cases, such as a .fetch() call to a durable object instance, or Response.redirect(),
143
+ // we need to return a mutable response object.
144
+ const mutableResponse = new Response(response.body, response);
145
+ for (const [key, value] of userHeaders.entries()) {
146
+ if (!response.headers.has(key)) {
147
+ mutableResponse.headers.set(key, value);
148
+ }
149
+ }
150
+ return mutableResponse;
151
+ }
152
+ catch (e) {
153
+ if (e instanceof ErrorResponse) {
154
+ return new Response(e.message, { status: e.code });
155
+ }
156
+ if (e instanceof Response) {
157
+ return e;
158
+ }
159
+ console.error("Unhandled error", e);
160
+ throw e;
161
+ }
162
+ },
163
+ };
164
+ };
165
+ export const SmokeTestWrapper = async ({ children }) => {
166
+ const smokeTestInfo = await Object.values(await import.meta.glob("/src/app/components/__SmokeTest.tsx"))[0]();
167
+ const SmokeTestInfo = smokeTestInfo.SmokeTestInfo;
168
+ return (_jsxs(_Fragment, { children: [_jsx(SmokeTestInfo, {}), children] }));
169
+ };
170
+ export const DefaultDocument = ({ children, }) => (_jsxs("html", { lang: "en", children: [_jsxs("head", { children: [_jsx("meta", { charSet: "utf-8" }), _jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1" })] }), _jsx("body", { children: _jsx("div", { id: "root", children: children }) })] }));
171
+ const isClientReference = (Component) => {
172
+ return Object.prototype.hasOwnProperty.call(Component, "$$isClientReference");
173
+ };
@@ -0,0 +1 @@
1
+ export declare const __sdk: (...args: string[]) => Promise<void>;
@@ -0,0 +1,14 @@
1
+ import { $ } from "../lib/$.mjs";
2
+ export const __sdk = async (...args) => {
3
+ console.log("Resetting development environment...");
4
+ await $({
5
+ shell: true,
6
+ }) `(cd ../../sdk && NODE_ENV=development pnpm build) && pnpm clean:vite && rm -r node_modules/rwsdk/dist && cp -r ../../sdk/{package.json,dist} node_modules/rwsdk/`;
7
+ if (args.length > 0) {
8
+ await $({ stdio: "inherit" }) `pnpm ${args.join(" ")}`;
9
+ }
10
+ };
11
+ if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
12
+ const args = process.argv.slice(2);
13
+ __sdk(...args);
14
+ }
@@ -0,0 +1,6 @@
1
+ export interface DebugSyncOptions {
2
+ targetDir: string;
3
+ sdkDir?: string;
4
+ watch?: string | boolean;
5
+ }
6
+ export declare const debugSync: (opts: DebugSyncOptions) => Promise<void>;
@@ -0,0 +1,224 @@
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ import { $ } from "execa";
4
+ import fs from "node:fs/promises";
5
+ import { existsSync } from "node:fs";
6
+ import chokidar from "chokidar";
7
+ import { lock } from "proper-lockfile";
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+ const getPackageManagerInfo = (targetDir) => {
10
+ const pnpmResult = {
11
+ name: "pnpm",
12
+ lockFile: "pnpm-lock.yaml",
13
+ command: "add",
14
+ };
15
+ if (existsSync(path.join(targetDir, "yarn.lock"))) {
16
+ return { name: "yarn", lockFile: "yarn.lock", command: "add" };
17
+ }
18
+ if (existsSync(path.join(targetDir, "pnpm-lock.yaml"))) {
19
+ return pnpmResult;
20
+ }
21
+ if (existsSync(path.join(targetDir, "package-lock.json"))) {
22
+ return { name: "npm", lockFile: "package-lock.json", command: "install" };
23
+ }
24
+ return pnpmResult;
25
+ };
26
+ const performFullSync = async (sdkDir, targetDir) => {
27
+ console.log("📦 Packing SDK...");
28
+ const packResult = await $ `npm pack`;
29
+ const tarballName = packResult.stdout?.trim() ?? "";
30
+ if (!tarballName) {
31
+ console.error("❌ Failed to get tarball name from npm pack.");
32
+ return;
33
+ }
34
+ const tarballPath = path.resolve(sdkDir, tarballName);
35
+ console.log(`💿 Installing ${tarballName} in ${targetDir}...`);
36
+ const pm = getPackageManagerInfo(targetDir);
37
+ const packageJsonPath = path.join(targetDir, "package.json");
38
+ const lockfilePath = path.join(targetDir, pm.lockFile);
39
+ const originalPackageJson = await fs
40
+ .readFile(packageJsonPath, "utf-8")
41
+ .catch(() => null);
42
+ const originalLockfile = await fs
43
+ .readFile(lockfilePath, "utf-8")
44
+ .catch(() => null);
45
+ try {
46
+ const cmd = pm.name;
47
+ const args = [pm.command];
48
+ if (pm.name === "yarn") {
49
+ args.push(`file:${tarballPath}`);
50
+ }
51
+ else {
52
+ args.push(tarballPath);
53
+ }
54
+ await $(cmd, args, {
55
+ cwd: targetDir,
56
+ stdio: "inherit",
57
+ });
58
+ }
59
+ finally {
60
+ if (originalPackageJson) {
61
+ console.log("Restoring package.json...");
62
+ await fs.writeFile(packageJsonPath, originalPackageJson);
63
+ }
64
+ if (originalLockfile) {
65
+ console.log(`Restoring ${pm.lockFile}...`);
66
+ await fs.writeFile(lockfilePath, originalLockfile);
67
+ }
68
+ await fs.unlink(tarballPath).catch(() => {
69
+ // ignore if deletion fails
70
+ });
71
+ }
72
+ };
73
+ const performFastSync = async (sdkDir, targetDir) => {
74
+ console.log("⚡️ No dependency changes, performing fast sync...");
75
+ const sdkPackageJson = JSON.parse(await fs.readFile(path.join(sdkDir, "package.json"), "utf-8"));
76
+ const filesToSync = sdkPackageJson.files || [];
77
+ for (const file of filesToSync) {
78
+ const source = path.join(sdkDir, file);
79
+ const destination = path.join(targetDir, "node_modules/rwsdk", file);
80
+ if (existsSync(source)) {
81
+ await fs.cp(source, destination, { recursive: true, force: true });
82
+ }
83
+ }
84
+ // Always copy package.json
85
+ await fs.copyFile(path.join(sdkDir, "package.json"), path.join(targetDir, "node_modules/rwsdk/package.json"));
86
+ };
87
+ const performSync = async (sdkDir, targetDir) => {
88
+ console.log("🏗️ Rebuilding SDK...");
89
+ await $ `pnpm build`;
90
+ const sdkPackageJsonPath = path.join(sdkDir, "package.json");
91
+ const installedSdkPackageJsonPath = path.join(targetDir, "node_modules/rwsdk/package.json");
92
+ let packageJsonChanged = true;
93
+ if (existsSync(installedSdkPackageJsonPath)) {
94
+ const sdkPackageJsonContent = await fs.readFile(sdkPackageJsonPath, "utf-8");
95
+ const installedSdkPackageJsonContent = await fs.readFile(installedSdkPackageJsonPath, "utf-8");
96
+ if (sdkPackageJsonContent === installedSdkPackageJsonContent) {
97
+ packageJsonChanged = false;
98
+ }
99
+ }
100
+ if (packageJsonChanged) {
101
+ console.log("📦 package.json changed, performing full sync...");
102
+ await performFullSync(sdkDir, targetDir);
103
+ }
104
+ else {
105
+ await performFastSync(sdkDir, targetDir);
106
+ }
107
+ console.log("✅ Done syncing");
108
+ };
109
+ export const debugSync = async (opts) => {
110
+ const { targetDir, sdkDir = process.cwd(), watch } = opts;
111
+ if (!targetDir) {
112
+ console.error("❌ Please provide a target directory as an argument.");
113
+ process.exit(1);
114
+ }
115
+ // If not in watch mode, just do a one-time sync and exit.
116
+ if (!watch) {
117
+ await performSync(sdkDir, targetDir);
118
+ return;
119
+ }
120
+ // --- Watch Mode Logic ---
121
+ const lockfilePath = path.join(targetDir, "node_modules", ".rwsync.lock");
122
+ let release;
123
+ // Ensure the directory for the lockfile exists
124
+ await fs.mkdir(path.dirname(lockfilePath), { recursive: true });
125
+ // "Touch" the file to ensure it exists before locking
126
+ await fs.appendFile(lockfilePath, "").catch(() => { });
127
+ try {
128
+ release = await lock(lockfilePath, { retries: 0 });
129
+ }
130
+ catch (e) {
131
+ if (e.code === "ELOCKED") {
132
+ console.error(`❌ Another rwsync process is already watching ${targetDir}.`);
133
+ console.error(` If this is not correct, please remove the lockfile at ${lockfilePath}`);
134
+ process.exit(1);
135
+ }
136
+ throw e;
137
+ }
138
+ // Initial sync for watch mode. We do it *after* acquiring the lock.
139
+ let initialSyncOk = false;
140
+ try {
141
+ await performSync(sdkDir, targetDir);
142
+ initialSyncOk = true;
143
+ }
144
+ catch (error) {
145
+ console.error("❌ Initial sync failed:", error);
146
+ console.log(" Still watching for changes...");
147
+ }
148
+ const filesToWatch = [
149
+ path.join(sdkDir, "src"),
150
+ path.join(sdkDir, "types"),
151
+ path.join(sdkDir, "bin"),
152
+ path.join(sdkDir, "package.json"),
153
+ ];
154
+ console.log("👀 Watching for changes...");
155
+ let childProc = null;
156
+ const runWatchedCommand = () => {
157
+ if (typeof watch === "string") {
158
+ console.log(`\n> ${watch}\n`);
159
+ childProc = $({
160
+ stdio: "inherit",
161
+ shell: true,
162
+ cwd: targetDir,
163
+ reject: false,
164
+ }) `${watch}`;
165
+ }
166
+ };
167
+ const watcher = chokidar.watch(filesToWatch, {
168
+ ignoreInitial: true,
169
+ cwd: sdkDir,
170
+ });
171
+ watcher.on("all", async () => {
172
+ console.log("\nDetected change, re-syncing...");
173
+ if (childProc && !childProc.killed) {
174
+ console.log("Stopping running process...");
175
+ childProc.kill();
176
+ await childProc.catch(() => {
177
+ /* ignore kill errors */
178
+ });
179
+ }
180
+ try {
181
+ await performSync(sdkDir, targetDir);
182
+ runWatchedCommand();
183
+ }
184
+ catch (error) {
185
+ console.error("❌ Sync failed:", error);
186
+ console.log(" Still watching for changes...");
187
+ }
188
+ });
189
+ const cleanup = async () => {
190
+ console.log("\nCleaning up...");
191
+ if (childProc && !childProc.killed) {
192
+ childProc.kill();
193
+ }
194
+ await release();
195
+ process.exit();
196
+ };
197
+ process.on("SIGINT", cleanup);
198
+ process.on("SIGTERM", cleanup);
199
+ if (initialSyncOk) {
200
+ runWatchedCommand();
201
+ }
202
+ };
203
+ if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
204
+ const args = process.argv.slice(2);
205
+ const watchFlagIndex = args.indexOf("--watch");
206
+ let watchCmd = watchFlagIndex !== -1;
207
+ let cmdArgs = args;
208
+ if (watchFlagIndex !== -1) {
209
+ if (watchFlagIndex + 1 < args.length &&
210
+ !args[watchFlagIndex + 1].startsWith("--")) {
211
+ watchCmd = args[watchFlagIndex + 1];
212
+ }
213
+ // remove --watch and its potential command from args
214
+ const watchArgCount = typeof watchCmd === "string" ? 2 : 1;
215
+ cmdArgs = args.filter((_, i) => i < watchFlagIndex || i >= watchFlagIndex + watchArgCount);
216
+ }
217
+ const targetDir = cmdArgs[0] ?? process.cwd();
218
+ const sdkDir = path.resolve(__dirname, "..", "..");
219
+ debugSync({
220
+ targetDir,
221
+ sdkDir,
222
+ watch: watchCmd,
223
+ });
224
+ }
@@ -0,0 +1 @@
1
+ export declare const initDev: () => Promise<never>;
@@ -0,0 +1,25 @@
1
+ import { $ } from "../lib/$.mjs";
2
+ import { hasPkgScript } from "../lib/hasPkgScript.mjs";
3
+ export const initDev = async () => {
4
+ console.log("Initializing development environment...");
5
+ const projectRootDir = process.cwd();
6
+ if (await hasPkgScript(projectRootDir, "generate")) {
7
+ console.log("Generating...");
8
+ await $ `npm run generate`;
9
+ }
10
+ if (await hasPkgScript(projectRootDir, "migrate:dev")) {
11
+ console.log("Running migrations...");
12
+ await $ `npm run migrate:dev`;
13
+ }
14
+ if (await hasPkgScript(projectRootDir, "seed")) {
15
+ console.log("Seeding database...");
16
+ await $ `npm run seed`;
17
+ }
18
+ console.log("Done!");
19
+ console.log();
20
+ // todo(justinvdm, 01 Apr 2025): Investigate what handles are remaining open
21
+ process.exit(0);
22
+ };
23
+ if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
24
+ initDev();
25
+ }
@@ -0,0 +1 @@
1
+ export declare const ensureDeployEnv: () => Promise<never>;