convex-env 2.0.0 → 2.1.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.
- package/README.md +4 -7
- package/dist/index.d.mts +5 -2
- package/dist/index.mjs +5 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,8 +14,9 @@ Validators currently supported:
|
|
|
14
14
|
- v.string()
|
|
15
15
|
- v.number()
|
|
16
16
|
- v.boolean()
|
|
17
|
+
- v.union() + v.literal() (strings only)
|
|
17
18
|
|
|
18
|
-
You can use `v.optional()` on _any_ supported validator, see [
|
|
19
|
+
You can use `v.optional()` on _any_ supported validator, see [examples](#usage) below
|
|
19
20
|
|
|
20
21
|
<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
22
|
|
|
@@ -50,6 +51,7 @@ import { createEnv } from "convex-env";
|
|
|
50
51
|
import { v } from "convex/values";
|
|
51
52
|
|
|
52
53
|
export const env = createEnv({
|
|
54
|
+
ENVIRONMENT: v.union(v.literal("development"), v.literal("production")),
|
|
53
55
|
CONVEX_SITE_URL: v.string(),
|
|
54
56
|
BETTER_AUTH_SECRET: v.string(),
|
|
55
57
|
GOOGLE_CLIENT_ID: v.string(),
|
|
@@ -93,6 +95,7 @@ export const env = createEnv({
|
|
|
93
95
|
MAX_REQUESTS_PER_USER: v.number(),
|
|
94
96
|
DEBUG_MODE: v.optional(v.boolean()),
|
|
95
97
|
},
|
|
98
|
+
// optional, defaults to process.env
|
|
96
99
|
values: {
|
|
97
100
|
CONVEX_SITE_URL: process.env.CONVEX_SITE_URL,
|
|
98
101
|
MAX_REQUESTS_PER_USER: process.env.MAX_REQUESTS_PER_USER,
|
|
@@ -117,12 +120,6 @@ export const schema = {
|
|
|
117
120
|
|
|
118
121
|
export const env = createEnv({
|
|
119
122
|
schema,
|
|
120
|
-
// optional, defaults to process.env
|
|
121
|
-
values: {
|
|
122
|
-
CONVEX_SITE_URL: process.env.CONVEX_SITE_URL,
|
|
123
|
-
MAX_REQUESTS_PER_USER: process.env.MAX_REQUESTS_PER_USER,
|
|
124
|
-
DEBUG_MODE: process.env.DEBUG_MODE,
|
|
125
|
-
},
|
|
126
123
|
options: {
|
|
127
124
|
skipValidation: true,
|
|
128
125
|
},
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { Infer, VBoolean, VFloat64, VOptional, VString } from "convex/values";
|
|
1
|
+
import { Infer, VBoolean, VFloat64, VLiteral, VOptional, VString, VUnion } from "convex/values";
|
|
2
2
|
|
|
3
3
|
//#region src/types.d.ts
|
|
4
|
-
type
|
|
4
|
+
type AllowedBaseValidators = VString | VFloat64 | VBoolean;
|
|
5
|
+
type AllowedLiteralValidators = VLiteral<string>;
|
|
6
|
+
type AllowedUnionValidators = VUnion<any, [AllowedLiteralValidators, AllowedLiteralValidators, ...AllowedLiteralValidators[]]>;
|
|
7
|
+
type AllowedPrimitiveValidators = AllowedBaseValidators | AllowedLiteralValidators | AllowedUnionValidators;
|
|
5
8
|
type AllowedOptionalValidators = VOptional<AllowedPrimitiveValidators>;
|
|
6
9
|
type AllowedValidators = AllowedPrimitiveValidators | AllowedOptionalValidators;
|
|
7
10
|
type InferredOuput<V extends AllowedValidators> = Infer<V>;
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { validate } from "convex-helpers/validators";
|
|
2
|
-
import { v } from "convex/values";
|
|
3
2
|
|
|
4
3
|
//#region src/transform.ts
|
|
5
4
|
const transformed = (value, validator) => {
|
|
6
5
|
if (value === void 0) return void 0;
|
|
7
6
|
if (value.trim() === "") throw new Error("Value is empty");
|
|
8
|
-
if (validator.kind ===
|
|
9
|
-
if (validator.kind ===
|
|
10
|
-
if (validator.kind ===
|
|
7
|
+
if (validator.kind === "union") return value;
|
|
8
|
+
if (validator.kind === "literal") return value;
|
|
9
|
+
if (validator.kind === "string") return value;
|
|
10
|
+
if (validator.kind === "float64") return validateAndTransformNumber(value);
|
|
11
|
+
if (validator.kind === "boolean") return validateAndTransformBoolean(value);
|
|
11
12
|
throw new Error("Validator is not supported");
|
|
12
13
|
};
|
|
13
14
|
const validateAndTransformNumber = (value) => {
|