astro 6.0.0-alpha.4 → 6.0.0-beta.0

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 (122) hide show
  1. package/dist/assets/build/generate.js +1 -1
  2. package/dist/assets/build/remote.js +1 -1
  3. package/dist/assets/endpoint/dev.js +44 -16
  4. package/dist/assets/fonts/config.d.ts +13 -0
  5. package/dist/assets/fonts/config.js +4 -2
  6. package/dist/assets/fonts/constants.js +2 -1
  7. package/dist/assets/fonts/core/resolve-families.js +1 -0
  8. package/dist/assets/fonts/definitions.d.ts +10 -2
  9. package/dist/assets/fonts/infra/remote-font-provider-resolver.d.ts +2 -2
  10. package/dist/assets/fonts/infra/unifont-font-resolver.d.ts +24 -0
  11. package/dist/assets/fonts/infra/unifont-font-resolver.js +59 -0
  12. package/dist/assets/fonts/orchestrate.d.ts +6 -4
  13. package/dist/assets/fonts/orchestrate.js +16 -32
  14. package/dist/assets/fonts/providers/entrypoints/bunny.d.ts +1 -1
  15. package/dist/assets/fonts/providers/entrypoints/fontshare.d.ts +1 -1
  16. package/dist/assets/fonts/providers/entrypoints/fontsource.d.ts +1 -1
  17. package/dist/assets/fonts/providers/index.d.ts +6 -8
  18. package/dist/assets/fonts/providers/index.js +10 -14
  19. package/dist/assets/fonts/types.d.ts +17 -4
  20. package/dist/assets/fonts/vite-plugin-fonts.js +6 -1
  21. package/dist/assets/utils/vendor/image-size/detector.d.ts +1 -1
  22. package/dist/assets/utils/vendor/image-size/detector.js +2 -1
  23. package/dist/assets/utils/vendor/image-size/types/bmp.js +1 -1
  24. package/dist/assets/utils/vendor/image-size/types/gif.js +1 -1
  25. package/dist/assets/utils/vendor/image-size/types/heif.js +51 -29
  26. package/dist/assets/utils/vendor/image-size/types/icns.js +13 -14
  27. package/dist/assets/utils/vendor/image-size/types/ico.js +5 -5
  28. package/dist/assets/utils/vendor/image-size/types/index.d.ts +3 -3
  29. package/dist/assets/utils/vendor/image-size/types/index.js +4 -0
  30. package/dist/assets/utils/vendor/image-size/types/interface.d.ts +6 -6
  31. package/dist/assets/utils/vendor/image-size/types/j2c.js +2 -2
  32. package/dist/assets/utils/vendor/image-size/types/jp2.js +5 -3
  33. package/dist/assets/utils/vendor/image-size/types/jpg.js +4 -4
  34. package/dist/assets/utils/vendor/image-size/types/jxl-stream.d.ts +2 -0
  35. package/dist/assets/utils/vendor/image-size/types/jxl-stream.js +36 -0
  36. package/dist/assets/utils/vendor/image-size/types/jxl.d.ts +2 -0
  37. package/dist/assets/utils/vendor/image-size/types/jxl.js +57 -0
  38. package/dist/assets/utils/vendor/image-size/types/ktx.js +1 -1
  39. package/dist/assets/utils/vendor/image-size/types/png.js +1 -1
  40. package/dist/assets/utils/vendor/image-size/types/pnm.js +5 -7
  41. package/dist/assets/utils/vendor/image-size/types/psd.js +1 -1
  42. package/dist/assets/utils/vendor/image-size/types/tiff.js +93 -40
  43. package/dist/assets/utils/vendor/image-size/types/utils.d.ts +3 -2
  44. package/dist/assets/utils/vendor/image-size/types/utils.js +24 -22
  45. package/dist/assets/utils/vendor/image-size/types/webp.js +5 -6
  46. package/dist/assets/utils/vendor/image-size/utils/bit-reader.d.ts +10 -0
  47. package/dist/assets/utils/vendor/image-size/utils/bit-reader.js +41 -0
  48. package/dist/assets/vite-plugin-assets.js +7 -0
  49. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  50. package/dist/config/entrypoint.d.ts +1 -2
  51. package/dist/config/entrypoint.js +1 -2
  52. package/dist/config/index.js +1 -1
  53. package/dist/content/config.d.ts +25 -9
  54. package/dist/content/config.js +13 -17
  55. package/dist/content/content-layer.js +38 -21
  56. package/dist/content/loaders/glob.d.ts +4 -1
  57. package/dist/content/loaders/glob.js +36 -8
  58. package/dist/content/types-generator.js +10 -6
  59. package/dist/content/utils.d.ts +17 -1
  60. package/dist/content/utils.js +129 -8
  61. package/dist/content/vite-plugin-content-assets.d.ts +4 -5
  62. package/dist/content/vite-plugin-content-assets.js +3 -10
  63. package/dist/content/vite-plugin-content-imports.js +5 -1
  64. package/dist/content/vite-plugin-content-virtual-mod.js +10 -2
  65. package/dist/core/app/app.d.ts +1 -0
  66. package/dist/core/app/app.js +3 -0
  67. package/dist/core/app/base.d.ts +12 -0
  68. package/dist/core/app/base.js +18 -1
  69. package/dist/core/app/dev/app.d.ts +4 -1
  70. package/dist/core/app/dev/app.js +24 -3
  71. package/dist/core/build/app.d.ts +1 -0
  72. package/dist/core/build/app.js +3 -0
  73. package/dist/core/build/index.js +1 -1
  74. package/dist/core/build/plugins/plugin-manifest.d.ts +4 -6
  75. package/dist/core/build/plugins/plugin-manifest.js +14 -45
  76. package/dist/core/build/static-build.d.ts +10 -0
  77. package/dist/core/build/static-build.js +42 -34
  78. package/dist/core/config/schemas/base.d.ts +19 -2
  79. package/dist/core/config/schemas/base.js +6 -2
  80. package/dist/core/config/schemas/relative.d.ts +24 -3
  81. package/dist/core/config/settings.js +5 -1
  82. package/dist/core/constants.js +1 -1
  83. package/dist/core/dev/container.js +1 -1
  84. package/dist/core/dev/dev.js +1 -1
  85. package/dist/core/messages.js +2 -2
  86. package/dist/core/preview/index.js +1 -1
  87. package/dist/core/routing/dev.d.ts +14 -0
  88. package/dist/core/routing/dev.js +67 -0
  89. package/dist/core/routing/index.d.ts +0 -1
  90. package/dist/core/routing/index.js +0 -2
  91. package/dist/core/routing/manifest/create.js +9 -6
  92. package/dist/core/sync/index.js +11 -3
  93. package/dist/prerender/routing.d.ts +1 -1
  94. package/dist/prerender/routing.js +4 -4
  95. package/dist/runtime/client/dev-toolbar/apps/audit/rules/perf.js +1 -0
  96. package/dist/runtime/server/jsx.js +18 -4
  97. package/dist/runtime/server/render/astro/render.js +26 -3
  98. package/dist/runtime/server/render/common.d.ts +1 -0
  99. package/dist/runtime/server/render/common.js +16 -0
  100. package/dist/runtime/server/render/component.js +28 -4
  101. package/dist/runtime/server/render/instruction.d.ts +6 -1
  102. package/dist/runtime/server/render/script.d.ts +5 -1
  103. package/dist/runtime/server/render/script.js +7 -10
  104. package/dist/runtime/server/render/slot.d.ts +5 -0
  105. package/dist/runtime/server/render/slot.js +9 -4
  106. package/dist/transitions/router.js +2 -0
  107. package/dist/types/public/config.d.ts +21 -3
  108. package/dist/types/public/context.d.ts +307 -291
  109. package/dist/vite-plugin-app/app.d.ts +3 -0
  110. package/dist/vite-plugin-app/app.js +30 -80
  111. package/dist/vite-plugin-app/pipeline.d.ts +0 -1
  112. package/dist/vite-plugin-app/pipeline.js +3 -12
  113. package/dist/vite-plugin-astro-server/base.js +3 -2
  114. package/dist/vite-plugin-astro-server/response.js +4 -6
  115. package/dist/vite-plugin-config-alias/index.js +3 -2
  116. package/dist/vite-plugin-pages/pages.js +17 -1
  117. package/dist/vite-plugin-routes/index.js +1 -1
  118. package/package.json +13 -13
  119. package/dist/assets/fonts/core/dedupe-font-faces.d.ts +0 -2
  120. package/dist/assets/fonts/core/dedupe-font-faces.js +0 -30
  121. package/dist/assets/fonts/core/extract-unifont-providers.d.ts +0 -10
  122. package/dist/assets/fonts/core/extract-unifont-providers.js +0 -28
