Skip to content

Commit eb37304

Browse files
EskiMojo14juliusmarminge
andauthoredJan 25, 2025··
Add Valibot presets, and move Zod presets to new entry point (#310)
Co-authored-by: juliusmarminge <julius0216@outlook.com>
1 parent 7c09bc3 commit eb37304

18 files changed

+592
-197
lines changed
 

‎.changeset/quick-elephants-confess.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@t3-oss/env-nextjs": minor
3+
"@t3-oss/env-core": minor
4+
"@t3-oss/env-nuxt": minor
5+
---
6+
7+
feat!: add valibot presets
8+
9+
Presets using Valibot are now available using the `/presets-valibot` entrypoint.
10+
11+
This feature comes with some breaking changes:
12+
13+
- Zod presets have now been moved to `/presets-zod`.

‎.vscode/settings.json

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,25 @@
55
},
66
"editor.formatOnSave": true,
77
"editor.defaultFormatter": "biomejs.biome",
8+
"[json]": {
9+
"editor.defaultFormatter": "biomejs.biome"
10+
},
11+
"[jsonc]": {
12+
"editor.defaultFormatter": "biomejs.biome"
13+
},
14+
"[javascript]": {
15+
"editor.defaultFormatter": "biomejs.biome"
16+
},
17+
"[typescript]": {
18+
"editor.defaultFormatter": "biomejs.biome"
19+
},
20+
"[typescriptreact]": {
21+
"editor.defaultFormatter": "biomejs.biome"
22+
},
823
"tailwindCSS.experimental.configFile": "./docs/tailwind.config.ts",
924
"tailwindCSS.experimental.classRegex": [
1025
["clsx\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"]
1126
],
12-
"mdx.experimentalLanguageServer": true,
1327
"typescript.tsdk": "node_modules/typescript/lib",
1428
"typescript.enablePromptUseWorkspaceTsdk": true
1529
}

‎bun.lock

+6
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,12 @@
109109
},
110110
"peerDependencies": {
111111
"typescript": ">=5.0.0",
112+
"valibot": "^1.0.0-beta.7 || ^1.0.0",
112113
"zod": "^3.24.0",
113114
},
114115
"optionalPeers": [
115116
"typescript",
117+
"valibot",
116118
"zod",
117119
],
118120
},
@@ -129,10 +131,12 @@
129131
},
130132
"peerDependencies": {
131133
"typescript": ">=5.0.0",
134+
"valibot": "^1.0.0-beta.7 || ^1.0.0",
132135
"zod": "^3.24.0",
133136
},
134137
"optionalPeers": [
135138
"typescript",
139+
"valibot",
136140
"zod",
137141
],
138142
},
@@ -149,10 +153,12 @@
149153
},
150154
"peerDependencies": {
151155
"typescript": ">=5.0.0",
156+
"valibot": "^1.0.0-beta.7 || ^1.0.0",
152157
"zod": "^3.24.0",
153158
},
154159
"optionalPeers": [
155160
"typescript",
161+
"valibot",
156162
"zod",
157163
],
158164
},

‎docs/src/app/docs/customization/page.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Your env object may extend other presets by using the `extends` property. This c
8383

