@geekmidas/envkit 0.0.7 → 0.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 +228 -174
- package/dist/EnvironmentBuilder-DHfDXJUm.d.mts +131 -0
- package/dist/EnvironmentBuilder-DfmYRBm-.mjs +83 -0
- package/dist/EnvironmentBuilder-DfmYRBm-.mjs.map +1 -0
- package/dist/EnvironmentBuilder-W2wku49g.cjs +95 -0
- package/dist/EnvironmentBuilder-W2wku49g.cjs.map +1 -0
- package/dist/EnvironmentBuilder-Xuf2Dd9u.d.cts +131 -0
- package/dist/EnvironmentBuilder.cjs +4 -0
- package/dist/EnvironmentBuilder.d.cts +2 -0
- package/dist/EnvironmentBuilder.d.mts +2 -0
- package/dist/EnvironmentBuilder.mjs +3 -0
- package/dist/{EnvironmentParser-BDPDLv6i.cjs → EnvironmentParser-Bt246UeP.cjs} +46 -3
- package/dist/EnvironmentParser-Bt246UeP.cjs.map +1 -0
- package/dist/{EnvironmentParser-C-arQEHQ.d.mts → EnvironmentParser-CVWU1ooT.d.mts} +40 -2
- package/dist/{EnvironmentParser-CQUOGqc0.mjs → EnvironmentParser-c06agx31.mjs} +46 -3
- package/dist/EnvironmentParser-c06agx31.mjs.map +1 -0
- package/dist/{EnvironmentParser-X4h2Vp4r.d.cts → EnvironmentParser-tV-JjCg7.d.cts} +40 -2
- package/dist/EnvironmentParser.cjs +1 -1
- package/dist/EnvironmentParser.d.cts +1 -1
- package/dist/EnvironmentParser.d.mts +1 -1
- package/dist/EnvironmentParser.mjs +1 -1
- package/dist/SnifferEnvironmentParser.cjs +140 -0
- package/dist/SnifferEnvironmentParser.cjs.map +1 -0
- package/dist/SnifferEnvironmentParser.d.cts +50 -0
- package/dist/SnifferEnvironmentParser.d.mts +50 -0
- package/dist/SnifferEnvironmentParser.mjs +139 -0
- package/dist/SnifferEnvironmentParser.mjs.map +1 -0
- package/dist/SstEnvironmentBuilder-BuFw1hCe.cjs +125 -0
- package/dist/SstEnvironmentBuilder-BuFw1hCe.cjs.map +1 -0
- package/dist/SstEnvironmentBuilder-CjURMGjW.d.mts +177 -0
- package/dist/SstEnvironmentBuilder-D4oSo_KX.d.cts +177 -0
- package/dist/SstEnvironmentBuilder-DEa3lTUB.mjs +108 -0
- package/dist/SstEnvironmentBuilder-DEa3lTUB.mjs.map +1 -0
- package/dist/SstEnvironmentBuilder.cjs +7 -0
- package/dist/SstEnvironmentBuilder.d.cts +3 -0
- package/dist/SstEnvironmentBuilder.d.mts +3 -0
- package/dist/SstEnvironmentBuilder.mjs +4 -0
- package/dist/index.cjs +6 -2
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +3 -2
- package/dist/sst.cjs +30 -4
- package/dist/sst.cjs.map +1 -0
- package/dist/sst.d.cts +15 -93
- package/dist/sst.d.mts +15 -93
- package/dist/sst.mjs +26 -2
- package/dist/sst.mjs.map +1 -0
- package/docs/async-secrets-design.md +355 -0
- package/package.json +11 -2
- package/src/EnvironmentBuilder.ts +196 -0
- package/src/EnvironmentParser.ts +51 -2
- package/src/SnifferEnvironmentParser.ts +209 -0
- package/src/SstEnvironmentBuilder.ts +298 -0
- package/src/__tests__/EnvironmentBuilder.spec.ts +274 -0
- package/src/__tests__/EnvironmentParser.spec.ts +147 -0
- package/src/__tests__/SnifferEnvironmentParser.spec.ts +332 -0
- package/src/__tests__/SstEnvironmentBuilder.spec.ts +373 -0
- package/src/__tests__/sst.spec.ts +1 -1
- package/src/index.ts +13 -1
- package/src/sst.ts +45 -207
- package/dist/__tests__/ConfigParser.spec.cjs +0 -323
- package/dist/__tests__/ConfigParser.spec.d.cts +0 -1
- package/dist/__tests__/ConfigParser.spec.d.mts +0 -1
- package/dist/__tests__/ConfigParser.spec.mjs +0 -322
- package/dist/__tests__/EnvironmentParser.spec.cjs +0 -422
- package/dist/__tests__/EnvironmentParser.spec.d.cts +0 -1
- package/dist/__tests__/EnvironmentParser.spec.d.mts +0 -1
- package/dist/__tests__/EnvironmentParser.spec.mjs +0 -421
- package/dist/__tests__/sst.spec.cjs +0 -305
- package/dist/__tests__/sst.spec.d.cts +0 -1
- package/dist/__tests__/sst.spec.d.mts +0 -1
- package/dist/__tests__/sst.spec.mjs +0 -304
- package/dist/sst-BSxwaAdz.cjs +0 -146
- package/dist/sst-CQhO0S6y.mjs +0 -128
package/src/index.ts
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
-
export { EnvironmentParser } from './EnvironmentParser';
|
|
1
|
+
export { EnvironmentParser, ConfigParser } from './EnvironmentParser';
|
|
2
|
+
export {
|
|
3
|
+
EnvironmentBuilder,
|
|
4
|
+
environmentCase,
|
|
5
|
+
type EnvRecord,
|
|
6
|
+
type EnvValue,
|
|
7
|
+
type EnvironmentResolver,
|
|
8
|
+
type Resolvers,
|
|
9
|
+
type EnvironmentBuilderOptions,
|
|
10
|
+
type InputValue,
|
|
11
|
+
type TypedInputValue,
|
|
12
|
+
type TypedResolvers,
|
|
13
|
+
} from './EnvironmentBuilder';
|
package/src/sst.ts
CHANGED
|
@@ -1,114 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
SSTApiGatewayV2 = 'sst:aws:ApiGatewayV2',
|
|
36
|
-
SSTPostgres = 'sst:aws:Postgres',
|
|
37
|
-
SSTBucket = 'sst:aws:Bucket',
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Processes a Secret resource into environment variables.
|
|
42
|
-
*
|
|
43
|
-
* @param name - The resource name
|
|
44
|
-
* @param value - The Secret resource
|
|
45
|
-
* @returns Object with environment variable mappings
|
|
46
|
-
*/
|
|
47
|
-
const secret = (name: string, value: Secret) => ({
|
|
48
|
-
[environmentCase(name)]: value.value,
|
|
49
|
-
});
|
|
50
|
-
/**
|
|
51
|
-
* Processes a Postgres database resource into environment variables.
|
|
52
|
-
* Creates multiple environment variables for database connection details.
|
|
53
|
-
*
|
|
54
|
-
* @param key - The resource key
|
|
55
|
-
* @param value - The Postgres resource
|
|
56
|
-
* @returns Object with database connection environment variables
|
|
57
|
-
*/
|
|
58
|
-
const postgres = (key: string, value: Postgres) => {
|
|
59
|
-
const prefix = `${environmentCase(key)}`;
|
|
60
|
-
return {
|
|
61
|
-
[`${prefix}_NAME`]: value.database,
|
|
62
|
-
[`${prefix}_HOST`]: value.host,
|
|
63
|
-
[`${prefix}_PASSWORD`]: value.password,
|
|
64
|
-
[`${prefix}_PORT`]: value.port,
|
|
65
|
-
[`${prefix}_USERNAME`]: value.username,
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Processes a Bucket resource into environment variables.
|
|
71
|
-
*
|
|
72
|
-
* @param name - The resource name
|
|
73
|
-
* @param value - The Bucket resource
|
|
74
|
-
* @returns Object with bucket name environment variable
|
|
75
|
-
*/
|
|
76
|
-
const bucket = (name: string, value: Bucket) => {
|
|
77
|
-
const prefix = `${environmentCase(name)}`;
|
|
78
|
-
return {
|
|
79
|
-
[`${prefix}_NAME`]: value.name,
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* No-operation processor for resources that don't require environment variables.
|
|
1
|
+
// Re-export everything from SstEnvironmentBuilder
|
|
2
|
+
export {
|
|
3
|
+
SstEnvironmentBuilder,
|
|
4
|
+
sstResolvers,
|
|
5
|
+
ResourceType,
|
|
6
|
+
type ApiGatewayV2,
|
|
7
|
+
type Postgres,
|
|
8
|
+
type Function,
|
|
9
|
+
type Bucket,
|
|
10
|
+
type Vpc,
|
|
11
|
+
type Secret,
|
|
12
|
+
type SnsTopic,
|
|
13
|
+
type SstResource,
|
|
14
|
+
type ResourceProcessor,
|
|
15
|
+
} from './SstEnvironmentBuilder';
|
|
16
|
+
|
|
17
|
+
// Re-export environmentCase from EnvironmentBuilder
|
|
18
|
+
export { environmentCase } from './EnvironmentBuilder';
|
|
19
|
+
|
|
20
|
+
// Re-export types from EnvironmentBuilder
|
|
21
|
+
export type {
|
|
22
|
+
EnvRecord,
|
|
23
|
+
EnvValue,
|
|
24
|
+
EnvironmentBuilderOptions,
|
|
25
|
+
} from './EnvironmentBuilder';
|
|
26
|
+
|
|
27
|
+
// Import for deprecated function
|
|
28
|
+
import {
|
|
29
|
+
SstEnvironmentBuilder,
|
|
30
|
+
type SstResource,
|
|
31
|
+
} from './SstEnvironmentBuilder';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated Use `new SstEnvironmentBuilder(record).build()` instead.
|
|
85
35
|
*
|
|
86
|
-
* @param name - The resource name (unused)
|
|
87
|
-
* @param value - The resource value (unused)
|
|
88
|
-
* @returns Empty object
|
|
89
|
-
*/
|
|
90
|
-
const noop = (name: string, value: any) => ({});
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Map of resource types to their corresponding processor functions.
|
|
94
|
-
* Each processor converts resource data into environment variables.
|
|
95
|
-
*/
|
|
96
|
-
const processors: Record<ResourceType, ResourceProcessor<any>> = {
|
|
97
|
-
[ResourceType.ApiGatewayV2]: noop,
|
|
98
|
-
[ResourceType.Function]: noop,
|
|
99
|
-
[ResourceType.Vpc]: noop,
|
|
100
|
-
[ResourceType.Secret]: secret,
|
|
101
|
-
[ResourceType.Postgres]: postgres,
|
|
102
|
-
[ResourceType.Bucket]: bucket,
|
|
103
|
-
|
|
104
|
-
[ResourceType.SSTSecret]: secret,
|
|
105
|
-
[ResourceType.SSTBucket]: bucket,
|
|
106
|
-
[ResourceType.SSTFunction]: noop,
|
|
107
|
-
[ResourceType.SSTPostgres]: postgres,
|
|
108
|
-
[ResourceType.SSTApiGatewayV2]: noop,
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
36
|
* Normalizes SST resources and plain strings into environment variables.
|
|
113
37
|
* Processes resources based on their type and converts names to environment case.
|
|
114
38
|
*
|
|
@@ -116,106 +40,20 @@ const processors: Record<ResourceType, ResourceProcessor<any>> = {
|
|
|
116
40
|
* @returns Normalized environment variables object
|
|
117
41
|
*
|
|
118
42
|
* @example
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
43
|
+
* // Old usage (deprecated):
|
|
44
|
+
* normalizeResourceEnv({ database: postgresResource })
|
|
45
|
+
*
|
|
46
|
+
* // New usage:
|
|
47
|
+
* new SstEnvironmentBuilder({ database: postgresResource }).build()
|
|
123
48
|
*/
|
|
124
49
|
export function normalizeResourceEnv(
|
|
125
|
-
record: Record<string,
|
|
126
|
-
): Record<string, string
|
|
127
|
-
|
|
128
|
-
for (const [k, value] of Object.entries(record)) {
|
|
129
|
-
if (typeof value === 'string') {
|
|
130
|
-
env[environmentCase(k)] = value;
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const processor = processors[value.type];
|
|
135
|
-
if (processor) {
|
|
136
|
-
Object.assign(env, processor(k, value));
|
|
137
|
-
} else {
|
|
138
|
-
console.warn(`No processor found for resource type: `, { value });
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return env;
|
|
50
|
+
record: Record<string, SstResource | string>,
|
|
51
|
+
): Record<string, string | number | boolean | Record<string, unknown>> {
|
|
52
|
+
return new SstEnvironmentBuilder(record).build();
|
|
143
53
|
}
|
|
144
54
|
|
|
55
|
+
// Keep Resource type as deprecated alias for backwards compatibility
|
|
145
56
|
/**
|
|
146
|
-
*
|
|
147
|
-
* Represents an HTTP/WebSocket API.
|
|
148
|
-
*/
|
|
149
|
-
export type ApiGatewayV2 = {
|
|
150
|
-
type: ResourceType.ApiGatewayV2;
|
|
151
|
-
url: string;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* PostgreSQL database resource type.
|
|
156
|
-
* Contains all connection details needed to connect to the database.
|
|
157
|
-
*/
|
|
158
|
-
export type Postgres = {
|
|
159
|
-
database: string;
|
|
160
|
-
host: string;
|
|
161
|
-
password: string;
|
|
162
|
-
port: number;
|
|
163
|
-
type: ResourceType.Postgres;
|
|
164
|
-
username: string;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* AWS Lambda Function resource type.
|
|
169
|
-
*/
|
|
170
|
-
export type Function = {
|
|
171
|
-
name: string;
|
|
172
|
-
type: ResourceType.Function;
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* AWS S3 Bucket resource type.
|
|
177
|
-
*/
|
|
178
|
-
export type Bucket = {
|
|
179
|
-
name: string;
|
|
180
|
-
type: ResourceType.Bucket;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* AWS VPC (Virtual Private Cloud) resource type.
|
|
185
|
-
*/
|
|
186
|
-
export type Vpc = {
|
|
187
|
-
bastion: string;
|
|
188
|
-
type: ResourceType.Vpc;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Secret resource type for storing sensitive values.
|
|
193
|
-
*/
|
|
194
|
-
export type Secret = {
|
|
195
|
-
type: ResourceType.Secret;
|
|
196
|
-
value: string;
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Union type of all supported SST resource types.
|
|
201
|
-
*/
|
|
202
|
-
export type Resource =
|
|
203
|
-
| ApiGatewayV2
|
|
204
|
-
| Postgres
|
|
205
|
-
| Function
|
|
206
|
-
| Bucket
|
|
207
|
-
| Vpc
|
|
208
|
-
| Secret;
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Function type for processing a specific resource type into environment variables.
|
|
212
|
-
*
|
|
213
|
-
* @template K - The specific resource type
|
|
214
|
-
* @param name - The resource name
|
|
215
|
-
* @param value - The resource value
|
|
216
|
-
* @returns Object mapping environment variable names to values
|
|
57
|
+
* @deprecated Use `SstResource` instead.
|
|
217
58
|
*/
|
|
218
|
-
export type
|
|
219
|
-
name: string,
|
|
220
|
-
value: K,
|
|
221
|
-
) => Record<string, string | number>;
|
|
59
|
+
export type Resource = SstResource;
|
|
@@ -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 { };
|