@geekmidas/envkit 0.0.6 → 0.0.8

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.
Files changed (47) hide show
  1. package/dist/{EnvironmentParser-C-arQEHQ.d.mts → EnvironmentParser-B8--woiB.d.cts} +40 -2
  2. package/dist/{EnvironmentParser-X4h2Vp4r.d.cts → EnvironmentParser-C_9v2BDw.d.mts} +40 -2
  3. package/dist/{EnvironmentParser-CQUOGqc0.mjs → EnvironmentParser-STvN_RCc.mjs} +46 -3
  4. package/dist/EnvironmentParser-STvN_RCc.mjs.map +1 -0
  5. package/dist/{EnvironmentParser-BDPDLv6i.cjs → EnvironmentParser-cnxuy7lw.cjs} +46 -3
  6. package/dist/EnvironmentParser-cnxuy7lw.cjs.map +1 -0
  7. package/dist/EnvironmentParser.cjs +1 -1
  8. package/dist/EnvironmentParser.d.cts +1 -1
  9. package/dist/EnvironmentParser.d.mts +1 -1
  10. package/dist/EnvironmentParser.mjs +1 -1
  11. package/dist/SnifferEnvironmentParser.cjs +140 -0
  12. package/dist/SnifferEnvironmentParser.cjs.map +1 -0
  13. package/dist/SnifferEnvironmentParser.d.cts +50 -0
  14. package/dist/SnifferEnvironmentParser.d.mts +50 -0
  15. package/dist/SnifferEnvironmentParser.mjs +139 -0
  16. package/dist/SnifferEnvironmentParser.mjs.map +1 -0
  17. package/dist/index.cjs +2 -1
  18. package/dist/index.d.cts +2 -2
  19. package/dist/index.d.mts +2 -2
  20. package/dist/index.mjs +2 -2
  21. package/dist/sst.cjs +131 -4
  22. package/dist/sst.cjs.map +1 -0
  23. package/dist/sst.d.cts +2 -1
  24. package/dist/sst.d.mts +2 -1
  25. package/dist/sst.mjs +128 -2
  26. package/dist/sst.mjs.map +1 -0
  27. package/package.json +9 -2
  28. package/src/EnvironmentParser.ts +51 -2
  29. package/src/SnifferEnvironmentParser.ts +207 -0
  30. package/src/__tests__/EnvironmentParser.spec.ts +147 -0
  31. package/src/__tests__/SnifferEnvironmentParser.spec.ts +332 -0
  32. package/src/__tests__/sst.spec.ts +9 -6
  33. package/src/index.ts +1 -1
  34. package/dist/__tests__/ConfigParser.spec.cjs +0 -323
  35. package/dist/__tests__/ConfigParser.spec.d.cts +0 -1
  36. package/dist/__tests__/ConfigParser.spec.d.mts +0 -1
  37. package/dist/__tests__/ConfigParser.spec.mjs +0 -322
  38. package/dist/__tests__/EnvironmentParser.spec.cjs +0 -422
  39. package/dist/__tests__/EnvironmentParser.spec.d.cts +0 -1
  40. package/dist/__tests__/EnvironmentParser.spec.d.mts +0 -1
  41. package/dist/__tests__/EnvironmentParser.spec.mjs +0 -421
  42. package/dist/__tests__/sst.spec.cjs +0 -305
  43. package/dist/__tests__/sst.spec.d.cts +0 -1
  44. package/dist/__tests__/sst.spec.d.mts +0 -1
  45. package/dist/__tests__/sst.spec.mjs +0 -304
  46. package/dist/sst-BSxwaAdz.cjs +0 -146
  47. package/dist/sst-CQhO0S6y.mjs +0 -128
