@romaintaillandier1978/dotenv-never-lies 0.4.0 → 1.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 +257 -239
- package/dist/cli/commands/export.d.ts +4 -3
- package/dist/cli/commands/export.d.ts.map +1 -1
- package/dist/cli/commands/export.js +105 -100
- package/dist/cli/commands/generate.d.ts +4 -1
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/reverseEnv.d.ts.map +1 -1
- package/dist/cli/commands/reverseEnv.js +8 -2
- package/dist/cli/index.js +146 -109
- package/dist/cli/utils/infer-schema.d.ts.map +1 -1
- package/dist/cli/utils/infer-schema.js +4 -3
- package/dist/cli/utils/load-schema.d.ts.map +1 -1
- package/dist/cli/utils/load-schema.js +5 -4
- package/dist/cli/utils/printer.d.ts.map +1 -1
- package/dist/cli/utils/printer.js +5 -4
- package/dist/core.d.ts +33 -33
- package/dist/core.js +8 -8
- package/package.json +1 -1
package/dist/core.d.ts
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* An object containing environment variables as strings, coming from a .env file or from process.env.
|
|
4
4
|
*/
|
|
5
5
|
export type EnvSource = Record<string, string | undefined>;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* An environment variable.
|
|
8
8
|
*/
|
|
9
9
|
export interface EnvVarDefinition<T extends z.ZodType = z.ZodType> {
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* The Zod schema of the environment variable.
|
|
12
12
|
*/
|
|
13
13
|
schema: T;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* The description of the environment variable.
|
|
16
16
|
*/
|
|
17
17
|
description: string;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Whether the environment variable is secret (for tokens, passwords), reserved for future use (RFU).
|
|
20
20
|
*/
|
|
21
21
|
secret?: boolean;
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Provides examples for this variable.
|
|
24
24
|
*/
|
|
25
25
|
examples?: string[];
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* An object containing the defined environment variables.
|
|
29
29
|
*/
|
|
30
30
|
export type EnvDefinition = Record<string, EnvVarDefinition<any>>;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* The Zod shape of the environment schema.
|
|
33
33
|
*/
|
|
34
34
|
export type ZodShapeFromEnv<T extends EnvDefinition> = {
|
|
35
35
|
[K in keyof T & string]: T[K]["schema"];
|
|
36
36
|
};
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* The inferred type of the environment schema.
|
|
39
39
|
*/
|
|
40
40
|
export type InferEnv<T extends EnvDefinition> = {
|
|
41
41
|
[K in keyof T & string]: z.infer<T[K]["schema"]>;
|
|
@@ -47,60 +47,60 @@ type AssertFn<T extends EnvDefinition> = (options?: {
|
|
|
47
47
|
source?: EnvSource | undefined;
|
|
48
48
|
}) => InferEnv<T>;
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
51
|
-
* @template T -
|
|
50
|
+
* An object containing functions to check and assert environment variables.
|
|
51
|
+
* @template T - The environment schema to define.
|
|
52
52
|
*/
|
|
53
53
|
export type EnvDefinitionHelper<T extends EnvDefinition> = {
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
55
|
+
* The defined environment schema.
|
|
56
56
|
*/
|
|
57
57
|
def: T;
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
59
|
+
* The Zod shape of the environment schema.
|
|
60
60
|
*/
|
|
61
61
|
zodShape: ZodShapeFromEnv<T>;
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* The Zod schema of the environment schema.
|
|
64
64
|
*/
|
|
65
65
|
zodSchema: z.ZodObject<ZodShapeFromEnv<T>>;
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
67
|
+
* Checks whether the environment variables are valid without throwing.
|
|
68
68
|
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
69
|
+
* If `options.source` is provided, it is used with strict mode (zod.strict()).
|
|
70
|
+
* Otherwise, `process.env` is used in non-strict mode.
|
|
71
71
|
*
|
|
72
|
-
* @param options -
|
|
73
|
-
* @returns true
|
|
72
|
+
* @param options - Options to check the environment variables.
|
|
73
|
+
* @returns true if the environment variables are valid, false otherwise.
|
|
74
74
|
*/
|
|
75
75
|
check: CheckFn;
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* Validates the environment variables and throws if they do not conform to the schema.
|
|
78
78
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
79
|
+
* If `options.source` is provided, it is used with strict mode (zod.strict()).
|
|
80
|
+
* Otherwise, `process.env` is used in non-strict mode.
|
|
81
81
|
*
|
|
82
|
-
* @param options -
|
|
83
|
-
* @returns
|
|
84
|
-
* @throws
|
|
82
|
+
* @param options - Options to load the environment variables.
|
|
83
|
+
* @returns The loaded environment variables.
|
|
84
|
+
* @throws If the environment variables are invalid.
|
|
85
85
|
*/
|
|
86
86
|
assert: AssertFn<T>;
|
|
87
87
|
};
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
90
|
-
* @param def -
|
|
91
|
-
* @returns
|
|
89
|
+
* Defines an environment schema.
|
|
90
|
+
* @param def - The environment schema to define.
|
|
91
|
+
* @returns An object exposing functions to check and assert environment variables.
|
|
92
92
|
*/
|
|
93
93
|
export declare const define: <T extends EnvDefinition>(def: T) => EnvDefinitionHelper<T>;
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
95
|
+
* Reads a .env file and returns environment variables as an object.
|
|
96
|
+
* Uses dotenv and dotenv-expand.
|
|
97
97
|
* @example
|
|
98
98
|
* ```typescript
|
|
99
99
|
* const ENV = envDefinition.load({ source: readEnvFile(".env") });
|
|
100
100
|
* ```
|
|
101
|
-
* @param path -
|
|
102
|
-
* @returns
|
|
103
|
-
* @throws
|
|
101
|
+
* @param path - The path to the .env file.
|
|
102
|
+
* @returns The environment variables as an object.
|
|
103
|
+
* @throws If the .env file does not exist, or is not valid.
|
|
104
104
|
*/
|
|
105
105
|
export declare const readEnvFile: (path: string) => EnvSource;
|
|
106
106
|
export {};
|
package/dist/core.js
CHANGED
|
@@ -4,9 +4,9 @@ import dotenvExpand from "dotenv-expand";
|
|
|
4
4
|
import { DnlError, ExitCodes } from "./errors.js";
|
|
5
5
|
import fs from "fs";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @param def -
|
|
9
|
-
* @returns
|
|
7
|
+
* Defines an environment schema.
|
|
8
|
+
* @param def - The environment schema to define.
|
|
9
|
+
* @returns An object exposing functions to check and assert environment variables.
|
|
10
10
|
*/
|
|
11
11
|
export const define = (def) => {
|
|
12
12
|
const zodShape = Object.fromEntries(Object.entries(def).map(([key, value]) => [key, value.schema]));
|
|
@@ -29,15 +29,15 @@ export const define = (def) => {
|
|
|
29
29
|
return { def, zodShape, zodSchema, check, assert };
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
32
|
+
* Reads a .env file and returns environment variables as an object.
|
|
33
|
+
* Uses dotenv and dotenv-expand.
|
|
34
34
|
* @example
|
|
35
35
|
* ```typescript
|
|
36
36
|
* const ENV = envDefinition.load({ source: readEnvFile(".env") });
|
|
37
37
|
* ```
|
|
38
|
-
* @param path -
|
|
39
|
-
* @returns
|
|
40
|
-
* @throws
|
|
38
|
+
* @param path - The path to the .env file.
|
|
39
|
+
* @returns The environment variables as an object.
|
|
40
|
+
* @throws If the .env file does not exist, or is not valid.
|
|
41
41
|
*/
|
|
42
42
|
export const readEnvFile = (path) => {
|
|
43
43
|
if (!fs.existsSync(path)) {
|
package/package.json
CHANGED