8484
```ts title="src/env.ts"
8585
import { createEnv } from "@t3-oss/env-core";
86-
import { vercel } from "@t3-oss/env-core/presets";
86+
import { vercel } from "@t3-oss/env-core/presets-zod";
8787

8888
export const env = createEnv({
8989
// ...

‎examples/nextjs/app/env.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createEnv } from "@t3-oss/env-nextjs";
2-
import { vercel } from "@t3-oss/env-nextjs/presets";
2+
import { vercel } from "@t3-oss/env-nextjs/presets-zod";
33
import { z } from "zod";
44

55
export const env = createEnv({

‎packages/core/package.json

+12-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616
"types": "./dist/index.d.ts",
1717
"default": "./dist/index.js"
1818
},
19-
"./presets": {
20-
"types": "./dist/presets.d.ts",
21-
"default": "./dist/presets.js"
19+
"./presets-zod": {
20+
"types": "./dist/presets-zod.d.ts",
21+
"default": "./dist/presets-zod.js"
22+
},
23+
"./presets-valibot": {
24+
"types": "./dist/presets-valibot.d.ts",
25+
"default": "./dist/presets-valibot.js"
2226
}
2327
},
2428
"files": ["dist", "package.json", "LICENSE", "README.md"],
@@ -29,14 +33,18 @@
2933
},
3034
"peerDependencies": {
3135
"typescript": ">=5.0.0",
32-
"zod": "^3.24.0"
36+
"zod": "^3.24.0",
37+
"valibot": "^1.0.0-beta.7 || ^1.0.0"
3338
},
3439
"peerDependenciesMeta": {
3540
"typescript": {
3641
"optional": true
3742
},
3843
"zod": {
3944
"optional": true
45+
},
46+
"valibot": {
47+
"optional": true
4048
}
4149
},
4250
"devDependencies": {

‎packages/core/src/presets-valibot.ts

+198
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
import { url, optional, picklist, pipe, string } from "valibot";
2+
import type { StandardSchemaDictionary } from ".";
3+
import { createEnv } from ".";
4+
import type {
5+
FlyEnv,
6+
NeonVercelEnv,
7+
NetlifyEnv,
8+
RailwayEnv,
9+
RenderEnv,
10+
UploadThingEnv,
11+
UploadThingV6Env,
12+
VercelEnv,
13+
} from "./presets";
14+
15+
/**
16+
* Vercel System Environment Variables
17+
* @see https://vercel.com/docs/projects/environment-variables/system-environment-variables#system-environment-variables
18+
*/
19+
export const vercel = () =>
20+
createEnv({
21+
server: {
22+
VERCEL: optional(string()),
23+
CI: optional(string()),
24+
VERCEL_ENV: optional(picklist(["development", "preview", "production"])),
25+
VERCEL_URL: optional(string()),
26+
VERCEL_PROJECT_PRODUCTION_URL: optional(string()),
27+
VERCEL_BRANCH_URL: optional(string()),
28+
VERCEL_REGION: optional(string()),
29+
VERCEL_DEPLOYMENT_ID: optional(string()),
30+
VERCEL_SKEW_PROTECTION_ENABLED: optional(string()),
31+
VERCEL_AUTOMATION_BYPASS_SECRET: optional(string()),
32+
VERCEL_GIT_PROVIDER: optional(string()),
33+
VERCEL_GIT_REPO_SLUG: optional(string()),
34+
VERCEL_GIT_REPO_OWNER: optional(string()),
35+
VERCEL_GIT_REPO_ID: optional(string()),
36+
VERCEL_GIT_COMMIT_REF: optional(string()),
37+
VERCEL_GIT_COMMIT_SHA: optional(string()),
38+
VERCEL_GIT_COMMIT_MESSAGE: optional(string()),
39+
VERCEL_GIT_COMMIT_AUTHOR_LOGIN: optional(string()),
40+
VERCEL_GIT_COMMIT_AUTHOR_NAME: optional(string()),
41+
VERCEL_GIT_PREVIOUS_SHA: optional(string()),
42+
VERCEL_GIT_PULL_REQUEST_ID: optional(string()),
43+
} satisfies StandardSchemaDictionary.Matching<VercelEnv>,
44+
runtimeEnv: process.env,
45+
});
46+
47+
/**
48+
* Neon for Vercel Environment Variables
49+
* @see https://neon.tech/docs/guides/vercel-native-integration#environment-variables-set-by-the-integration
50+
*/
51+
export const neonVercel = () =>
52+
createEnv({
53+
server: {
54+
DATABASE_URL: string(),
55+
DATABASE_URL_UNPOOLED: optional(string()),
56+
PGHOST: optional(string()),
57+
PGHOST_UNPOOLED: optional(string()),
58+
PGUSER: optional(string()),
59+
PGDATABASE: optional(string()),
60+
PGPASSWORD: optional(string()),
61+
POSTGRES_URL: optional(pipe(string(), url())),
62+
POSTGRES_URL_NON_POOLING: optional(pipe(string(), url())),
63+
POSTGRES_USER: optional(string()),
64+
POSTGRES_HOST: optional(string()),
65+
POSTGRES_PASSWORD: optional(string()),
66+
POSTGRES_DATABASE: optional(string()),
67+
POSTGRES_URL_NO_SSL: optional(pipe(string(), url())),
68+
POSTGRES_PRISMA_URL: optional(pipe(string(), url())),
69+
} satisfies StandardSchemaDictionary.Matching<NeonVercelEnv>,
70+
runtimeEnv: process.env,
71+
});
72+
73+
/**
74+
* @see https://v6.docs.uploadthing.com/getting-started/nuxt#add-env-variables
75+
*/
76+
export const uploadthingV6 = () =>
77+
createEnv({
78+
server: {
79+
UPLOADTHING_TOKEN: string(),
80+
} satisfies StandardSchemaDictionary.Matching<UploadThingV6Env>,
81+
runtimeEnv: process.env,
82+
});
83+
84+
/**
85+
* @see https://docs.uploadthing.com/getting-started/appdir#add-env-variables
86+
*/
87+
export const uploadthing = () =>
88+
createEnv({
89+
server: {
90+
UPLOADTHING_TOKEN: string(),
91+
} satisfies StandardSchemaDictionary.Matching<UploadThingEnv>,
92+
runtimeEnv: process.env,
93+
});
94+
95+
/**
96+
* Render System Environment Variables
97+
* @see https://docs.render.com/environment-variables#all-runtimes
98+
*/
99+
export const render = () =>
100+
createEnv({
101+
server: {
102+
IS_PULL_REQUEST: optional(string()),
103+
RENDER_DISCOVERY_SERVICE: optional(string()),
104+
RENDER_EXTERNAL_HOSTNAME: optional(string()),
105+
RENDER_EXTERNAL_URL: optional(pipe(string(), url())),
106+
RENDER_GIT_BRANCH: optional(string()),
107+
RENDER_GIT_COMMIT: optional(string()),
108+
RENDER_GIT_REPO_SLUG: optional(string()),
109+
RENDER_INSTANCE_ID: optional(string()),
110+
RENDER_SERVICE_ID: optional(string()),
111+
RENDER_SERVICE_NAME: optional(string()),
112+
RENDER_SERVICE_TYPE: optional(
113+
picklist(["web", "pserv", "cron", "worker", "static"]),
114+
),
115+
RENDER: optional(string()),
116+
} satisfies StandardSchemaDictionary.Matching<RenderEnv>,
117+
runtimeEnv: process.env,
118+
});
119+
120+
/**
121+
* Railway Environment Variables
122+
* @see https://docs.railway.app/reference/variables#railway-provided-variables
123+
*/
124+
export const railway = () =>
125+
createEnv({
126+
server: {
127+
RAILWAY_PUBLIC_DOMAIN: optional(string()),
128+
RAILWAY_PRIVATE_DOMAIN: optional(string()),
129+
RAILWAY_TCP_PROXY_DOMAIN: optional(string()),
130+
RAILWAY_TCP_PROXY_PORT: optional(string()),
131+
RAILWAY_TCP_APPLICATION_PORT: optional(string()),
132+
RAILWAY_PROJECT_NAME: optional(string()),
133+
RAILWAY_PROJECT_ID: optional(string()),
134+
RAILWAY_ENVIRONMENT_NAME: optional(string()),
135+
RAILWAY_ENVIRONMENT_ID: optional(string()),
136+
RAILWAY_SERVICE_NAME: optional(string()),
137+
RAILWAY_SERVICE_ID: optional(string()),
138+
RAILWAY_REPLICA_ID: optional(string()),
139+
RAILWAY_DEPLOYMENT_ID: optional(string()),
140+
RAILWAY_SNAPSHOT_ID: optional(string()),
141+
RAILWAY_VOLUME_NAME: optional(string()),
142+
RAILWAY_VOLUME_MOUNT_PATH: optional(string()),
143+
RAILWAY_RUN_UID: optional(string()),
144+
RAILWAY_GIT_COMMIT_SHA: optional(string()),
145+
RAILWAY_GIT_AUTHOR_EMAIL: optional(string()),
146+
RAILWAY_GIT_BRANCH: optional(string()),
147+
RAILWAY_GIT_REPO_NAME: optional(string()),
148+
RAILWAY_GIT_REPO_OWNER: optional(string()),
149+
RAILWAY_GIT_COMMIT_MESSAGE: optional(string()),
150+
} satisfies StandardSchemaDictionary.Matching<RailwayEnv>,
151+
runtimeEnv: process.env,
152+
});
153+
154+
/**
155+
* Fly.io Environment Variables
156+
* @see https://fly.io/docs/machines/runtime-environment/#environment-variables
157+
*/
158+
export const fly = () =>
159+
createEnv({
160+
server: {
161+
FLY_APP_NAME: optional(string()),
162+
FLY_MACHINE_ID: optional(string()),
163+
FLY_ALLOC_ID: optional(string()),
164+
FLY_REGION: optional(string()),
165+
FLY_PUBLIC_IP: optional(string()),
166+
FLY_IMAGE_REF: optional(string()),
167+
FLY_MACHINE_VERSION: optional(string()),
168+
FLY_PRIVATE_IP: optional(string()),
169+
FLY_PROCESS_GROUP: optional(string()),
170+
FLY_VM_MEMORY_MB: optional(string()),
171+
PRIMARY_REGION: optional(string()),
172+
} satisfies StandardSchemaDictionary.Matching<FlyEnv>,
173+
runtimeEnv: process.env,
174+
});
175+
176+
/**
177+
* Netlify Environment Variables
178+
* @see https://docs.netlify.com/configure-builds/environment-variables
179+
*/
180+
export const netlify = () =>
181+
createEnv({
182+
server: {
183+
NETLIFY: optional(string()),
184+
BUILD_ID: optional(string()),
185+
CONTEXT: optional(
186+
picklist(["production", "deploy-preview", "branch-deploy", "dev"]),
187+
),
188+
REPOSITORY_URL: optional(string()),
189+
BRANCH: optional(string()),
190+
URL: optional(string()),
191+
DEPLOY_URL: optional(string()),
192+
DEPLOY_PRIME_URL: optional(string()),
193+
DEPLOY_ID: optional(string()),
194+
SITE_NAME: optional(string()),
195+
SITE_ID: optional(string()),
196+
} satisfies StandardSchemaDictionary.Matching<NetlifyEnv>,
197+
runtimeEnv: process.env,
198+
});

‎packages/core/src/presets-zod.ts

+198
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
import { z } from "zod";
2+
import type { StandardSchemaDictionary } from ".";
3+
import { createEnv } from ".";
4+
import type {
5+
FlyEnv,
6+
NeonVercelEnv,
7+
NetlifyEnv,
8+
RailwayEnv,
9+
RenderEnv,
10+
UploadThingEnv,
11+
UploadThingV6Env,
12+
VercelEnv,
13+
} from "./presets";
14+
15+
/**
16+
* Vercel System Environment Variables
17+
* @see https://vercel.com/docs/projects/environment-variables/system-environment-variables#system-environment-variables
18+
*/
19+
export const vercel = () =>
20+
createEnv({
21+
server: {
22+
VERCEL: z.string().optional(),
23+
CI: z.string().optional(),
24+
VERCEL_ENV: z.enum(["development", "preview", "production"]).optional(),
25+
VERCEL_URL: z.string().optional(),
26+
VERCEL_PROJECT_PRODUCTION_URL: z.string().optional(),
27+
VERCEL_BRANCH_URL: z.string().optional(),
28+
VERCEL_REGION: z.string().optional(),
29+
VERCEL_DEPLOYMENT_ID: z.string().optional(),
30+
VERCEL_SKEW_PROTECTION_ENABLED: z.string().optional(),
31+
VERCEL_AUTOMATION_BYPASS_SECRET: z.string().optional(),
32+
VERCEL_GIT_PROVIDER: z.string().optional(),
33+
VERCEL_GIT_REPO_SLUG: z.string().optional(),
34+
VERCEL_GIT_REPO_OWNER: z.string().optional(),
35+
VERCEL_GIT_REPO_ID: z.string().optional(),
36+
VERCEL_GIT_COMMIT_REF: z.string().optional(),
37+
VERCEL_GIT_COMMIT_SHA: z.string().optional(),
38+
VERCEL_GIT_COMMIT_MESSAGE: z.string().optional(),
39+
VERCEL_GIT_COMMIT_AUTHOR_LOGIN: z.string().optional(),
40+
VERCEL_GIT_COMMIT_AUTHOR_NAME: z.string().optional(),
41+
VERCEL_GIT_PREVIOUS_SHA: z.string().optional(),
42+
VERCEL_GIT_PULL_REQUEST_ID: z.string().optional(),
43+
} satisfies StandardSchemaDictionary.Matching<VercelEnv>,
44+
runtimeEnv: process.env,
45+
});
46+
47+
/**
48+
* Neon for Vercel Environment Variables
49+
* @see https://neon.tech/docs/guides/vercel-native-integration#environment-variables-set-by-the-integration
50+
*/
51+
export const neonVercel = () =>
52+
createEnv({
53+
server: {
54+
DATABASE_URL: z.string(),
55+
DATABASE_URL_UNPOOLED: z.string().optional(),
56+
PGHOST: z.string().optional(),
57+
PGHOST_UNPOOLED: z.string().optional(),
58+
PGUSER: z.string().optional(),
59+
PGDATABASE: z.string().optional(),
60+
PGPASSWORD: z.string().optional(),
61+
POSTGRES_URL: z.string().url().optional(),
62+
POSTGRES_URL_NON_POOLING: z.string().url().optional(),
63+
POSTGRES_USER: z.string().optional(),
64+
POSTGRES_HOST: z.string().optional(),
65+
POSTGRES_PASSWORD: z.string().optional(),
66+
POSTGRES_DATABASE: z.string().optional(),
67+
POSTGRES_URL_NO_SSL: z.string().url().optional(),
68+
POSTGRES_PRISMA_URL: z.string().url().optional(),
69+
} satisfies StandardSchemaDictionary.Matching<NeonVercelEnv>,
70+
runtimeEnv: process.env,
71+
});
72+
73+
/**
74+
* @see https://v6.docs.uploadthing.com/getting-started/nuxt#add-env-variables
75+
*/
76+
export const uploadthingV6 = () =>
77+
createEnv({
78+
server: {
79+
UPLOADTHING_TOKEN: z.string(),
80+
} satisfies StandardSchemaDictionary.Matching<UploadThingV6Env>,
81+
runtimeEnv: process.env,
82+
});
83+
84+
/**
85+
* @see https://docs.uploadthing.com/getting-started/appdir#add-env-variables
86+
*/
87+
export const uploadthing = () =>
88+
createEnv({
89+
server: {
90+
UPLOADTHING_TOKEN: z.string(),
91+
} satisfies StandardSchemaDictionary.Matching<UploadThingEnv>,
92+
runtimeEnv: process.env,
93+
});
94+
95+
/**
96+
* Render System Environment Variables
97+
* @see https://docs.render.com/environment-variables#all-runtimes
98+
*/
99+
export const render = () =>
100+
createEnv({
101+
server: {
102+
IS_PULL_REQUEST: z.string().optional(),
103+
RENDER_DISCOVERY_SERVICE: z.string().optional(),
104+
RENDER_EXTERNAL_HOSTNAME: z.string().optional(),
105+
RENDER_EXTERNAL_URL: z.string().url().optional(),
106+
RENDER_GIT_BRANCH: z.string().optional(),
107+
RENDER_GIT_COMMIT: z.string().optional(),
108+
RENDER_GIT_REPO_SLUG: z.string().optional(),
109+
RENDER_INSTANCE_ID: z.string().optional(),
110+
RENDER_SERVICE_ID: z.string().optional(),
111+
RENDER_SERVICE_NAME: z.string().optional(),
112+
RENDER_SERVICE_TYPE: z
113+
.enum(["web", "pserv", "cron", "worker", "static"])
114+
.optional(),
115+
RENDER: z.string().optional(),
116+
} satisfies StandardSchemaDictionary.Matching<RenderEnv>,
117+
runtimeEnv: process.env,
118+
});
119+
120+
/**
121+
* Railway Environment Variables
122+
* @see https://docs.railway.app/reference/variables#railway-provided-variables
123+
*/
124+
export const railway = () =>
125+
createEnv({
126+
server: {
127+
RAILWAY_PUBLIC_DOMAIN: z.string().optional(),
128+
RAILWAY_PRIVATE_DOMAIN: z.string().optional(),
129+
RAILWAY_TCP_PROXY_DOMAIN: z.string().optional(),
130+
RAILWAY_TCP_PROXY_PORT: z.string().optional(),
131+
RAILWAY_TCP_APPLICATION_PORT: z.string().optional(),
132+
RAILWAY_PROJECT_NAME: z.string().optional(),
133+
RAILWAY_PROJECT_ID: z.string().optional(),
134+
RAILWAY_ENVIRONMENT_NAME: z.string().optional(),
135+
RAILWAY_ENVIRONMENT_ID: z.string().optional(),
136+
RAILWAY_SERVICE_NAME: z.string().optional(),
137+
RAILWAY_SERVICE_ID: z.string().optional(),
138+
RAILWAY_REPLICA_ID: z.string().optional(),
139+
RAILWAY_DEPLOYMENT_ID: z.string().optional(),
140+
RAILWAY_SNAPSHOT_ID: z.string().optional(),
141+
RAILWAY_VOLUME_NAME: z.string().optional(),
142+
RAILWAY_VOLUME_MOUNT_PATH: z.string().optional(),
143+
RAILWAY_RUN_UID: z.string().optional(),
144+
RAILWAY_GIT_COMMIT_SHA: z.string().optional(),
145+
RAILWAY_GIT_AUTHOR_EMAIL: z.string().optional(),
146+
RAILWAY_GIT_BRANCH: z.string().optional(),
147+
RAILWAY_GIT_REPO_NAME: z.string().optional(),
148+
RAILWAY_GIT_REPO_OWNER: z.string().optional(),
149+
RAILWAY_GIT_COMMIT_MESSAGE: z.string().optional(),
150+
} satisfies StandardSchemaDictionary.Matching<RailwayEnv>,
151+
runtimeEnv: process.env,
152+
});
153+
154+
/**
155+
* Fly.io Environment Variables
156+
* @see https://fly.io/docs/machines/runtime-environment/#environment-variables
157+
*/
158+
export const fly = () =>
159+
createEnv({
160+
server: {
161+
FLY_APP_NAME: z.string().optional(),
162+
FLY_MACHINE_ID: z.string().optional(),
163+
FLY_ALLOC_ID: z.string().optional(),
164+
FLY_REGION: z.string().optional(),
165+
FLY_PUBLIC_IP: z.string().optional(),
166+
FLY_IMAGE_REF: z.string().optional(),
167+
FLY_MACHINE_VERSION: z.string().optional(),
168+
FLY_PRIVATE_IP: z.string().optional(),
169+
FLY_PROCESS_GROUP: z.string().optional(),
170+
FLY_VM_MEMORY_MB: z.string().optional(),
171+
PRIMARY_REGION: z.string().optional(),
172+
} satisfies StandardSchemaDictionary.Matching<FlyEnv>,
173+
runtimeEnv: process.env,
174+
});
175+
176+
/**
177+
* Netlify Environment Variables
178+
* @see https://docs.netlify.com/configure-builds/environment-variables
179+
*/
180+
export const netlify = () =>
181+
createEnv({
182+
server: {
183+
NETLIFY: z.string().optional(),
184+
BUILD_ID: z.string().optional(),
185+
CONTEXT: z
186+
.enum(["production", "deploy-preview", "branch-deploy", "dev"])
187+
.optional(),
188+
REPOSITORY_URL: z.string().optional(),
189+
BRANCH: z.string().optional(),
190+
URL: z.string().optional(),
191+
DEPLOY_URL: z.string().optional(),
192+
DEPLOY_PRIME_URL: z.string().optional(),
193+
DEPLOY_ID: z.string().optional(),
194+
SITE_NAME: z.string().optional(),
195+
SITE_ID: z.string().optional(),
196+
} satisfies StandardSchemaDictionary.Matching<NetlifyEnv>,
197+
runtimeEnv: process.env,
198+
});

‎packages/core/src/presets.ts

+111-180
Original file line numberDiff line numberDiff line change
@@ -1,187 +1,118 @@
1-
import { z } from "zod";
2-
import { createEnv } from ".";
1+
export interface VercelEnv {
2+
VERCEL?: string;
3+
CI?: string;
4+
VERCEL_ENV?: "development" | "preview" | "production";
5+
VERCEL_URL?: string;
6+
VERCEL_PROJECT_PRODUCTION_URL?: string;
7+
VERCEL_BRANCH_URL?: string;
8+
VERCEL_REGION?: string;
9+
VERCEL_DEPLOYMENT_ID?: string;
10+
VERCEL_SKEW_PROTECTION_ENABLED?: string;
11+
VERCEL_AUTOMATION_BYPASS_SECRET?: string;
12+
VERCEL_GIT_PROVIDER?: string;
13+
VERCEL_GIT_REPO_SLUG?: string;
14+
VERCEL_GIT_REPO_OWNER?: string;
15+
VERCEL_GIT_REPO_ID?: string;
16+
VERCEL_GIT_COMMIT_REF?: string;
17+
VERCEL_GIT_COMMIT_SHA?: string;
18+
VERCEL_GIT_COMMIT_MESSAGE?: string;
19+
VERCEL_GIT_COMMIT_AUTHOR_LOGIN?: string;
20+
VERCEL_GIT_COMMIT_AUTHOR_NAME?: string;
21+
VERCEL_GIT_PREVIOUS_SHA?: string;
22+
VERCEL_GIT_PULL_REQUEST_ID?: string;
23+
}
324

4-
/**
5-
* Vercel System Environment Variables
6-
* @see https://vercel.com/docs/projects/environment-variables/system-environment-variables#system-environment-variables
7-
*/
8-
export const vercel = () =>
9-
createEnv({
10-
server: {
11-
VERCEL: z.string().optional(),
12-
CI: z.string().optional(),
13-
VERCEL_ENV: z.enum(["development", "preview", "production"]).optional(),
14-
VERCEL_URL: z.string().optional(),
15-
VERCEL_PROJECT_PRODUCTION_URL: z.string().optional(),
16-
VERCEL_BRANCH_URL: z.string().optional(),
17-
VERCEL_REGION: z.string().optional(),
18-
VERCEL_DEPLOYMENT_ID: z.string().optional(),
19-
VERCEL_SKEW_PROTECTION_ENABLED: z.string().optional(),
20-
VERCEL_AUTOMATION_BYPASS_SECRET: z.string().optional(),
21-
VERCEL_GIT_PROVIDER: z.string().optional(),
22-
VERCEL_GIT_REPO_SLUG: z.string().optional(),
23-
VERCEL_GIT_REPO_OWNER: z.string().optional(),
24-
VERCEL_GIT_REPO_ID: z.string().optional(),
25-
VERCEL_GIT_COMMIT_REF: z.string().optional(),
26-
VERCEL_GIT_COMMIT_SHA: z.string().optional(),
27-
VERCEL_GIT_COMMIT_MESSAGE: z.string().optional(),
28-
VERCEL_GIT_COMMIT_AUTHOR_LOGIN: z.string().optional(),
29-
VERCEL_GIT_COMMIT_AUTHOR_NAME: z.string().optional(),
30-
VERCEL_GIT_PREVIOUS_SHA: z.string().optional(),
31-
VERCEL_GIT_PULL_REQUEST_ID: z.string().optional(),
32-
},
33-
runtimeEnv: process.env,
34-
});
25+
export interface NeonVercelEnv {
26+
DATABASE_URL: string;
27+
DATABASE_URL_UNPOOLED?: string;
28+
PGHOST?: string;
29+
PGHOST_UNPOOLED?: string;
30+
PGUSER?: string;
31+
PGDATABASE?: string;
32+
PGPASSWORD?: string;
33+
POSTGRES_URL?: string;
34+
POSTGRES_URL_NON_POOLING?: string;
35+
POSTGRES_USER?: string;
36+
POSTGRES_HOST?: string;
37+
POSTGRES_PASSWORD?: string;
38+
POSTGRES_DATABASE?: string;
39+
POSTGRES_URL_NO_SSL?: string;
40+
POSTGRES_PRISMA_URL?: string;
41+
}
3542

36-
/**
37-
* Neon for Vercel Environment Variables
38-
* @see https://neon.tech/docs/guides/vercel-native-integration#environment-variables-set-by-the-integration
39-
*/
40-
export const neonVercel = () =>
41-
createEnv({
42-
server: {
43-
DATABASE_URL: z.string(),
44-
DATABASE_URL_UNPOOLED: z.string().optional(),
45-
PGHOST: z.string().optional(),
46-
PGHOST_UNPOOLED: z.string().optional(),
47-
PGUSER: z.string().optional(),
48-
PGDATABASE: z.string().optional(),
49-
PGPASSWORD: z.string().optional(),
50-
POSTGRES_URL: z.string().url().optional(),
51-
POSTGRES_URL_NON_POOLING: z.string().url().optional(),
52-
POSTGRES_USER: z.string().optional(),
53-
POSTGRES_HOST: z.string().optional(),
54-
POSTGRES_PASSWORD: z.string().optional(),
55-
POSTGRES_DATABASE: z.string().optional(),
56-
POSTGRES_URL_NO_SSL: z.string().url().optional(),
57-
POSTGRES_PRISMA_URL: z.string().url().optional(),
58-
},
59-
runtimeEnv: process.env,
60-
});
43+
export interface UploadThingV6Env {
44+
UPLOADTHING_TOKEN: string;
45+
}
6146

62-
/**
63-
* @see https://v6.docs.uploadthing.com/getting-started/nuxt#add-env-variables
64-
*/
65-
export const uploadthingV6 = () =>
66-
createEnv({
67-
server: {
68-
UPLOADTHING_TOKEN: z.string(),
69-
},
70-
runtimeEnv: process.env,
71-
});
47+
export interface UploadThingEnv {
48+
UPLOADTHING_TOKEN: string;
49+
}
7250

73-
/**
74-
* @see https://docs.uploadthing.com/getting-started/appdir#add-env-variables
75-
*/
76-
export const uploadthing = () =>
77-
createEnv({
78-
server: {
79-
UPLOADTHING_TOKEN: z.string(),
80-
},
81-
runtimeEnv: process.env,
82-
});
51+
export interface RenderEnv {
52+
IS_PULL_REQUEST?: string;
53+
RENDER_DISCOVERY_SERVICE?: string;
54+
RENDER_EXTERNAL_HOSTNAME?: string;
55+
RENDER_EXTERNAL_URL?: string;
56+
RENDER_GIT_BRANCH?: string;
57+
RENDER_GIT_COMMIT?: string;
58+
RENDER_GIT_REPO_SLUG?: string;
59+
RENDER_INSTANCE_ID?: string;
60+
RENDER_SERVICE_ID?: string;
61+
RENDER_SERVICE_NAME?: string;
62+
RENDER_SERVICE_TYPE?: "web" | "pserv" | "cron" | "worker" | "static";
63+
RENDER?: string;
64+
}
8365

84-
/**
85-
* Render System Environment Variables
86-
* @see https://docs.render.com/environment-variables#all-runtimes
87-
*/
88-
export const render = () =>
89-
createEnv({
90-
server: {
91-
IS_PULL_REQUEST: z.string().optional(),
92-
RENDER_DISCOVERY_SERVICE: z.string().optional(),
93-
RENDER_EXTERNAL_HOSTNAME: z.string().optional(),
94-
RENDER_EXTERNAL_URL: z.string().url().optional(),
95-
RENDER_GIT_BRANCH: z.string().optional(),
96-
RENDER_GIT_COMMIT: z.string().optional(),
97-
RENDER_GIT_REPO_SLUG: z.string().optional(),
98-
RENDER_INSTANCE_ID: z.string().optional(),
99-
RENDER_SERVICE_ID: z.string().optional(),
100-
RENDER_SERVICE_NAME: z.string().optional(),
101-
RENDER_SERVICE_TYPE: z
102-
.enum(["web", "pserv", "cron", "worker", "static"])
103-
.optional(),
104-
RENDER: z.string().optional(),
105-
},
106-
runtimeEnv: process.env,
107-
});
66+
export interface RailwayEnv {
67+
RAILWAY_PUBLIC_DOMAIN?: string;
68+
RAILWAY_PRIVATE_DOMAIN?: string;
69+
RAILWAY_TCP_PROXY_DOMAIN?: string;
70+
RAILWAY_TCP_PROXY_PORT?: string;
71+
RAILWAY_TCP_APPLICATION_PORT?: string;
72+
RAILWAY_PROJECT_NAME?: string;
73+
RAILWAY_PROJECT_ID?: string;
74+
RAILWAY_ENVIRONMENT_NAME?: string;
75+
RAILWAY_ENVIRONMENT_ID?: string;
76+
RAILWAY_SERVICE_NAME?: string;
77+
RAILWAY_SERVICE_ID?: string;
78+
RAILWAY_REPLICA_ID?: string;
79+
RAILWAY_DEPLOYMENT_ID?: string;
80+
RAILWAY_SNAPSHOT_ID?: string;
81+
RAILWAY_VOLUME_NAME?: string;
82+
RAILWAY_VOLUME_MOUNT_PATH?: string;
83+
RAILWAY_RUN_UID?: string;
84+
RAILWAY_GIT_COMMIT_SHA?: string;
85+
RAILWAY_GIT_AUTHOR_EMAIL?: string;
86+
RAILWAY_GIT_BRANCH?: string;
87+
RAILWAY_GIT_REPO_NAME?: string;
88+
RAILWAY_GIT_REPO_OWNER?: string;
89+
RAILWAY_GIT_COMMIT_MESSAGE?: string;
90+
}
10891

109-
/**
110-
* Railway Environment Variables
111-
* @see https://docs.railway.app/reference/variables#railway-provided-variables
112-
*/
113-
export const railway = () =>
114-
createEnv({
115-
server: {
116-
RAILWAY_PUBLIC_DOMAIN: z.string().optional(),
117-
RAILWAY_PRIVATE_DOMAIN: z.string().optional(),
118-
RAILWAY_TCP_PROXY_DOMAIN: z.string().optional(),
119-
RAILWAY_TCP_PROXY_PORT: z.string().optional(),
120-
RAILWAY_TCP_APPLICATION_PORT: z.string().optional(),
121-
RAILWAY_PROJECT_NAME: z.string().optional(),
122-
RAILWAY_PROJECT_ID: z.string().optional(),
123-
RAILWAY_ENVIRONMENT_NAME: z.string().optional(),
124-
RAILWAY_ENVIRONMENT_ID: z.string().optional(),
125-
RAILWAY_SERVICE_NAME: z.string().optional(),
126-
RAILWAY_SERVICE_ID: z.string().optional(),
127-
RAILWAY_REPLICA_ID: z.string().optional(),
128-
RAILWAY_DEPLOYMENT_ID: z.string().optional(),
129-
RAILWAY_SNAPSHOT_ID: z.string().optional(),
130-
RAILWAY_VOLUME_NAME: z.string().optional(),
131-
RAILWAY_VOLUME_MOUNT_PATH: z.string().optional(),
132-
RAILWAY_RUN_UID: z.string().optional(),
133-
RAILWAY_GIT_COMMIT_SHA: z.string().optional(),
134-
RAILWAY_GIT_AUTHOR_EMAIL: z.string().optional(),
135-
RAILWAY_GIT_BRANCH: z.string().optional(),
136-
RAILWAY_GIT_REPO_NAME: z.string().optional(),
137-
RAILWAY_GIT_REPO_OWNER: z.string().optional(),
138-
RAILWAY_GIT_COMMIT_MESSAGE: z.string().optional(),
139-
},
140-
runtimeEnv: process.env,
141-
});
92+
export interface FlyEnv {
93+
FLY_APP_NAME?: string;
94+
FLY_MACHINE_ID?: string;
95+
FLY_ALLOC_ID?: string;
96+
FLY_REGION?: string;
97+
FLY_PUBLIC_IP?: string;
98+
FLY_IMAGE_REF?: string;
99+
FLY_MACHINE_VERSION?: string;
100+
FLY_PRIVATE_IP?: string;
101+
FLY_PROCESS_GROUP?: string;
102+
FLY_VM_MEMORY_MB?: string;
103+
PRIMARY_REGION?: string;
104+
}
142105

143-
/**
144-
* Fly.io Environment Variables
145-
* @see https://fly.io/docs/machines/runtime-environment/#environment-variables
146-
*/
147-
export const fly = () =>
148-
createEnv({
149-
server: {
150-
FLY_APP_NAME: z.string().optional(),
151-
FLY_MACHINE_ID: z.string().optional(),
152-
FLY_ALLOC_ID: z.string().optional(),
153-
FLY_REGION: z.string().optional(),
154-
FLY_PUBLIC_IP: z.string().optional(),
155-
FLY_IMAGE_REF: z.string().optional(),
156-
FLY_MACHINE_VERSION: z.string().optional(),
157-
FLY_PRIVATE_IP: z.string().optional(),
158-
FLY_PROCESS_GROUP: z.string().optional(),
159-
FLY_VM_MEMORY_MB: z.string().optional(),
160-
PRIMARY_REGION: z.string().optional(),
161-
},
162-
runtimeEnv: process.env,
163-
});
164-
165-
/**
166-
* Netlify Environment Variables
167-
* @see https://docs.netlify.com/configure-builds/environment-variables
168-
*/
169-
export const netlify = () =>
170-
createEnv({
171-
server: {
172-
NETLIFY: z.string().optional(),
173-
BUILD_ID: z.string().optional(),
174-
CONTEXT: z
175-
.enum(["production", "deploy-preview", "branch-deploy", "dev"])
176-
.optional(),
177-
REPOSITORY_URL: z.string().optional(),
178-
BRANCH: z.string().optional(),
179-
URL: z.string().optional(),
180-
DEPLOY_URL: z.string().optional(),
181-
DEPLOY_PRIME_URL: z.string().optional(),
182-
DEPLOY_ID: z.string().optional(),
183-
SITE_NAME: z.string().optional(),
184-
SITE_ID: z.string().optional(),
185-
},
186-
runtimeEnv: process.env,
187-
});
106+
export interface NetlifyEnv {
107+
NETLIFY?: string;
108+
BUILD_ID?: string;
109+
CONTEXT?: "production" | "deploy-preview" | "branch-deploy" | "dev";
110+
REPOSITORY_URL?: string;
111+
BRANCH?: string;
112+
URL?: string;
113+
DEPLOY_URL?: string;
114+
DEPLOY_PRIME_URL?: string;
115+
DEPLOY_ID?: string;
116+
SITE_NAME?: string;
117+
SITE_ID?: string;
118+
}

‎packages/core/src/standard.ts

+9
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ export declare namespace StandardSchemaV1 {
7171

7272
export type StandardSchemaDictionary = Record<string, StandardSchemaV1>;
7373
export namespace StandardSchemaDictionary {
74+
/**
75+
* A dictionary of Standard Schemas that match the input and output types.
76+
*/
77+
export type Matching<
78+
Input,
79+
Output extends Record<keyof Input, unknown> = Input,
80+
> = {
81+
[K in keyof Input]-?: StandardSchemaV1<Input[K], Output[K]>;
82+
};
7483
export type InferInput<T extends StandardSchemaDictionary> = {
7584
[K in keyof T]: StandardSchemaV1.InferInput<T[K]>;
7685
};

‎packages/nextjs/package.json

+12-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616
"types": "./dist/index.d.ts",
1717
"default": "./dist/index.js"
1818
},
19-
"./presets": {
20-
"types": "./dist/presets.d.ts",
21-
"default": "./dist/presets.js"
19+
"./presets-zod": {
20+
"types": "./dist/presets-zod.d.ts",
21+
"default": "./dist/presets-zod.js"
22+
},
23+
"./presets-valibot": {
24+
"types": "./dist/presets-valibot.d.ts",
25+
"default": "./dist/presets-valibot.js"
2226
}
2327
},
2428
"files": ["dist", "package.json", "LICENSE", "README.md"],
@@ -33,14 +37,18 @@
3337
},
3438
"peerDependencies": {
3539
"typescript": ">=5.0.0",
36-
"zod": "^3.24.0"
40+
"zod": "^3.24.0",
41+
"valibot": "^1.0.0-beta.7 || ^1.0.0"
3742
},
3843
"peerDependenciesMeta": {
3944
"typescript": {
4045
"optional": true
4146
},
4247
"zod": {
4348
"optional": true
49+
},
50+
"valibot": {
51+
"optional": true
4452
}
4553
},
4654
"devDependencies": {
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "@t3-oss/env-core/presets-valibot";

‎packages/nextjs/src/presets-zod.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "@t3-oss/env-core/presets-zod";

‎packages/nextjs/src/presets.ts

-1
This file was deleted.

‎packages/nuxt/package.json

+12-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616
"types": "./dist/index.d.ts",
1717
"default": "./dist/index.js"
1818
},
19-
"./presets": {
20-
"types": "./dist/presets.d.ts",
21-
"default": "./dist/presets.js"
19+
"./presets-zod": {
20+
"types": "./dist/presets-zod.d.ts",
21+
"default": "./dist/presets-zod.js"
22+
},
23+
"./presets-valibot": {
24+
"types": "./dist/presets-valibot.d.ts",
25+
"default": "./dist/presets-valibot.js"
2226
}
2327
},
2428
"files": ["dist", "package.json", "LICENSE", "README.md"],
@@ -33,14 +37,18 @@
3337
},
3438
"peerDependencies": {
3539
"typescript": ">=5.0.0",
36-
"zod": "^3.24.0"
40+
"zod": "^3.24.0",
41+
"valibot": "^1.0.0-beta.7 || ^1.0.0"
3742
},
3843
"peerDependenciesMeta": {
3944
"typescript": {
4045
"optional": true
4146
},
4247
"zod": {
4348
"optional": true
49+
},
50+
"valibot": {
51+
"optional": true
4452
}
4553
},
4654
"devDependencies": {

‎packages/nuxt/src/presets-valibot.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "@t3-oss/env-core/presets-valibot";

‎packages/nuxt/src/presets-zod.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "@t3-oss/env-core/presets-zod";

‎packages/nuxt/src/presets.ts

-1
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.