@@ -3,181 +3,93 @@ import type { AstroCookies } from '../../core/cookies/cookies.js';
3
3
  import type { CspDirective, CspHash } from '../../core/csp/config.js';
4
4
  import type { AstroSession } from '../../core/session/runtime.js';
5
5
  import type { AstroComponentFactory } from '../../runtime/server/index.js';
6
- import type { Params, RewritePayload } from './common.js';
6
+ import type { RewritePayload } from './common.js';
7
7
  import type { ValidRedirectStatus } from './config.js';
8
8
  /**
9
9
  * Astro global available in all contexts in .astro files
10
10
  *
11
- * [Astro reference](https://docs.astro.build/reference/api-reference/#astro-global)
11
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/)
12
12
  */
13
- export interface AstroGlobal<Props extends Record<string, any> = Record<string, any>, Self = AstroComponentFactory, Params extends Record<string, string | undefined> = Record<string, string | undefined>> extends AstroSharedContext<Props, Params> {
13
+ export interface AstroGlobal<Props extends Record<string, any> = Record<string, any>, Self = AstroComponentFactory, Params extends Record<string, string | undefined> = Record<string, string | undefined>> extends APIContext<Props, Params> {
14
14
  /**
15
- * Returns a [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) object built from the [site](https://docs.astro.build/en/reference/configuration-reference/#site) config option
15
+ * A standard [ResponseInit](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#init) object describing the outgoing response.
16
16
  *
17
- * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astrosite)
18
- */
19
- site: URL | undefined;
20
- /**
21
- * Returns a string with the current version of Astro.
22
- *
23
- * Useful for using `<meta name="generator" content={Astro.generator} />` or crediting Astro in a site footer.
24
- *
25
- * [HTML Specification for `generator`](https://html.spec.whatwg.org/multipage/semantics.html#meta-generator)
26
- *
27
- * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astrogenerator)
28
- */
29
- generator: string;
30
- /**
31
- * A full URL object of the request URL.
32
- * Equivalent to: `new URL(Astro.request.url)`
33
- *
34
- * [Astro reference](https://docs.astro.build/en/reference/api-reference/#url)
35
- */
36
- url: AstroSharedContext['url'];
37
- /** Parameters passed to a dynamic page generated using [getStaticPaths](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
38
- *
39
- * Example usage:
40
- * ```astro
41
- * ---
42
- * export async function getStaticPaths() {
43
- * return [
44
- * { params: { id: '1' } },
45
- * ];
46
- * }
47
- *
48
- * const { id } = Astro.params;
49
- * ---
50
- * <h1>{id}</h1>
51
- * ```
52
- *
53
- * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroparams)
54
- */
55
- params: AstroSharedContext<Props, Params>['params'];
56
- /** List of props passed to this component
57
- *
58
- * A common way to get specific props is through [destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment), ex:
59
- * ```typescript
60
- * const { name } = Astro.props
61
- * ```
62
- *
63
- * [Astro reference](https://docs.astro.build/en/basics/astro-components/#component-props)
64
- */
65
- props: AstroSharedContext<Props, Params>['props'];
66
- /** Information about the current request. This is a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object
67
- *
68
- * For example, to get a URL object of the current URL, you can use:
69
- * ```typescript
70
- * const url = new URL(Astro.request.url);
71
- * ```
72
- *
73
- * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astrorequest)
74
- */
75
- request: Request;
76
- /** Information about the outgoing response. This is a standard [ResponseInit](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#init) object
17
+ * ## Example
77
18
  *
78
- * For example, to change the status code you can set a different status on this object:
19
+ * You can change the status code by assigning a value to this property:
79
20
  * ```typescript
80
21
  * Astro.response.status = 404;
81
22
  * ```
82
23
  *
83
- * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroresponse)
24
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#response)
84
25
  */
85
26
  response: ResponseInit & {
86
27
  readonly headers: Headers;
87
28
  };
88
29
  /**
89
- * Get an action result on the server when using a form POST.
90
- * Expects the action function as a parameter.
91
- * Returns a type-safe result with the action data when
92
- * a matching POST request is received
93
- * and `undefined` otherwise.
30
+ * Allows a component to be recursively called.
94
31
  *
95
- * Example usage:
96
- *
97
- * ```typescript
98
- * import { actions } from 'astro:actions';
99
- *
100
- * const result = await Astro.getActionResult(actions.myAction);
101
- * ```
102
- */
103
- getActionResult: AstroSharedContext['getActionResult'];
104
- /**
105
- * Call an Action directly from an Astro page or API endpoint.
106
- * Expects the action function as the first parameter,
107
- * and the type-safe action input as the second parameter.
108
- * Returns a Promise with the action result.
109
- *
110
- * Example usage:
111
- *
112
- * ```typescript
113
- * import { actions } from 'astro:actions';
114
- *
115
- * const result = await Astro.callAction(actions.getPost, { postId: 'test' });
116
- * ```
117
- */
118
- callAction: AstroSharedContext['callAction'];
119
- /** Redirect to another page
120
- *
121
- * Example usage:
122
- * ```typescript
123
- * if(!isLoggedIn) {
124
- * return Astro.redirect('/login');
125
- * }
126
- * ```
127
- *
128
- * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroredirect)
129
- */
130
- redirect: AstroSharedContext['redirect'];
131
- /**
132
- * It rewrites to another page. As opposed to redirects, the URL won't change, and Astro will render the HTML emitted
133
- * by the rewritten URL passed as argument.
32
+ * This is useful when you need to render an Astro component from within
33
+ * itself. `Astro.self` accepts the same properties as the component itself.
134
34
  *
135
35
  * ## Example
136
36
  *
137
- * ```js
138
- * if (pageIsNotEnabled) {
139
- * return Astro.rewrite('/fallback-page')
140
- * }
37
+ * ```astro
38
+ * ---
39
+ * const { items } = Astro.props;
40
+ * ---
41
+ * <ul>
42
+ * {items.map((item) => (
43
+ * <li>
44
+ * {Array.isArray(item) ? (
45
+ * <Astro.self items={item} />
46
+ * ) : (
47
+ * item
48
+ * )}
49
+ * </li>
50
+ * ))}
51
+ * </ul>
141
52
  * ```
142
- */
143
- rewrite: AstroSharedContext['rewrite'];
144
- /**
145
- * The route currently rendered. It's stripped of the `srcDir` and the `pages` folder, and it doesn't contain the extension.
146
- *
147
- * ## Example
148
- * - The value when rendering `src/pages/index.astro` will be `/`.
149
- * - The value when rendering `src/pages/blog/[slug].astro` will be `/blog/[slug]`.
150
- * - The value when rendering `src/pages/[...path].astro` will be `/[...path]`.
151
- */
152
- routePattern: string;
153
- /**
154
- * The <Astro.self /> element allows a component to reference itself recursively.
155
53
  *
156
- * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroself)
54
+ * [Astro reference](https://docs.astro.build/en/reference/astro-syntax/#astroself)
157
55
  */
158
56
  self: Self;
159
- /** Utility functions for modifying an Astro component’s slotted children
57
+ /**
58
+ * An object containing utility functions for modifying an Astro component’s
59
+ * slotted children.
160
60
  *
161
- * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroslots)
61
+ * [Astro reference](https://docs.astro.build/en/reference/astro-syntax/#astroslots)
162
62
  */
163
63
  slots: Record<string, true | undefined> & {
164
64
  /**
165
65
  * Check whether content for this slot name exists
166
66
  *
167
- * Example usage:
168
- * ```typescript
169
- * if (Astro.slots.has('default')) {
67
+ * @param {string} slotName - The name of the slot to check.
68
+ * @returns {boolean} Whether the slot exists.
69
+ *
70
+ * ## Example
71
+ *
72
+ * ```astro
73
+ * ---
74
+ * ---
75
+ * <slot />
76
+ * {Astro.slots.has('more') && (
170
77
  * // Do something...
171
- * }
78
+ * }
172
79
  * ```
173
80
  *
174
- * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroslots)
81
+ * [Astro reference](https://docs.astro.build/en/reference/astro-syntax/#astroslotshas)
175
82
  */
176
83
  has(slotName: string): boolean;
177
84
  /**
178
- * Asynchronously renders this slot and returns a string
85
+ * Asynchronously renders the contents of a slot to a string of HTML.
86
+ *
87
+ * @param {string} slotName - The name of the slot to render.
88
+ * @param {any[]} [args] - The additional arguments to pass to the callback.
89
+ * @returns {Promise<string>} The rendered slot as HTML string.
90
+ *
91
+ * ## Examples
179
92
  *
180
- * Example usage:
181
93
  * ```astro
182
94
  * ---
183
95
  * let html: string = '';
@@ -190,7 +102,6 @@ export interface AstroGlobal<Props extends Record<string, any> = Record<string,
190
102
  *
191
103
  * A second parameter can be used to pass arguments to a slotted callback
192
104
  *
193
- * Example usage:
194
105
  * ```astro
195
106
  * ---
196
107
  * html = await Astro.slots.render('default', ["Hello", "World"])
@@ -203,181 +114,169 @@ export interface AstroGlobal<Props extends Record<string, any> = Record<string,
203
114
  * </Component>
204
115
  * ```
205
116
  *
206
- * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroslots)
117
+ * [Astro reference](https://docs.astro.build/en/reference/astro-syntax/#astroslotsrender)
207
118
  */
208
119
  render(slotName: string, args?: any[]): Promise<string>;
209
120
  };
210
121
  }
211
- interface AstroSharedContext<Props extends Record<string, any> = Record<string, any>, RouteParams extends Record<string, string | undefined> = Record<string, string | undefined>> {
122
+ /**
123
+ * The `APIContext` is the object made available to endpoints and middleware.
124
+ * It is a subset of the `Astro` global object available in pages.
125
+ *
126
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/)
127
+ */
128
+ export interface APIContext<Props extends Record<string, any> = Record<string, any>, Params extends Record<string, string | undefined> = Record<string, string | undefined>> {
212
129
  /**
213
- * The address (usually IP address) of the user.
130
+ * The site provided in the astro config, parsed as an instance of `URL`, without base.
131
+ * `undefined` if the site is not provided in the config.
214
132
  *
215
- * Throws an error if used within a static site, or within a prerendered page.
216
- */
217
- clientAddress: string;
218
- /**
219
- * Utility for getting and setting the values of cookies.
220
- */
221
- cookies: AstroCookies;
222
- /**
223
- * Utility for handling sessions.
224
- */
225
- session?: AstroSession;
226
- /**
227
- * Information about the current request. This is a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object
228
- */
229
- request: Request;
230
- /**
231
- * A full URL object of the request URL.
232
- */
233
- url: URL;
234
- /**
235
- * The origin pathname of the request URL.
236
- * Useful to track the original URL before rewrites were applied.
237
- */
238
- originPathname: string;
239
- /**
240
- * Get action result on the server when using a form POST.
241
- */
242
- getActionResult: <TAction extends ActionClient<any, any, any>>(action: TAction) => ActionReturnType<TAction> | undefined;
243
- /**
244
- * Call action handler from the server.
245
- */
246
- callAction: <TAction extends ActionClient<any, any, any> | ActionClient<any, any, any>['orThrow']>(action: TAction, input: Parameters<TAction>[0]) => Promise<ActionReturnType<TAction>>;
247
- /**
248
- * Route parameters for this request if this is a dynamic route.
249
- */
250
- params: RouteParams;
251
- /**
252
- * List of props returned for this path by `getStaticPaths` (**Static Only**).
133
+ * ## Example
134
+ *
135
+ * ```astro
136
+ * <link
137
+ * rel="alternate"
138
+ * type="application/rss+xml"
139
+ * title="Your Site's Title"
140
+ * href={new URL("rss.xml", Astro.site)}
141
+ * />
142
+ * ```
143
+ *
144
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#site)
253
145
  */
254
- props: Props;
146
+ site: URL | undefined;
255
147
  /**
256
- * Redirect to another page (**SSR Only**).
148
+ * A human-readable string representing the Astro version used to create the project. It follows the format "Astro v5.x.x".
149
+ *
150
+ * ## Example
151
+ *
152
+ * ```astro
153
+ * <meta name="generator" content={Astro.generator} />
154
+ * ```
155
+ *
156
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#generator)
257
157
  */
258
- redirect(path: string, status?: ValidRedirectStatus): Response;
158
+ generator: string;
259
159
  /**
260
- * It rewrites to another page. As opposed to redirects, the URL won't change, and Astro will render the HTML emitted
261
- * by the rerouted URL passed as argument.
160
+ * The address (usually IP address) of the user.
161
+ *
162
+ * Throws an error if used within a static site, or within a prerendered page.
262
163
  *
263
164
  * ## Example
264
165
  *
265
- * ```js
266
- * if (pageIsNotEnabled) {
267
- * return Astro.rewrite('/fallback-page')
166
+ * ```ts
167
+ * import type { APIContext } from 'astro';
168
+ *
169
+ * export function GET({ clientAddress }: APIContext) {
170
+ * return new Response(`Your IP address is: ${clientAddress}`);
268
171
  * }
269
172
  * ```
173
+ *
174
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#clientaddress)
270
175
  */
271
- rewrite(rewritePayload: RewritePayload): Promise<Response>;
272
- /**
273
- * Object accessed via Astro middleware
274
- */
275
- locals: App.Locals;
276
- /**
277
- * The current locale that is computed from the `Accept-Language` header of the browser (**SSR Only**).
278
- */
279
- preferredLocale: string | undefined;
280
- /**
281
- * The list of locales computed from the `Accept-Language` header of the browser, sorted by quality value (**SSR Only**).
282
- */
283
- preferredLocaleList: string[] | undefined;
284
- /**
285
- * The current locale computed from the URL of the request. It matches the locales in `i18n.locales`, and returns `undefined` otherwise.
286
- */
287
- currentLocale: string | undefined;
176
+ clientAddress: string;
288
177
  /**
289
- * Whether the current route is prerendered or not.
178
+ * An object containing utilities for reading and manipulating the values of cookies in on-demand routes.
179
+ *
180
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#cookies)
290
181
  */
291
- isPrerendered: boolean;
182
+ cookies: AstroCookies;
292
183
  /**
293
- * It exposes utilities to control CSP headers
184
+ * An object containing utilities for handling sessions in on-demand rendered routes.
185
+ *
186
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#session)
294
187
  */
295
- csp: AstroSharedContextCsp;
296
- }
297
- export type AstroSharedContextCsp = {
188
+ session?: AstroSession;
298
189
  /**
299
- * It adds a specific CSP directive to the route being rendered.
190
+ * A standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object containing information about the current request.
300
191
  *
301
192
  * ## Example
302
193
  *
303
- * ```js
304
- * ctx.insertDirective("default-src 'self' 'unsafe-inline' https://example.com")
194
+ * To get a URL object of the current URL, you can use:
195
+ * ```typescript
196
+ * const url = new URL(Astro.request.url);
305
197
  * ```
198
+ *
199
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#request)
306
200
  */
307
- insertDirective: (directive: CspDirective) => void;
201
+ request: Request;
308
202
  /**
309
- * It set the resource for the directive `style-src` in the route being rendered. It overrides Astro's default.
203
+ * A URL object constructed from the current `request.url` value. This is
204
+ * equivalent to doing `new URL(context.request.url)`.
310
205
  *
311
206
  * ## Example
312
207
  *
313
- * ```js
314
- * ctx.insertStyleResource("https://styles.cdn.example.com/")
208
+ * ```astro
209
+ * <p>The current URL is: {Astro.url}</p>
210
+ * <p>The current URL pathname is: {Astro.url.pathname}</p>
211
+ * <p>The current URL origin is: {Astro.url.origin}</p>
315
212
  * ```
213
+ *
214
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#url)
316
215
  */
317
- insertStyleResource: (payload: string) => void;
216
+ url: URL;
318
217
  /**
319
- * Insert a single style hash to the route being rendered.
218
+ * The origin pathname of the request URL.
219
+ * Useful to track the original URL before rewrites were applied.
320
220
  *
321
221
  * ## Example
322
222
  *
323
- * ```js
324
- * ctx.insertStyleHash("sha256-1234567890abcdef1234567890")
223
+ * ```astro
224
+ * <p>The origin path is {Astro.originPathname}</p>
225
+ * <p>The rewritten path is {Astro.url.pathname}</p>
325
226
  * ```
227
+ *
228
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#originpathname)
326
229
  */
327
- insertStyleHash: (hash: CspHash) => void;
230
+ originPathname: string;
328
231
  /**
329
- * It set the resource for the directive `script-src` in the route being rendered.
232
+ * A function that returns the result of an Action submission when using a form POST.
233
+ *
234
+ * This accepts an action function as an argument and returns a type-safe
235
+ * data or error object when a submission is received. Otherwise, it will
236
+ * return undefined.
237
+ *
238
+ * @param {TAction} action - The action function to process.
239
+ * @returns {ActionReturnType<TAction> | undefined} An object describing the result of an action.
330
240
  *
331
241
  * ## Example
332
242
  *
333
- * ```js
334
- * ctx.insertScriptResource("https://scripts.cdn.example.com/")
243
+ * ```astro
244
+ * import { actions } from 'astro:actions';
245
+ *
246
+ * const result = await Astro.getActionResult(actions.myAction);
335
247
  * ```
248
+ *
249
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#getactionresult)
336
250
  */
337
- insertScriptResource: (resource: string) => void;
251
+ getActionResult: <TAction extends ActionClient<any, any, any>>(action: TAction) => ActionReturnType<TAction> | undefined;
338
252
  /**
339
- * Insert a single script hash to the route being rendered.
253
+ * A function used to call an Action handler directly from your Astro
254
+ * component or API endpoint.
255
+ *
256
+ * This accepts an Action function and a type-safe action input, and returns
257
+ * the result of the action as a Promise.
340
258
  *
341
259
  * ## Example
342
260
  *
343
- * ```js
344
- * ctx.insertScriptHash("sha256-1234567890abcdef1234567890")
345
- * ```
346
- */
347
- insertScriptHash: (hash: CspHash) => void;
348
- };
349
- /**
350
- * The `APIContext` is the object made available to endpoints and middleware.
351
- * It is a subset of the `Astro` global object available in pages.
352
- *
353
- * [Reference](https://docs.astro.build/en/reference/api-reference/#endpoint-context)
354
- */
355
- export interface APIContext<Props extends Record<string, any> = Record<string, any>, APIParams extends Record<string, string | undefined> = Record<string, string | undefined>> extends AstroSharedContext<Props, Params> {
356
- /**
357
- * The site provided in the astro config, parsed as an instance of `URL`, without base.
358
- * `undefined` if the site is not provided in the config.
359
- */
360
- site: URL | undefined;
361
- /**
362
- * A human-readable string representing the Astro version used to create the project.
363
- * For example, `"Astro v1.1.1"`.
364
- */
365
- generator: string;
366
- /**
367
- * The url of the current request, parsed as an instance of `URL`.
261
+ * ```typescript
262
+ * import { actions } from 'astro:actions';
368
263
  *
369
- * Equivalent to:
370
- * ```ts
371
- * new URL(context.request.url)
264
+ * const result = await Astro.callAction(actions.getPost, { postId: 'test' });
372
265
  * ```
266
+ *
267
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#callaction)
268
+ *
269
+ * @param {TAction} action - Any Action function.
270
+ * @param {Parameters<TAction>[0]} input - Any input that the given action receives.
373
271
  */
374
- url: AstroSharedContext['url'];
272
+ callAction: <TAction extends ActionClient<any, any, any> | ActionClient<any, any, any>['orThrow']>(action: TAction, input: Parameters<TAction>[0]) => Promise<ActionReturnType<TAction>>;
375
273
  /**
376
- * Parameters matching the page’s dynamic route pattern.
377
- * In static builds, this will be the `params` generated by `getStaticPaths`.
378
- * In SSR builds, this can be any path segments matching the dynamic route pattern.
274
+ * An object containing the values of dynamic route segments matched for a request.
275
+ *
276
+ * In static builds, this will be the `params` returned by [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths). With on-demand rendering, `params` can be any value matching the path segments in the dynamic route pattern.
277
+ *
278
+ * ## Example
379
279
  *
380
- * Example usage:
381
280
  * ```ts
382
281
  * import type { APIContext } from "astro"
383
282
  *
@@ -389,18 +288,19 @@ export interface APIContext<Props extends Record<string, any> = Record<string, a
389
288
  * ];
390
289
  * }
391
290
  *
392
- * export async function GET({ params }: APIContext) {
393
- * return new Response(`Hello user ${params.id}!`)
291
+ * export function GET({ params }: APIContext): Response {
292
+ * return new Response(`The current id is ${params.id}.`);
394
293
  * }
395
294
  * ```
396
295
  *
397
- * [Reference](https://docs.astro.build/en/reference/api-reference/#contextparams)
296
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#params)
398
297
  */
399
- params: AstroSharedContext<Props, APIParams>['params'];
298
+ params: Params;
400
299
  /**
401
- * List of props passed from `getStaticPaths`. Only available to static builds.
300
+ * An object containing any values that have been passed as component attributes. In static builds, this can also be the `props` returned by [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths).
301
+ *
302
+ * ## Example
402
303
  *
403
- * Example usage:
404
304
  * ```ts
405
305
  * import type { APIContext } from "astro"
406
306
  *
@@ -417,13 +317,20 @@ export interface APIContext<Props extends Record<string, any> = Record<string, a
417
317
  * }
418
318
  * ```
419
319
  *
420
- * [Reference](https://docs.astro.build/en/reference/api-reference/#contextprops)
320
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#props)
421
321
  */
422
- props: AstroSharedContext<Props, APIParams>['props'];
322
+ props: Props;
423
323
  /**
424
324
  * Create a response that redirects to another page.
425
325
  *
426
- * Example usage:
326
+ * This accepts a custom status code when redirecting for on-demand rendered routes only.
327
+ *
328
+ * @param {string} path - The path to redirect to.
329
+ * @param {ValidRedirectStatus} [status] - An optional HTTP status code.
330
+ * @returns {Response} A Response object describing the redirection.
331
+ *
332
+ * ## Example
333
+ *
427
334
  * ```ts
428
335
  * // src/pages/secret.ts
429
336
  * export function GET({ redirect }) {
@@ -431,12 +338,18 @@ export interface APIContext<Props extends Record<string, any> = Record<string, a
431
338
  * }
432
339
  * ```
433
340
  *
434
- * [Reference](https://docs.astro.build/en/guides/api-reference/#contextredirect)
341
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#redirect)
435
342
  */
436
- redirect: AstroSharedContext['redirect'];
343
+ redirect: (path: string, status?: ValidRedirectStatus) => Response;
437
344
  /**
438
- * It reroutes to another page. As opposed to redirects, the URL won't change, and Astro will render the HTML emitted
439
- * by the rerouted URL passed as argument.
345
+ * Allows you to serve content from a different URL or path without
346
+ * redirecting the browser to a new page.
347
+ *
348
+ * As opposed to redirects, the URL won't change, and Astro will render the
349
+ * HTML emitted by the rerouted URL passed as argument.
350
+ *
351
+ * @param {RewritePayload} rewritePayload - The location of the path.
352
+ * @returns {Promise<Response>} A Response object describing the rewrite.
440
353
  *
441
354
  * ## Example
442
355
  *
@@ -446,14 +359,16 @@ export interface APIContext<Props extends Record<string, any> = Record<string, a
446
359
  * return ctx.rewrite(new URL("../"), ctx.url);
447
360
  * }
448
361
  * ```
362
+ *
363
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#rewrite)
449
364
  */
450
- rewrite: AstroSharedContext['rewrite'];
365
+ rewrite: (rewritePayload: RewritePayload) => Promise<Response>;
451
366
  /**
452
367
  * An object that middlewares can use to store extra information related to the request.
453
368
  *
454
369
  * It will be made available to pages as `Astro.locals`, and to endpoints as `context.locals`.
455
370
  *
456
- * Example usage:
371
+ * ## Example
457
372
  *
458
373
  * ```ts
459
374
  * // src/middleware.ts
@@ -464,7 +379,7 @@ export interface APIContext<Props extends Record<string, any> = Record<string, a
464
379
  * return next();
465
380
  * });
466
381
  * ```
467
- * Inside a `.astro` file:
382
+ * You can then access the value inside a `.astro` file:
468
383
  * ```astro
469
384
  * ---
470
385
  * // src/pages/index.astro
@@ -473,47 +388,148 @@ export interface APIContext<Props extends Record<string, any> = Record<string, a
473
388
  * <h1>{greeting}</h1>
474
389
  * ```
475
390
  *
476
- * [Reference](https://docs.astro.build/en/reference/api-reference/#contextlocals)
391
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#locals)
477
392
  */
478
393
  locals: App.Locals;
479
394
  /**
480
- * Available only when `i18n` configured and in SSR.
395
+ * A computed value to find the best match between your visitor’s browser
396
+ * language preferences and the locales supported by your site.
481
397
  *
482
- * It represents the preferred locale of the user. It's computed by checking the supported locales in `i18n.locales`
483
- * and locales supported by the users's browser via the header `Accept-Language`
398
+ * This property is only available for routes rendered on demand and cannot
399
+ * be used on prerendered, static pages.
484
400
  *
485
- * For example, given `i18n.locales` equals to `['fr', 'de']`, and the `Accept-Language` value equals to `en, de;q=0.2, fr;q=0.6`, the
486
- * `Astro.preferredLanguage` will be `fr` because `en` is not supported, its [quality value] is the highest.
401
+ * The preferred locale of the user is computed by checking the supported
402
+ * locales in `i18n.locales` and locales supported by the users's browser via
403
+ * the header `Accept-Language`.
487
404
  *
488
- * [quality value]: https://developer.mozilla.org/en-US/docs/Glossary/Quality_values
405
+ * ## Example
406
+ *
407
+ * Given `i18n.locales` equals to `['fr', 'de']`, and the `Accept-Language` value equals to `en, de;q=0.2, fr;q=0.6`, the
408
+ * `Astro.preferredLanguage` will be `fr` because `en` is not supported, its [quality value](https://developer.mozilla.org/en-US/docs/Glossary/Quality_values) is the highest.
409
+ *
410
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#preferredlocale)
489
411
  */
490
412
  preferredLocale: string | undefined;
491
413
  /**
492
- * Available only when `i18n` configured and in SSR.
414
+ * Represents the list of all locales, sorted via [quality value](https://developer.mozilla.org/en-US/docs/Glossary/Quality_values), that are both
415
+ * requested by the browser and supported by your website.
493
416
  *
494
- * It represents the list of the preferred locales that are supported by the application. The list is sorted via [quality value].
417
+ * This property is only available for routes rendered on demand and cannot
418
+ * be used on prerendered, static pages.
495
419
  *
496
- * For example, given `i18n.locales` equals to `['fr', 'pt', 'de']`, and the `Accept-Language` value equals to `en, de;q=0.2, fr;q=0.6`, the
497
- * `Astro.preferredLocaleList` will be equal to `['fs', 'de']` because `en` isn't supported, and `pt` isn't part of the locales contained in the
498
- * header.
420
+ * When the `Accept-Header` is `*`, the original `i18n.locales` are returned.
421
+ * The value `*` means no preferences, so Astro returns all the supported locales.
499
422
  *
500
- * When the `Accept-Header` is `*`, the original `i18n.locales` are returned. The value `*` means no preferences, so Astro returns all the supported locales.
423
+ * ## Example
424
+ *
425
+ * Given `i18n.locales` equals to `['fr', 'pt', 'de']`, and the
426
+ * `Accept-Language` value equals to `en, de;q=0.2, fr;q=0.6`, the
427
+ * `Astro.preferredLocaleList` will be equal to `['fs', 'de']` because `en`
428
+ * isn't supported, and `pt` isn't part of the locales contained in the
429
+ * header.
501
430
  *
502
- * [quality value]: https://developer.mozilla.org/en-US/docs/Glossary/Quality_values
431
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#preferredlocalelist)
503
432
  */
504
433
  preferredLocaleList: string[] | undefined;
505
434
  /**
506
435
  * The current locale computed from the URL of the request. It matches the locales in `i18n.locales`, and returns `undefined` otherwise.
436
+ *
437
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#currentlocale)
507
438
  */
508
439
  currentLocale: string | undefined;
440
+ /**
441
+ * Whether the current route is prerendered or not.
442
+ *
443
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#isprerendered)
444
+ */
445
+ isPrerendered: boolean;
446
+ /**
447
+ * It exposes utilities to control CSP headers
448
+ *
449
+ * [Astro reference](https://docs.astro.build/en/reference/experimental-flags/csp/)
450
+ */
451
+ csp: {
452
+ /**
453
+ * It adds a specific CSP directive to the route being rendered.
454
+ *
455
+ * @param {CspDirective} directive - The directive to add to the current page.
456
+ *
457
+ * ## Example
458
+ *
459
+ * ```js
460
+ * ctx.insertDirective("default-src 'self' 'unsafe-inline' https://example.com")
461
+ * ```
462
+ *
463
+ * [Astro reference](https://docs.astro.build/en/reference/experimental-flags/csp/#cspinsertdirective)
464
+ */
465
+ insertDirective: (directive: CspDirective) => void;
466
+ /**
467
+ * It set the resource for the directive `style-src` in the route being rendered. It overrides Astro's default.
468
+ *
469
+ * @param {string} payload - The source to insert in the `style-src` directive.
470
+ *
471
+ * ## Example
472
+ *
473
+ * ```js
474
+ * ctx.insertStyleResource("https://styles.cdn.example.com/")
475
+ * ```
476
+ *
477
+ * [Astro reference](https://docs.astro.build/en/reference/experimental-flags/csp/#cspinsertstyleresource)
478
+ */
479
+ insertStyleResource: (payload: string) => void;
480
+ /**
481
+ * Insert a single style hash to the route being rendered.
482
+ *
483
+ * @param {CspHash} hash - The hash to insert in the `style-src` directive.
484
+ *
485
+ * ## Example
486
+ *
487
+ * ```js
488
+ * ctx.insertStyleHash("sha256-1234567890abcdef1234567890")
489
+ * ```
490
+ *
491
+ * [Astro reference](https://docs.astro.build/en/reference/experimental-flags/csp/#cspinsertstylehash)
492
+ */
493
+ insertStyleHash: (hash: CspHash) => void;
494
+ /**
495
+ * It set the resource for the directive `script-src` in the route being rendered.
496
+ *
497
+ * @param {string} resource - The source to insert in the `script-src` directive.
498
+ *
499
+ * ## Example
500
+ *
501
+ * ```js
502
+ * ctx.insertScriptResource("https://scripts.cdn.example.com/")
503
+ * ```
504
+ *
505
+ * [Astro reference](https://docs.astro.build/en/reference/experimental-flags/csp/#cspinsertscriptresource)
506
+ */
507
+ insertScriptResource: (resource: string) => void;
508
+ /**
509
+ * Insert a single script hash to the route being rendered.
510
+ *
511
+ * @param {CspHash} hash - The hash to insert in the `script-src` directive.
512
+ *
513
+ * ## Example
514
+ *
515
+ * ```js
516
+ * ctx.insertScriptHash("sha256-1234567890abcdef1234567890")
517
+ * ```
518
+ *
519
+ * [Astro reference](https://docs.astro.build/en/reference/experimental-flags/csp/#cspinsertscripthash)
520
+ */
521
+ insertScriptHash: (hash: CspHash) => void;
522
+ };
509
523
  /**
510
524
  * The route currently rendered. It's stripped of the `srcDir` and the `pages` folder, and it doesn't contain the extension.
511
525
  *
512
526
  * ## Example
527
+ *
513
528
  * - The value when rendering `src/pages/index.astro` will be `/`.
514
529
  * - The value when rendering `src/pages/blog/[slug].astro` will be `/blog/[slug]`.
515
530
  * - The value when rendering `src/pages/[...path].astro` will be `/[...path]`.
531
+ *
532
+ * [Astro reference](https://docs.astro.build/en/reference/api-reference/#routepattern)
516
533
  */
517
534
  routePattern: string;
518
535
  }
519
- export {};