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.
Files changed (151) hide show
  1. package/dist/actions/handler.d.ts +6 -12
  2. package/dist/actions/handler.js +30 -40
  3. package/dist/actions/load.d.ts +12 -0
  4. package/dist/actions/load.js +55 -0
  5. package/dist/actions/runtime/entrypoints/server.js +5 -4
  6. package/dist/actions/runtime/server.js +8 -6
  7. package/dist/assets/fonts/providers/index.d.ts +1 -1
  8. package/dist/assets/fonts/providers/index.js +2 -12
  9. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  10. package/dist/container/environment.d.ts +20 -0
  11. package/dist/container/environment.js +106 -0
  12. package/dist/container/index.js +65 -32
  13. package/dist/content/content-layer.js +3 -3
  14. package/dist/content/data-store-writer.d.ts +7 -10
  15. package/dist/content/data-store-writer.js +62 -27
  16. package/dist/content/data-store.d.ts +20 -3
  17. package/dist/content/data-store.js +28 -7
  18. package/dist/content/mutable-data-store.js +15 -10
  19. package/dist/content/runtime.d.ts +3 -2
  20. package/dist/content/runtime.js +43 -26
  21. package/dist/core/app/app.d.ts +0 -2
  22. package/dist/core/app/app.js +0 -7
  23. package/dist/core/app/base.d.ts +32 -20
  24. package/dist/core/app/base.js +76 -66
  25. package/dist/core/app/dev-facade.d.ts +27 -0
  26. package/dist/core/app/dev-facade.js +51 -0
  27. package/dist/core/app/entrypoints/index.d.ts +0 -1
  28. package/dist/core/app/entrypoints/index.js +0 -2
  29. package/dist/core/app/entrypoints/virtual/dev.js +24 -19
  30. package/dist/core/app/node.js +13 -14
  31. package/dist/core/app/prepare-response.d.ts +1 -1
  32. package/dist/core/app/validate-headers.js +7 -3
  33. package/dist/core/build/app.d.ts +31 -6
  34. package/dist/core/build/app.js +31 -13
  35. package/dist/core/build/environment.d.ts +25 -0
  36. package/dist/core/build/environment.js +157 -0
  37. package/dist/core/cache/handler.d.ts +13 -7
  38. package/dist/core/cache/handler.js +55 -51
  39. package/dist/core/cache/provider.d.ts +4 -0
  40. package/dist/core/cache/provider.js +15 -0
  41. package/dist/core/constants.d.ts +0 -11
  42. package/dist/core/constants.js +1 -5
  43. package/dist/core/dev/dev.js +1 -1
  44. package/dist/core/environment/dev-nonrunnable.d.ts +6 -0
  45. package/dist/core/environment/dev-nonrunnable.js +170 -0
  46. package/dist/core/environment/index.d.ts +90 -0
  47. package/dist/core/environment/index.js +12 -0
  48. package/dist/core/environment/production.d.ts +6 -0
  49. package/dist/core/environment/production.js +117 -0
  50. package/dist/core/errors/build-handler.d.ts +5 -10
  51. package/dist/core/errors/build-handler.js +11 -17
  52. package/dist/core/errors/default-handler.d.ts +4 -9
  53. package/dist/core/errors/default-handler.js +92 -107
  54. package/dist/core/errors/dev-handler.d.ts +7 -11
  55. package/dist/core/errors/dev-handler.js +71 -69
  56. package/dist/core/errors/errors-data.d.ts +18 -0
  57. package/dist/core/errors/errors-data.js +7 -0
  58. package/dist/core/errors/handler.d.ts +22 -3
  59. package/dist/core/errors/handler.js +25 -0
  60. package/dist/core/fetch/default-handler.d.ts +15 -8
  61. package/dist/core/fetch/default-handler.js +12 -34
  62. package/dist/core/fetch/features.d.ts +23 -0
  63. package/dist/core/fetch/features.js +27 -0
  64. package/dist/core/fetch/fetch-state.d.ts +52 -7
  65. package/dist/core/fetch/fetch-state.js +92 -81
  66. package/dist/core/fetch/index.d.ts +9 -2
  67. package/dist/core/fetch/index.js +18 -79
  68. package/dist/core/fetch/vite-plugin.js +2 -1
  69. package/dist/core/i18n/handler.d.ts +28 -13
  70. package/dist/core/i18n/handler.js +100 -100
  71. package/dist/core/logger/manifest-logger.d.ts +31 -0
  72. package/dist/core/logger/manifest-logger.js +37 -0
  73. package/dist/core/manifest/ambient-source.d.ts +2 -0
  74. package/dist/core/manifest/ambient-source.js +4 -0
  75. package/dist/core/manifest/ambient.d.ts +16 -0
  76. package/dist/core/manifest/ambient.js +22 -0
  77. package/dist/core/manifest/derived.d.ts +3 -0
  78. package/dist/core/manifest/derived.js +10 -0
  79. package/dist/core/manifest/memo.d.ts +31 -0
  80. package/dist/core/manifest/memo.js +47 -0
  81. package/dist/core/messages/runtime.js +1 -1
  82. package/dist/core/middleware/astro-middleware.d.ts +25 -35
  83. package/dist/core/middleware/astro-middleware.js +61 -81
  84. package/dist/core/middleware/load.d.ts +19 -0
  85. package/dist/core/middleware/load.js +36 -0
  86. package/dist/core/middleware/sequence.js +15 -7
  87. package/dist/core/pages/handler.d.ts +18 -25
  88. package/dist/core/pages/handler.js +68 -84
  89. package/dist/core/redirects/render.js +3 -8
  90. package/dist/core/render/index.d.ts +0 -1
  91. package/dist/core/render/index.js +0 -2
  92. package/dist/core/render/route-cache.d.ts +6 -1
  93. package/dist/core/render/route-cache.js +11 -1
  94. package/dist/core/rewrites/handler.d.ts +4 -6
  95. package/dist/core/rewrites/handler.js +19 -20
  96. package/dist/core/routing/default.d.ts +2 -0
  97. package/dist/core/routing/default.js +7 -1
  98. package/dist/core/routing/dev.d.ts +1 -3
  99. package/dist/core/routing/dev.js +12 -5
  100. package/dist/core/routing/handler.d.ts +6 -16
  101. package/dist/core/routing/handler.js +126 -164
  102. package/dist/core/routing/helpers.d.ts +7 -1
  103. package/dist/core/routing/helpers.js +21 -0
  104. package/dist/core/routing/match-request.d.ts +10 -0
  105. package/dist/core/routing/match-request.js +57 -0
  106. package/dist/core/routing/route-table.d.ts +34 -0
  107. package/dist/core/routing/route-table.js +41 -0
  108. package/dist/core/routing/trailing-slash-handler.d.ts +4 -14
  109. package/dist/core/routing/trailing-slash-handler.js +39 -50
  110. package/dist/core/server-islands/mappings.d.ts +6 -0
  111. package/dist/core/server-islands/mappings.js +12 -0
  112. package/dist/core/session/driver.d.ts +4 -0
  113. package/dist/core/session/driver.js +14 -0
  114. package/dist/core/session/handler.d.ts +1 -1
  115. package/dist/core/session/handler.js +8 -8
  116. package/dist/core/session/provider-disabled.js +2 -2
  117. package/dist/entrypoints/prerender.js +5 -1
  118. package/dist/i18n/middleware.d.ts +4 -4
  119. package/dist/i18n/middleware.js +3 -3
  120. package/dist/manifest/serialized.d.ts +1 -0
  121. package/dist/manifest/serialized.js +9 -2
  122. package/dist/runtime/prerender/static-paths.d.ts +14 -2
  123. package/dist/runtime/prerender/static-paths.js +4 -3
  124. package/dist/types/public/config.d.ts +433 -241
  125. package/dist/vite-plugin-app/createAstroServerApp.js +22 -18
  126. package/dist/vite-plugin-app/environment.d.ts +18 -0
  127. package/dist/vite-plugin-app/environment.js +210 -0
  128. package/dist/vite-plugin-app/handle-request.d.ts +30 -0
  129. package/dist/vite-plugin-app/handle-request.js +129 -0
  130. package/dist/vite-plugin-app/index.d.ts +1 -1
  131. package/dist/vite-plugin-app/index.js +1 -1
  132. package/package.json +14 -7
  133. package/src/core/README.md +37 -0
  134. package/src/core/manifest/ambient-source.ts +9 -0
  135. package/src/types/README.md +5 -0
  136. package/dist/container/pipeline.d.ts +0 -14
  137. package/dist/container/pipeline.js +0 -78
  138. package/dist/core/app/dev/app.d.ts +0 -31
  139. package/dist/core/app/dev/app.js +0 -80
  140. package/dist/core/app/dev/pipeline.d.ts +0 -17
  141. package/dist/core/app/dev/pipeline.js +0 -133
  142. package/dist/core/app/pipeline.d.ts +0 -14
  143. package/dist/core/app/pipeline.js +0 -123
  144. package/dist/core/base-pipeline.d.ts +0 -183
  145. package/dist/core/base-pipeline.js +0 -293
  146. package/dist/core/build/pipeline.d.ts +0 -38
  147. package/dist/core/build/pipeline.js +0 -202
  148. package/dist/vite-plugin-app/app.d.ts +0 -62
  149. package/dist/vite-plugin-app/app.js +0 -237
  150. package/dist/vite-plugin-app/pipeline.d.ts +0 -25
  151. 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 { PipelineFeatures } from "../base-pipeline.js";
