astro 7.2.2 → 7.2.3
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/actions/handler.d.ts +6 -12
- package/dist/actions/handler.js +30 -40
- package/dist/actions/load.d.ts +12 -0
- package/dist/actions/load.js +55 -0
- package/dist/actions/runtime/entrypoints/server.js +5 -4
- package/dist/actions/runtime/server.js +8 -6
- package/dist/assets/fonts/providers/index.d.ts +1 -1
- package/dist/assets/fonts/providers/index.js +2 -12
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/container/environment.d.ts +20 -0
- package/dist/container/environment.js +106 -0
- package/dist/container/index.js +65 -32
- package/dist/content/content-layer.js +3 -3
- package/dist/content/data-store-writer.d.ts +7 -10
- package/dist/content/data-store-writer.js +62 -27
- package/dist/content/data-store.d.ts +20 -3
- package/dist/content/data-store.js +28 -7
- package/dist/content/mutable-data-store.js +15 -10
- package/dist/content/runtime.d.ts +3 -2
- package/dist/content/runtime.js +43 -26
- package/dist/core/app/app.d.ts +0 -2
- package/dist/core/app/app.js +0 -7
- package/dist/core/app/base.d.ts +32 -20
- package/dist/core/app/base.js +76 -66
- package/dist/core/app/dev-facade.d.ts +27 -0
- package/dist/core/app/dev-facade.js +51 -0
- package/dist/core/app/entrypoints/index.d.ts +0 -1
- package/dist/core/app/entrypoints/index.js +0 -2
- package/dist/core/app/entrypoints/virtual/dev.js +24 -19
- package/dist/core/app/node.js +13 -14
- package/dist/core/app/prepare-response.d.ts +1 -1
- package/dist/core/app/validate-headers.js +7 -3
- package/dist/core/build/app.d.ts +31 -6
- package/dist/core/build/app.js +31 -13
- package/dist/core/build/environment.d.ts +25 -0
- package/dist/core/build/environment.js +157 -0
- package/dist/core/cache/handler.d.ts +13 -7
- package/dist/core/cache/handler.js +55 -51
- package/dist/core/cache/provider.d.ts +4 -0
- package/dist/core/cache/provider.js +15 -0
- package/dist/core/constants.d.ts +0 -11
- package/dist/core/constants.js +1 -5
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/environment/dev-nonrunnable.d.ts +6 -0
- package/dist/core/environment/dev-nonrunnable.js +170 -0
- package/dist/core/environment/index.d.ts +90 -0
- package/dist/core/environment/index.js +12 -0
- package/dist/core/environment/production.d.ts +6 -0
- package/dist/core/environment/production.js +117 -0
- package/dist/core/errors/build-handler.d.ts +5 -10
- package/dist/core/errors/build-handler.js +11 -17
- package/dist/core/errors/default-handler.d.ts +4 -9
- package/dist/core/errors/default-handler.js +92 -107
- package/dist/core/errors/dev-handler.d.ts +7 -11
- package/dist/core/errors/dev-handler.js +71 -69
- package/dist/core/errors/errors-data.d.ts +18 -0
- package/dist/core/errors/errors-data.js +7 -0
- package/dist/core/errors/handler.d.ts +22 -3
- package/dist/core/errors/handler.js +25 -0
- package/dist/core/fetch/default-handler.d.ts +15 -8
- package/dist/core/fetch/default-handler.js +12 -34
- package/dist/core/fetch/features.d.ts +23 -0
- package/dist/core/fetch/features.js +27 -0
- package/dist/core/fetch/fetch-state.d.ts +52 -7
- package/dist/core/fetch/fetch-state.js +92 -81
- package/dist/core/fetch/index.d.ts +9 -2
- package/dist/core/fetch/index.js +18 -79
- package/dist/core/fetch/vite-plugin.js +2 -1
- package/dist/core/i18n/handler.d.ts +28 -13
- package/dist/core/i18n/handler.js +100 -100
- package/dist/core/logger/manifest-logger.d.ts +31 -0
- package/dist/core/logger/manifest-logger.js +37 -0
- package/dist/core/manifest/ambient-source.d.ts +2 -0
- package/dist/core/manifest/ambient-source.js +4 -0
- package/dist/core/manifest/ambient.d.ts +16 -0
- package/dist/core/manifest/ambient.js +22 -0
- package/dist/core/manifest/derived.d.ts +3 -0
- package/dist/core/manifest/derived.js +10 -0
- package/dist/core/manifest/memo.d.ts +31 -0
- package/dist/core/manifest/memo.js +47 -0
- package/dist/core/messages/runtime.js +1 -1
- package/dist/core/middleware/astro-middleware.d.ts +25 -35
- package/dist/core/middleware/astro-middleware.js +61 -81
- package/dist/core/middleware/load.d.ts +19 -0
- package/dist/core/middleware/load.js +36 -0
- package/dist/core/middleware/sequence.js +15 -7
- package/dist/core/pages/handler.d.ts +18 -25
- package/dist/core/pages/handler.js +68 -84
- package/dist/core/redirects/render.js +3 -8
- package/dist/core/render/index.d.ts +0 -1
- package/dist/core/render/index.js +0 -2
- package/dist/core/render/route-cache.d.ts +6 -1
- package/dist/core/render/route-cache.js +11 -1
- package/dist/core/rewrites/handler.d.ts +4 -6
- package/dist/core/rewrites/handler.js +19 -20
- package/dist/core/routing/default.d.ts +2 -0
- package/dist/core/routing/default.js +7 -1
- package/dist/core/routing/dev.d.ts +1 -3
- package/dist/core/routing/dev.js +12 -5
- package/dist/core/routing/handler.d.ts +6 -16
- package/dist/core/routing/handler.js +126 -164
- package/dist/core/routing/helpers.d.ts +7 -1
- package/dist/core/routing/helpers.js +21 -0
- package/dist/core/routing/match-request.d.ts +10 -0
- package/dist/core/routing/match-request.js +57 -0
- package/dist/core/routing/route-table.d.ts +34 -0
- package/dist/core/routing/route-table.js +41 -0
- package/dist/core/routing/trailing-slash-handler.d.ts +4 -14
- package/dist/core/routing/trailing-slash-handler.js +39 -50
- package/dist/core/server-islands/mappings.d.ts +6 -0
- package/dist/core/server-islands/mappings.js +12 -0
- package/dist/core/session/driver.d.ts +4 -0
- package/dist/core/session/driver.js +14 -0
- package/dist/core/session/handler.d.ts +1 -1
- package/dist/core/session/handler.js +8 -8
- package/dist/core/session/provider-disabled.js +2 -2
- package/dist/entrypoints/prerender.js +5 -1
- package/dist/i18n/middleware.d.ts +4 -4
- package/dist/i18n/middleware.js +3 -3
- package/dist/manifest/serialized.d.ts +1 -0
- package/dist/manifest/serialized.js +9 -2
- package/dist/runtime/prerender/static-paths.d.ts +14 -2
- package/dist/runtime/prerender/static-paths.js +4 -3
- package/dist/types/public/config.d.ts +433 -241
- package/dist/vite-plugin-app/createAstroServerApp.js +22 -18
- package/dist/vite-plugin-app/environment.d.ts +18 -0
- package/dist/vite-plugin-app/environment.js +210 -0
- package/dist/vite-plugin-app/handle-request.d.ts +30 -0
- package/dist/vite-plugin-app/handle-request.js +129 -0
- package/dist/vite-plugin-app/index.d.ts +1 -1
- package/dist/vite-plugin-app/index.js +1 -1
- package/package.json +14 -7
- package/src/core/README.md +37 -0
- package/src/core/manifest/ambient-source.ts +9 -0
- package/src/types/README.md +5 -0
- package/dist/container/pipeline.d.ts +0 -14
- package/dist/container/pipeline.js +0 -78
- package/dist/core/app/dev/app.d.ts +0 -31
- package/dist/core/app/dev/app.js +0 -80
- package/dist/core/app/dev/pipeline.d.ts +0 -17
- package/dist/core/app/dev/pipeline.js +0 -133
- package/dist/core/app/pipeline.d.ts +0 -14
- package/dist/core/app/pipeline.js +0 -123
- package/dist/core/base-pipeline.d.ts +0 -183
- package/dist/core/base-pipeline.js +0 -293
- package/dist/core/build/pipeline.d.ts +0 -38
- package/dist/core/build/pipeline.js +0 -202
- package/dist/vite-plugin-app/app.d.ts +0 -62
- package/dist/vite-plugin-app/app.js +0 -237
- package/dist/vite-plugin-app/pipeline.d.ts +0 -25
- package/dist/vite-plugin-app/pipeline.js +0 -189
|
@@ -1,116 +1,116 @@
|
|
|
1
1
|
import { appendForwardSlash } from "@astrojs/internal-helpers/path";
|
|
2
2
|
import { computeFallbackRoute } from "../../i18n/fallback.js";
|
|
3
3
|
import { I18nRouter } from "../../i18n/router.js";
|
|
4
|
-
import {
|
|
4
|
+
import { markFeatureUsed, FetchFeatures } from "../fetch/features.js";
|
|
5
5
|
import { shouldAppendForwardSlash } from "../build/util.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
6
|
+
import { createManifestMemo } from "../manifest/memo.js";
|
|
7
|
+
function compileI18n(i18n, base, trailingSlash, format) {
|
|
8
|
+
const router = new I18nRouter({
|
|
9
|
+
strategy: i18n.strategy,
|
|
10
|
+
defaultLocale: i18n.defaultLocale,
|
|
11
|
+
locales: i18n.locales,
|
|
12
|
+
base,
|
|
13
|
+
domains: i18n.domainLookupTable ? Object.keys(i18n.domainLookupTable).reduce(
|
|
14
|
+
(acc, domain) => {
|
|
15
|
+
const locale = i18n.domainLookupTable[domain];
|
|
16
|
+
if (!acc[domain]) {
|
|
17
|
+
acc[domain] = [];
|
|
18
|
+
}
|
|
19
|
+
acc[domain].push(locale);
|
|
20
|
+
return acc;
|
|
21
|
+
},
|
|
22
|
+
{}
|
|
23
|
+
) : void 0
|
|
24
|
+
});
|
|
25
|
+
return { config: i18n, base, trailingSlash, format, router };
|
|
26
|
+
}
|
|
27
|
+
const i18nMemo = createManifestMemo((manifest) => {
|
|
28
|
+
const config = manifest.i18n;
|
|
29
|
+
return config && config.strategy !== "manual" ? compileI18n(config, manifest.base, manifest.trailingSlash, manifest.buildFormat) : null;
|
|
30
|
+
});
|
|
31
|
+
function getI18n(manifest) {
|
|
32
|
+
return i18nMemo.get(manifest);
|
|
33
|
+
}
|
|
34
|
+
async function finalizeI18n(compiled, state, response) {
|
|
35
|
+
markFeatureUsed(state.manifest, FetchFeatures.i18n);
|
|
36
|
+
const i18n = compiled.config;
|
|
37
|
+
if (state.skipErrorReroute && typeof i18n.fallback === "undefined") {
|
|
38
|
+
return response;
|
|
34
39
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
if (state.responseRouteType !== "page" && state.responseRouteType !== "fallback") {
|
|
41
|
+
return response;
|
|
42
|
+
}
|
|
43
|
+
const url = state.url;
|
|
44
|
+
const currentLocale = state.computeCurrentLocale();
|
|
45
|
+
const isPrerendered = state.routeData.prerender;
|
|
46
|
+
const routerContext = {
|
|
47
|
+
currentLocale,
|
|
48
|
+
currentDomain: url.hostname,
|
|
49
|
+
routeType: state.responseRouteType,
|
|
50
|
+
isReroute: false
|
|
51
|
+
};
|
|
52
|
+
const routeDecision = compiled.router.match(url.pathname, routerContext);
|
|
53
|
+
switch (routeDecision.type) {
|
|
54
|
+
case "redirect": {
|
|
55
|
+
let location = routeDecision.location;
|
|
56
|
+
if (shouldAppendForwardSlash(compiled.trailingSlash, compiled.format)) {
|
|
57
|
+
location = appendForwardSlash(location);
|
|
58
|
+
}
|
|
59
|
+
return new Response(null, {
|
|
60
|
+
status: routeDecision.status ?? 302,
|
|
61
|
+
headers: { Location: location }
|
|
62
|
+
});
|
|
43
63
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
currentDomain: url.hostname,
|
|
50
|
-
routeType: state.responseRouteType,
|
|
51
|
-
isReroute: false
|
|
52
|
-
};
|
|
53
|
-
const routeDecision = this.#router.match(url.pathname, routerContext);
|
|
54
|
-
switch (routeDecision.type) {
|
|
55
|
-
case "redirect": {
|
|
56
|
-
let location = routeDecision.location;
|
|
57
|
-
if (shouldAppendForwardSlash(this.#trailingSlash, this.#format)) {
|
|
58
|
-
location = appendForwardSlash(location);
|
|
59
|
-
}
|
|
60
|
-
return new Response(null, {
|
|
61
|
-
status: routeDecision.status ?? 302,
|
|
62
|
-
headers: { Location: location }
|
|
64
|
+
case "notFound": {
|
|
65
|
+
if (isPrerendered) {
|
|
66
|
+
const prerenderedRes = new Response(response.body, {
|
|
67
|
+
status: 404,
|
|
68
|
+
headers: response.headers
|
|
63
69
|
});
|
|
64
|
-
|
|
65
|
-
case "notFound": {
|
|
66
|
-
if (isPrerendered) {
|
|
67
|
-
const prerenderedRes = new Response(response.body, {
|
|
68
|
-
status: 404,
|
|
69
|
-
headers: response.headers
|
|
70
|
-
});
|
|
71
|
-
state.skipErrorReroute = true;
|
|
72
|
-
if (routeDecision.location) {
|
|
73
|
-
prerenderedRes.headers.set("Location", routeDecision.location);
|
|
74
|
-
}
|
|
75
|
-
return prerenderedRes;
|
|
76
|
-
}
|
|
77
|
-
const headers = new Headers();
|
|
70
|
+
state.skipErrorReroute = true;
|
|
78
71
|
if (routeDecision.location) {
|
|
79
|
-
headers.set("Location", routeDecision.location);
|
|
72
|
+
prerenderedRes.headers.set("Location", routeDecision.location);
|
|
80
73
|
}
|
|
81
|
-
return
|
|
74
|
+
return prerenderedRes;
|
|
82
75
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (i18n.fallback && i18n.fallbackType) {
|
|
87
|
-
const effectiveStatus = state.responseRouteType === "fallback" ? 404 : response.status;
|
|
88
|
-
const fallbackDecision = computeFallbackRoute({
|
|
89
|
-
pathname: url.pathname,
|
|
90
|
-
responseStatus: effectiveStatus,
|
|
91
|
-
currentLocale,
|
|
92
|
-
fallback: i18n.fallback,
|
|
93
|
-
fallbackType: i18n.fallbackType,
|
|
94
|
-
locales: i18n.locales,
|
|
95
|
-
defaultLocale: i18n.defaultLocale,
|
|
96
|
-
strategy: i18n.strategy,
|
|
97
|
-
base: this.#base
|
|
98
|
-
});
|
|
99
|
-
switch (fallbackDecision.type) {
|
|
100
|
-
case "redirect":
|
|
101
|
-
return new Response(null, {
|
|
102
|
-
status: 302,
|
|
103
|
-
headers: { Location: fallbackDecision.pathname + url.search }
|
|
104
|
-
});
|
|
105
|
-
case "rewrite":
|
|
106
|
-
return await state.rewrite(fallbackDecision.pathname + url.search);
|
|
107
|
-
case "none":
|
|
108
|
-
break;
|
|
76
|
+
const headers = new Headers();
|
|
77
|
+
if (routeDecision.location) {
|
|
78
|
+
headers.set("Location", routeDecision.location);
|
|
109
79
|
}
|
|
80
|
+
return new Response(null, { status: 404, headers });
|
|
81
|
+
}
|
|
82
|
+
case "continue":
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
if (i18n.fallback && i18n.fallbackType) {
|
|
86
|
+
const effectiveStatus = state.responseRouteType === "fallback" ? 404 : response.status;
|
|
87
|
+
const fallbackDecision = computeFallbackRoute({
|
|
88
|
+
pathname: url.pathname,
|
|
89
|
+
responseStatus: effectiveStatus,
|
|
90
|
+
currentLocale,
|
|
91
|
+
fallback: i18n.fallback,
|
|
92
|
+
fallbackType: i18n.fallbackType,
|
|
93
|
+
locales: i18n.locales,
|
|
94
|
+
defaultLocale: i18n.defaultLocale,
|
|
95
|
+
strategy: i18n.strategy,
|
|
96
|
+
base: compiled.base
|
|
97
|
+
});
|
|
98
|
+
switch (fallbackDecision.type) {
|
|
99
|
+
case "redirect":
|
|
100
|
+
return new Response(null, {
|
|
101
|
+
status: 302,
|
|
102
|
+
headers: { Location: fallbackDecision.pathname + url.search }
|
|
103
|
+
});
|
|
104
|
+
case "rewrite":
|
|
105
|
+
return await state.rewrite(fallbackDecision.pathname + url.search);
|
|
106
|
+
case "none":
|
|
107
|
+
break;
|
|
110
108
|
}
|
|
111
|
-
return response;
|
|
112
109
|
}
|
|
110
|
+
return response;
|
|
113
111
|
}
|
|
114
112
|
export {
|
|
115
|
-
|
|
113
|
+
compileI18n,
|
|
114
|
+
finalizeI18n,
|
|
115
|
+
getI18n
|
|
116
116
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SSRManifest } from '../app/types.js';
|
|
2
|
+
import type { AstroLogger } from './core.js';
|
|
3
|
+
/**
|
|
4
|
+
* One identity-stable logger per manifest. Created on first access as a
|
|
5
|
+
* console logger at `manifest.logLevel`.
|
|
6
|
+
*
|
|
7
|
+
* The instance is never replaced: `getResolvedLogger` swaps the
|
|
8
|
+
* destination in place via `AstroLogger.setDestination`, so every holder
|
|
9
|
+
* (state-captured logger, adapterLogger's retained options) writes to the
|
|
10
|
+
* new destination immediately.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getLogger(manifest: SSRManifest): AstroLogger;
|
|
13
|
+
/**
|
|
14
|
+
* Composition-time injection (dev server logger, DevApp console logger, an
|
|
15
|
+
* App facade constructed with a custom logger path, tests). Must be called
|
|
16
|
+
* before the first `getLogger()` read to take effect deterministically;
|
|
17
|
+
* replaces the stored instance either way.
|
|
18
|
+
*/
|
|
19
|
+
export declare function setLogger(manifest: SSRManifest, logger: AstroLogger): void;
|
|
20
|
+
/**
|
|
21
|
+
* The manifest's logger with the user-configured destination (the
|
|
22
|
+
* `manifest.logger` thunk) resolved and applied via `setDestination` on the
|
|
23
|
+
* identity-stable logger. Memoized single-flight; awaited at request entry.
|
|
24
|
+
*
|
|
25
|
+
* Never rejects: a destination that fails to load is reported through the
|
|
26
|
+
* unswapped (console) logger, which stays in place — a broken custom
|
|
27
|
+
* destination cannot fail a request. Because the derivation always resolves,
|
|
28
|
+
* the memo's delete-on-rejection retry path never triggers: the thunk runs
|
|
29
|
+
* at most once per manifest.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getResolvedLogger(manifest: SSRManifest): Promise<AstroLogger>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createAsyncManifestMemo } from "../manifest/memo.js";
|
|
2
|
+
import { createConsoleLogger } from "./impls/console.js";
|
|
3
|
+
const loggers = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
function getLogger(manifest) {
|
|
5
|
+
let logger = loggers.get(manifest);
|
|
6
|
+
if (!logger) {
|
|
7
|
+
logger = createConsoleLogger({ level: manifest.logLevel });
|
|
8
|
+
loggers.set(manifest, logger);
|
|
9
|
+
}
|
|
10
|
+
return logger;
|
|
11
|
+
}
|
|
12
|
+
function setLogger(manifest, logger) {
|
|
13
|
+
loggers.set(manifest, logger);
|
|
14
|
+
}
|
|
15
|
+
const resolvedLogger = createAsyncManifestMemo(async (manifest) => {
|
|
16
|
+
const logger = getLogger(manifest);
|
|
17
|
+
try {
|
|
18
|
+
const destination = (await manifest.logger?.())?.default;
|
|
19
|
+
if (destination) {
|
|
20
|
+
logger.setDestination(destination);
|
|
21
|
+
}
|
|
22
|
+
} catch (error) {
|
|
23
|
+
logger.error(
|
|
24
|
+
"config",
|
|
25
|
+
"Failed to load the configured logger destination; continuing with the console logger.\n" + (error instanceof Error ? error.stack ?? error.message : String(error))
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
return logger;
|
|
29
|
+
});
|
|
30
|
+
function getResolvedLogger(manifest) {
|
|
31
|
+
return resolvedLogger.get(manifest);
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
getLogger,
|
|
35
|
+
getResolvedLogger,
|
|
36
|
+
setLogger
|
|
37
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SSRManifest } from '../app/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Registers a manifest for environments where `virtual:astro:manifest` cannot
|
|
4
|
+
* resolve (plain Node: unit tests, embedders). Internal API — deliberately not
|
|
5
|
+
* exported from any public entrypoint.
|
|
6
|
+
* Pass `undefined` to clear (test teardown).
|
|
7
|
+
*/
|
|
8
|
+
export declare function setAmbientManifest(manifest: SSRManifest | undefined): void;
|
|
9
|
+
/**
|
|
10
|
+
* The ambient manifest: the explicitly registered one, else the virtual
|
|
11
|
+
* module's. Throws lazily when neither is available, so merely importing a
|
|
12
|
+
* module that uses this never fails — only actually handling a request does.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getAmbientManifest(): SSRManifest;
|
|
15
|
+
/** The ambient manifest if one is available, else `undefined`. Never throws. */
|
|
16
|
+
export declare function tryGetAmbientManifest(): SSRManifest | undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NoManifestAvailable } from "../errors/errors-data.js";
|
|
2
|
+
import { AstroError } from "../errors/index.js";
|
|
3
|
+
import { manifest as viteManifest } from "#astro-internal/ambient-manifest";
|
|
4
|
+
let registered;
|
|
5
|
+
function setAmbientManifest(manifest) {
|
|
6
|
+
registered = manifest;
|
|
7
|
+
}
|
|
8
|
+
function getAmbientManifest() {
|
|
9
|
+
const manifest = registered ?? viteManifest;
|
|
10
|
+
if (!manifest) {
|
|
11
|
+
throw new AstroError(NoManifestAvailable);
|
|
12
|
+
}
|
|
13
|
+
return manifest;
|
|
14
|
+
}
|
|
15
|
+
function tryGetAmbientManifest() {
|
|
16
|
+
return registered ?? viteManifest;
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
getAmbientManifest,
|
|
20
|
+
setAmbientManifest,
|
|
21
|
+
tryGetAmbientManifest
|
|
22
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SSRManifest } from '../app/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Shared helpers for "derived once per process per manifest" memoization.
|
|
4
|
+
* Manifest-keyed WeakMaps are the sanctioned memoization primitive of the
|
|
5
|
+
* request core: each derivation lives in its owning module with its own memo —
|
|
6
|
+
* there is deliberately no central registry and no "get all derived state"
|
|
7
|
+
* function anywhere.
|
|
8
|
+
*
|
|
9
|
+
* Note: values are scoped per manifest OBJECT. Two `App`s constructed over the
|
|
10
|
+
* same manifest object (e.g. the cloudflare custom-fetch worker) share every
|
|
11
|
+
* memoized derivation.
|
|
12
|
+
*/
|
|
13
|
+
export interface ManifestMemo<T> {
|
|
14
|
+
get(manifest: SSRManifest): T;
|
|
15
|
+
/** Whether a value is currently stored for the manifest (derived or set). */
|
|
16
|
+
has(manifest: SSRManifest): boolean;
|
|
17
|
+
/** Replaces the stored value atomically (HMR replacement). */
|
|
18
|
+
set(manifest: SSRManifest, value: T): void;
|
|
19
|
+
invalidate(manifest: SSRManifest): void;
|
|
20
|
+
}
|
|
21
|
+
export declare function createManifestMemo<T>(derive: (manifest: SSRManifest) => T): ManifestMemo<T>;
|
|
22
|
+
export interface AsyncManifestMemo<T> {
|
|
23
|
+
get(manifest: SSRManifest): Promise<T>;
|
|
24
|
+
invalidate(manifest: SSRManifest): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Caches the PROMISE (single-flight: concurrent callers share one derivation).
|
|
28
|
+
* On rejection the entry is DELETED so the next call retries a failed lazy
|
|
29
|
+
* resolve instead of caching the failure forever.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createAsyncManifestMemo<T>(derive: (manifest: SSRManifest) => Promise<T>): AsyncManifestMemo<T>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
function createManifestMemo(derive) {
|
|
2
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
return {
|
|
4
|
+
get(manifest) {
|
|
5
|
+
if (cache.has(manifest)) {
|
|
6
|
+
return cache.get(manifest);
|
|
7
|
+
}
|
|
8
|
+
const value = derive(manifest);
|
|
9
|
+
cache.set(manifest, value);
|
|
10
|
+
return value;
|
|
11
|
+
},
|
|
12
|
+
has(manifest) {
|
|
13
|
+
return cache.has(manifest);
|
|
14
|
+
},
|
|
15
|
+
set(manifest, value) {
|
|
16
|
+
cache.set(manifest, value);
|
|
17
|
+
},
|
|
18
|
+
invalidate(manifest) {
|
|
19
|
+
cache.delete(manifest);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function createAsyncManifestMemo(derive) {
|
|
24
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
25
|
+
return {
|
|
26
|
+
get(manifest) {
|
|
27
|
+
let promise = cache.get(manifest);
|
|
28
|
+
if (!promise) {
|
|
29
|
+
promise = derive(manifest);
|
|
30
|
+
cache.set(manifest, promise);
|
|
31
|
+
promise.catch(() => {
|
|
32
|
+
if (cache.get(manifest) === promise) {
|
|
33
|
+
cache.delete(manifest);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return promise;
|
|
38
|
+
},
|
|
39
|
+
invalidate(manifest) {
|
|
40
|
+
cache.delete(manifest);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
createAsyncManifestMemo,
|
|
46
|
+
createManifestMemo
|
|
47
|
+
};
|
|
@@ -1,46 +1,36 @@
|
|
|
1
1
|
import type { FetchState } from '../fetch/fetch-state.js';
|
|
2
2
|
import type { APIContext } from '../../types/public/context.js';
|
|
3
|
-
import type { BaseApp } from '../app/base.js';
|
|
4
|
-
import { type Pipeline } from '../base-pipeline.js';
|
|
5
3
|
/**
|
|
6
4
|
* Callback invoked at the bottom of the middleware chain to dispatch the
|
|
7
5
|
* request to the matched route (endpoint / redirect / page / fallback).
|
|
8
6
|
*
|
|
9
|
-
* Callers of `
|
|
10
|
-
*
|
|
11
|
-
* middleware layer.
|
|
7
|
+
* Callers of `handleMiddleware` pass `handlePages` (or a wrapper around it)
|
|
8
|
+
* so route dispatch logic stays out of the middleware layer.
|
|
12
9
|
*/
|
|
13
10
|
export type RenderRouteCallback = (state: FetchState, ctx: APIContext) => Promise<Response>;
|
|
14
11
|
/**
|
|
15
|
-
*
|
|
16
|
-
* single render
|
|
17
|
-
*
|
|
12
|
+
* Runs Astro's middleware chain (origin check + user `onRequest`) for a
|
|
13
|
+
* single render, reading the composed middleware from the manifest and
|
|
14
|
+
* per-request data (componentInstance, slots, props, API contexts) off the
|
|
15
|
+
* supplied `FetchState`. The actual route dispatch (endpoint / redirect /
|
|
16
|
+
* page / fallback) is supplied by the caller as `renderRouteCallback` —
|
|
17
|
+
* typically `handlePages`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function handleMiddleware(state: FetchState, renderRouteCallback: RenderRouteCallback): Promise<Response>;
|
|
20
|
+
/**
|
|
21
|
+
* Like `handleMiddleware`, but mirrors the app-level error handling that
|
|
22
|
+
* `handleRequest` provides on the standard path, the same way
|
|
23
|
+
* `handlePagesWithErrorFallback` does for `pages()`. When no route matched
|
|
24
|
+
* it returns a 404 marked with `X-Astro-Error` for the app's post-check;
|
|
25
|
+
* when Astro's own middleware chain throws it logs the error and renders
|
|
26
|
+
* the custom `500.astro`.
|
|
27
|
+
*
|
|
28
|
+
* Errors surfaced through `renderRouteCallback` (the host framework's
|
|
29
|
+
* `next`, e.g. host middleware mounted below `middleware()`) are re-thrown
|
|
30
|
+
* instead, so the host's own error handling still runs rather than being
|
|
31
|
+
* swallowed into Astro's 500 page. A sentinel tells the two apart.
|
|
18
32
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* redirect / page / fallback) is supplied by the caller as
|
|
22
|
-
* `renderRouteCallback` — typically bound to a `PagesHandler.handle`.
|
|
33
|
+
* Used by the composable `astro/fetch` `middleware()` entry point, where
|
|
34
|
+
* there is no surrounding `handleRequest` to supply this fallback.
|
|
23
35
|
*/
|
|
24
|
-
export declare
|
|
25
|
-
#private;
|
|
26
|
-
constructor(pipeline: Pipeline);
|
|
27
|
-
handle(state: FetchState, renderRouteCallback: RenderRouteCallback): Promise<Response>;
|
|
28
|
-
/**
|
|
29
|
-
* Like `handle`, but mirrors the app-level error handling that
|
|
30
|
-
* `AstroHandler` provides on the standard path, the same way
|
|
31
|
-
* `PagesHandler.handleWithErrorFallback` does for `pages()`. When no
|
|
32
|
-
* route matched it returns a 404 marked with `X-Astro-Error` for the
|
|
33
|
-
* app's post-check; when Astro's own middleware chain throws it logs the
|
|
34
|
-
* error and renders the custom `500.astro`.
|
|
35
|
-
*
|
|
36
|
-
* Errors surfaced through `renderRouteCallback` (the host framework's
|
|
37
|
-
* `next`, e.g. host middleware mounted below `middleware()`) are
|
|
38
|
-
* re-thrown instead, so the host's own error handling still runs rather
|
|
39
|
-
* than being swallowed into Astro's 500 page. A sentinel tells the two
|
|
40
|
-
* apart.
|
|
41
|
-
*
|
|
42
|
-
* Used by the composable `astro/fetch` `middleware()` entry point, where
|
|
43
|
-
* there is no surrounding `AstroHandler` to supply this fallback.
|
|
44
|
-
*/
|
|
45
|
-
handleWithErrorFallback(app: BaseApp<Pipeline>, state: FetchState, renderRouteCallback: RenderRouteCallback): Promise<Response>;
|
|
46
|
-
}
|
|
36
|
+
export declare function handleMiddlewareWithErrorFallback(state: FetchState, renderRouteCallback: RenderRouteCallback): Promise<Response>;
|