astro 5.16.6 → 5.16.7

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