Skip to content

Commit

Permalink
feat(next): envField jsdoc (#11927)
Browse files Browse the repository at this point in the history
Co-authored-by: Sarah Rainsberger <[email protected]>
  • Loading branch information
florian-lefebvre and sarah11918 authored Sep 6, 2024
1 parent a8a3d2c commit 5b4e3ab
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/pink-yaks-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Updates the `env` configuration reference docs to include a full API reference for `envField`.
42 changes: 41 additions & 1 deletion packages/astro/src/types/public/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ export interface AstroUserConfig {
* @version 5.0.0
* @description
*
* An object that uses `envField` to define the data type (`string`, `number`, or `boolean`) and properties of your environment variables: `context` (client or server), `access` (public or secret), a `default` value to use, and whether or not this environment variable is `optional` (defaults to `false`).
* An object that uses `envField` to define the data type and properties of your environment variables: `context` (client or server), `access` (public or secret), a `default` value to use, and whether or not this environment variable is `optional` (defaults to `false`).
* ```js
* // astro.config.mjs
* import { defineConfig, envField } from "astro/config"
Expand All @@ -1453,6 +1453,46 @@ export interface AstroUserConfig {
* }
* })
* ```
*
* `envField` supports four data types: string, number, enum, and boolean. `context` and `access` are required properties for all data types. The following shows the complete list of properties available for each data type:
*
* ```js
* import { envField } from "astro/config"
*
* envField.string({
* // context & access
* optional: true,
* default: "foo",
* max: 20,
* min: 1,
* length: 13,
* url: true,
* includes: "oo",
* startsWith: "f",
* endsWith: "o",
* })
* envField.number({
* // context & access
* optional: true,
* default: 15,
* gt: 2,
* min: 1,
* lt: 3,
* max: 4,
* int: true,
* })
* envField.boolean({
* // context & access
* optional: true,
* default: true,
* })
* envField.enum({
* // context & access
* values: ['foo', 'bar', 'baz'], // required
* optional: true,
* default: 'baz',
* })
* ```
*/
schema?: EnvSchema;

Expand Down

0 comments on commit 5b4e3ab

Please sign in to comment.