4
+ import { markFeatureUsed, FetchFeatures } from "../fetch/features.js";
5
5
  import { shouldAppendForwardSlash } from "../build/util.js";
6
- class I18n {
7
- #i18n;
8
- #base;
9
- #trailingSlash;
10
- #format;
11
- #router;
12
- constructor(i18n, base, trailingSlash, format) {
13
- this.#i18n = i18n;
14
- this.#base = base;
15
- this.#trailingSlash = trailingSlash;
16
- this.#format = format;
17
- this.#router = new I18nRouter({
18
- strategy: i18n.strategy,
19
- defaultLocale: i18n.defaultLocale,
20
- locales: i18n.locales,
21
- base,
22
- domains: i18n.domainLookupTable ? Object.keys(i18n.domainLookupTable).reduce(
23
- (acc, domain) => {
24
- const locale = i18n.domainLookupTable[domain];
25
- if (!acc[domain]) {
26
- acc[domain] = [];
27
- }
28
- acc[domain].push(locale);
29
- return acc;
30
- },
31
- {}
32
- ) : void 0
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
- async finalize(state, response) {
36
- state.pipeline.usedFeatures |= PipelineFeatures.i18n;
37
- const i18n = this.#i18n;
38
- if (state.skipErrorReroute && typeof i18n.fallback === "undefined") {
39
- return response;
40
- }
41
- if (state.responseRouteType !== "page" && state.responseRouteType !== "fallback") {
42
- return response;
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
- const url = state.url;
45
- const currentLocale = state.computeCurrentLocale();
46
- const isPrerendered = state.routeData.prerender;
47
- const routerContext = {
48
- currentLocale,
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 new Response(null, { status: 404, headers });
74
+ return prerenderedRes;
82
75
  }
83
- case "continue":
84
- break;
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
- I18n
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,2 @@
1
+ import type { SSRManifest } from '../app/types.js';
2
+ export declare const manifest: SSRManifest | undefined;
@@ -0,0 +1,4 @@
1
+ const manifest = void 0;
2
+ export {
3
+ manifest
4
+ };
@@ -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,3 @@
1
+ import type { SSRManifest } from '../app/types.js';
2
+ /** The manifest's `site` as a `URL` (used for `Astro.site`). */
3
+ export declare function getSite(manifest: SSRManifest): URL | undefined;
@@ -0,0 +1,10 @@
1
+ import { createManifestMemo } from "./memo.js";
2
+ const sites = createManifestMemo(
3
+ (manifest) => manifest.site ? new URL(manifest.site) : void 0
4
+ );
5
+ function getSite(manifest) {
6
+ return sites.get(manifest);
7
+ }
8
+ export {
9
+ getSite
10
+ };
@@ -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
+ };
@@ -270,7 +270,7 @@ function printHelp({
270
270
  message.push(
271
271
  linebreak(),
272
272
  ` ${bgGreen(black(` ${commandName} `))} ${green(
273
- `v${"7.2.2"}`
273
+ `v${"7.2.3"}`
274
274
  )} ${headline}`
275
275
  );
276
276
  }
@@ -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 `AstroMiddleware.handle` pass their owned `PagesHandler`'s
10
- * `handle` method (bound) so route dispatch logic stays out of the
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
- * Handles the execution of Astro's middleware chain (internal + user) for a
16
- * single render. Holds a reference to the `Pipeline` and composes the
17
- * internal and user middleware at render time.
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
- * Reads per-request data (componentInstance, slots, props, API contexts)
20
- * off the supplied `FetchState`. The actual route dispatch (endpoint /
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 class AstroMiddleware {
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>;