@@ -0,0 +1,332 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { z } from 'zod/v4';
3
+ import { SnifferEnvironmentParser } from '../SnifferEnvironmentParser';
4
+
5
+ describe('SnifferEnvironmentParser', () => {
6
+ describe('Environment variable tracking', () => {
7
+ it('should track accessed environment variables', () => {
8
+ const sniffer = new SnifferEnvironmentParser();
9
+
10
+ sniffer.create((get) => ({
11
+ appName: get('APP_NAME').string(),
12
+ port: get('PORT').string().transform(Number),
13
+ }));
14
+
15
+ const envVars = sniffer.getEnvironmentVariables();
16
+ expect(envVars).toEqual(['APP_NAME', 'PORT']);
17
+ });
18
+
19
+ it('should track variables in nested configurations', () => {
20
+ const sniffer = new SnifferEnvironmentParser();
21
+
22
+ sniffer.create((get) => ({
23
+ database: {
24
+ host: get('DB_HOST').string(),
25
+ port: get('DB_PORT').string().transform(Number),
26
+ },
27
+ api: {
28
+ key: get('API_KEY').string(),
29
+ },
30
+ }));
31
+
32
+ const envVars = sniffer.getEnvironmentVariables();
33
+ expect(envVars).toEqual(['API_KEY', 'DB_HOST', 'DB_PORT']);
34
+ });
35
+
36
+ it('should return sorted environment variable names', () => {
37
+ const sniffer = new SnifferEnvironmentParser();
38
+
39
+ sniffer.create((get) => ({
40
+ zValue: get('Z_VALUE').string(),
41
+ aValue: get('A_VALUE').string(),
42
+ mValue: get('M_VALUE').string(),
43
+ }));
44
+
45
+ const envVars = sniffer.getEnvironmentVariables();
46
+ expect(envVars).toEqual(['A_VALUE', 'M_VALUE', 'Z_VALUE']);
47
+ });
48
+
49
+ it('should deduplicate environment variable names', () => {
50
+ const sniffer = new SnifferEnvironmentParser();
51
+
52
+ sniffer.create((get) => ({
53
+ value1: get('SHARED_VAR').string(),
54
+ value2: get('SHARED_VAR').string(),
55
+ value3: get('SHARED_VAR').string(),
56
+ }));
57
+
58
+ const envVars = sniffer.getEnvironmentVariables();
59
+ expect(envVars).toEqual(['SHARED_VAR']);
60
+ });
61
+
62
+ it('should track variables accessed through coerce', () => {
63
+ const sniffer = new SnifferEnvironmentParser();
64
+
65
+ sniffer.create((get) => ({
66
+ workers: get('NUM_WORKERS').coerce.number(),
67
+ timeout: get('TIMEOUT').coerce.number(),
68
+ }));
69
+
70
+ const envVars = sniffer.getEnvironmentVariables();
71
+ expect(envVars).toEqual(['NUM_WORKERS', 'TIMEOUT']);
72
+ });
73
+ });
74
+
75
+ describe('Mock value parsing', () => {
76
+ it('should never throw when parsing - returns mock values', () => {
77
+ const sniffer = new SnifferEnvironmentParser();
78
+
79
+ const config = sniffer.create((get) => ({
80
+ required: get('REQUIRED_VAR').string(),
81
+ alsoRequired: get('ALSO_REQUIRED').string(),
82
+ }));
83
+
84
+ // Should not throw even though env vars are not set
85
+ expect(() => config.parse()).not.toThrow();
86
+ });
87
+
88
+ it('should return empty string for string schemas', () => {
89
+ const sniffer = new SnifferEnvironmentParser();
90
+
91
+ const config = sniffer
92
+ .create((get) => ({
93
+ value: get('STRING_VAR').string(),
94
+ }))
95
+ .parse();
96
+
97
+ expect(config.value).toBe('');
98
+ });
99
+
100
+ it('should return 0 for number schemas', () => {
101
+ const sniffer = new SnifferEnvironmentParser();
102
+
103
+ const config = sniffer
104
+ .create((get) => ({
105
+ value: get('NUMBER_VAR').coerce.number(),
106
+ }))
107
+ .parse();
108
+
109
+ expect(config.value).toBe(0);
110
+ });
111
+
112
+ it('should return false for boolean schemas', () => {
113
+ const sniffer = new SnifferEnvironmentParser();
114
+
115
+ const config = sniffer
116
+ .create((get) => ({
117
+ value: get('BOOL_VAR').coerce.boolean(),
118
+ }))
119
+ .parse();
120
+
121
+ expect(config.value).toBe(false);
122
+ });
123
+
124
+ it('should return empty array for array schemas', () => {
125
+ const sniffer = new SnifferEnvironmentParser();
126
+
127
+ const config = sniffer
128
+ .create((get) => ({
129
+ value: get('ARRAY_VAR').array(z.string()),
130
+ }))
131
+ .parse();
132
+
133
+ expect(config.value).toEqual([]);
134
+ });
135
+
136
+ it('should return undefined for optional schemas', () => {
137
+ const sniffer = new SnifferEnvironmentParser();
138
+
139
+ const config = sniffer
140
+ .create((get) => ({
141
+ value: get('OPTIONAL_VAR').string().optional(),
142
+ }))
143
+ .parse();
144
+
145
+ expect(config.value).toBeUndefined();
146
+ });
147
+
148
+ it('should handle nested configurations', () => {
149
+ const sniffer = new SnifferEnvironmentParser();
150
+
151
+ const config = sniffer
152
+ .create((get) => ({
153
+ database: {
154
+ host: get('DB_HOST').string(),
155
+ port: get('DB_PORT').coerce.number(),
156
+ },
157
+ cache: {
158
+ enabled: get('CACHE_ENABLED').coerce.boolean(),
159
+ },
160
+ }))
161
+ .parse();
162
+
163
+ expect(config).toEqual({
164
+ database: {
165
+ host: '',
166
+ port: 0,
167
+ },
168
+ cache: {
169
+ enabled: false,
170
+ },
171
+ });
172
+ });
173
+
174
+ it('should track variables with transforms', () => {
175
+ const sniffer = new SnifferEnvironmentParser();
176
+
177
+ sniffer.create((get) => ({
178
+ origins: get('ALLOWED_ORIGINS')
179
+ .string()
180
+ .transform((v) => v.split(',')),
181
+ port: get('PORT').string().transform(Number),
182
+ }));
183
+
184
+ // Should track the env vars even with transforms
185
+ expect(sniffer.getEnvironmentVariables()).toEqual([
186
+ 'ALLOWED_ORIGINS',
187
+ 'PORT',
188
+ ]);
189
+ });
190
+ });
191
+
192
+ describe('Service registration simulation', () => {
193
+ it('should allow simulated service registration to succeed', () => {
194
+ const sniffer = new SnifferEnvironmentParser();
195
+
196
+ // Simulate a service that would normally fail without env vars
197
+ const mockService = {
198
+ serviceName: 'database' as const,
199
+ register(envParser: SnifferEnvironmentParser) {
200
+ const config = envParser
201
+ .create((get) => ({
202
+ url: get('DATABASE_URL').string(),
203
+ poolSize: get('DB_POOL_SIZE').coerce.number(),
204
+ }))
205
+ .parse();
206
+
207
+ // Service uses parsed values to create connection
208
+ return { url: config.url, poolSize: config.poolSize };
209
+ },
210
+ };
211
+
212
+ // Should not throw
213
+ expect(() => mockService.register(sniffer)).not.toThrow();
214
+
215
+ // Should have tracked the env vars
216
+ expect(sniffer.getEnvironmentVariables()).toEqual([
217
+ 'DATABASE_URL',
218
+ 'DB_POOL_SIZE',
219
+ ]);
220
+ });
221
+
222
+ it('should work with multiple services', () => {
223
+ const sniffer = new SnifferEnvironmentParser();
224
+
225
+ const databaseService = {
226
+ serviceName: 'db' as const,
227
+ register(envParser: SnifferEnvironmentParser) {
228
+ return envParser
229
+ .create((get) => ({
230
+ host: get('DB_HOST').string(),
231
+ port: get('DB_PORT').coerce.number(),
232
+ }))
233
+ .parse();
234
+ },
235
+ };
236
+
237
+ const cacheService = {
238
+ serviceName: 'cache' as const,
239
+ register(envParser: SnifferEnvironmentParser) {
240
+ return envParser
241
+ .create((get) => ({
242
+ url: get('REDIS_URL').string(),
243
+ ttl: get('CACHE_TTL').coerce.number(),
244
+ }))
245
+ .parse();
246
+ },
247
+ };
248
+
249
+ // Register both services
250
+ databaseService.register(sniffer);
251
+ cacheService.register(sniffer);
252
+
253
+ // Should have tracked all env vars from both services
254
+ expect(sniffer.getEnvironmentVariables()).toEqual([
255
+ 'CACHE_TTL',
256
+ 'DB_HOST',
257
+ 'DB_PORT',
258
+ 'REDIS_URL',
259
+ ]);
260
+ });
261
+
262
+ it('should handle async service registration', async () => {
263
+ const sniffer = new SnifferEnvironmentParser();
264
+
265
+ const asyncService = {
266
+ serviceName: 'async' as const,
267
+ async register(envParser: SnifferEnvironmentParser) {
268
+ const config = envParser
269
+ .create((get) => ({
270
+ apiKey: get('API_KEY').string(),
271
+ endpoint: get('API_ENDPOINT').string(),
272
+ }))
273
+ .parse();
274
+
275
+ // Simulate async initialization
276
+ await Promise.resolve();
277
+ return config;
278
+ },
279
+ };
280
+
281
+ await expect(asyncService.register(sniffer)).resolves.not.toThrow();
282
+ expect(sniffer.getEnvironmentVariables()).toEqual([
283
+ 'API_ENDPOINT',
284
+ 'API_KEY',
285
+ ]);
286
+ });
287
+ });
288
+
289
+ describe('Edge cases', () => {
290
+ it('should return empty array when no variables accessed', () => {
291
+ const sniffer = new SnifferEnvironmentParser();
292
+
293
+ sniffer.create(() => ({}));
294
+
295
+ expect(sniffer.getEnvironmentVariables()).toEqual([]);
296
+ });
297
+
298
+ it('should handle deeply nested objects', () => {
299
+ const sniffer = new SnifferEnvironmentParser();
300
+
301
+ sniffer.create((get) => ({
302
+ level1: {
303
+ level2: {
304
+ level3: {
305
+ value: get('DEEP_VALUE').string(),
306
+ },
307
+ },
308
+ },
309
+ }));
310
+
311
+ expect(sniffer.getEnvironmentVariables()).toEqual(['DEEP_VALUE']);
312
+ });
313
+
314
+ it('should handle multiple create calls', () => {
315
+ const sniffer = new SnifferEnvironmentParser();
316
+
317
+ sniffer.create((get) => ({
318
+ first: get('FIRST_VAR').string(),
319
+ }));
320
+
321
+ sniffer.create((get) => ({
322
+ second: get('SECOND_VAR').string(),
323
+ }));
324
+
325
+ // Should accumulate vars from both create calls
326
+ expect(sniffer.getEnvironmentVariables()).toEqual([
327
+ 'FIRST_VAR',
328
+ 'SECOND_VAR',
329
+ ]);
330
+ });
331
+ });
332
+ });
@@ -306,7 +306,9 @@ describe('sst', () => {
306
306
 
307
307
  describe('edge cases', () => {
308
308
  it('should warn for unknown resource types', () => {
309
- const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
309
+ const consoleWarnSpy = vi
310
+ .spyOn(console, 'warn')
311
+ .mockImplementation(() => {});
310
312
 
311
313
  const unknownResource = {
312
314
  type: 'unknown.resource.Type' as any,
@@ -320,7 +322,7 @@ describe('sst', () => {
320
322
  expect(result).toEqual({});
321
323
  expect(consoleWarnSpy).toHaveBeenCalledWith(
322
324
  'No processor found for resource type: ',
323
- { value: unknownResource }
325
+ { value: unknownResource },
324
326
  );
325
327
 
326
328
  consoleWarnSpy.mockRestore();
@@ -374,7 +376,8 @@ describe('sst', () => {
374
376
  });
375
377
 
376
378
  expect(result).toEqual({
377
- THIS_IS_A_VERY_LONG_KEY_NAME_THAT_SHOULD_BE_CONVERTED_PROPERLY: 'value',
379
+ THIS_IS_A_VERY_LONG_KEY_NAME_THAT_SHOULD_BE_CONVERTED_PROPERLY:
380
+ 'value',
378
381
  });
379
382
  });
380
383
 
@@ -385,8 +388,8 @@ describe('sst', () => {
385
388
  };
386
389
 
387
390
  const result = normalizeResourceEnv({
388
- 's3_bucket_v2_1': bucket,
389
- 'bucket_123_456': bucket,
391
+ s3_bucket_v2_1: bucket,
392
+ bucket_123_456: bucket,
390
393
  });
391
394
 
392
395
  expect(result).toEqual({
@@ -412,4 +415,4 @@ describe('sst', () => {
412
415
  expect(ResourceType.SSTBucket).toBe('sst:aws:Bucket');
413
416
  });
414
417
  });
415
- });
418
+ });
package/src/index.ts CHANGED
@@ -1 +1 @@
1
- export { EnvironmentParser } from './EnvironmentParser';
1
+ export { EnvironmentParser, ConfigParser } from './EnvironmentParser';
@@ -1,323 +0,0 @@
1
- const require_chunk = require('../chunk-CUT6urMc.cjs');
2
- const require_EnvironmentParser = require('../EnvironmentParser-BDPDLv6i.cjs');
3
- const zod_v4 = require_chunk.__toESM(require("zod/v4"));
4
- const vitest = require_chunk.__toESM(require("vitest"));
5
-
6
- //#region src/__tests__/ConfigParser.spec.ts
7
- (0, vitest.describe)("ConfigParser", () => {
8
- (0, vitest.describe)("Basic functionality", () => {
9
- (0, vitest.it)("should parse simple Zod schemas", () => {
10
- const config = {
11
- name: zod_v4.z.string().default("Test"),
12
- age: zod_v4.z.number().default(25),
13
- active: zod_v4.z.boolean().default(true)
14
- };
15
- const parser = new require_EnvironmentParser.ConfigParser(config);
16
- const result = parser.parse();
17
- (0, vitest.expect)(result).toEqual({
18
- name: "Test",
19
- age: 25,
20
- active: true
21
- });
22
- });
23
- (0, vitest.it)("should handle optional values", () => {
24
- const config = {
25
- required: zod_v4.z.string().default("value"),
26
- optional: zod_v4.z.string().optional()
27
- };
28
- const parser = new require_EnvironmentParser.ConfigParser(config);
29
- const result = parser.parse();
30
- (0, vitest.expect)(result).toEqual({
31
- required: "value",
32
- optional: void 0
33
- });
34
- });
35
- (0, vitest.it)("should validate and use provided default values", () => {
36
- const config = {
37
- port: zod_v4.z.number().default(3e3),
38
- host: zod_v4.z.string().default("localhost"),
39
- debug: zod_v4.z.boolean().default(false)
40
- };
41
- const parser = new require_EnvironmentParser.ConfigParser(config);
42
- const result = parser.parse();
43
- (0, vitest.expect)(result).toEqual({
44
- port: 3e3,
45
- host: "localhost",
46
- debug: false
47
- });
48
- });
49
- });
50
- (0, vitest.describe)("Nested objects", () => {
51
- (0, vitest.it)("should parse nested configuration objects", () => {
52
- const config = {
53
- database: {
54
- host: zod_v4.z.string().default("localhost"),
55
- port: zod_v4.z.number().default(5432),
56
- ssl: zod_v4.z.boolean().default(false)
57
- },
58
- api: {
59
- key: zod_v4.z.string().default("default-key"),
60
- timeout: zod_v4.z.number().default(5e3)
61
- }
62
- };
63
- const parser = new require_EnvironmentParser.ConfigParser(config);
64
- const result = parser.parse();
65
- (0, vitest.expect)(result).toEqual({
66
- database: {
67
- host: "localhost",
68
- port: 5432,
69
- ssl: false
70
- },
71
- api: {
72
- key: "default-key",
73
- timeout: 5e3
74
- }
75
- });
76
- });
77
- (0, vitest.it)("should handle deeply nested objects", () => {
78
- const config = { app: {
79
- name: zod_v4.z.string().default("MyApp"),
80
- version: zod_v4.z.string().default("1.0.0"),
81
- features: {
82
- auth: {
83
- enabled: zod_v4.z.boolean().default(true),
84
- provider: zod_v4.z.string().default("local")
85
- },
86
- cache: {
87
- enabled: zod_v4.z.boolean().default(false),
88
- ttl: zod_v4.z.number().default(3600)
89
- }
90
- }
91
- } };
92
- const parser = new require_EnvironmentParser.ConfigParser(config);
93
- const result = parser.parse();
94
- (0, vitest.expect)(result).toEqual({ app: {
95
- name: "MyApp",
96
- version: "1.0.0",
97
- features: {
98
- auth: {
99
- enabled: true,
100
- provider: "local"
101
- },
102
- cache: {
103
- enabled: false,
104
- ttl: 3600
105
- }
106
- }
107
- } });
108
- });
109
- (0, vitest.it)("should handle mixed nested and flat configuration", () => {
110
- const config = {
111
- appName: zod_v4.z.string().default("Test App"),
112
- database: {
113
- url: zod_v4.z.string().default("postgres://localhost/test"),
114
- poolSize: zod_v4.z.number().default(10)
115
- },
116
- port: zod_v4.z.number().default(3e3),
117
- features: { logging: {
118
- level: zod_v4.z.string().default("info"),
119
- pretty: zod_v4.z.boolean().default(true)
120
- } }
121
- };
122
- const parser = new require_EnvironmentParser.ConfigParser(config);
123
- const result = parser.parse();
124
- (0, vitest.expect)(result).toEqual({
125
- appName: "Test App",
126
- database: {
127
- url: "postgres://localhost/test",
128
- poolSize: 10
129
- },
130
- port: 3e3,
131
- features: { logging: {
132
- level: "info",
133
- pretty: true
134
- } }
135
- });
136
- });
137
- });
138
- (0, vitest.describe)("Error handling", () => {
139
- (0, vitest.it)("should throw ZodError for schemas without defaults", () => {
140
- const config = {
141
- required: zod_v4.z.string(),
142
- alsoRequired: zod_v4.z.number()
143
- };
144
- const parser = new require_EnvironmentParser.ConfigParser(config);
145
- (0, vitest.expect)(() => parser.parse()).toThrow(zod_v4.z.ZodError);
146
- });
147
- (0, vitest.it)("should collect multiple validation errors", () => {
148
- const config = {
149
- field1: zod_v4.z.string(),
150
- field2: zod_v4.z.number(),
151
- field3: zod_v4.z.boolean()
152
- };
153
- const parser = new require_EnvironmentParser.ConfigParser(config);
154
- try {
155
- parser.parse();
156
- (0, vitest.expect)(true).toBe(false);
157
- } catch (error) {
158
- (0, vitest.expect)(error).toBeInstanceOf(zod_v4.z.ZodError);
159
- const zodError = error;
160
- (0, vitest.expect)(zodError.issues).toHaveLength(3);
161
- }
162
- });
163
- (0, vitest.it)("should include correct paths in nested validation errors", () => {
164
- const config = {
165
- database: {
166
- host: zod_v4.z.string(),
167
- port: zod_v4.z.number()
168
- },
169
- api: { key: zod_v4.z.string() }
170
- };
171
- const parser = new require_EnvironmentParser.ConfigParser(config);
172
- try {
173
- parser.parse();
174
- (0, vitest.expect)(true).toBe(false);
175
- } catch (error) {
176
- (0, vitest.expect)(error).toBeInstanceOf(zod_v4.z.ZodError);
177
- const zodError = error;
178
- const paths = zodError.issues.map((err) => err.path.join("."));
179
- (0, vitest.expect)(paths).toContain("database.host");
180
- (0, vitest.expect)(paths).toContain("database.port");
181
- (0, vitest.expect)(paths).toContain("api.key");
182
- }
183
- });
184
- (0, vitest.it)("should use default values that pass validation", () => {
185
- const config = {
186
- port: zod_v4.z.number().min(1e3).max(65535).default(3e3),
187
- email: zod_v4.z.string().email().default("admin@example.com")
188
- };
189
- const parser = new require_EnvironmentParser.ConfigParser(config);
190
- const result = parser.parse();
191
- (0, vitest.expect)(result).toEqual({
192
- port: 3e3,
193
- email: "admin@example.com"
194
- });
195
- });
196
- });
197
- (0, vitest.describe)("Type safety", () => {
198
- (0, vitest.it)("should infer correct types for simple configuration", () => {
199
- const config = {
200
- name: zod_v4.z.string().default("test"),
201
- count: zod_v4.z.number().default(42),
202
- enabled: zod_v4.z.boolean().default(true)
203
- };
204
- const parser = new require_EnvironmentParser.ConfigParser(config);
205
- const result = parser.parse();
206
- const _typeCheck = true;
207
- const _typeCheck2 = true;
208
- (0, vitest.expect)(_typeCheck).toBe(true);
209
- (0, vitest.expect)(_typeCheck2).toBe(true);
210
- });
211
- (0, vitest.it)("should infer correct types for nested configuration", () => {
212
- const config = {
213
- database: {
214
- host: zod_v4.z.string().default("localhost"),
215
- port: zod_v4.z.number().default(5432)
216
- },
217
- features: { auth: zod_v4.z.boolean().default(true) }
218
- };
219
- const parser = new require_EnvironmentParser.ConfigParser(config);
220
- const result = parser.parse();
221
- const _typeCheck = true;
222
- const _typeCheck2 = true;
223
- (0, vitest.expect)(_typeCheck).toBe(true);
224
- (0, vitest.expect)(_typeCheck2).toBe(true);
225
- });
226
- (0, vitest.it)("should handle optional types correctly", () => {
227
- const config = {
228
- required: zod_v4.z.string().default("value"),
229
- optional: zod_v4.z.string().optional(),
230
- nullable: zod_v4.z.string().nullable().default(null)
231
- };
232
- const parser = new require_EnvironmentParser.ConfigParser(config);
233
- const result = parser.parse();
234
- });
235
- });
236
- (0, vitest.describe)("Complex schemas", () => {
237
- (0, vitest.it)("should handle enum schemas", () => {
238
- const config = {
239
- environment: zod_v4.z.enum([
240
- "development",
241
- "staging",
242
- "production"
243
- ]).default("development"),
244
- logLevel: zod_v4.z.enum([
245
- "debug",
246
- "info",
247
- "warn",
248
- "error"
249
- ]).default("info")
250
- };
251
- const parser = new require_EnvironmentParser.ConfigParser(config);
252
- const result = parser.parse();
253
- (0, vitest.expect)(result).toEqual({
254
- environment: "development",
255
- logLevel: "info"
256
- });
257
- });
258
- (0, vitest.it)("should handle union schemas", () => {
259
- const config = {
260
- port: zod_v4.z.union([zod_v4.z.string(), zod_v4.z.number()]).default(3e3),
261
- timeout: zod_v4.z.union([zod_v4.z.number(), zod_v4.z.null()]).default(null)
262
- };
263
- const parser = new require_EnvironmentParser.ConfigParser(config);
264
- const result = parser.parse();
265
- (0, vitest.expect)(result).toEqual({
266
- port: 3e3,
267
- timeout: null
268
- });
269
- });
270
- (0, vitest.it)("should handle array schemas", () => {
271
- const config = {
272
- tags: zod_v4.z.array(zod_v4.z.string()).default(["tag1", "tag2"]),
273
- ports: zod_v4.z.array(zod_v4.z.number()).default([3e3, 3001])
274
- };
275
- const parser = new require_EnvironmentParser.ConfigParser(config);
276
- const result = parser.parse();
277
- (0, vitest.expect)(result).toEqual({
278
- tags: ["tag1", "tag2"],
279
- ports: [3e3, 3001]
280
- });
281
- });
282
- (0, vitest.it)("should handle record schemas", () => {
283
- const config = {
284
- metadata: zod_v4.z.record(zod_v4.z.string(), zod_v4.z.string()).default({
285
- key1: "value1",
286
- key2: "value2"
287
- }),
288
- counters: zod_v4.z.record(zod_v4.z.string(), zod_v4.z.number()).default({
289
- count1: 1,
290
- count2: 2
291
- })
292
- };
293
- const parser = new require_EnvironmentParser.ConfigParser(config);
294
- const result = parser.parse();
295
- (0, vitest.expect)(result).toEqual({
296
- metadata: {
297
- key1: "value1",
298
- key2: "value2"
299
- },
300
- counters: {
301
- count1: 1,
302
- count2: 2
303
- }
304
- });
305
- });
306
- (0, vitest.it)("should handle transformed schemas", () => {
307
- const config = {
308
- portString: zod_v4.z.string().transform(Number).default(8080),
309
- booleanString: zod_v4.z.string().transform((v) => v === "true").default(false),
310
- jsonString: zod_v4.z.string().transform((v) => JSON.parse(v)).default({ key: "value" })
311
- };
312
- const parser = new require_EnvironmentParser.ConfigParser(config);
313
- const result = parser.parse();
314
- (0, vitest.expect)(result).toEqual({
315
- portString: 8080,
316
- booleanString: false,
317
- jsonString: { key: "value" }
318
- });
319
- });
320
- });
321
- });
322
-
323
- //#endregion
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- export { };