@skyramp/mcp 0.3.2 → 0.3.4
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/build/index.js +47 -2
- package/build/playwright/PlaywrightTraceService.d.ts +8 -0
- package/build/playwright/PlaywrightTraceService.js +1 -0
- package/build/playwright/registerPlaywrightTools.js +42 -1
- package/build/prompts/enhance-assertions/sharedAssertionRules.js +19 -0
- package/build/prompts/pom-aware-code-reuse.js +17 -8
- package/build/prompts/test-maintenance/actionsInstructions.js +2 -2
- package/build/prompts/test-recommendation/analysisOutputPrompt.js +1 -4
- package/build/prompts/test-recommendation/recommendationSections.d.ts +1 -1
- package/build/prompts/test-recommendation/recommendationSections.js +5 -5
- package/build/prompts/test-recommendation/test-recommendation-prompt.js +13 -7
- package/build/prompts/testbot/testbot-prompts.d.ts +2 -12
- package/build/prompts/testbot/testbot-prompts.js +28 -16
- package/build/recommendation/discriminators.d.ts +7 -1
- package/build/recommendation/discriminators.js +16 -3
- package/build/resources/testbotResource.js +20 -4
- package/build/services/ScenarioGenerationService.js +5 -2
- package/build/services/TestExecutionService.d.ts +13 -8
- package/build/services/TestExecutionService.js +73 -26
- package/build/services/TestGenerationService.js +24 -9
- package/build/services/containerEnv.d.ts +12 -1
- package/build/services/containerEnv.js +118 -1
- package/build/tools/executeSkyrampTestTool.d.ts +9 -0
- package/build/tools/executeSkyrampTestTool.js +20 -6
- package/build/tools/execution-video-state.d.ts +21 -0
- package/build/tools/execution-video-state.js +51 -0
- package/build/tools/generate-tests/generateBatchScenarioRestTool.js +31 -11
- package/build/tools/generate-tests/planGuard.d.ts +5 -5
- package/build/tools/generate-tests/planGuard.js +5 -17
- package/build/tools/queryProxyMocksTool.js +0 -1
- package/build/tools/submitReportTool.d.ts +83 -10
- package/build/tools/submitReportTool.js +179 -29
- package/build/tools/test-management/actionsTool.js +52 -41
- package/build/tools/test-management/analyzeChangesTool.d.ts +11 -0
- package/build/tools/test-management/analyzeChangesTool.js +37 -33
- package/build/tools/test-management/analyzeTestHealthTool.js +3 -3
- package/build/tools/test-management/registerTestPlanTool.js +113 -31
- package/build/types/TestAnalysis.d.ts +7 -3
- package/build/types/TestExecution.d.ts +14 -0
- package/build/types/TestTypes.js +3 -2
- package/build/types/TestbotPromptOptions.d.ts +34 -0
- package/build/types/TestbotPromptOptions.js +1 -0
- package/build/types/TestbotReport.d.ts +10 -0
- package/build/types/TestbotReport.js +10 -1
- package/build/types/index.d.ts +2 -0
- package/build/types/index.js +1 -0
- package/build/utils/AnalysisStateManager.d.ts +36 -2
- package/build/utils/AnalysisStateManager.js +34 -13
- package/build/utils/frontendSelectors.js +0 -1
- package/build/utils/gitStaging.d.ts +5 -0
- package/build/utils/gitStaging.js +1 -1
- package/build/utils/pom-catalog.d.ts +23 -0
- package/build/utils/pom-catalog.js +30 -0
- package/build/utils/pom-scope/pom-files.d.ts +14 -0
- package/build/utils/pom-scope/pom-files.js +32 -6
- package/build/utils/pom-scope/testIdDiscovery.d.ts +40 -0
- package/build/utils/pom-scope/testIdDiscovery.js +104 -0
- package/build/utils/reportVerification.d.ts +7 -2
- package/build/utils/reportVerification.js +9 -3
- package/build/utils/scenarioDrafting.js +7 -1
- package/build/utils/skyrampMdContent.d.ts +1 -1
- package/build/utils/skyrampMdContent.js +1 -1
- package/build/utils/urlPath.d.ts +37 -0
- package/build/utils/urlPath.js +55 -0
- package/build/utils/utils.d.ts +45 -0
- package/build/utils/utils.js +50 -0
- package/build/utils/versions.d.ts +3 -3
- package/build/utils/versions.js +1 -1
- package/build/utils/workspaceAuth.d.ts +15 -15
- package/build/utils/workspaceAuth.js +32 -17
- package/build/workspace/queryParamResolution.d.ts +93 -0
- package/build/workspace/queryParamResolution.js +201 -0
- package/build/workspace/workspace.d.ts +104 -0
- package/build/workspace/workspace.js +24 -0
- package/node_modules/playwright/ThirdPartyNotices.txt +319 -266
- package/node_modules/playwright/lib/dom-analyzer/blueprint.js +154 -27
- package/node_modules/playwright/lib/dom-analyzer/crawler.js +2 -2
- package/node_modules/playwright/lib/mcp/browser/tools/pageBlueprint.js +1 -1
- package/node_modules/playwright/lib/mcp/browser/tools/sitemap.js +6 -2
- package/node_modules/playwright/lib/mcp/skyramp/loadTraceTool.js +3 -2
- package/node_modules/playwright/lib/mcp/skyramp/resultCode.js +4 -3
- package/node_modules/playwright/lib/mcp/skyramp/skyRampImport.js +15 -3
- package/node_modules/playwright/lib/mcp/skyramp/specImport.js +781 -0
- package/node_modules/playwright/lib/mcp/skyramp/traceRecordingBackend.js +14 -3
- package/node_modules/playwright/lib/mcp/test/resultCode.test.js +2 -1
- package/node_modules/playwright/lib/mcp/test/skyRampExport.js +1 -1
- package/node_modules/playwright/lib/mcp/test/skyRampExport.test.js +30 -0
- package/node_modules/playwright/lib/transform/babelBundleImpl.js +200 -199
- package/node_modules/playwright/node_modules/playwright-core/ThirdPartyNotices.txt +3 -3
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/.package-lock.json +3 -3
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/adapter/aws-lambda/handler.js +16 -25
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/adapter/bun/websocket.js +3 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/adapter/lambda-edge/handler.js +20 -4
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +16 -25
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/adapter/bun/websocket.js +3 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +20 -4
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/client/client.js +10 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/client/utils.js +1 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/helper/css/common.js +3 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/helper/css/index.js +9 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/jsx/base.js +8 -14
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/jsx/components.js +41 -21
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/jsx/context.js +131 -5
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/jsx/streaming.js +9 -7
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/middleware/bearer-auth/index.js +1 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/middleware/cache/index.js +1 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/middleware/compress/index.js +2 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/middleware/cors/index.js +2 -5
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/middleware/etag/index.js +2 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/middleware/language/language.js +10 -32
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/middleware/method-override/index.js +5 -3
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/middleware/serve-static/index.js +2 -2
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/middleware/timing/timing.js +3 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/router/trie-router/node.js +9 -0
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/utils/body.js +12 -4
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/utils/buffer.js +2 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/utils/ipaddr.js +6 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/cjs/validator/validator.js +3 -3
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/client/client.js +10 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/client/utils.js +1 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/helper/css/common.js +3 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/helper/css/index.js +9 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/jsx/base.js +15 -15
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/jsx/components.js +42 -22
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/jsx/context.js +129 -5
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/jsx/streaming.js +10 -8
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/middleware/bearer-auth/index.js +1 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/middleware/cache/index.js +1 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/middleware/compress/index.js +2 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/middleware/cors/index.js +2 -5
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/middleware/etag/index.js +2 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/middleware/language/language.js +10 -32
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/middleware/method-override/index.js +5 -3
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/middleware/serve-static/index.js +2 -2
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/middleware/timing/timing.js +3 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/router/trie-router/node.js +9 -0
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/types/adapter/aws-lambda/handler.d.ts +1 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/types/adapter/lambda-edge/handler.d.ts +1 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/types/helper/websocket/index.d.ts +1 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/types/jsx/base.d.ts +1 -3
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/types/jsx/context.d.ts +39 -0
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/types/middleware/context-storage/index.d.ts +2 -2
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/types/middleware/language/language.d.ts +18 -0
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/types/utils/body.d.ts +1 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/types/utils/types.d.ts +1 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/utils/body.js +12 -4
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/utils/buffer.js +2 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/utils/ipaddr.js +6 -1
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/validator/validator.js +3 -3
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/package.json +29 -22
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/package-lock.json +3 -3
- package/node_modules/playwright/node_modules/playwright-core/lib/generated/pollingRecorderSource.js +1 -1
- package/node_modules/playwright/node_modules/playwright-core/lib/server/codegen/skyramp/jsonlReader.js +5 -1
- package/node_modules/playwright/node_modules/playwright-core/lib/server/codegen/skyramp/specReader.js +781 -0
- package/node_modules/playwright/node_modules/playwright-core/lib/server/recorder/recorderApp.js +25 -6
- package/node_modules/playwright/node_modules/playwright-core/lib/server/recorder/skyramp/replayEngine.js +3 -1
- package/node_modules/playwright/node_modules/playwright-core/lib/utils.js +2 -0
- package/node_modules/playwright/node_modules/playwright-core/lib/vite/htmlReport/index.html +253 -27
- package/node_modules/playwright/node_modules/playwright-core/lib/vite/recorder/assets/{codeMirrorModule-D0BjbCb7.js → codeMirrorModule-DtudTj_v.js} +1 -1
- package/node_modules/playwright/node_modules/playwright-core/lib/vite/recorder/assets/index-BpDwp16L.js +422 -0
- package/node_modules/playwright/node_modules/playwright-core/lib/vite/recorder/index.html +1 -1
- package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/assets/{codeMirrorModule-Bzd72-bG.js → codeMirrorModule-FNMuBzX1.js} +1 -1
- package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/assets/defaultSettingsView-Co9upU5h.js +1035 -0
- package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/index.DXNIQ_dx.js +2 -0
- package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/index.html +2 -2
- package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/uiMode.CIKB3XSv.js +5 -0
- package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/uiMode.html +2 -2
- package/node_modules/playwright/node_modules/playwright-core/package.json +1 -1
- package/node_modules/playwright/node_modules/playwright-core/src/generated/pollingRecorderSource.ts +1 -1
- package/node_modules/playwright/node_modules/playwright-core/src/server/codegen/skyramp/jsonlReader.ts +4 -0
- package/node_modules/playwright/node_modules/playwright-core/src/server/codegen/skyramp/specReader.ts +1028 -0
- package/node_modules/playwright/node_modules/playwright-core/src/server/recorder/recorderApp.ts +31 -8
- package/node_modules/playwright/node_modules/playwright-core/src/server/recorder/skyramp/replayEngine.ts +1 -0
- package/node_modules/playwright/node_modules/playwright-core/src/utils.ts +1 -0
- package/node_modules/playwright/package.json +1 -1
- package/package.json +10 -6
- package/node_modules/playwright/node_modules/playwright-core/bundles/mcp/node_modules/hono/dist/tsconfig.build.tsbuildinfo +0 -1
- package/node_modules/playwright/node_modules/playwright-core/lib/vite/recorder/assets/index-lvTRGFx-.js +0 -193
- package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/assets/defaultSettingsView-DzxTioTK.js +0 -809
- package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/index.BGc30U3S.js +0 -2
- package/node_modules/playwright/node_modules/playwright-core/lib/vite/traceViewer/uiMode.IaDrb29A.js +0 -5
|
@@ -3,7 +3,7 @@ import { raw } from "../helper/html/index.js";
|
|
|
3
3
|
import { HtmlEscapedCallbackPhase, resolveCallback } from "../utils/html.js";
|
|
4
4
|
import { jsx, Fragment } from "./base.js";
|
|
5
5
|
import { DOM_RENDERER } from "./constants.js";
|
|
6
|
-
import { useContext } from "./context.js";
|
|
6
|
+
import { captureRenderContext, useContext } from "./context.js";
|
|
7
7
|
import { ErrorBoundary as ErrorBoundaryDomRenderer } from "./dom/components.js";
|
|
8
8
|
import { StreamingContext } from "./streaming.js";
|
|
9
9
|
var errorBoundaryCounter = 0;
|
|
@@ -12,8 +12,9 @@ var childrenToString = async (children) => {
|
|
|
12
12
|
return children.flat().map((c) => c == null || typeof c === "boolean" ? "" : c.toString());
|
|
13
13
|
} catch (e) {
|
|
14
14
|
if (e instanceof Promise) {
|
|
15
|
+
const resume = captureRenderContext();
|
|
15
16
|
await e;
|
|
16
|
-
return childrenToString(children);
|
|
17
|
+
return resume(() => childrenToString(children));
|
|
17
18
|
} else {
|
|
18
19
|
throw e;
|
|
19
20
|
}
|
|
@@ -41,51 +42,68 @@ var ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) => {
|
|
|
41
42
|
children = [children];
|
|
42
43
|
}
|
|
43
44
|
const nonce = useContext(StreamingContext)?.scriptNonce;
|
|
44
|
-
let
|
|
45
|
-
const
|
|
45
|
+
let resume;
|
|
46
|
+
const getResume = () => resume ||= captureRenderContext();
|
|
47
|
+
let fallbackStrPromise;
|
|
48
|
+
const resolveFallbackStr = () => fallbackStrPromise ||= (async () => {
|
|
46
49
|
const awaitedFallback = await fallback;
|
|
47
50
|
if (typeof awaitedFallback === "string") {
|
|
48
|
-
|
|
51
|
+
return awaitedFallback;
|
|
49
52
|
} else {
|
|
50
|
-
|
|
51
|
-
if (typeof
|
|
52
|
-
|
|
53
|
+
const fallbackResult = await getResume()(() => awaitedFallback?.toString());
|
|
54
|
+
if (typeof fallbackResult === "string") {
|
|
55
|
+
return raw(
|
|
56
|
+
fallbackResult,
|
|
57
|
+
fallbackResult.callbacks || awaitedFallback?.callbacks
|
|
58
|
+
);
|
|
53
59
|
}
|
|
54
60
|
}
|
|
55
|
-
};
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
return
|
|
61
|
+
})();
|
|
62
|
+
const renderFallback = async (error) => {
|
|
63
|
+
const fallbackStr = await resolveFallbackStr();
|
|
64
|
+
return getResume()(async () => {
|
|
65
|
+
onError?.(error);
|
|
66
|
+
const fallbackRes = fallbackStr !== void 0 ? fallbackStr : fallbackRender && jsx(Fragment, {}, fallbackRender(error)) || "";
|
|
67
|
+
const fallbackResString = await Fragment({
|
|
68
|
+
children: fallbackRes
|
|
69
|
+
}).toString();
|
|
70
|
+
return raw(
|
|
71
|
+
fallbackResString,
|
|
72
|
+
fallbackResString.callbacks || fallbackRes.callbacks
|
|
73
|
+
);
|
|
74
|
+
});
|
|
59
75
|
};
|
|
60
76
|
let resArray = [];
|
|
61
77
|
try {
|
|
62
78
|
resArray = children.map(resolveChildEarly);
|
|
63
79
|
} catch (e) {
|
|
64
|
-
|
|
80
|
+
const resume2 = getResume();
|
|
65
81
|
if (e instanceof Promise) {
|
|
66
82
|
resArray = [
|
|
67
|
-
e.then(() => childrenToString(children)).catch((e2) =>
|
|
83
|
+
e.then(() => resume2(() => childrenToString(children))).catch((e2) => renderFallback(e2))
|
|
68
84
|
];
|
|
69
85
|
} else {
|
|
70
|
-
resArray = [
|
|
86
|
+
resArray = [await renderFallback(e)];
|
|
71
87
|
}
|
|
72
88
|
}
|
|
73
89
|
if (resArray.some((res) => res instanceof Promise)) {
|
|
74
|
-
|
|
90
|
+
getResume();
|
|
75
91
|
const index = errorBoundaryCounter++;
|
|
76
92
|
const replaceRe = RegExp(`(<template id="E:${index}"></template>.*?)(.*?)(<!--E:${index}-->)`);
|
|
77
|
-
|
|
93
|
+
let caught = false;
|
|
78
94
|
const catchCallback = async ({ error: error2, buffer }) => {
|
|
79
95
|
if (caught) {
|
|
80
96
|
return "";
|
|
81
97
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
98
|
+
caught = true;
|
|
99
|
+
const fallbackResString = await renderFallback(error2);
|
|
100
|
+
const fallbackCallbacks = fallbackResString.callbacks;
|
|
85
101
|
if (buffer) {
|
|
86
102
|
buffer[0] = buffer[0].replace(replaceRe, fallbackResString);
|
|
103
|
+
return fallbackCallbacks?.length ? raw("", fallbackCallbacks) : "";
|
|
87
104
|
}
|
|
88
|
-
return
|
|
105
|
+
return raw(
|
|
106
|
+
`<template data-hono-target="E:${index}">${fallbackResString}</template><script>
|
|
89
107
|
((d,c,n) => {
|
|
90
108
|
c=d.currentScript.previousSibling
|
|
91
109
|
d=d.getElementById('E:${index}')
|
|
@@ -93,7 +111,9 @@ if(!d)return
|
|
|
93
111
|
do{n=d.nextSibling;n.remove()}while(n.nodeType!=8||n.nodeValue!='E:${index}')
|
|
94
112
|
d.replaceWith(c.content)
|
|
95
113
|
})(document)
|
|
96
|
-
</script
|
|
114
|
+
</script>`,
|
|
115
|
+
fallbackCallbacks
|
|
116
|
+
);
|
|
97
117
|
};
|
|
98
118
|
let error;
|
|
99
119
|
const promiseAll = Promise.all(resArray).catch((e) => error = e);
|
|
@@ -4,21 +4,143 @@ import { JSXFragmentNode } from "./base.js";
|
|
|
4
4
|
import { DOM_RENDERER } from "./constants.js";
|
|
5
5
|
import { createContextProviderFunction } from "./dom/context.js";
|
|
6
6
|
var globalContexts = [];
|
|
7
|
+
var alsProbed = false;
|
|
8
|
+
var asyncLocalStorage;
|
|
9
|
+
var fallbackStore;
|
|
10
|
+
var fallbackRendersInFlight = 0;
|
|
11
|
+
var warnedFallbackDefault = false;
|
|
12
|
+
var loadAsyncLocalStorage = () => {
|
|
13
|
+
if (alsProbed) {
|
|
14
|
+
return asyncLocalStorage;
|
|
15
|
+
}
|
|
16
|
+
alsProbed = true;
|
|
17
|
+
const global = globalThis;
|
|
18
|
+
let AsyncLocalStorage;
|
|
19
|
+
for (const probe of [
|
|
20
|
+
// Node.js >= 20.16, Deno, Bun, Cloudflare Workers (nodejs_compat). Property
|
|
21
|
+
// access only, so bundlers don't statically resolve `node:async_hooks`.
|
|
22
|
+
() => global.process?.getBuiltinModule?.("node:async_hooks")?.AsyncLocalStorage,
|
|
23
|
+
// Node.js < 20.16 has no `process.getBuiltinModule`, but a CJS entrypoint
|
|
24
|
+
// exposes the main module's `require` here.
|
|
25
|
+
() => global.process?.mainModule?.require?.("node:async_hooks")?.AsyncLocalStorage
|
|
26
|
+
]) {
|
|
27
|
+
try {
|
|
28
|
+
AsyncLocalStorage = probe();
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
if (AsyncLocalStorage) {
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (AsyncLocalStorage) {
|
|
36
|
+
asyncLocalStorage = new AsyncLocalStorage();
|
|
37
|
+
}
|
|
38
|
+
return asyncLocalStorage;
|
|
39
|
+
};
|
|
40
|
+
var getCurrentStore = () => {
|
|
41
|
+
return loadAsyncLocalStorage()?.getStore() || fallbackStore;
|
|
42
|
+
};
|
|
43
|
+
var warnIfStorelessAccess = () => {
|
|
44
|
+
if (fallbackRendersInFlight > 0 && !warnedFallbackDefault) {
|
|
45
|
+
warnedFallbackDefault = true;
|
|
46
|
+
console.warn(
|
|
47
|
+
"hono/jsx: AsyncLocalStorage is unavailable in this runtime, so useContext() after an await in an async component falls back to the context default value during server-side rendering. To get provided values across await boundaries, use a runtime with AsyncLocalStorage (Node.js >= 20.16, Deno, Bun, or Cloudflare Workers with the nodejs_compat flag)."
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var getContextValuesIn = (store, context) => {
|
|
52
|
+
if (!store) {
|
|
53
|
+
warnIfStorelessAccess();
|
|
54
|
+
return context.values;
|
|
55
|
+
}
|
|
56
|
+
let values = store.get(context);
|
|
57
|
+
if (!values) {
|
|
58
|
+
values = [context.values[0]];
|
|
59
|
+
store.set(context, values);
|
|
60
|
+
}
|
|
61
|
+
return values;
|
|
62
|
+
};
|
|
63
|
+
var readContextValueIn = (store, context) => {
|
|
64
|
+
if (!store) {
|
|
65
|
+
warnIfStorelessAccess();
|
|
66
|
+
return context.values.at(-1);
|
|
67
|
+
}
|
|
68
|
+
const values = store.get(context);
|
|
69
|
+
return values?.length ? values.at(-1) : context.values[0];
|
|
70
|
+
};
|
|
71
|
+
var captureContextValues = (store) => (store ? globalContexts.filter((c) => store.has(c)) : globalContexts).map((c) => [
|
|
72
|
+
c,
|
|
73
|
+
readContextValueIn(store, c)
|
|
74
|
+
]);
|
|
75
|
+
var resumeWithContextValues = (callback, store, contexts) => runWithRenderContext(() => {
|
|
76
|
+
const currentStore = getCurrentStore();
|
|
77
|
+
const valuesPerContext = contexts.map(([context, value]) => {
|
|
78
|
+
const values = getContextValuesIn(currentStore, context);
|
|
79
|
+
values.push(value);
|
|
80
|
+
return values;
|
|
81
|
+
});
|
|
82
|
+
const popContextValues = () => {
|
|
83
|
+
valuesPerContext.forEach((values) => {
|
|
84
|
+
values.pop();
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
try {
|
|
88
|
+
const result = callback();
|
|
89
|
+
if (result instanceof Promise) {
|
|
90
|
+
return result.finally(popContextValues);
|
|
91
|
+
}
|
|
92
|
+
popContextValues();
|
|
93
|
+
return result;
|
|
94
|
+
} catch (e) {
|
|
95
|
+
popContextValues();
|
|
96
|
+
throw e;
|
|
97
|
+
}
|
|
98
|
+
}, store);
|
|
99
|
+
var runWithRenderContext = (callback, resumeStore) => {
|
|
100
|
+
if (getCurrentStore()) {
|
|
101
|
+
return callback();
|
|
102
|
+
}
|
|
103
|
+
const store = resumeStore ?? /* @__PURE__ */ new WeakMap();
|
|
104
|
+
const storage = loadAsyncLocalStorage();
|
|
105
|
+
if (storage) {
|
|
106
|
+
return storage.run(store, callback);
|
|
107
|
+
}
|
|
108
|
+
fallbackStore = store;
|
|
109
|
+
let result;
|
|
110
|
+
try {
|
|
111
|
+
result = callback();
|
|
112
|
+
} finally {
|
|
113
|
+
fallbackStore = void 0;
|
|
114
|
+
}
|
|
115
|
+
if (!warnedFallbackDefault && result instanceof Promise) {
|
|
116
|
+
fallbackRendersInFlight++;
|
|
117
|
+
result = result.finally(() => {
|
|
118
|
+
fallbackRendersInFlight--;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
};
|
|
123
|
+
var captureRenderContext = () => {
|
|
124
|
+
const store = getCurrentStore();
|
|
125
|
+
const contexts = captureContextValues(store);
|
|
126
|
+
return (callback) => resumeWithContextValues(callback, store, contexts);
|
|
127
|
+
};
|
|
7
128
|
var createContext = (defaultValue) => {
|
|
8
129
|
const values = [defaultValue];
|
|
9
130
|
const context = ((props) => {
|
|
10
|
-
|
|
131
|
+
const contextValues = getContextValuesIn(getCurrentStore(), context);
|
|
132
|
+
contextValues.push(props.value);
|
|
11
133
|
let string;
|
|
12
134
|
try {
|
|
13
135
|
string = props.children ? (Array.isArray(props.children) ? new JSXFragmentNode("", {}, props.children) : props.children).toString() : "";
|
|
14
136
|
} catch (e) {
|
|
15
|
-
|
|
137
|
+
contextValues.pop();
|
|
16
138
|
throw e;
|
|
17
139
|
}
|
|
18
140
|
if (string instanceof Promise) {
|
|
19
|
-
return string.finally(() =>
|
|
141
|
+
return string.finally(() => contextValues.pop()).then((resString) => raw(resString, resString.callbacks));
|
|
20
142
|
} else {
|
|
21
|
-
|
|
143
|
+
contextValues.pop();
|
|
22
144
|
return raw(string);
|
|
23
145
|
}
|
|
24
146
|
});
|
|
@@ -29,10 +151,12 @@ var createContext = (defaultValue) => {
|
|
|
29
151
|
return context;
|
|
30
152
|
};
|
|
31
153
|
var useContext = (context) => {
|
|
32
|
-
return
|
|
154
|
+
return readContextValueIn(getCurrentStore(), context);
|
|
33
155
|
};
|
|
34
156
|
export {
|
|
157
|
+
captureRenderContext,
|
|
35
158
|
createContext,
|
|
36
159
|
globalContexts,
|
|
160
|
+
runWithRenderContext,
|
|
37
161
|
useContext
|
|
38
162
|
};
|
|
@@ -4,7 +4,7 @@ import { HtmlEscapedCallbackPhase, resolveCallback } from "../utils/html.js";
|
|
|
4
4
|
import { JSXNode } from "./base.js";
|
|
5
5
|
import { childrenToString } from "./components.js";
|
|
6
6
|
import { DOM_RENDERER, DOM_STASH } from "./constants.js";
|
|
7
|
-
import { createContext, useContext } from "./context.js";
|
|
7
|
+
import { captureRenderContext, createContext, useContext } from "./context.js";
|
|
8
8
|
import { Suspense as SuspenseDomRenderer } from "./dom/components.js";
|
|
9
9
|
import { buildDataStack } from "./dom/render.js";
|
|
10
10
|
var StreamingContext = createContext(null);
|
|
@@ -19,9 +19,8 @@ var Suspense = async ({
|
|
|
19
19
|
const nonce = useContext(StreamingContext)?.scriptNonce;
|
|
20
20
|
let resArray = [];
|
|
21
21
|
const stackNode = { [DOM_STASH]: [0, []] };
|
|
22
|
-
const popNodeStack = (
|
|
22
|
+
const popNodeStack = () => {
|
|
23
23
|
buildDataStack.pop();
|
|
24
|
-
return value;
|
|
25
24
|
};
|
|
26
25
|
try {
|
|
27
26
|
stackNode[DOM_STASH][0] = 0;
|
|
@@ -31,12 +30,15 @@ var Suspense = async ({
|
|
|
31
30
|
);
|
|
32
31
|
} catch (e) {
|
|
33
32
|
if (e instanceof Promise) {
|
|
33
|
+
const resume = captureRenderContext();
|
|
34
34
|
resArray = [
|
|
35
|
-
e.then(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
e.then(
|
|
36
|
+
() => resume(() => {
|
|
37
|
+
stackNode[DOM_STASH][0] = 0;
|
|
38
|
+
buildDataStack.push([[], stackNode]);
|
|
39
|
+
return childrenToString(children).finally(popNodeStack);
|
|
40
|
+
})
|
|
41
|
+
)
|
|
40
42
|
];
|
|
41
43
|
} else {
|
|
42
44
|
throw e;
|
|
@@ -6,7 +6,7 @@ var PREFIX = "Bearer";
|
|
|
6
6
|
var HEADER = "Authorization";
|
|
7
7
|
var bearerAuth = (options) => {
|
|
8
8
|
if (!("token" in options || "verifyToken" in options)) {
|
|
9
|
-
throw new Error('bearer auth middleware requires options for "token"');
|
|
9
|
+
throw new Error('bearer auth middleware requires options for "token" or "verifyToken"');
|
|
10
10
|
}
|
|
11
11
|
if (!options.realm) {
|
|
12
12
|
options.realm = "";
|
|
@@ -34,7 +34,7 @@ var cache = (options) => {
|
|
|
34
34
|
);
|
|
35
35
|
const addHeader = (c, responseVary) => {
|
|
36
36
|
if (cacheControlDirectives) {
|
|
37
|
-
const existingDirectives = c.res.headers.get("Cache-Control")?.split(",").map((d) => d.trim().split("=", 1)[0]) ?? [];
|
|
37
|
+
const existingDirectives = c.res.headers.get("Cache-Control")?.split(",").map((d) => d.trim().split("=", 1)[0].toLowerCase()) ?? [];
|
|
38
38
|
for (const directive of cacheControlDirectives) {
|
|
39
39
|
let [name, value] = directive.trim().split("=", 2);
|
|
40
40
|
name = name.toLowerCase();
|
|
@@ -35,7 +35,8 @@ var compress = (options) => {
|
|
|
35
35
|
return async function compress2(ctx, next) {
|
|
36
36
|
await next();
|
|
37
37
|
const contentLength = ctx.res.headers.get("Content-Length");
|
|
38
|
-
if (ctx.res.
|
|
38
|
+
if (ctx.res.status === 206 || // partial content, Content-Range refers to the uncompressed bytes
|
|
39
|
+
ctx.res.headers.has("Content-Encoding") || // already encoded
|
|
39
40
|
ctx.res.headers.has("Transfer-Encoding") || // already encoded or chunked
|
|
40
41
|
ctx.req.method === "HEAD" || // HEAD request
|
|
41
42
|
contentLength && Number(contentLength) < threshold || // content-length below threshold
|
|
@@ -10,9 +10,6 @@ var cors = (options) => {
|
|
|
10
10
|
const findAllowOrigin = ((optsOrigin) => {
|
|
11
11
|
if (typeof optsOrigin === "string") {
|
|
12
12
|
if (optsOrigin === "*") {
|
|
13
|
-
if (opts.credentials) {
|
|
14
|
-
return (origin) => origin || null;
|
|
15
|
-
}
|
|
16
13
|
return () => optsOrigin;
|
|
17
14
|
} else {
|
|
18
15
|
return (origin) => optsOrigin === origin ? origin : null;
|
|
@@ -47,7 +44,7 @@ var cors = (options) => {
|
|
|
47
44
|
set("Access-Control-Expose-Headers", opts.exposeHeaders.join(","));
|
|
48
45
|
}
|
|
49
46
|
if (c.req.method === "OPTIONS") {
|
|
50
|
-
if (opts.origin !== "*"
|
|
47
|
+
if (opts.origin !== "*") {
|
|
51
48
|
set("Vary", "Origin");
|
|
52
49
|
}
|
|
53
50
|
if (opts.maxAge != null) {
|
|
@@ -77,7 +74,7 @@ var cors = (options) => {
|
|
|
77
74
|
});
|
|
78
75
|
}
|
|
79
76
|
await next();
|
|
80
|
-
if (opts.origin !== "*"
|
|
77
|
+
if (opts.origin !== "*") {
|
|
81
78
|
c.header("Vary", "Origin", { append: true });
|
|
82
79
|
}
|
|
83
80
|
};
|
|
@@ -48,7 +48,8 @@ var etag = (options) => {
|
|
|
48
48
|
}
|
|
49
49
|
etag3 = weak ? `W/"${hash}"` : `"${hash}"`;
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
const matched = ifNoneMatch === "*" ? (c.req.method === "GET" || c.req.method === "HEAD") && res.ok : etagMatches(etag3, ifNoneMatch);
|
|
52
|
+
if (matched) {
|
|
52
53
|
c.res = new Response(null, {
|
|
53
54
|
status: 304,
|
|
54
55
|
statusText: "Not Modified",
|
|
@@ -53,20 +53,12 @@ var normalizeLanguage = (lang, options) => {
|
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
var detectFromQuery = (c, options) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return normalizeLanguage(query, options);
|
|
59
|
-
} catch {
|
|
60
|
-
return void 0;
|
|
61
|
-
}
|
|
56
|
+
const query = c.req.query(options.lookupQueryString);
|
|
57
|
+
return normalizeLanguage(query, options);
|
|
62
58
|
};
|
|
63
59
|
var detectFromCookie = (c, options) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return normalizeLanguage(cookie, options);
|
|
67
|
-
} catch {
|
|
68
|
-
return void 0;
|
|
69
|
-
}
|
|
60
|
+
const cookie = getCookie(c, options.lookupCookie);
|
|
61
|
+
return normalizeLanguage(cookie, options);
|
|
70
62
|
};
|
|
71
63
|
function detectFromHeader(c, options) {
|
|
72
64
|
try {
|
|
@@ -87,14 +79,10 @@ function detectFromHeader(c, options) {
|
|
|
87
79
|
}
|
|
88
80
|
}
|
|
89
81
|
function detectFromPath(c, options) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return normalizeLanguage(langSegment, options);
|
|
95
|
-
} catch {
|
|
96
|
-
return void 0;
|
|
97
|
-
}
|
|
82
|
+
const url = new URL(c.req.url);
|
|
83
|
+
const pathSegments = url.pathname.split("/").filter(Boolean);
|
|
84
|
+
const langSegment = pathSegments[options.lookupFromPathIndex];
|
|
85
|
+
return normalizeLanguage(langSegment, options);
|
|
98
86
|
}
|
|
99
87
|
var detectors = {
|
|
100
88
|
querystring: detectFromQuery,
|
|
@@ -129,9 +117,6 @@ var detectLanguage = (c, options) => {
|
|
|
129
117
|
let detectedLang;
|
|
130
118
|
for (const detectorName of options.order) {
|
|
131
119
|
const detector = detectors[detectorName];
|
|
132
|
-
if (!detector) {
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
120
|
try {
|
|
136
121
|
detectedLang = detector(c, options);
|
|
137
122
|
if (detectedLang) {
|
|
@@ -164,15 +149,8 @@ var languageDetector = (userOptions) => {
|
|
|
164
149
|
};
|
|
165
150
|
validateOptions(options);
|
|
166
151
|
return async function languageDetector2(ctx, next) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
ctx.set("language", lang);
|
|
170
|
-
} catch (error) {
|
|
171
|
-
if (options.debug) {
|
|
172
|
-
console.error("Language detection failed:", error);
|
|
173
|
-
}
|
|
174
|
-
ctx.set("language", options.fallbackLanguage);
|
|
175
|
-
}
|
|
152
|
+
const lang = detectLanguage(ctx, options);
|
|
153
|
+
ctx.set("language", lang);
|
|
176
154
|
await next();
|
|
177
155
|
};
|
|
178
156
|
};
|
|
@@ -59,11 +59,13 @@ var methodOverride = (options) => async function methodOverride2(c, next) {
|
|
|
59
59
|
if (method) {
|
|
60
60
|
const url = new URL(c.req.url);
|
|
61
61
|
url.searchParams.delete(queryName);
|
|
62
|
-
const
|
|
62
|
+
const requestInit = {
|
|
63
63
|
body: c.req.raw.body,
|
|
64
64
|
headers: c.req.raw.headers,
|
|
65
|
-
method
|
|
66
|
-
|
|
65
|
+
method,
|
|
66
|
+
duplex: c.req.raw.body ? "half" : void 0
|
|
67
|
+
};
|
|
68
|
+
const request = new Request(url.toString(), requestInit);
|
|
67
69
|
return app.fetch(request, c.env, getExecutionCtx(c));
|
|
68
70
|
}
|
|
69
71
|
}
|
|
@@ -24,7 +24,7 @@ var serveStatic = (options) => {
|
|
|
24
24
|
} else {
|
|
25
25
|
try {
|
|
26
26
|
filename = tryDecodeURI(c.req.path);
|
|
27
|
-
if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}
|
|
27
|
+
if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}|\\/.test(filename)) {
|
|
28
28
|
throw new Error();
|
|
29
29
|
}
|
|
30
30
|
} catch {
|
|
@@ -44,7 +44,7 @@ var serveStatic = (options) => {
|
|
|
44
44
|
if (content instanceof Response) {
|
|
45
45
|
return c.newResponse(content.body, content);
|
|
46
46
|
}
|
|
47
|
-
if (content) {
|
|
47
|
+
if (content != null) {
|
|
48
48
|
const mimeType = options.mimes && getMimeType(path, options.mimes) || getMimeType(path);
|
|
49
49
|
c.header("Content-Type", mimeType || "application/octet-stream");
|
|
50
50
|
if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
|
|
@@ -31,7 +31,9 @@ var timing = (config) => {
|
|
|
31
31
|
endTime(c, "total");
|
|
32
32
|
}
|
|
33
33
|
if (options.autoEnd) {
|
|
34
|
-
timers.forEach((_, key) =>
|
|
34
|
+
timers.forEach((_, key) => {
|
|
35
|
+
endTime(c, key);
|
|
36
|
+
});
|
|
35
37
|
}
|
|
36
38
|
const enabled = typeof options.enabled === "function" ? options.enabled(c) : options.enabled;
|
|
37
39
|
if (enabled) {
|
|
@@ -134,6 +134,15 @@ var Node = class _Node {
|
|
|
134
134
|
if (m) {
|
|
135
135
|
params[name] = m[0];
|
|
136
136
|
this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
|
|
137
|
+
if (m[0].length === restPathString.length && child.#children["*"]) {
|
|
138
|
+
this.#pushHandlerSets(
|
|
139
|
+
handlerSets,
|
|
140
|
+
child.#children["*"],
|
|
141
|
+
method,
|
|
142
|
+
node.#params,
|
|
143
|
+
params
|
|
144
|
+
);
|
|
145
|
+
}
|
|
137
146
|
if (hasChildren(child.#children)) {
|
|
138
147
|
child.#params = params;
|
|
139
148
|
const componentCount = m[0].match(/\//)?.length ?? 0;
|
|
@@ -81,7 +81,7 @@ interface CloudFrontResult {
|
|
|
81
81
|
body?: string;
|
|
82
82
|
bodyEncoding?: 'text' | 'base64';
|
|
83
83
|
}
|
|
84
|
-
export declare const handle: (app: Hono<any>) => ((event: CloudFrontEdgeEvent, context?: CloudFrontContext, callback?: Callback) => Promise<CloudFrontResult>);
|
|
84
|
+
export declare const handle: (app: Hono<any>) => ((event: CloudFrontEdgeEvent, context?: CloudFrontContext, callback?: Callback) => Promise<CloudFrontResult | CloudFrontRequest>);
|
|
85
85
|
export declare const createBody: (method: string, requestBody: CloudFrontRequest["body"]) => string | Uint8Array<ArrayBuffer> | undefined;
|
|
86
86
|
export declare const isContentTypeBinary: (contentType: string) => boolean;
|
|
87
87
|
export {};
|
|
@@ -31,7 +31,7 @@ export type WSReadyState = 0 | 1 | 2 | 3;
|
|
|
31
31
|
* An argument for WSContext class
|
|
32
32
|
*/
|
|
33
33
|
export interface WSContextInit<T = unknown> {
|
|
34
|
-
send(data: string | ArrayBuffer | Uint8Array
|
|
34
|
+
send(data: string | ArrayBuffer | Uint8Array<ArrayBuffer>, options: SendOptions): void;
|
|
35
35
|
close(code?: number, reason?: string): void;
|
|
36
36
|
raw?: T;
|
|
37
37
|
readyState: WSReadyState;
|
|
@@ -23,7 +23,6 @@ export declare namespace JSX {
|
|
|
23
23
|
}
|
|
24
24
|
export declare const getNameSpaceContext: () => Context<string> | undefined;
|
|
25
25
|
export declare const booleanAttributes: string[];
|
|
26
|
-
type LocalContexts = [Context<unknown>, unknown][];
|
|
27
26
|
export type Child = string | Promise<string> | number | JSXNode | null | undefined | boolean | Child[];
|
|
28
27
|
export declare class JSXNode implements HtmlEscaped {
|
|
29
28
|
tag: string | Function;
|
|
@@ -31,7 +30,7 @@ export declare class JSXNode implements HtmlEscaped {
|
|
|
31
30
|
key?: string;
|
|
32
31
|
children: Child[];
|
|
33
32
|
isEscaped: true;
|
|
34
|
-
|
|
33
|
+
suspendedContext?: <T>(callback: () => T) => T;
|
|
35
34
|
constructor(tag: string | Function, props: Props, children: Child[]);
|
|
36
35
|
get type(): string | Function;
|
|
37
36
|
get ref(): any;
|
|
@@ -55,4 +54,3 @@ export declare const Fragment: ({ children, }: {
|
|
|
55
54
|
export declare const isValidElement: (element: unknown) => element is JSXNode;
|
|
56
55
|
export declare const cloneElement: <T extends JSXNode | JSX.Element>(element: T, props: Partial<Props>, ...children: Child[]) => T;
|
|
57
56
|
export declare const reactAPICompatVersion = "19.0.0-hono-jsx";
|
|
58
|
-
export {};
|
|
@@ -8,5 +8,44 @@ export interface Context<T> extends FC<PropsWithChildren<{
|
|
|
8
8
|
}>>;
|
|
9
9
|
}
|
|
10
10
|
export declare const globalContexts: Context<unknown>[];
|
|
11
|
+
/** Per-render context store, isolated per request so values never leak across renders. */
|
|
12
|
+
type RenderStore = WeakMap<Context<unknown>, unknown[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Establish the request-scoped context store for a render.
|
|
15
|
+
*
|
|
16
|
+
* `resumeStore` continues a suspended subtree in the same store on the fallback
|
|
17
|
+
* path (ignored when `AsyncLocalStorage` is available, where isolation is
|
|
18
|
+
* automatic).
|
|
19
|
+
*
|
|
20
|
+
* Without `AsyncLocalStorage` a render can't be followed across `await`, so the
|
|
21
|
+
* store lives in `fallbackStore` only during synchronous work (mirroring
|
|
22
|
+
* React's request storage). Reading context after `await` then finds no store
|
|
23
|
+
* and falls back to the default value — never another request's value.
|
|
24
|
+
*/
|
|
25
|
+
export declare const runWithRenderContext: <T>(callback: () => T, resumeStore?: RenderStore) => T;
|
|
26
|
+
/**
|
|
27
|
+
* Capture the current render store and return a resumer that re-establishes it
|
|
28
|
+
* around a deferred continuation (e.g. a re-render after a suspended promise
|
|
29
|
+
* settles). Shared by every suspension point so none reimplements it.
|
|
30
|
+
*/
|
|
31
|
+
export declare const captureRenderContext: () => (<T>(callback: () => T) => T);
|
|
32
|
+
/**
|
|
33
|
+
* Create a context whose value can be provided with `<Context.Provider>` and
|
|
34
|
+
* read with {@link useContext}.
|
|
35
|
+
*
|
|
36
|
+
* Server-side renders are isolated per request, so a provided value never leaks
|
|
37
|
+
* into a concurrent request — even across `await` in an async component, when
|
|
38
|
+
* `AsyncLocalStorage` is available (Node.js >= 20.16, Deno, Bun, Cloudflare
|
|
39
|
+
* Workers with `nodejs_compat`). Without it, reading context after `await`
|
|
40
|
+
* returns the default value; synchronous components and `use()`-based
|
|
41
|
+
* suspension are unaffected.
|
|
42
|
+
*/
|
|
11
43
|
export declare const createContext: <T>(defaultValue: T) => Context<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Read the current value of a context created with {@link createContext}.
|
|
46
|
+
*
|
|
47
|
+
* Safe to call from async components after `await`. See {@link createContext}
|
|
48
|
+
* for the per-runtime isolation guarantees.
|
|
49
|
+
*/
|
|
12
50
|
export declare const useContext: <T>(context: Context<T>) => T;
|
|
51
|
+
export {};
|
|
@@ -24,11 +24,11 @@ import type { Env, MiddlewareHandler } from '../../types';
|
|
|
24
24
|
* app.use(contextStorage())
|
|
25
25
|
*
|
|
26
26
|
* app.use(async (c, next) => {
|
|
27
|
-
* c.set('message', 'Hono is hot!!)
|
|
27
|
+
* c.set('message', 'Hono is hot!!')
|
|
28
28
|
* await next()
|
|
29
29
|
* })
|
|
30
30
|
*
|
|
31
|
-
* app.get('/', async (c) =>
|
|
31
|
+
* app.get('/', async (c) => c.text(getMessage()))
|
|
32
32
|
*
|
|
33
33
|
* const getMessage = () => {
|
|
34
34
|
* return getContext<Env>().var.message
|