convex-env 1.0.0 → 1.0.1
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.
- package/README.md +20 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://b9sa6juqtj.ufs.sh/f/
|
|
2
|
+
<img src="https://b9sa6juqtj.ufs.sh/f/WmevHvqCEmRajVTwwtXKdHb7pg9oz0hCWQNZntX6PAcxi34L" alt="Convex Env Example" style="max-width: 700px; width: 100%;">
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<h2 align="center">Convex Env</h2>
|
|
@@ -15,7 +15,7 @@ Validators currently supported:
|
|
|
15
15
|
- v.number()
|
|
16
16
|
- v.boolean()
|
|
17
17
|
|
|
18
|
-
you can use `v.optional()` on
|
|
18
|
+
you can use `v.optional()` on _any_ supported validator, see [example](#usage) below
|
|
19
19
|
|
|
20
20
|
<span style="color: red;"><strong>IMPORTANT</strong></span>: The <code>env</code> object from <code>createEnv</code> should only be used in the Convex runtime, the values on it will not be accessible client side.
|
|
21
21
|
|
|
@@ -44,7 +44,7 @@ yarn add convex-env
|
|
|
44
44
|
### Usage
|
|
45
45
|
|
|
46
46
|
```typescript
|
|
47
|
-
// convex.env.ts
|
|
47
|
+
// convex/convex.env.ts
|
|
48
48
|
|
|
49
49
|
import { createEnv } from "convex-env";
|
|
50
50
|
import { v } from "convex/values";
|
|
@@ -62,7 +62,7 @@ export const env = createEnv({
|
|
|
62
62
|
Then access them anywhere in Convex.
|
|
63
63
|
|
|
64
64
|
```typescript
|
|
65
|
-
// auth.ts
|
|
65
|
+
// convex/auth.ts
|
|
66
66
|
|
|
67
67
|
import { env } from "./convex.env";
|
|
68
68
|
|
|
@@ -82,7 +82,7 @@ export const createAuth = (ctx: GenericCtx<DataModel>) => {
|
|
|
82
82
|
You can also pass values manually
|
|
83
83
|
|
|
84
84
|
```typescript
|
|
85
|
-
// convex.env.ts
|
|
85
|
+
// convex/convex.env.ts
|
|
86
86
|
|
|
87
87
|
import { createEnv } from "convex-env";
|
|
88
88
|
import { v } from "convex/values";
|
|
@@ -106,3 +106,18 @@ export const env = createEnv(
|
|
|
106
106
|
}
|
|
107
107
|
);
|
|
108
108
|
```
|
|
109
|
+
|
|
110
|
+
### Why use it?
|
|
111
|
+
|
|
112
|
+
User defined values on the `process.env` object will always be typed `string | undefined`. If you want to store anything other than a string, you have to cast it at each use and hope that you typed the value correctly in `.env`
|
|
113
|
+
|
|
114
|
+
This package gives you the reassurance that when you use an environment variable in your code, it will:
|
|
115
|
+
|
|
116
|
+
- Actually be there
|
|
117
|
+
- Will be the type you expect it to be
|
|
118
|
+
|
|
119
|
+
It can also prevent you from shipping bugs to production. If an environment variable is missing or doesn't match its validator, your deployment to Convex will fail.
|
|
120
|
+
|
|
121
|
+
<p align="center">
|
|
122
|
+
<img src="https://b9sa6juqtj.ufs.sh/f/WmevHvqCEmRaetBLb0NWmSZIsPhkweq8TtVxHraXLjAdgyEC" alt="Convex Env build failure example" style="max-width: 700px; width: 100%;">
|
|
123
|
+
</p>
|