@geekmidas/envkit 0.0.3 → 0.0.4
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/dist/{EnvironmentParser-Bz9IoLJs.cjs → EnvironmentParser-Bo2CCl_K.cjs} +56 -43
- package/dist/{EnvironmentParser-Boj5EFmL.mjs → EnvironmentParser-jKrGMBhP.mjs} +52 -2
- package/dist/EnvironmentParser.cjs +1 -1
- package/dist/EnvironmentParser.mjs +1 -1
- package/dist/__tests__/ConfigParser.spec.cjs +53 -52
- package/dist/__tests__/ConfigParser.spec.mjs +27 -27
- package/dist/__tests__/EnvironmentParser.spec.cjs +79 -78
- package/dist/__tests__/EnvironmentParser.spec.mjs +41 -41
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/sst.cjs +131 -0
- package/dist/sst.mjs +128 -0
- package/package.json +10 -3
- package/src/EnvironmentParser.ts +80 -3
- package/src/sst.ts +221 -0
- package/dist/magic-string.es-BrLHy2bw.cjs +0 -1015
- package/dist/magic-string.es-u4lFXMgd.mjs +0 -1014
- package/dist/vi.bdSIJ99Y-CT9xbG7X.cjs +0 -14895
- package/dist/vi.bdSIJ99Y-CkiV-M6Y.mjs +0 -14903
|
@@ -1,35 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __commonJS = (cb, mod) => function() {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
|
-
key = keys[i];
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
-
get: ((k) => from[k]).bind(null, key),
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
22
|
-
value: mod,
|
|
23
|
-
enumerable: true
|
|
24
|
-
}) : target, mod));
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
const lodash_get = __toESM(require("lodash.get"));
|
|
28
|
-
const lodash_set = __toESM(require("lodash.set"));
|
|
29
|
-
const zod_v4 = __toESM(require("zod/v4"));
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const lodash_get = require_chunk.__toESM(require("lodash.get"));
|
|
3
|
+
const lodash_set = require_chunk.__toESM(require("lodash.set"));
|
|
4
|
+
const zod_v4 = require_chunk.__toESM(require("zod/v4"));
|
|
30
5
|
|
|
31
6
|
//#region src/EnvironmentParser.ts
|
|
7
|
+
/**
|
|
8
|
+
* Parses and validates configuration objects against Zod schemas.
|
|
9
|
+
* Handles nested configurations and aggregates validation errors.
|
|
10
|
+
*
|
|
11
|
+
* @template TResponse - The shape of the configuration object
|
|
12
|
+
*/
|
|
32
13
|
var ConfigParser = class {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new ConfigParser instance.
|
|
16
|
+
*
|
|
17
|
+
* @param config - The configuration object to parse
|
|
18
|
+
*/
|
|
33
19
|
constructor(config) {
|
|
34
20
|
this.config = config;
|
|
35
21
|
}
|
|
@@ -61,10 +47,42 @@ var ConfigParser = class {
|
|
|
61
47
|
return parsedConfig;
|
|
62
48
|
}
|
|
63
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Parses environment variables with type-safe validation using Zod schemas.
|
|
52
|
+
* Provides a fluent API for defining environment variable schemas with automatic
|
|
53
|
+
* error context enrichment.
|
|
54
|
+
*
|
|
55
|
+
* @template T - The type of the configuration object (typically process.env)
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const config = new EnvironmentParser(process.env)
|
|
60
|
+
* .create((get) => ({
|
|
61
|
+
* port: get('PORT').string().transform(Number).default(3000),
|
|
62
|
+
* database: {
|
|
63
|
+
* url: get('DATABASE_URL').string().url()
|
|
64
|
+
* }
|
|
65
|
+
* }))
|
|
66
|
+
* .parse();
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
64
69
|
var EnvironmentParser = class {
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new EnvironmentParser instance.
|
|
72
|
+
*
|
|
73
|
+
* @param config - The configuration object to parse (typically process.env)
|
|
74
|
+
*/
|
|
65
75
|
constructor(config) {
|
|
66
76
|
this.config = config;
|
|
67
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages
|
|
80
|
+
* with environment variable context.
|
|
81
|
+
*
|
|
82
|
+
* @param schema - The Zod schema to wrap
|
|
83
|
+
* @param name - The environment variable name for error context
|
|
84
|
+
* @returns A wrapped Zod schema with enhanced error reporting
|
|
85
|
+
*/
|
|
68
86
|
wrapSchema = (schema, name) => {
|
|
69
87
|
return new Proxy(schema, { get: (target, prop) => {
|
|
70
88
|
if (prop === "parse") return () => {
|
|
@@ -108,6 +126,13 @@ var EnvironmentParser = class {
|
|
|
108
126
|
return originalProp;
|
|
109
127
|
} });
|
|
110
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* Creates a proxied version of the Zod object that wraps all schema creators
|
|
131
|
+
* to provide enhanced error messages with environment variable context.
|
|
132
|
+
*
|
|
133
|
+
* @param name - The environment variable name
|
|
134
|
+
* @returns A proxied Zod object with wrapped schema creators
|
|
135
|
+
*/
|
|
111
136
|
getZodGetter = (name) => {
|
|
112
137
|
return new Proxy({ ...zod_v4.z }, { get: (target, prop) => {
|
|
113
138
|
const value = target[prop];
|
|
@@ -127,10 +152,10 @@ var EnvironmentParser = class {
|
|
|
127
152
|
} });
|
|
128
153
|
};
|
|
129
154
|
/**
|
|
130
|
-
* Creates a new
|
|
155
|
+
* Creates a new ConfigParser object that can be used to parse the config object
|
|
131
156
|
*
|
|
132
157
|
* @param builder - A function that takes a getter function and returns a config object
|
|
133
|
-
* @returns A
|
|
158
|
+
* @returns A ConfigParser object that can be used to parse the config object
|
|
134
159
|
*/
|
|
135
160
|
create(builder) {
|
|
136
161
|
const config = builder(this.getZodGetter);
|
|
@@ -150,16 +175,4 @@ Object.defineProperty(exports, 'EnvironmentParser', {
|
|
|
150
175
|
get: function () {
|
|
151
176
|
return EnvironmentParser;
|
|
152
177
|
}
|
|
153
|
-
});
|
|
154
|
-
Object.defineProperty(exports, '__commonJS', {
|
|
155
|
-
enumerable: true,
|
|
156
|
-
get: function () {
|
|
157
|
-
return __commonJS;
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
Object.defineProperty(exports, '__toESM', {
|
|
161
|
-
enumerable: true,
|
|
162
|
-
get: function () {
|
|
163
|
-
return __toESM;
|
|
164
|
-
}
|
|
165
178
|
});
|
|
@@ -3,7 +3,18 @@ import set from "lodash.set";
|
|
|
3
3
|
import { z } from "zod/v4";
|
|
4
4
|
|
|
5
5
|
//#region src/EnvironmentParser.ts
|
|
6
|
+
/**
|
|
7
|
+
* Parses and validates configuration objects against Zod schemas.
|
|
8
|
+
* Handles nested configurations and aggregates validation errors.
|
|
9
|
+
*
|
|
10
|
+
* @template TResponse - The shape of the configuration object
|
|
11
|
+
*/
|
|
6
12
|
var ConfigParser = class {
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new ConfigParser instance.
|
|
15
|
+
*
|
|
16
|
+
* @param config - The configuration object to parse
|
|
17
|
+
*/
|
|
7
18
|
constructor(config) {
|
|
8
19
|
this.config = config;
|
|
9
20
|
}
|
|
@@ -35,10 +46,42 @@ var ConfigParser = class {
|
|
|
35
46
|
return parsedConfig;
|
|
36
47
|
}
|
|
37
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Parses environment variables with type-safe validation using Zod schemas.
|
|
51
|
+
* Provides a fluent API for defining environment variable schemas with automatic
|
|
52
|
+
* error context enrichment.
|
|
53
|
+
*
|
|
54
|
+
* @template T - The type of the configuration object (typically process.env)
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const config = new EnvironmentParser(process.env)
|
|
59
|
+
* .create((get) => ({
|
|
60
|
+
* port: get('PORT').string().transform(Number).default(3000),
|
|
61
|
+
* database: {
|
|
62
|
+
* url: get('DATABASE_URL').string().url()
|
|
63
|
+
* }
|
|
64
|
+
* }))
|
|
65
|
+
* .parse();
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
38
68
|
var EnvironmentParser = class {
|
|
69
|
+
/**
|
|
70
|
+
* Creates a new EnvironmentParser instance.
|
|
71
|
+
*
|
|
72
|
+
* @param config - The configuration object to parse (typically process.env)
|
|
73
|
+
*/
|
|
39
74
|
constructor(config) {
|
|
40
75
|
this.config = config;
|
|
41
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages
|
|
79
|
+
* with environment variable context.
|
|
80
|
+
*
|
|
81
|
+
* @param schema - The Zod schema to wrap
|
|
82
|
+
* @param name - The environment variable name for error context
|
|
83
|
+
* @returns A wrapped Zod schema with enhanced error reporting
|
|
84
|
+
*/
|
|
42
85
|
wrapSchema = (schema, name) => {
|
|
43
86
|
return new Proxy(schema, { get: (target, prop) => {
|
|
44
87
|
if (prop === "parse") return () => {
|
|
@@ -82,6 +125,13 @@ var EnvironmentParser = class {
|
|
|
82
125
|
return originalProp;
|
|
83
126
|
} });
|
|
84
127
|
};
|
|
128
|
+
/**
|
|
129
|
+
* Creates a proxied version of the Zod object that wraps all schema creators
|
|
130
|
+
* to provide enhanced error messages with environment variable context.
|
|
131
|
+
*
|
|
132
|
+
* @param name - The environment variable name
|
|
133
|
+
* @returns A proxied Zod object with wrapped schema creators
|
|
134
|
+
*/
|
|
85
135
|
getZodGetter = (name) => {
|
|
86
136
|
return new Proxy({ ...z }, { get: (target, prop) => {
|
|
87
137
|
const value = target[prop];
|
|
@@ -101,10 +151,10 @@ var EnvironmentParser = class {
|
|
|
101
151
|
} });
|
|
102
152
|
};
|
|
103
153
|
/**
|
|
104
|
-
* Creates a new
|
|
154
|
+
* Creates a new ConfigParser object that can be used to parse the config object
|
|
105
155
|
*
|
|
106
156
|
* @param builder - A function that takes a getter function and returns a config object
|
|
107
|
-
* @returns A
|
|
157
|
+
* @returns A ConfigParser object that can be used to parse the config object
|
|
108
158
|
*/
|
|
109
159
|
create(builder) {
|
|
110
160
|
const config = builder(this.getZodGetter);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_EnvironmentParser = require('./EnvironmentParser-
|
|
1
|
+
const require_EnvironmentParser = require('./EnvironmentParser-Bo2CCl_K.cjs');
|
|
2
2
|
|
|
3
3
|
exports.ConfigParser = require_EnvironmentParser.ConfigParser;
|
|
4
4
|
exports.EnvironmentParser = require_EnvironmentParser.EnvironmentParser;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const zod_v4 =
|
|
1
|
+
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_EnvironmentParser = require('../EnvironmentParser-Bo2CCl_K.cjs');
|
|
3
|
+
const zod_v4 = require_chunk.__toESM(require("zod/v4"));
|
|
4
|
+
const vitest = require_chunk.__toESM(require("vitest"));
|
|
4
5
|
|
|
5
6
|
//#region src/__tests__/ConfigParser.spec.ts
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
(0, vitest.describe)("ConfigParser", () => {
|
|
8
|
+
(0, vitest.describe)("Basic functionality", () => {
|
|
9
|
+
(0, vitest.it)("should parse simple Zod schemas", () => {
|
|
9
10
|
const config = {
|
|
10
11
|
name: zod_v4.z.string().default("Test"),
|
|
11
12
|
age: zod_v4.z.number().default(25),
|
|
@@ -13,25 +14,25 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
13
14
|
};
|
|
14
15
|
const parser = new require_EnvironmentParser.ConfigParser(config);
|
|
15
16
|
const result = parser.parse();
|
|
16
|
-
|
|
17
|
+
(0, vitest.expect)(result).toEqual({
|
|
17
18
|
name: "Test",
|
|
18
19
|
age: 25,
|
|
19
20
|
active: true
|
|
20
21
|
});
|
|
21
22
|
});
|
|
22
|
-
|
|
23
|
+
(0, vitest.it)("should handle optional values", () => {
|
|
23
24
|
const config = {
|
|
24
25
|
required: zod_v4.z.string().default("value"),
|
|
25
26
|
optional: zod_v4.z.string().optional()
|
|
26
27
|
};
|
|
27
28
|
const parser = new require_EnvironmentParser.ConfigParser(config);
|
|
28
29
|
const result = parser.parse();
|
|
29
|
-
|
|
30
|
+
(0, vitest.expect)(result).toEqual({
|
|
30
31
|
required: "value",
|
|
31
32
|
optional: void 0
|
|
32
33
|
});
|
|
33
34
|
});
|
|
34
|
-
|
|
35
|
+
(0, vitest.it)("should validate and use provided default values", () => {
|
|
35
36
|
const config = {
|
|
36
37
|
port: zod_v4.z.number().default(3e3),
|
|
37
38
|
host: zod_v4.z.string().default("localhost"),
|
|
@@ -39,15 +40,15 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
39
40
|
};
|
|
40
41
|
const parser = new require_EnvironmentParser.ConfigParser(config);
|
|
41
42
|
const result = parser.parse();
|
|
42
|
-
|
|
43
|
+
(0, vitest.expect)(result).toEqual({
|
|
43
44
|
port: 3e3,
|
|
44
45
|
host: "localhost",
|
|
45
46
|
debug: false
|
|
46
47
|
});
|
|
47
48
|
});
|
|
48
49
|
});
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
(0, vitest.describe)("Nested objects", () => {
|
|
51
|
+
(0, vitest.it)("should parse nested configuration objects", () => {
|
|
51
52
|
const config = {
|
|
52
53
|
database: {
|
|
53
54
|
host: zod_v4.z.string().default("localhost"),
|
|
@@ -61,7 +62,7 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
61
62
|
};
|
|
62
63
|
const parser = new require_EnvironmentParser.ConfigParser(config);
|
|
63
64
|
const result = parser.parse();
|
|
64
|
-
|
|
65
|
+
(0, vitest.expect)(result).toEqual({
|
|
65
66
|
database: {
|
|
66
67
|
host: "localhost",
|
|
67
68
|
port: 5432,
|
|
@@ -73,7 +74,7 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
73
74
|
}
|
|
74
75
|
});
|
|
75
76
|
});
|
|
76
|
-
|
|
77
|
+
(0, vitest.it)("should handle deeply nested objects", () => {
|
|
77
78
|
const config = { app: {
|
|
78
79
|
name: zod_v4.z.string().default("MyApp"),
|
|
79
80
|
version: zod_v4.z.string().default("1.0.0"),
|
|
@@ -90,7 +91,7 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
90
91
|
} };
|
|
91
92
|
const parser = new require_EnvironmentParser.ConfigParser(config);
|
|
92
93
|
const result = parser.parse();
|
|
93
|
-
|
|
94
|
+
(0, vitest.expect)(result).toEqual({ app: {
|
|
94
95
|
name: "MyApp",
|
|
95
96
|
version: "1.0.0",
|
|
96
97
|
features: {
|
|
@@ -105,7 +106,7 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
105
106
|
}
|
|
106
107
|
} });
|
|
107
108
|
});
|
|
108
|
-
|
|
109
|
+
(0, vitest.it)("should handle mixed nested and flat configuration", () => {
|
|
109
110
|
const config = {
|
|
110
111
|
appName: zod_v4.z.string().default("Test App"),
|
|
111
112
|
database: {
|
|
@@ -120,7 +121,7 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
120
121
|
};
|
|
121
122
|
const parser = new require_EnvironmentParser.ConfigParser(config);
|
|
122
123
|
const result = parser.parse();
|
|
123
|
-
|
|
124
|
+
(0, vitest.expect)(result).toEqual({
|
|
124
125
|
appName: "Test App",
|
|
125
126
|
database: {
|
|
126
127
|
url: "postgres://localhost/test",
|
|
@@ -134,16 +135,16 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
134
135
|
});
|
|
135
136
|
});
|
|
136
137
|
});
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
(0, vitest.describe)("Error handling", () => {
|
|
139
|
+
(0, vitest.it)("should throw ZodError for schemas without defaults", () => {
|
|
139
140
|
const config = {
|
|
140
141
|
required: zod_v4.z.string(),
|
|
141
142
|
alsoRequired: zod_v4.z.number()
|
|
142
143
|
};
|
|
143
144
|
const parser = new require_EnvironmentParser.ConfigParser(config);
|
|
144
|
-
|
|
145
|
+
(0, vitest.expect)(() => parser.parse()).toThrow(zod_v4.z.ZodError);
|
|
145
146
|
});
|
|
146
|
-
|
|
147
|
+
(0, vitest.it)("should collect multiple validation errors", () => {
|
|
147
148
|
const config = {
|
|
148
149
|
field1: zod_v4.z.string(),
|
|
149
150
|
field2: zod_v4.z.number(),
|
|
@@ -152,14 +153,14 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
152
153
|
const parser = new require_EnvironmentParser.ConfigParser(config);
|
|
153
154
|
try {
|
|
154
155
|
parser.parse();
|
|
155
|
-
|
|
156
|
+
(0, vitest.expect)(true).toBe(false);
|
|
156
157
|
} catch (error) {
|
|
157
|
-
|
|
158
|
+
(0, vitest.expect)(error).toBeInstanceOf(zod_v4.z.ZodError);
|
|
158
159
|
const zodError = error;
|
|
159
|
-
|
|
160
|
+
(0, vitest.expect)(zodError.issues).toHaveLength(3);
|
|
160
161
|
}
|
|
161
162
|
});
|
|
162
|
-
|
|
163
|
+
(0, vitest.it)("should include correct paths in nested validation errors", () => {
|
|
163
164
|
const config = {
|
|
164
165
|
database: {
|
|
165
166
|
host: zod_v4.z.string(),
|
|
@@ -170,31 +171,31 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
170
171
|
const parser = new require_EnvironmentParser.ConfigParser(config);
|
|
171
172
|
try {
|
|
172
173
|
parser.parse();
|
|
173
|
-
|
|
174
|
+
(0, vitest.expect)(true).toBe(false);
|
|
174
175
|
} catch (error) {
|
|
175
|
-
|
|
176
|
+
(0, vitest.expect)(error).toBeInstanceOf(zod_v4.z.ZodError);
|
|
176
177
|
const zodError = error;
|
|
177
178
|
const paths = zodError.issues.map((err) => err.path.join("."));
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
(0, vitest.expect)(paths).toContain("database.host");
|
|
180
|
+
(0, vitest.expect)(paths).toContain("database.port");
|
|
181
|
+
(0, vitest.expect)(paths).toContain("api.key");
|
|
181
182
|
}
|
|
182
183
|
});
|
|
183
|
-
|
|
184
|
+
(0, vitest.it)("should use default values that pass validation", () => {
|
|
184
185
|
const config = {
|
|
185
186
|
port: zod_v4.z.number().min(1e3).max(65535).default(3e3),
|
|
186
187
|
email: zod_v4.z.string().email().default("admin@example.com")
|
|
187
188
|
};
|
|
188
189
|
const parser = new require_EnvironmentParser.ConfigParser(config);
|
|
189
190
|
const result = parser.parse();
|
|
190
|
-
|
|
191
|
+
(0, vitest.expect)(result).toEqual({
|
|
191
192
|
port: 3e3,
|
|
192
193
|
email: "admin@example.com"
|
|
193
194
|
});
|
|
194
195
|
});
|
|
195
196
|
});
|
|
196
|
-
|
|
197
|
-
|
|
197
|
+
(0, vitest.describe)("Type safety", () => {
|
|
198
|
+
(0, vitest.it)("should infer correct types for simple configuration", () => {
|
|
198
199
|
const config = {
|
|
199
200
|
name: zod_v4.z.string().default("test"),
|
|
200
201
|
count: zod_v4.z.number().default(42),
|
|
@@ -204,10 +205,10 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
204
205
|
const result = parser.parse();
|
|
205
206
|
const _typeCheck = true;
|
|
206
207
|
const _typeCheck2 = true;
|
|
207
|
-
|
|
208
|
-
|
|
208
|
+
(0, vitest.expect)(_typeCheck).toBe(true);
|
|
209
|
+
(0, vitest.expect)(_typeCheck2).toBe(true);
|
|
209
210
|
});
|
|
210
|
-
|
|
211
|
+
(0, vitest.it)("should infer correct types for nested configuration", () => {
|
|
211
212
|
const config = {
|
|
212
213
|
database: {
|
|
213
214
|
host: zod_v4.z.string().default("localhost"),
|
|
@@ -219,10 +220,10 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
219
220
|
const result = parser.parse();
|
|
220
221
|
const _typeCheck = true;
|
|
221
222
|
const _typeCheck2 = true;
|
|
222
|
-
|
|
223
|
-
|
|
223
|
+
(0, vitest.expect)(_typeCheck).toBe(true);
|
|
224
|
+
(0, vitest.expect)(_typeCheck2).toBe(true);
|
|
224
225
|
});
|
|
225
|
-
|
|
226
|
+
(0, vitest.it)("should handle optional types correctly", () => {
|
|
226
227
|
const config = {
|
|
227
228
|
required: zod_v4.z.string().default("value"),
|
|
228
229
|
optional: zod_v4.z.string().optional(),
|
|
@@ -232,8 +233,8 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
232
233
|
const result = parser.parse();
|
|
233
234
|
});
|
|
234
235
|
});
|
|
235
|
-
|
|
236
|
-
|
|
236
|
+
(0, vitest.describe)("Complex schemas", () => {
|
|
237
|
+
(0, vitest.it)("should handle enum schemas", () => {
|
|
237
238
|
const config = {
|
|
238
239
|
environment: zod_v4.z.enum([
|
|
239
240
|
"development",
|
|
@@ -249,36 +250,36 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
249
250
|
};
|
|
250
251
|
const parser = new require_EnvironmentParser.ConfigParser(config);
|
|
251
252
|
const result = parser.parse();
|
|
252
|
-
|
|
253
|
+
(0, vitest.expect)(result).toEqual({
|
|
253
254
|
environment: "development",
|
|
254
255
|
logLevel: "info"
|
|
255
256
|
});
|
|
256
257
|
});
|
|
257
|
-
|
|
258
|
+
(0, vitest.it)("should handle union schemas", () => {
|
|
258
259
|
const config = {
|
|
259
260
|
port: zod_v4.z.union([zod_v4.z.string(), zod_v4.z.number()]).default(3e3),
|
|
260
261
|
timeout: zod_v4.z.union([zod_v4.z.number(), zod_v4.z.null()]).default(null)
|
|
261
262
|
};
|
|
262
263
|
const parser = new require_EnvironmentParser.ConfigParser(config);
|
|
263
264
|
const result = parser.parse();
|
|
264
|
-
|
|
265
|
+
(0, vitest.expect)(result).toEqual({
|
|
265
266
|
port: 3e3,
|
|
266
267
|
timeout: null
|
|
267
268
|
});
|
|
268
269
|
});
|
|
269
|
-
|
|
270
|
+
(0, vitest.it)("should handle array schemas", () => {
|
|
270
271
|
const config = {
|
|
271
272
|
tags: zod_v4.z.array(zod_v4.z.string()).default(["tag1", "tag2"]),
|
|
272
273
|
ports: zod_v4.z.array(zod_v4.z.number()).default([3e3, 3001])
|
|
273
274
|
};
|
|
274
275
|
const parser = new require_EnvironmentParser.ConfigParser(config);
|
|
275
276
|
const result = parser.parse();
|
|
276
|
-
|
|
277
|
+
(0, vitest.expect)(result).toEqual({
|
|
277
278
|
tags: ["tag1", "tag2"],
|
|
278
279
|
ports: [3e3, 3001]
|
|
279
280
|
});
|
|
280
281
|
});
|
|
281
|
-
|
|
282
|
+
(0, vitest.it)("should handle record schemas", () => {
|
|
282
283
|
const config = {
|
|
283
284
|
metadata: zod_v4.z.record(zod_v4.z.string(), zod_v4.z.string()).default({
|
|
284
285
|
key1: "value1",
|
|
@@ -291,7 +292,7 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
291
292
|
};
|
|
292
293
|
const parser = new require_EnvironmentParser.ConfigParser(config);
|
|
293
294
|
const result = parser.parse();
|
|
294
|
-
|
|
295
|
+
(0, vitest.expect)(result).toEqual({
|
|
295
296
|
metadata: {
|
|
296
297
|
key1: "value1",
|
|
297
298
|
key2: "value2"
|
|
@@ -302,7 +303,7 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
302
303
|
}
|
|
303
304
|
});
|
|
304
305
|
});
|
|
305
|
-
|
|
306
|
+
(0, vitest.it)("should handle transformed schemas", () => {
|
|
306
307
|
const config = {
|
|
307
308
|
portString: zod_v4.z.string().transform(Number).default(8080),
|
|
308
309
|
booleanString: zod_v4.z.string().transform((v) => v === "true").default(false),
|
|
@@ -310,7 +311,7 @@ require_vi_bdSIJ99Y.describe("ConfigParser", () => {
|
|
|
310
311
|
};
|
|
311
312
|
const parser = new require_EnvironmentParser.ConfigParser(config);
|
|
312
313
|
const result = parser.parse();
|
|
313
|
-
|
|
314
|
+
(0, vitest.expect)(result).toEqual({
|
|
314
315
|
portString: 8080,
|
|
315
316
|
booleanString: false,
|
|
316
317
|
jsonString: { key: "value" }
|