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.
- package/dist/lib/$.d.mts +8 -0
- package/dist/lib/$.mjs +5 -0
- package/dist/lib/constants.d.mts +4 -0
- package/dist/lib/constants.mjs +6 -0
- package/dist/lib/findWranglerConfig.d.mts +1 -0
- package/dist/lib/findWranglerConfig.mjs +12 -0
- package/dist/lib/getShortName.d.mts +1 -0
- package/dist/lib/getShortName.mjs +2 -0
- package/dist/lib/getSrcPaths.d.ts +15 -0
- package/dist/lib/getSrcPaths.js +80 -0
- package/dist/lib/hasPkgScript.d.mts +1 -0
- package/dist/lib/hasPkgScript.mjs +9 -0
- package/dist/lib/jsonUtils.d.mts +28 -0
- package/dist/lib/jsonUtils.mjs +167 -0
- package/dist/lib/setupEnvFiles.d.mts +4 -0
- package/dist/lib/setupEnvFiles.mjs +31 -0
- package/dist/lib/smokeTests/artifacts.d.mts +10 -0
- package/dist/lib/smokeTests/artifacts.mjs +164 -0
- package/dist/lib/smokeTests/browser.d.mts +48 -0
- package/dist/lib/smokeTests/browser.mjs +1041 -0
- package/dist/lib/smokeTests/cleanup.d.mts +5 -0
- package/dist/lib/smokeTests/cleanup.mjs +214 -0
- package/dist/lib/smokeTests/codeUpdates.d.mts +8 -0
- package/dist/lib/smokeTests/codeUpdates.mjs +229 -0
- package/dist/lib/smokeTests/constants.d.mts +5 -0
- package/dist/lib/smokeTests/constants.mjs +10 -0
- package/dist/lib/smokeTests/development.d.mts +11 -0
- package/dist/lib/smokeTests/development.mjs +209 -0
- package/dist/lib/smokeTests/environment.d.mts +14 -0
- package/dist/lib/smokeTests/environment.mjs +163 -0
- package/dist/lib/smokeTests/release.d.mts +61 -0
- package/dist/lib/smokeTests/release.mjs +526 -0
- package/dist/lib/smokeTests/reporting.d.mts +13 -0
- package/dist/lib/smokeTests/reporting.mjs +355 -0
- package/dist/lib/smokeTests/runSmokeTests.d.mts +5 -0
- package/dist/lib/smokeTests/runSmokeTests.mjs +144 -0
- package/dist/lib/smokeTests/state.d.mts +48 -0
- package/dist/lib/smokeTests/state.mjs +57 -0
- package/dist/lib/smokeTests/templates/SmokeTest.template.d.ts +1 -0
- package/dist/lib/smokeTests/templates/SmokeTest.template.js +81 -0
- package/dist/lib/smokeTests/templates/SmokeTestClient.template.d.ts +1 -0
- package/dist/lib/smokeTests/templates/SmokeTestClient.template.js +159 -0
- package/dist/lib/smokeTests/templates/smokeTestFunctions.template.d.ts +1 -0
- package/dist/lib/smokeTests/templates/smokeTestFunctions.template.js +19 -0
- package/dist/lib/smokeTests/types.d.mts +75 -0
- package/dist/lib/smokeTests/utils.d.mts +15 -0
- package/dist/lib/smokeTests/utils.mjs +147 -0
- package/dist/llms/index.d.ts +3 -0
- package/dist/llms/index.js +35 -0
- package/dist/llms/rules/interruptors.d.ts +1 -0
- package/dist/llms/rules/interruptors.js +243 -0
- package/dist/llms/rules/middleware.d.ts +1 -0
- package/dist/llms/rules/middleware.js +71 -0
- package/dist/llms/rules/react.d.ts +1 -0
- package/dist/llms/rules/react.js +106 -0
- package/dist/llms/rules/request-response.d.ts +1 -0
- package/dist/llms/rules/request-response.js +209 -0
- package/dist/runtime/client.d.ts +17 -0
- package/dist/runtime/client.js +74 -0
- package/dist/runtime/clientNavigation.d.ts +4 -0
- package/dist/runtime/clientNavigation.js +53 -0
- package/dist/runtime/clientNavigation.test.d.ts +1 -0
- package/dist/runtime/clientNavigation.test.js +55 -0
- package/dist/runtime/constants.d.ts +1 -0
- package/dist/runtime/constants.js +1 -0
- package/dist/runtime/entries/auth.d.ts +1 -0
- package/dist/runtime/entries/auth.js +1 -0
- package/dist/runtime/entries/client.d.ts +4 -0
- package/dist/runtime/entries/client.js +4 -0
- package/dist/runtime/entries/clientSSR.d.ts +1 -0
- package/dist/runtime/entries/clientSSR.js +1 -0
- package/dist/runtime/entries/no-react-server.d.ts +0 -0
- package/dist/runtime/entries/no-react-server.js +2 -0
- package/dist/runtime/entries/react-server-only.d.ts +0 -0
- package/dist/runtime/entries/react-server-only.js +2 -0
- package/dist/runtime/entries/router.d.ts +2 -0
- package/dist/runtime/entries/router.js +2 -0
- package/dist/runtime/entries/ssr.d.ts +1 -0
- package/dist/runtime/entries/ssr.js +1 -0
- package/dist/runtime/entries/worker.d.ts +9 -0
- package/dist/runtime/entries/worker.js +9 -0
- package/dist/runtime/error.d.ts +6 -0
- package/dist/runtime/error.js +8 -0
- package/dist/runtime/imports/ClientOnly.d.ts +3 -0
- package/dist/runtime/imports/ClientOnly.js +8 -0
- package/dist/runtime/imports/client.d.ts +4 -0
- package/dist/runtime/imports/client.js +33 -0
- package/dist/runtime/imports/ssr.d.ts +5 -0
- package/dist/runtime/imports/ssr.js +20 -0
- package/dist/runtime/imports/worker.d.ts +5 -0
- package/dist/runtime/imports/worker.js +22 -0
- package/dist/runtime/lib/auth/index.d.ts +1 -0
- package/dist/runtime/lib/auth/index.js +1 -0
- package/dist/runtime/lib/auth/session.d.ts +50 -0
- package/dist/runtime/lib/auth/session.js +148 -0
- package/dist/runtime/lib/db/DOWorkerDialect.d.ts +29 -0
- package/dist/runtime/lib/db/DOWorkerDialect.js +66 -0
- package/dist/runtime/lib/db/SqliteDurableObject.d.ts +14 -0
- package/dist/runtime/lib/db/SqliteDurableObject.js +42 -0
- package/dist/runtime/lib/db/createDb.d.ts +2 -0
- package/dist/runtime/lib/db/createDb.js +33 -0
- package/dist/runtime/lib/db/index.d.ts +4 -0
- package/dist/runtime/lib/db/index.js +3 -0
- package/dist/runtime/lib/db/migrations.d.ts +23 -0
- package/dist/runtime/lib/db/migrations.js +34 -0
- package/dist/runtime/lib/db/typeInference/assert.d.ts +2 -0
- package/dist/runtime/lib/db/typeInference/assert.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/alterColumn.d.ts +27 -0
- package/dist/runtime/lib/db/typeInference/builders/alterColumn.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/alterTable.d.ts +53 -0
- package/dist/runtime/lib/db/typeInference/builders/alterTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/columnDefinition.d.ts +26 -0
- package/dist/runtime/lib/db/typeInference/builders/columnDefinition.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/createTable.d.ts +49 -0
- package/dist/runtime/lib/db/typeInference/builders/createTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/createView.d.ts +17 -0
- package/dist/runtime/lib/db/typeInference/builders/createView.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/dropTable.d.ts +11 -0
- package/dist/runtime/lib/db/typeInference/builders/dropTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/dropView.d.ts +12 -0
- package/dist/runtime/lib/db/typeInference/builders/dropView.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/schema.d.ts +24 -0
- package/dist/runtime/lib/db/typeInference/builders/schema.js +1 -0
- package/dist/runtime/lib/db/typeInference/database.d.ts +27 -0
- package/dist/runtime/lib/db/typeInference/database.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.js +360 -0
- package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.js +33 -0
- package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.js +143 -0
- package/dist/runtime/lib/db/typeInference/typetests/print.d.ts +3 -0
- package/dist/runtime/lib/db/typeInference/typetests/print.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/testUtils.d.ts +2 -0
- package/dist/runtime/lib/db/typeInference/typetests/testUtils.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.js +17 -0
- package/dist/runtime/lib/db/typeInference/utils.d.ts +82 -0
- package/dist/runtime/lib/db/typeInference/utils.js +2 -0
- package/dist/runtime/lib/debug.d.ts +2 -0
- package/dist/runtime/lib/debug.js +36 -0
- package/dist/runtime/lib/links.d.ts +14 -0
- package/dist/runtime/lib/links.js +38 -0
- package/dist/runtime/lib/realtime/client.d.ts +7 -0
- package/dist/runtime/lib/realtime/client.js +166 -0
- package/dist/runtime/lib/realtime/constants.d.ts +1 -0
- package/dist/runtime/lib/realtime/constants.js +1 -0
- package/dist/runtime/lib/realtime/durableObject.d.ts +29 -0
- package/dist/runtime/lib/realtime/durableObject.js +187 -0
- package/dist/runtime/lib/realtime/renderRealtimeClients.d.ts +7 -0
- package/dist/runtime/lib/realtime/renderRealtimeClients.js +6 -0
- package/dist/runtime/lib/realtime/shared.d.ts +10 -0
- package/dist/runtime/lib/realtime/shared.js +10 -0
- package/dist/runtime/lib/realtime/validateUpgradeRequest.d.ts +6 -0
- package/dist/runtime/lib/realtime/validateUpgradeRequest.js +29 -0
- package/dist/runtime/lib/realtime/worker.d.ts +3 -0
- package/dist/runtime/lib/realtime/worker.js +16 -0
- package/dist/runtime/lib/router.d.ts +56 -0
- package/dist/runtime/lib/router.js +210 -0
- package/dist/runtime/lib/router.test.d.ts +1 -0
- package/dist/runtime/lib/router.test.js +58 -0
- package/dist/runtime/lib/streams/consumeEventStream.d.ts +4 -0
- package/dist/runtime/lib/streams/consumeEventStream.js +13 -0
- package/dist/runtime/lib/turnstile/TurnstileScript.d.ts +1 -0
- package/dist/runtime/lib/turnstile/TurnstileScript.js +2 -0
- package/dist/runtime/lib/turnstile/turnstile.d.ts +3 -0
- package/dist/runtime/lib/turnstile/turnstile.js +3 -0
- package/dist/runtime/lib/turnstile/useTurnstile.d.ts +4 -0
- package/dist/runtime/lib/turnstile/useTurnstile.js +23 -0
- package/dist/runtime/lib/turnstile/verifyTurnstileToken.d.ts +4 -0
- package/dist/runtime/lib/turnstile/verifyTurnstileToken.js +15 -0
- package/dist/runtime/lib/utils.d.ts +1 -0
- package/dist/runtime/lib/utils.js +1 -0
- package/dist/runtime/register/client.d.ts +1 -0
- package/dist/runtime/register/client.js +5 -0
- package/dist/runtime/register/ssr.d.ts +3 -0
- package/dist/runtime/register/ssr.js +26 -0
- package/dist/runtime/register/worker.d.ts +4 -0
- package/dist/runtime/register/worker.js +42 -0
- package/dist/runtime/render/createClientManifest.d.ts +1 -0
- package/dist/runtime/render/createClientManifest.js +7 -0
- package/dist/runtime/render/createModuleMap.d.ts +1 -0
- package/dist/runtime/render/createModuleMap.js +13 -0
- package/dist/runtime/render/renderRscThenableToHtmlStream.d.ts +9 -0
- package/dist/runtime/render/renderRscThenableToHtmlStream.js +49 -0
- package/dist/runtime/render/renderToRscStream.d.ts +5 -0
- package/dist/runtime/render/renderToRscStream.js +46 -0
- package/dist/runtime/render/renderToStream.d.ts +9 -0
- package/dist/runtime/render/renderToStream.js +27 -0
- package/dist/runtime/render/renderToString.d.ts +7 -0
- package/dist/runtime/render/renderToString.js +26 -0
- package/dist/runtime/render/transformRscToHtmlStream.d.ts +8 -0
- package/dist/runtime/render/transformRscToHtmlStream.js +19 -0
- package/dist/runtime/requestInfo/types.d.ts +11 -0
- package/dist/runtime/requestInfo/types.js +1 -0
- package/dist/runtime/requestInfo/worker.d.ts +5 -0
- package/dist/runtime/requestInfo/worker.js +33 -0
- package/dist/runtime/script.d.ts +5 -0
- package/dist/runtime/script.js +8 -0
- package/dist/runtime/ssrBridge.d.ts +2 -0
- package/dist/runtime/ssrBridge.js +11 -0
- package/dist/runtime/worker.d.ts +18 -0
- package/dist/runtime/worker.js +173 -0
- package/dist/scripts/__sdk.d.mts +1 -0
- package/dist/scripts/__sdk.mjs +14 -0
- package/dist/scripts/debug-sync.d.mts +6 -0
- package/dist/scripts/debug-sync.mjs +224 -0
- package/dist/scripts/dev-init.d.mts +1 -0
- package/dist/scripts/dev-init.mjs +25 -0
- package/dist/scripts/ensure-deploy-env.d.mts +1 -0
- package/dist/scripts/ensure-deploy-env.mjs +271 -0
- package/dist/scripts/ensure-env.d.mts +1 -0
- package/dist/scripts/ensure-env.mjs +9 -0
- package/dist/scripts/migrate-new.d.mts +1 -0
- package/dist/scripts/migrate-new.mjs +51 -0
- package/dist/scripts/smoke-test.d.mts +1 -0
- package/dist/scripts/smoke-test.mjs +166 -0
- package/dist/scripts/worker-run.d.mts +1 -0
- package/dist/scripts/worker-run.mjs +82 -0
- package/dist/vite/checkIsUsingPrisma.d.mts +6 -0
- package/dist/vite/checkIsUsingPrisma.mjs +18 -0
- package/dist/vite/configPlugin.d.mts +9 -0
- package/dist/vite/configPlugin.mjs +169 -0
- package/dist/vite/createDirectiveLookupPlugin.d.mts +21 -0
- package/dist/vite/createDirectiveLookupPlugin.mjs +231 -0
- package/dist/vite/devServerTimingPlugin.d.mts +2 -0
- package/dist/vite/devServerTimingPlugin.mjs +24 -0
- package/dist/vite/directivesPlugin.d.mts +6 -0
- package/dist/vite/directivesPlugin.mjs +200 -0
- package/dist/vite/ensureAliasArray.d.mts +2 -0
- package/dist/vite/ensureAliasArray.mjs +17 -0
- package/dist/vite/findSpecifiers.d.mts +31 -0
- package/dist/vite/findSpecifiers.mjs +230 -0
- package/dist/vite/findSsrSpecifiers.d.mts +11 -0
- package/dist/vite/findSsrSpecifiers.mjs +67 -0
- package/dist/vite/hasDirective.d.mts +7 -0
- package/dist/vite/hasDirective.mjs +54 -0
- package/dist/vite/hasOwnCloudflareVitePlugin.d.mts +3 -0
- package/dist/vite/hasOwnCloudflareVitePlugin.mjs +14 -0
- package/dist/vite/index.d.mts +1 -0
- package/dist/vite/index.mjs +1 -0
- package/dist/vite/injectVitePreamblePlugin.d.mts +4 -0
- package/dist/vite/injectVitePreamblePlugin.mjs +23 -0
- package/dist/vite/invalidateCacheIfPrismaClientChanged.d.mts +3 -0
- package/dist/vite/invalidateCacheIfPrismaClientChanged.mjs +27 -0
- package/dist/vite/invalidateModule.d.mts +6 -0
- package/dist/vite/invalidateModule.mjs +30 -0
- package/dist/vite/miniflareHMRPlugin.d.mts +10 -0
- package/dist/vite/miniflareHMRPlugin.mjs +209 -0
- package/dist/vite/moveStaticAssetsPlugin.d.mts +4 -0
- package/dist/vite/moveStaticAssetsPlugin.mjs +12 -0
- package/dist/vite/normalizeModulePath.d.mts +1 -0
- package/dist/vite/normalizeModulePath.mjs +13 -0
- package/dist/vite/prismaPlugin.d.mts +4 -0
- package/dist/vite/prismaPlugin.mjs +43 -0
- package/dist/vite/reactConditionsResolverPlugin.d.mts +16 -0
- package/dist/vite/reactConditionsResolverPlugin.mjs +179 -0
- package/dist/vite/redwoodPlugin.d.mts +12 -0
- package/dist/vite/redwoodPlugin.mjs +105 -0
- package/dist/vite/ssrBridgePlugin.d.mts +7 -0
- package/dist/vite/ssrBridgePlugin.mjs +137 -0
- package/dist/vite/transformClientComponents.d.mts +12 -0
- package/dist/vite/transformClientComponents.mjs +116 -0
- package/dist/vite/transformClientComponents.test.d.mts +1 -0
- package/dist/vite/transformClientComponents.test.mjs +264 -0
- package/dist/vite/transformJsxScriptTagsPlugin.d.mts +8 -0
- package/dist/vite/transformJsxScriptTagsPlugin.mjs +315 -0
- package/dist/vite/transformJsxScriptTagsPlugin.test.d.mts +1 -0
- package/dist/vite/transformJsxScriptTagsPlugin.test.mjs +334 -0
- package/dist/vite/transformServerFunctions.d.mts +16 -0
- package/dist/vite/transformServerFunctions.mjs +296 -0
- package/dist/vite/transformServerFunctions.test.d.mts +1 -0
- package/dist/vite/transformServerFunctions.test.mjs +124 -0
- package/dist/vite/useClientLookupPlugin.d.mts +5 -0
- package/dist/vite/useClientLookupPlugin.mjs +15 -0
- package/dist/vite/useServerLookupPlugin.d.mts +5 -0
- package/dist/vite/useServerLookupPlugin.mjs +15 -0
- package/dist/vite/useServerPlugin.d.mts +1 -0
- package/dist/vite/useServerPlugin.mjs +1 -0
- package/dist/vite/virtualPlugin.d.mts +2 -0
- package/dist/vite/virtualPlugin.mjs +18 -0
- package/dist/vite/vitePreamblePlugin.d.mts +1 -0
- package/dist/vite/vitePreamblePlugin.mjs +11 -0
- package/package.json +1 -1
- package/dist/runtime/lib/db/typeInference/builders/table.d.ts +0 -10
- package/dist/vite/invalidateClientModule.d.mts +0 -2
- package/dist/vite/invalidateClientModule.mjs +0 -8
- package/dist/vite/invalidateModule copy.d.mts +0 -2
- package/dist/vite/invalidateModule copy.mjs +0 -14
- package/dist/vite/invalidateSSRModule.d.mts +0 -2
- package/dist/vite/invalidateSSRModule.mjs +0 -7
- package/dist/vite/mode.d.mts +0 -5
- package/dist/vite/mode.mjs +0 -25
- package/dist/vite/modePlugin.d.mts +0 -2
- package/dist/vite/modePlugin.mjs +0 -10
- /package/dist/{runtime/lib/db/typeInference/builders/table.js → lib/smokeTests/types.mjs} +0 -0
- /package/dist/vite/{isJsFile.d.ts → isJsFile.d.mts} +0 -0
- /package/dist/vite/{isJsFile.js → isJsFile.mjs} +0 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { isValidElementType } from "react-is";
|
|
3
|
+
export function matchPath(routePath, requestPath) {
|
|
4
|
+
// Check for invalid pattern: multiple colons in a segment (e.g., /:param1:param2/)
|
|
5
|
+
if (routePath.includes(":")) {
|
|
6
|
+
const segments = routePath.split("/");
|
|
7
|
+
for (const segment of segments) {
|
|
8
|
+
if ((segment.match(/:/g) || []).length > 1) {
|
|
9
|
+
throw new Error(`Invalid route pattern: segment "${segment}" in "${routePath}" contains multiple colons.`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
// Check for invalid pattern: double wildcard (e.g., /**/)
|
|
14
|
+
if (routePath.indexOf("**") !== -1) {
|
|
15
|
+
throw new Error(`Invalid route pattern: "${routePath}" contains "**". Use "*" for a single wildcard segment.`);
|
|
16
|
+
}
|
|
17
|
+
const pattern = routePath
|
|
18
|
+
.replace(/:[a-zA-Z0-9]+/g, "([^/]+)") // Convert :param to capture group
|
|
19
|
+
.replace(/\*/g, "(.*)"); // Convert * to wildcard capture group
|
|
20
|
+
const regex = new RegExp(`^${pattern}$`);
|
|
21
|
+
const matches = requestPath.match(regex);
|
|
22
|
+
if (!matches) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
// Revised parameter extraction:
|
|
26
|
+
const params = {};
|
|
27
|
+
let currentMatchIndex = 1; // Regex matches are 1-indexed
|
|
28
|
+
// This regex finds either a named parameter token (e.g., ":id") or a wildcard star token ("*").
|
|
29
|
+
const tokenRegex = /:([a-zA-Z0-9_]+)|\*/g;
|
|
30
|
+
let matchToken;
|
|
31
|
+
let wildcardCounter = 0;
|
|
32
|
+
// Ensure regex starts from the beginning of the routePath for each call if it's stateful (it is with /g)
|
|
33
|
+
tokenRegex.lastIndex = 0;
|
|
34
|
+
while ((matchToken = tokenRegex.exec(routePath)) !== null) {
|
|
35
|
+
// Ensure we have a corresponding match from the regex execution
|
|
36
|
+
if (matches[currentMatchIndex] === undefined) {
|
|
37
|
+
// This case should ideally not be hit if routePath and pattern generation are correct
|
|
38
|
+
// and all parts of the regex matched.
|
|
39
|
+
// Consider logging a warning or throwing an error if critical.
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
if (matchToken[1]) {
|
|
43
|
+
// This token is a named parameter (e.g., matchToken[1] is "id" for ":id")
|
|
44
|
+
params[matchToken[1]] = matches[currentMatchIndex];
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// This token is a wildcard "*"
|
|
48
|
+
params[`$${wildcardCounter}`] = matches[currentMatchIndex];
|
|
49
|
+
wildcardCounter++;
|
|
50
|
+
}
|
|
51
|
+
currentMatchIndex++;
|
|
52
|
+
}
|
|
53
|
+
return params;
|
|
54
|
+
}
|
|
55
|
+
function flattenRoutes(routes) {
|
|
56
|
+
return routes.reduce((acc, route) => {
|
|
57
|
+
if (Array.isArray(route)) {
|
|
58
|
+
return [...acc, ...flattenRoutes(route)];
|
|
59
|
+
}
|
|
60
|
+
return [...acc, route];
|
|
61
|
+
}, []);
|
|
62
|
+
}
|
|
63
|
+
export function defineRoutes(routes) {
|
|
64
|
+
const flattenedRoutes = flattenRoutes(routes);
|
|
65
|
+
return {
|
|
66
|
+
routes: flattenedRoutes,
|
|
67
|
+
async handle({ request, renderPage, getRequestInfo, onError, runWithRequestInfoOverrides, }) {
|
|
68
|
+
const url = new URL(request.url);
|
|
69
|
+
let path = url.pathname;
|
|
70
|
+
// Must end with a trailing slash.
|
|
71
|
+
if (path !== "/" && !path.endsWith("/")) {
|
|
72
|
+
path = path + "/";
|
|
73
|
+
}
|
|
74
|
+
// Find matching route
|
|
75
|
+
let match = null;
|
|
76
|
+
for (const route of flattenedRoutes) {
|
|
77
|
+
if (typeof route === "function") {
|
|
78
|
+
const r = await route(getRequestInfo());
|
|
79
|
+
if (r instanceof Response) {
|
|
80
|
+
return r;
|
|
81
|
+
}
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const params = matchPath(route.path, path);
|
|
85
|
+
if (params) {
|
|
86
|
+
match = { params, handler: route.handler, layouts: route.layouts };
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (!match) {
|
|
91
|
+
// todo(peterp, 2025-01-28): Allow the user to define their own "not found" route.
|
|
92
|
+
return new Response("Not Found", { status: 404 });
|
|
93
|
+
}
|
|
94
|
+
let { params, handler, layouts } = match;
|
|
95
|
+
return runWithRequestInfoOverrides({ params }, async () => {
|
|
96
|
+
const handlers = Array.isArray(handler) ? handler : [handler];
|
|
97
|
+
for (const h of handlers) {
|
|
98
|
+
if (isRouteComponent(h)) {
|
|
99
|
+
const requestInfo = getRequestInfo();
|
|
100
|
+
const WrappedComponent = wrapWithLayouts(h, layouts || [], requestInfo);
|
|
101
|
+
return await renderPage(requestInfo, WrappedComponent, onError);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const r = await h(getRequestInfo());
|
|
105
|
+
if (r instanceof Response) {
|
|
106
|
+
return r;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// Add fallback return
|
|
111
|
+
return new Response("Response not returned from route handler", {
|
|
112
|
+
status: 500,
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export function route(path, handler) {
|
|
119
|
+
if (!path.endsWith("/")) {
|
|
120
|
+
path = path + "/";
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
path,
|
|
124
|
+
handler,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export function index(handler) {
|
|
128
|
+
return route("/", handler);
|
|
129
|
+
}
|
|
130
|
+
export function prefix(prefixPath, routes) {
|
|
131
|
+
return routes.map((r) => {
|
|
132
|
+
if (typeof r === "function") {
|
|
133
|
+
// Pass through middleware as-is
|
|
134
|
+
return r;
|
|
135
|
+
}
|
|
136
|
+
if (Array.isArray(r)) {
|
|
137
|
+
// Recursively process nested route arrays
|
|
138
|
+
return prefix(prefixPath, r);
|
|
139
|
+
}
|
|
140
|
+
// For RouteDefinition objects, update the path and preserve layouts
|
|
141
|
+
return {
|
|
142
|
+
path: prefixPath + r.path,
|
|
143
|
+
handler: r.handler,
|
|
144
|
+
...(r.layouts && { layouts: r.layouts }),
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function wrapWithLayouts(Component, layouts = [], requestInfo) {
|
|
149
|
+
if (layouts.length === 0) {
|
|
150
|
+
return Component;
|
|
151
|
+
}
|
|
152
|
+
// Check if the final route component is a client component
|
|
153
|
+
const isRouteClientComponent = Object.prototype.hasOwnProperty.call(Component, "$$isClientReference");
|
|
154
|
+
// Create nested layout structure - layouts[0] should be outermost, so use reduceRight
|
|
155
|
+
return layouts.reduceRight((WrappedComponent, Layout) => {
|
|
156
|
+
const Wrapped = (props) => {
|
|
157
|
+
const isClientComponent = Object.prototype.hasOwnProperty.call(Layout, "$$isClientReference");
|
|
158
|
+
return React.createElement(Layout, {
|
|
159
|
+
children: React.createElement(WrappedComponent, isRouteClientComponent ? {} : props),
|
|
160
|
+
// Only pass requestInfo to server components to avoid serialization issues
|
|
161
|
+
...(isClientComponent ? {} : { requestInfo }),
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
return Wrapped;
|
|
165
|
+
}, Component);
|
|
166
|
+
}
|
|
167
|
+
export function layout(LayoutComponent, routes) {
|
|
168
|
+
// Attach layouts directly to route definitions
|
|
169
|
+
return routes.map((route) => {
|
|
170
|
+
if (typeof route === "function") {
|
|
171
|
+
// Pass through middleware as-is
|
|
172
|
+
return route;
|
|
173
|
+
}
|
|
174
|
+
if (Array.isArray(route)) {
|
|
175
|
+
// Recursively process nested route arrays
|
|
176
|
+
return layout(LayoutComponent, route);
|
|
177
|
+
}
|
|
178
|
+
// For RouteDefinition objects, prepend the layout so outer layouts come first
|
|
179
|
+
return {
|
|
180
|
+
...route,
|
|
181
|
+
layouts: [LayoutComponent, ...(route.layouts || [])],
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
export function render(Document, routes,
|
|
186
|
+
/**
|
|
187
|
+
* @param options - Configuration options for rendering.
|
|
188
|
+
* @param options.rscPayload - Toggle the RSC payload that's appended to the Document. Disabling this will mean that interactivity no longer works.
|
|
189
|
+
* @param options.ssr - Disable sever side rendering for all these routes. This only allow client side rendering`, which requires `rscPayload` to be enabled.
|
|
190
|
+
*/
|
|
191
|
+
options = {}) {
|
|
192
|
+
options = {
|
|
193
|
+
rscPayload: true,
|
|
194
|
+
ssr: true,
|
|
195
|
+
...options,
|
|
196
|
+
};
|
|
197
|
+
const documentMiddleware = ({ rw }) => {
|
|
198
|
+
rw.Document = Document;
|
|
199
|
+
rw.rscPayload = options.rscPayload ?? true;
|
|
200
|
+
rw.ssr = options.ssr ?? true;
|
|
201
|
+
};
|
|
202
|
+
return [documentMiddleware, ...routes];
|
|
203
|
+
}
|
|
204
|
+
function isRouteComponent(handler) {
|
|
205
|
+
return ((isValidElementType(handler) && handler.toString().includes("jsx")) ||
|
|
206
|
+
isClientReference(handler));
|
|
207
|
+
}
|
|
208
|
+
export const isClientReference = (Component) => {
|
|
209
|
+
return Object.prototype.hasOwnProperty.call(Component, "$$isClientReference");
|
|
210
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { matchPath } from "./router";
|
|
3
|
+
describe("matchPath", () => {
|
|
4
|
+
// Test case 1: Static paths
|
|
5
|
+
it("should match static paths", () => {
|
|
6
|
+
expect(matchPath("/about/", "/about/")).toEqual({});
|
|
7
|
+
expect(matchPath("/contact/", "/contact/")).toEqual({});
|
|
8
|
+
});
|
|
9
|
+
it("should not match different static paths", () => {
|
|
10
|
+
expect(matchPath("/about/", "/service/")).toBeNull();
|
|
11
|
+
});
|
|
12
|
+
// Test case 2: Paths with parameters
|
|
13
|
+
it("should match paths with parameters and extract them", () => {
|
|
14
|
+
expect(matchPath("/users/:id/", "/users/123/")).toEqual({ id: "123" });
|
|
15
|
+
expect(matchPath("/posts/:category/:slug/", "/posts/tech/my-first-post/")).toEqual({ category: "tech", slug: "my-first-post" });
|
|
16
|
+
});
|
|
17
|
+
it("should not match if parameter is missing", () => {
|
|
18
|
+
expect(matchPath("/users/:id/", "/users/")).toBeNull();
|
|
19
|
+
});
|
|
20
|
+
// Test case 3: Paths with wildcards
|
|
21
|
+
it("should match paths with wildcards and extract them", () => {
|
|
22
|
+
expect(matchPath("/files/*/", "/files/document.pdf/")).toEqual({
|
|
23
|
+
$0: "document.pdf",
|
|
24
|
+
});
|
|
25
|
+
expect(matchPath("/data/*\/content/", "/data/archive/content/")).toEqual({
|
|
26
|
+
$0: "archive",
|
|
27
|
+
});
|
|
28
|
+
expect(matchPath("/assets/*/*/", "/assets/images/pic.png/")).toEqual({
|
|
29
|
+
$0: "images",
|
|
30
|
+
$1: "pic.png",
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
it("should match empty wildcard", () => {
|
|
34
|
+
expect(matchPath("/files/*/", "/files//")).toEqual({ $0: "" });
|
|
35
|
+
});
|
|
36
|
+
// Test case 4: Paths with both parameters and wildcards
|
|
37
|
+
it("should match paths with both parameters and wildcards", () => {
|
|
38
|
+
expect(matchPath("/products/:productId/*/", "/products/abc/details/more/")).toEqual({ productId: "abc", $0: "details/more" });
|
|
39
|
+
});
|
|
40
|
+
// Test case 5: Paths that don't match
|
|
41
|
+
it("should return null for non-matching paths", () => {
|
|
42
|
+
expect(matchPath("/specific/path/", "/a/different/path/")).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
// Test case 6: Edge cases
|
|
45
|
+
it("should handle trailing slashes correctly", () => {
|
|
46
|
+
// Current implementation in defineRoutes adds a trailing slash if missing,
|
|
47
|
+
// and route() function also enforces it. matchPath itself doesn't normalize.
|
|
48
|
+
expect(matchPath("/path/", "/path")).toBeNull(); // Path to match must end with /
|
|
49
|
+
expect(matchPath("/path/", "/path/")).toEqual({});
|
|
50
|
+
});
|
|
51
|
+
it("should handle paths with multiple parameters and wildcards interspersed", () => {
|
|
52
|
+
expect(matchPath("/type/:typeId/item/*/:itemId/*/", "/type/a/item/image/b/thumb/")).toEqual({ typeId: "a", $0: "image", itemId: "b", $1: "thumb" });
|
|
53
|
+
});
|
|
54
|
+
it("should not allow named parameters or wildcards in the same path", () => {
|
|
55
|
+
expect(() => matchPath("/type/:typeId:is:broken", "/type/a-thumb-drive")).toThrow();
|
|
56
|
+
expect(() => matchPath("/type/**", "/type/a-thumb-drive")).toThrow();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EventSourceParserStream, } from "eventsource-parser/stream";
|
|
2
|
+
export function consumeEventStream({ onChunk, }) {
|
|
3
|
+
const stream = new TransformStream();
|
|
4
|
+
stream.readable
|
|
5
|
+
.pipeThrough(new TextDecoderStream())
|
|
6
|
+
.pipeThrough(new EventSourceParserStream())
|
|
7
|
+
.pipeTo(new WritableStream({
|
|
8
|
+
write(chunk) {
|
|
9
|
+
onChunk(chunk);
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
return stream.writable;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TurnstileScript: () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRef, useCallback } from "react";
|
|
3
|
+
import { IS_DEV } from "../../constants";
|
|
4
|
+
export function useTurnstile(siteKey) {
|
|
5
|
+
const containerRef = useRef(null);
|
|
6
|
+
const resolverRef = useRef(Promise.withResolvers());
|
|
7
|
+
const widgetIdRef = useRef(null);
|
|
8
|
+
const challenge = useCallback(async () => {
|
|
9
|
+
if (!widgetIdRef.current &&
|
|
10
|
+
containerRef.current &&
|
|
11
|
+
window.turnstile) {
|
|
12
|
+
widgetIdRef.current = window.turnstile.render(containerRef.current, {
|
|
13
|
+
sitekey: IS_DEV ? "1x00000000000000000000AA" : siteKey,
|
|
14
|
+
callback: (token) => resolverRef.current.resolve(token),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return resolverRef.current.promise;
|
|
18
|
+
}, [siteKey]);
|
|
19
|
+
return {
|
|
20
|
+
ref: containerRef,
|
|
21
|
+
challenge,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const verifyTurnstileToken = async ({ token, secretKey, }) => {
|
|
2
|
+
const response = await fetch("https://challenges.cloudflare.com/turnstile/v0/siteverify", {
|
|
3
|
+
method: "POST",
|
|
4
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
5
|
+
body: new URLSearchParams({ secret: secretKey, response: token }),
|
|
6
|
+
});
|
|
7
|
+
try {
|
|
8
|
+
const data = (await response.json());
|
|
9
|
+
return data?.success === true;
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
console.error("Error verifying Turnstile token", error);
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateNonce: () => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const generateNonce = () => btoa(crypto.getRandomValues(new Uint8Array(16)).join(""));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createServerReference: (id: string, name: string) => Function;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import memoize from "lodash/memoize";
|
|
2
|
+
import { createServerReference as baseCreateServerReference } from "react-server-dom-webpack/client.edge";
|
|
3
|
+
export const loadServerModule = memoize(async (id) => {
|
|
4
|
+
const { useServerLookup } = await import("virtual:use-server-lookup.js");
|
|
5
|
+
const moduleFn = useServerLookup[id];
|
|
6
|
+
if (!moduleFn) {
|
|
7
|
+
throw new Error(`(worker) No module found for '${id}' in module lookup for "use server" directive`);
|
|
8
|
+
}
|
|
9
|
+
return await moduleFn();
|
|
10
|
+
});
|
|
11
|
+
export const getServerModuleExport = async (id) => {
|
|
12
|
+
const [file, name] = id.split("#");
|
|
13
|
+
const module = await loadServerModule(file);
|
|
14
|
+
return module[name];
|
|
15
|
+
};
|
|
16
|
+
const ssrCallServer = async (id, args) => {
|
|
17
|
+
const action = await getServerModuleExport(id);
|
|
18
|
+
if (typeof action !== "function") {
|
|
19
|
+
throw new Error(`Server function ${id} is not a function`);
|
|
20
|
+
}
|
|
21
|
+
return action(...args);
|
|
22
|
+
};
|
|
23
|
+
export const createServerReference = (id, name) => {
|
|
24
|
+
id = id + "#" + name;
|
|
25
|
+
return baseCreateServerReference(id, ssrCallServer);
|
|
26
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function registerServerReference(action: Function, id: string, name: string): Function;
|
|
2
|
+
export declare function registerClientReference<Target extends Record<string, any>>(id: string, exportName: string, value: any): any;
|
|
3
|
+
export declare function __smokeTestActionHandler(timestamp?: number): Promise<unknown>;
|
|
4
|
+
export declare function rscActionHandler(req: Request): Promise<unknown>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { registerServerReference as baseRegisterServerReference, registerClientReference as baseRegisterClientReference, decodeReply, } from "react-server-dom-webpack/server.edge";
|
|
2
|
+
import { getServerModuleExport } from "../imports/worker.js";
|
|
3
|
+
import { IS_DEV } from "../constants";
|
|
4
|
+
export function registerServerReference(action, id, name) {
|
|
5
|
+
if (typeof action !== "function") {
|
|
6
|
+
return action;
|
|
7
|
+
}
|
|
8
|
+
// Note: We no longer need to register in a Map since we use virtual lookup
|
|
9
|
+
return baseRegisterServerReference(action, id, name);
|
|
10
|
+
}
|
|
11
|
+
export function registerClientReference(id, exportName, value) {
|
|
12
|
+
const wrappedValue = (value && typeof value === "function") || typeof value === "object"
|
|
13
|
+
? value
|
|
14
|
+
: () => null;
|
|
15
|
+
const reference = baseRegisterClientReference({}, id, exportName);
|
|
16
|
+
return Object.defineProperties(wrappedValue, {
|
|
17
|
+
...Object.getOwnPropertyDescriptors(reference),
|
|
18
|
+
$$async: { value: true },
|
|
19
|
+
$$isClientReference: { value: true },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export async function __smokeTestActionHandler(timestamp) {
|
|
23
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
24
|
+
return { status: "ok", timestamp };
|
|
25
|
+
}
|
|
26
|
+
export async function rscActionHandler(req) {
|
|
27
|
+
const url = new URL(req.url);
|
|
28
|
+
const contentType = req.headers.get("content-type");
|
|
29
|
+
const data = contentType?.startsWith("multipart/form-data")
|
|
30
|
+
? await req.formData()
|
|
31
|
+
: await req.text();
|
|
32
|
+
const args = (await decodeReply(data, null));
|
|
33
|
+
const actionId = url.searchParams.get("__rsc_action_id");
|
|
34
|
+
if (IS_DEV && actionId === "__rsc_hot_update") {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const action = await getServerModuleExport(actionId);
|
|
38
|
+
if (typeof action !== "function") {
|
|
39
|
+
throw new Error(`Action ${actionId} is not a function`);
|
|
40
|
+
}
|
|
41
|
+
return action(...args);
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createClientManifest: () => ClientManifest;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createModuleMap: () => {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type DocumentProps } from "../lib/router";
|
|
2
|
+
import { type RequestInfo } from "../requestInfo/types";
|
|
3
|
+
export declare const renderRscThenableToHtmlStream: ({ thenable, Document, requestInfo, shouldSSR, onError, }: {
|
|
4
|
+
thenable: any;
|
|
5
|
+
Document: React.FC<DocumentProps>;
|
|
6
|
+
requestInfo: RequestInfo;
|
|
7
|
+
shouldSSR: boolean;
|
|
8
|
+
onError: (error: unknown) => void;
|
|
9
|
+
}) => Promise<import("react-dom/server").ReactDOMServerReadableStream>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { use } from "react";
|
|
3
|
+
import { renderToReadableStream } from "react-dom/server.edge";
|
|
4
|
+
export const renderRscThenableToHtmlStream = async ({ thenable, Document, requestInfo, shouldSSR, onError, }) => {
|
|
5
|
+
const Component = () => {
|
|
6
|
+
const node = use(thenable).node;
|
|
7
|
+
// todo(justinvdm, 18 Jun 2025): We can build on this later to allow users
|
|
8
|
+
// surface context. e.g:
|
|
9
|
+
// * we assign `user: requestInfo.clientCtx` here
|
|
10
|
+
// * user populates requestInfo.clientCtx on worker side
|
|
11
|
+
// * user can import a read only `import { clientCtx } from "rwsdk/client"`
|
|
12
|
+
// on client side
|
|
13
|
+
const clientContext = {
|
|
14
|
+
rw: {
|
|
15
|
+
ssr: shouldSSR,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
return (_jsxs(Document, { ...requestInfo, children: [_jsx("script", { nonce: requestInfo.rw.nonce, dangerouslySetInnerHTML: {
|
|
19
|
+
__html: `globalThis.__RWSDK_CONTEXT = ${JSON.stringify(clientContext)}`,
|
|
20
|
+
} }), _jsx("div", { id: "hydrate-root", children: node })] }));
|
|
21
|
+
};
|
|
22
|
+
return await renderToReadableStream(_jsx(Component, {}), {
|
|
23
|
+
nonce: requestInfo.rw.nonce,
|
|
24
|
+
onError(error, { componentStack }) {
|
|
25
|
+
try {
|
|
26
|
+
if (!error) {
|
|
27
|
+
error = new Error(`A falsy value was thrown during rendering: ${String(error)}.`);
|
|
28
|
+
}
|
|
29
|
+
const message = error
|
|
30
|
+
? (error.stack ?? error.message ?? error)
|
|
31
|
+
: error;
|
|
32
|
+
const wrappedMessage = `${message}\n\nComponent stack:${componentStack}`;
|
|
33
|
+
if (error instanceof Error) {
|
|
34
|
+
const wrappedError = new Error(wrappedMessage);
|
|
35
|
+
wrappedError.stack = error.stack;
|
|
36
|
+
error = wrappedError;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
error = new Error(wrappedMessage);
|
|
40
|
+
error.stack = componentStack;
|
|
41
|
+
}
|
|
42
|
+
onError(error);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
onError(error);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { renderToReadableStream as baseRenderToRscStream } from "react-server-dom-webpack/server.edge";
|
|
2
|
+
import { createClientManifest } from "./createClientManifest.js";
|
|
3
|
+
// context(justinvdm, 24 Mar 2025): React flight limits chunks to 28 bytes, so we need to rechunk
|
|
4
|
+
// the stream to avoid losing data
|
|
5
|
+
function rechunkStream(stream, maxChunkSize = 28) {
|
|
6
|
+
const reader = stream.getReader();
|
|
7
|
+
return new ReadableStream({
|
|
8
|
+
async pull(controller) {
|
|
9
|
+
let buffer = new Uint8Array(0);
|
|
10
|
+
try {
|
|
11
|
+
while (true) {
|
|
12
|
+
const { done, value } = await reader.read();
|
|
13
|
+
if (done && buffer.length === 0) {
|
|
14
|
+
controller.close();
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (value) {
|
|
18
|
+
buffer = new Uint8Array([...buffer, ...value]);
|
|
19
|
+
}
|
|
20
|
+
while (buffer.length >= maxChunkSize || (done && buffer.length > 0)) {
|
|
21
|
+
const chunk = buffer.slice(0, maxChunkSize);
|
|
22
|
+
buffer = buffer.slice(maxChunkSize);
|
|
23
|
+
controller.enqueue(chunk);
|
|
24
|
+
}
|
|
25
|
+
if (done) {
|
|
26
|
+
controller.close();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
controller.error(error);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export const renderToRscStream = (app) => {
|
|
38
|
+
const { node, onError } = app;
|
|
39
|
+
let { actionResult } = app;
|
|
40
|
+
if (actionResult instanceof ReadableStream) {
|
|
41
|
+
actionResult = rechunkStream(actionResult);
|
|
42
|
+
}
|
|
43
|
+
return baseRenderToRscStream({ node, actionResult }, createClientManifest(), {
|
|
44
|
+
onError,
|
|
45
|
+
});
|
|
46
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactElement, FC } from "react";
|
|
2
|
+
import { DocumentProps } from "../lib/router";
|
|
3
|
+
export interface RenderToStreamOptions {
|
|
4
|
+
Document?: FC<DocumentProps>;
|
|
5
|
+
injectRSCPayload?: boolean;
|
|
6
|
+
onError?: (error: unknown) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const IdentityDocument: FC<DocumentProps>;
|
|
9
|
+
export declare const renderToStream: (element: ReactElement, { Document, injectRSCPayload: shouldInjectRSCPayload, onError, }?: RenderToStreamOptions) => Promise<ReadableStream>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { renderToRscStream } from "./renderToRscStream";
|
|
3
|
+
import { transformRscToHtmlStream } from "./transformRscToHtmlStream";
|
|
4
|
+
import { requestInfo } from "../requestInfo/worker";
|
|
5
|
+
import { injectRSCPayload } from "rsc-html-stream/server";
|
|
6
|
+
export const IdentityDocument = ({ children }) => (_jsx(_Fragment, { children: children }));
|
|
7
|
+
export const renderToStream = async (element, { Document = IdentityDocument, injectRSCPayload: shouldInjectRSCPayload = false, onError = () => { }, } = {}) => {
|
|
8
|
+
let rscStream = renderToRscStream({
|
|
9
|
+
node: element,
|
|
10
|
+
actionResult: null,
|
|
11
|
+
onError,
|
|
12
|
+
});
|
|
13
|
+
if (shouldInjectRSCPayload) {
|
|
14
|
+
const [rscPayloadStream1, rscPayloadStream2] = rscStream.tee();
|
|
15
|
+
rscStream = rscPayloadStream1;
|
|
16
|
+
rscStream = rscStream.pipeThrough(injectRSCPayload(rscPayloadStream2, {
|
|
17
|
+
nonce: requestInfo.rw.nonce,
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
const htmlStream = await transformRscToHtmlStream({
|
|
21
|
+
stream: rscStream,
|
|
22
|
+
Document,
|
|
23
|
+
requestInfo,
|
|
24
|
+
onError,
|
|
25
|
+
});
|
|
26
|
+
return htmlStream;
|
|
27
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FC, ReactElement } from "react";
|
|
2
|
+
import { DocumentProps } from "../lib/router";
|
|
3
|
+
export interface RenderToStringOptions {
|
|
4
|
+
Document?: FC<DocumentProps>;
|
|
5
|
+
injectRSCPayload?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const renderToString: (element: ReactElement, options?: RenderToStringOptions) => Promise<string>;
|