@spfn/core 0.1.0-alpha.88 → 0.2.0-beta.10
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 +298 -466
- package/dist/boss-DI1r4kTS.d.ts +244 -0
- package/dist/cache/index.d.ts +13 -33
- package/dist/cache/index.js +14 -703
- package/dist/cache/index.js.map +1 -1
- package/dist/codegen/index.d.ts +214 -17
- package/dist/codegen/index.js +231 -1420
- package/dist/codegen/index.js.map +1 -1
- package/dist/config/index.d.ts +1227 -0
- package/dist/config/index.js +273 -0
- package/dist/config/index.js.map +1 -0
- package/dist/db/index.d.ts +741 -59
- package/dist/db/index.js +1063 -1226
- package/dist/db/index.js.map +1 -1
- package/dist/env/index.d.ts +658 -308
- package/dist/env/index.js +503 -928
- package/dist/env/index.js.map +1 -1
- package/dist/env/loader.d.ts +87 -0
- package/dist/env/loader.js +70 -0
- package/dist/env/loader.js.map +1 -0
- package/dist/errors/index.d.ts +417 -29
- package/dist/errors/index.js +359 -98
- package/dist/errors/index.js.map +1 -1
- package/dist/event/index.d.ts +41 -0
- package/dist/event/index.js +131 -0
- package/dist/event/index.js.map +1 -0
- package/dist/event/sse/client.d.ts +82 -0
- package/dist/event/sse/client.js +115 -0
- package/dist/event/sse/client.js.map +1 -0
- package/dist/event/sse/index.d.ts +40 -0
- package/dist/event/sse/index.js +92 -0
- package/dist/event/sse/index.js.map +1 -0
- package/dist/job/index.d.ts +218 -0
- package/dist/job/index.js +410 -0
- package/dist/job/index.js.map +1 -0
- package/dist/logger/index.d.ts +20 -79
- package/dist/logger/index.js +82 -387
- package/dist/logger/index.js.map +1 -1
- package/dist/middleware/index.d.ts +102 -20
- package/dist/middleware/index.js +51 -705
- package/dist/middleware/index.js.map +1 -1
- package/dist/nextjs/index.d.ts +120 -0
- package/dist/nextjs/index.js +448 -0
- package/dist/nextjs/index.js.map +1 -0
- package/dist/{client/nextjs/index.d.ts → nextjs/server.d.ts} +335 -262
- package/dist/nextjs/server.js +637 -0
- package/dist/nextjs/server.js.map +1 -0
- package/dist/route/index.d.ts +879 -25
- package/dist/route/index.js +697 -1271
- package/dist/route/index.js.map +1 -1
- package/dist/route/types.d.ts +9 -0
- package/dist/route/types.js +3 -0
- package/dist/route/types.js.map +1 -0
- package/dist/router-Di7ENoah.d.ts +151 -0
- package/dist/server/index.d.ts +345 -64
- package/dist/server/index.js +1174 -3233
- package/dist/server/index.js.map +1 -1
- package/dist/types-B-e_f2dQ.d.ts +121 -0
- package/dist/types-BGl4QL1w.d.ts +77 -0
- package/dist/types-BOPTApC2.d.ts +245 -0
- package/docs/cache.md +133 -0
- package/docs/codegen.md +74 -0
- package/docs/database.md +346 -0
- package/docs/entity.md +539 -0
- package/docs/env.md +477 -0
- package/docs/errors.md +319 -0
- package/docs/event.md +116 -0
- package/docs/file-upload.md +717 -0
- package/docs/job.md +131 -0
- package/docs/logger.md +108 -0
- package/docs/middleware.md +337 -0
- package/docs/nextjs.md +241 -0
- package/docs/repository.md +496 -0
- package/docs/route.md +497 -0
- package/docs/server.md +307 -0
- package/package.json +68 -48
- package/dist/auto-loader-JFaZ9gON.d.ts +0 -80
- package/dist/client/index.d.ts +0 -358
- package/dist/client/index.js +0 -357
- package/dist/client/index.js.map +0 -1
- package/dist/client/nextjs/index.js +0 -371
- package/dist/client/nextjs/index.js.map +0 -1
- package/dist/codegen/generators/index.d.ts +0 -19
- package/dist/codegen/generators/index.js +0 -1404
- package/dist/codegen/generators/index.js.map +0 -1
- package/dist/database-errors-BNNmLTJE.d.ts +0 -86
- package/dist/events/index.d.ts +0 -183
- package/dist/events/index.js +0 -77
- package/dist/events/index.js.map +0 -1
- package/dist/index-DHiAqhKv.d.ts +0 -101
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -3674
- package/dist/index.js.map +0 -1
- package/dist/types/index.d.ts +0 -121
- package/dist/types/index.js +0 -38
- package/dist/types/index.js.map +0 -1
- package/dist/types-BXibIEyj.d.ts +0 -60
package/dist/env/index.d.ts
CHANGED
|
@@ -1,508 +1,858 @@
|
|
|
1
|
+
export { L as LogLevel } from '../types-BGl4QL1w.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* Environment Variable Management -
|
|
4
|
+
* Environment Variable Management - Parsers
|
|
3
5
|
*
|
|
4
|
-
*
|
|
6
|
+
* Parser functions that transform and validate environment variable strings.
|
|
7
|
+
* All parsers follow the pattern: (value: string) => T or throw Error
|
|
5
8
|
*/
|
|
6
9
|
/**
|
|
7
|
-
*
|
|
10
|
+
* Parser function that transforms and validates a string value
|
|
11
|
+
* @throws Error if validation fails
|
|
8
12
|
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Base directory for .env files
|
|
12
|
-
* @default process.cwd()
|
|
13
|
-
*/
|
|
14
|
-
basePath?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Additional custom paths to load
|
|
17
|
-
* Loaded after standard files
|
|
18
|
-
* @default []
|
|
19
|
-
*/
|
|
20
|
-
customPaths?: string[];
|
|
21
|
-
/**
|
|
22
|
-
* Enable debug logging
|
|
23
|
-
* @default false
|
|
24
|
-
*/
|
|
25
|
-
debug?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Override NODE_ENV for file selection
|
|
28
|
-
* @default process.env.NODE_ENV
|
|
29
|
-
*/
|
|
30
|
-
nodeEnv?: string;
|
|
31
|
-
/**
|
|
32
|
-
* Required environment variables
|
|
33
|
-
* Throws error if any are missing after loading
|
|
34
|
-
* @default []
|
|
35
|
-
*/
|
|
36
|
-
required?: string[];
|
|
37
|
-
/**
|
|
38
|
-
* Skip loading if environment already loaded
|
|
39
|
-
* Set to false to force reload (useful for testing)
|
|
40
|
-
* @default true
|
|
41
|
-
*/
|
|
42
|
-
useCache?: boolean;
|
|
43
|
-
}
|
|
13
|
+
type Parser<T> = (value: string) => T;
|
|
44
14
|
/**
|
|
45
|
-
*
|
|
15
|
+
* Parse a non-empty string
|
|
16
|
+
*
|
|
17
|
+
* @param value - Value to parse
|
|
18
|
+
* @returns Trimmed string
|
|
19
|
+
* @throws Error if string is empty after trimming
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const name = getEnvVar('APP_NAME', {
|
|
24
|
+
* validator: parseString,
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
46
27
|
*/
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Whether loading was successful overall
|
|
50
|
-
*/
|
|
51
|
-
success: boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Files that were successfully loaded
|
|
54
|
-
*/
|
|
55
|
-
loaded: string[];
|
|
56
|
-
/**
|
|
57
|
-
* Files that failed to load (with reasons)
|
|
58
|
-
*/
|
|
59
|
-
failed: Array<{
|
|
60
|
-
path: string;
|
|
61
|
-
reason: string;
|
|
62
|
-
}>;
|
|
63
|
-
/**
|
|
64
|
-
* Environment variables that were parsed from files
|
|
65
|
-
*/
|
|
66
|
-
parsed: Record<string, string>;
|
|
67
|
-
/**
|
|
68
|
-
* Error messages if any critical errors occurred
|
|
69
|
-
*/
|
|
70
|
-
errors?: string[];
|
|
71
|
-
/**
|
|
72
|
-
* Warning messages for non-critical issues
|
|
73
|
-
*/
|
|
74
|
-
warnings: string[];
|
|
75
|
-
}
|
|
28
|
+
declare function parseString(value: string): string;
|
|
76
29
|
/**
|
|
77
|
-
*
|
|
30
|
+
* Create a string parser with validation rules
|
|
31
|
+
*
|
|
32
|
+
* @param options - Validation options
|
|
33
|
+
* @returns Parser function
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const apiKey = getEnvVar('API_KEY', {
|
|
38
|
+
* validator: createStringParser({
|
|
39
|
+
* minLength: 32,
|
|
40
|
+
* pattern: /^[A-Za-z0-9_-]+$/,
|
|
41
|
+
* }),
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
78
44
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Default value if variable not found
|
|
87
|
-
* Only used if required is false
|
|
88
|
-
*/
|
|
89
|
-
default?: string;
|
|
90
|
-
/**
|
|
91
|
-
* Custom validation function
|
|
92
|
-
* Return true if valid, false if invalid
|
|
93
|
-
*/
|
|
94
|
-
validator?: (value: string) => boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Custom error message for validation failure
|
|
97
|
-
*/
|
|
98
|
-
validationError?: string;
|
|
99
|
-
}
|
|
45
|
+
declare function createStringParser(options?: {
|
|
46
|
+
minLength?: number;
|
|
47
|
+
maxLength?: number;
|
|
48
|
+
pattern?: RegExp;
|
|
49
|
+
trim?: boolean;
|
|
50
|
+
}): Parser<string>;
|
|
100
51
|
/**
|
|
101
|
-
*
|
|
52
|
+
* Parse a boolean environment variable
|
|
102
53
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* - production: .env → .env.production → .env.local → .env.production.local
|
|
106
|
-
* - test: .env → .env.test → (skip .env.local) → .env.test.local
|
|
54
|
+
* Accepts: 'true', '1', 'yes' (case-insensitive) → true
|
|
55
|
+
* 'false', '0', 'no' (case-insensitive) → false
|
|
107
56
|
*
|
|
108
|
-
*
|
|
57
|
+
* @param value - Value to parse
|
|
58
|
+
* @returns Boolean value
|
|
59
|
+
* @throws Error if value is not a valid boolean string
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const debug = getEnvVar('DEBUG', {
|
|
64
|
+
* default: 'false',
|
|
65
|
+
* validator: parseBoolean,
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
109
68
|
*/
|
|
110
|
-
declare
|
|
69
|
+
declare function parseBoolean(value: string): boolean;
|
|
111
70
|
/**
|
|
112
|
-
*
|
|
71
|
+
* Parse and validate number
|
|
72
|
+
*
|
|
73
|
+
* @param value - Value to parse
|
|
74
|
+
* @param options - Validation options
|
|
75
|
+
* @returns Parsed number
|
|
76
|
+
* @throws Error if invalid number or constraint violation
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const port = getEnvVar('PORT', {
|
|
81
|
+
* default: '3000',
|
|
82
|
+
* validator: (val) => parseNumber(val, { min: 1, max: 65535, integer: true }),
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
113
85
|
*/
|
|
114
|
-
declare
|
|
115
|
-
|
|
86
|
+
declare function parseNumber(value: string, options?: {
|
|
87
|
+
min?: number;
|
|
88
|
+
max?: number;
|
|
89
|
+
integer?: boolean;
|
|
90
|
+
}): number;
|
|
116
91
|
/**
|
|
117
|
-
*
|
|
92
|
+
* Create a number parser with specific constraints
|
|
118
93
|
*
|
|
119
|
-
*
|
|
94
|
+
* @param options - Validation constraints
|
|
95
|
+
* @returns Parser function
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const port = getEnvVar('PORT', {
|
|
100
|
+
* default: '3000',
|
|
101
|
+
* validator: createNumberParser({ min: 1, max: 65535, integer: true }),
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
120
104
|
*/
|
|
121
|
-
|
|
105
|
+
declare function createNumberParser(options?: {
|
|
106
|
+
min?: number;
|
|
107
|
+
max?: number;
|
|
108
|
+
integer?: boolean;
|
|
109
|
+
}): Parser<number>;
|
|
122
110
|
/**
|
|
123
|
-
*
|
|
111
|
+
* Parse integer with optional constraints
|
|
124
112
|
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* - test: .env → .env.test → (skip .env.local) → .env.test.local
|
|
130
|
-
* - local: .env → .env.local → .env.local.local (duplicate .env.local prevented)
|
|
131
|
-
* - staging/qa/etc: .env → .env.{NODE_ENV} → .env.local → .env.{NODE_ENV}.local
|
|
113
|
+
* @param value - Value to parse
|
|
114
|
+
* @param options - Min/max constraints
|
|
115
|
+
* @returns Parsed integer
|
|
116
|
+
* @throws Error if invalid or out of range
|
|
132
117
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const retries = getEnvVar('MAX_RETRIES', {
|
|
121
|
+
* default: '3',
|
|
122
|
+
* validator: (val) => parseInteger(val, { min: 1, max: 10 }),
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
declare function parseInteger(value: string, options?: {
|
|
127
|
+
min?: number;
|
|
128
|
+
max?: number;
|
|
129
|
+
}): number;
|
|
130
|
+
/**
|
|
131
|
+
* Parse float/decimal number with optional constraints
|
|
137
132
|
*
|
|
138
|
-
* @param
|
|
139
|
-
* @
|
|
133
|
+
* @param value - Value to parse
|
|
134
|
+
* @param options - Min/max constraints
|
|
135
|
+
* @returns Parsed decimal number
|
|
136
|
+
* @throws Error if invalid or out of range
|
|
140
137
|
*
|
|
141
138
|
* @example
|
|
142
139
|
* ```typescript
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* // With NODE_ENV=local
|
|
147
|
-
* process.env.NODE_ENV = 'local';
|
|
148
|
-
* const result = loadEnvironment({
|
|
149
|
-
* debug: true,
|
|
150
|
-
* required: ['DATABASE_URL'],
|
|
140
|
+
* const ratio = getEnvVar('CACHE_RATIO', {
|
|
141
|
+
* default: '0.75',
|
|
142
|
+
* validator: (val) => parseDecimal(val, { min: 0, max: 1 }),
|
|
151
143
|
* });
|
|
152
|
-
*
|
|
153
|
-
* // With custom environment
|
|
154
|
-
* process.env.NODE_ENV = 'staging';
|
|
155
|
-
* const result = loadEnvironment();
|
|
156
144
|
* ```
|
|
157
145
|
*/
|
|
158
|
-
declare function
|
|
146
|
+
declare function parseDecimal(value: string, options?: {
|
|
147
|
+
min?: number;
|
|
148
|
+
max?: number;
|
|
149
|
+
}): number;
|
|
159
150
|
/**
|
|
160
|
-
*
|
|
151
|
+
* Parse and validate URL
|
|
161
152
|
*
|
|
162
|
-
* @param
|
|
163
|
-
* @param options -
|
|
164
|
-
* @returns
|
|
165
|
-
* @throws Error if
|
|
153
|
+
* @param value - Value to parse
|
|
154
|
+
* @param options - Validation options
|
|
155
|
+
* @returns Validated URL string
|
|
156
|
+
* @throws Error if invalid URL or protocol mismatch
|
|
166
157
|
*
|
|
167
158
|
* @example
|
|
168
159
|
* ```typescript
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
|
|
160
|
+
* const apiUrl = getEnvVar('API_URL', {
|
|
161
|
+
* validator: (val) => parseUrl(val, { protocol: 'https' }),
|
|
162
|
+
* });
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
declare function parseUrl(value: string, options?: {
|
|
166
|
+
protocol?: 'http' | 'https' | 'any';
|
|
167
|
+
}): string;
|
|
168
|
+
/**
|
|
169
|
+
* Create a URL parser with specific protocol requirement
|
|
174
170
|
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
171
|
+
* @param protocol - Required protocol ('http', 'https', or 'any')
|
|
172
|
+
* @returns Parser function
|
|
177
173
|
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const apiUrl = getEnvVar('API_URL', {
|
|
177
|
+
* validator: createUrlParser('https'),
|
|
182
178
|
* });
|
|
183
179
|
* ```
|
|
184
180
|
*/
|
|
185
|
-
declare function
|
|
181
|
+
declare function createUrlParser(protocol?: 'http' | 'https' | 'any'): Parser<string>;
|
|
186
182
|
/**
|
|
187
|
-
*
|
|
183
|
+
* Parse PostgreSQL connection string
|
|
188
184
|
*
|
|
189
|
-
* @param
|
|
190
|
-
* @returns
|
|
191
|
-
* @throws Error if
|
|
185
|
+
* @param value - Value to parse
|
|
186
|
+
* @returns Validated PostgreSQL URL string
|
|
187
|
+
* @throws Error if invalid PostgreSQL URL
|
|
192
188
|
*
|
|
193
189
|
* @example
|
|
194
190
|
* ```typescript
|
|
195
|
-
* const dbUrl =
|
|
191
|
+
* const dbUrl = getEnvVar('DATABASE_URL', {
|
|
192
|
+
* required: true,
|
|
193
|
+
* validator: parsePostgresUrl,
|
|
194
|
+
* });
|
|
196
195
|
* ```
|
|
197
196
|
*/
|
|
198
|
-
declare function
|
|
197
|
+
declare function parsePostgresUrl(value: string): string;
|
|
199
198
|
/**
|
|
200
|
-
*
|
|
199
|
+
* Parse Redis connection string
|
|
201
200
|
*
|
|
202
|
-
* @param
|
|
203
|
-
* @returns
|
|
201
|
+
* @param value - Value to parse
|
|
202
|
+
* @returns Validated Redis URL string
|
|
203
|
+
* @throws Error if invalid Redis URL
|
|
204
204
|
*
|
|
205
205
|
* @example
|
|
206
206
|
* ```typescript
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
207
|
+
* const redisUrl = getEnvVar('REDIS_URL', {
|
|
208
|
+
* required: true,
|
|
209
|
+
* validator: parseRedisUrl,
|
|
210
|
+
* });
|
|
210
211
|
* ```
|
|
211
212
|
*/
|
|
212
|
-
declare function
|
|
213
|
+
declare function parseRedisUrl(value: string): string;
|
|
213
214
|
/**
|
|
214
|
-
*
|
|
215
|
+
* Parse and validate enum value
|
|
215
216
|
*
|
|
216
|
-
* @param
|
|
217
|
-
* @
|
|
217
|
+
* @param value - Value to parse
|
|
218
|
+
* @param allowed - Array of allowed values
|
|
219
|
+
* @param caseInsensitive - Whether to perform case-insensitive comparison
|
|
220
|
+
* @returns Validated enum value
|
|
221
|
+
* @throws Error if value not in allowed list
|
|
218
222
|
*
|
|
219
223
|
* @example
|
|
220
224
|
* ```typescript
|
|
221
|
-
* const
|
|
222
|
-
* '
|
|
223
|
-
*
|
|
224
|
-
* ]);
|
|
225
|
+
* const env = getEnvVar('NODE_ENV', {
|
|
226
|
+
* validator: (val) => parseEnum(val, ['development', 'production', 'test']),
|
|
227
|
+
* });
|
|
225
228
|
* ```
|
|
226
229
|
*/
|
|
227
|
-
declare function
|
|
230
|
+
declare function parseEnum(value: string, allowed: string[], caseInsensitive?: boolean): string;
|
|
228
231
|
/**
|
|
229
|
-
*
|
|
232
|
+
* Create an enum parser with specific allowed values
|
|
230
233
|
*
|
|
231
|
-
* @
|
|
234
|
+
* @param allowed - Array of allowed values
|
|
235
|
+
* @param caseInsensitive - Whether to perform case-insensitive comparison
|
|
236
|
+
* @returns Parser function
|
|
232
237
|
*
|
|
233
238
|
* @example
|
|
234
239
|
* ```typescript
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
240
|
+
* const logLevel = getEnvVar('LOG_LEVEL', {
|
|
241
|
+
* default: 'info',
|
|
242
|
+
* validator: createEnumParser(['debug', 'info', 'warn', 'error']),
|
|
243
|
+
* });
|
|
238
244
|
* ```
|
|
239
245
|
*/
|
|
240
|
-
declare function
|
|
246
|
+
declare function createEnumParser(allowed: string[], caseInsensitive?: boolean): Parser<string>;
|
|
241
247
|
/**
|
|
242
|
-
*
|
|
243
|
-
*
|
|
248
|
+
* Parse JSON string
|
|
249
|
+
*
|
|
250
|
+
* @param value - JSON string to parse
|
|
251
|
+
* @returns Parsed JSON value
|
|
252
|
+
* @throws Error if invalid JSON
|
|
244
253
|
*
|
|
245
254
|
* @example
|
|
246
255
|
* ```typescript
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
* resetEnvironment();
|
|
256
|
+
* const config = getEnvVar('CONFIG_JSON', {
|
|
257
|
+
* validator: parseJson,
|
|
250
258
|
* });
|
|
251
259
|
* ```
|
|
252
260
|
*/
|
|
253
|
-
declare function
|
|
254
|
-
|
|
261
|
+
declare function parseJson<T = any>(value: string): T;
|
|
255
262
|
/**
|
|
256
|
-
*
|
|
263
|
+
* Create a typed JSON parser
|
|
264
|
+
*
|
|
265
|
+
* @returns Parser function
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* interface Config {
|
|
270
|
+
* host: string;
|
|
271
|
+
* port: number;
|
|
272
|
+
* }
|
|
257
273
|
*
|
|
258
|
-
*
|
|
274
|
+
* const config = getEnvVar('CONFIG_JSON', {
|
|
275
|
+
* validator: createJsonParser<Config>(),
|
|
276
|
+
* });
|
|
277
|
+
* ```
|
|
259
278
|
*/
|
|
279
|
+
declare function createJsonParser<T>(): Parser<T>;
|
|
260
280
|
/**
|
|
261
|
-
*
|
|
281
|
+
* Parse comma-separated values into array
|
|
262
282
|
*
|
|
263
|
-
* @param value -
|
|
264
|
-
* @param options -
|
|
265
|
-
* @returns
|
|
283
|
+
* @param value - Comma-separated string
|
|
284
|
+
* @param options - Parser options
|
|
285
|
+
* @returns Array of strings
|
|
266
286
|
*
|
|
267
287
|
* @example
|
|
268
288
|
* ```typescript
|
|
269
|
-
* const
|
|
270
|
-
* validator:
|
|
289
|
+
* const hosts = getEnvVar('ALLOWED_HOSTS', {
|
|
290
|
+
* validator: parseArray,
|
|
271
291
|
* });
|
|
292
|
+
* // "localhost,example.com,api.example.com" → ['localhost', 'example.com', 'api.example.com']
|
|
272
293
|
* ```
|
|
273
294
|
*/
|
|
274
|
-
declare function
|
|
275
|
-
|
|
276
|
-
|
|
295
|
+
declare function parseArray(value: string, options?: {
|
|
296
|
+
separator?: string;
|
|
297
|
+
trim?: boolean;
|
|
298
|
+
filter?: (item: string) => boolean;
|
|
299
|
+
}): string[];
|
|
277
300
|
/**
|
|
278
|
-
* Create
|
|
301
|
+
* Create an array parser with item parser
|
|
279
302
|
*
|
|
280
|
-
* @param
|
|
281
|
-
* @
|
|
303
|
+
* @param itemParser - Parser to apply to each array item
|
|
304
|
+
* @param options - Array parsing options
|
|
305
|
+
* @returns Parser function
|
|
282
306
|
*
|
|
283
307
|
* @example
|
|
284
308
|
* ```typescript
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
309
|
+
* // Parse comma-separated ports
|
|
310
|
+
* const ports = getEnvVar('PORTS', {
|
|
311
|
+
* validator: createArrayParser(
|
|
312
|
+
* createNumberParser({ min: 1, max: 65535, integer: true })
|
|
313
|
+
* ),
|
|
288
314
|
* });
|
|
315
|
+
* // "3000,4000,5000" → [3000, 4000, 5000]
|
|
289
316
|
* ```
|
|
290
317
|
*/
|
|
291
|
-
declare function
|
|
318
|
+
declare function createArrayParser<T>(itemParser: Parser<T>, options?: {
|
|
319
|
+
separator?: string;
|
|
320
|
+
}): Parser<T[]>;
|
|
292
321
|
/**
|
|
293
|
-
*
|
|
322
|
+
* Create a secure secret parser with entropy validation
|
|
323
|
+
*
|
|
324
|
+
* Validates cryptographic secrets for sufficient length, character diversity, and randomness.
|
|
325
|
+
* Uses Shannon entropy to measure randomness quality.
|
|
294
326
|
*
|
|
295
|
-
* @param value - Value to validate
|
|
296
327
|
* @param options - Validation options
|
|
297
|
-
* @returns
|
|
328
|
+
* @returns Parser function
|
|
298
329
|
*
|
|
299
330
|
* @example
|
|
300
331
|
* ```typescript
|
|
301
|
-
* const
|
|
302
|
-
* validator: (
|
|
332
|
+
* const sessionSecret = getEnvVar('SESSION_SECRET', {
|
|
333
|
+
* validator: createSecureSecretParser({
|
|
334
|
+
* minLength: 32, // Minimum 256-bit
|
|
335
|
+
* minUniqueChars: 16, // Character diversity
|
|
336
|
+
* minEntropy: 3.5, // Shannon entropy (bits/char)
|
|
337
|
+
* }),
|
|
303
338
|
* });
|
|
304
339
|
* ```
|
|
305
340
|
*/
|
|
306
|
-
declare function
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}):
|
|
341
|
+
declare function createSecureSecretParser(options?: {
|
|
342
|
+
minLength?: number;
|
|
343
|
+
minUniqueChars?: number;
|
|
344
|
+
minEntropy?: number;
|
|
345
|
+
}): Parser<string>;
|
|
311
346
|
/**
|
|
312
|
-
* Create a
|
|
347
|
+
* Create a password strength parser
|
|
313
348
|
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
349
|
+
* Validates password strength based on configurable requirements.
|
|
350
|
+
* Useful for enforcing password policies in environment variables or user input.
|
|
351
|
+
*
|
|
352
|
+
* @param options - Validation options
|
|
353
|
+
* @returns Parser function
|
|
316
354
|
*
|
|
317
355
|
* @example
|
|
318
356
|
* ```typescript
|
|
319
|
-
* const
|
|
320
|
-
* validator:
|
|
321
|
-
*
|
|
357
|
+
* const adminPassword = getEnvVar('ADMIN_PASSWORD', {
|
|
358
|
+
* validator: createPasswordParser({
|
|
359
|
+
* minLength: 12,
|
|
360
|
+
* requireUppercase: true,
|
|
361
|
+
* requireLowercase: true,
|
|
362
|
+
* requireNumber: true,
|
|
363
|
+
* requireSpecial: true,
|
|
364
|
+
* }),
|
|
322
365
|
* });
|
|
323
366
|
* ```
|
|
324
367
|
*/
|
|
325
|
-
declare function
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
368
|
+
declare function createPasswordParser(options?: {
|
|
369
|
+
minLength?: number;
|
|
370
|
+
requireUppercase?: boolean;
|
|
371
|
+
requireLowercase?: boolean;
|
|
372
|
+
requireNumber?: boolean;
|
|
373
|
+
requireSpecial?: boolean;
|
|
374
|
+
}): Parser<string>;
|
|
330
375
|
/**
|
|
331
|
-
*
|
|
376
|
+
* Chain multiple parsers sequentially
|
|
377
|
+
*
|
|
378
|
+
* Each parser receives the output of the previous parser.
|
|
379
|
+
* Useful for multi-step validation/transformation.
|
|
332
380
|
*
|
|
333
|
-
* @param
|
|
334
|
-
* @returns
|
|
381
|
+
* @param parsers - Array of parser functions
|
|
382
|
+
* @returns Combined parser function
|
|
335
383
|
*
|
|
336
384
|
* @example
|
|
337
385
|
* ```typescript
|
|
338
|
-
* const
|
|
339
|
-
* validator:
|
|
386
|
+
* const apiKey = getEnvVar('API_KEY', {
|
|
387
|
+
* validator: chain(
|
|
388
|
+
* parseString,
|
|
389
|
+
* createStringParser({ minLength: 32, pattern: /^[A-Za-z0-9_-]+$/ }),
|
|
390
|
+
* ),
|
|
340
391
|
* });
|
|
341
392
|
* ```
|
|
342
393
|
*/
|
|
343
|
-
declare function
|
|
394
|
+
declare function chain<T>(...parsers: Array<Parser<T>>): Parser<T>;
|
|
344
395
|
/**
|
|
345
|
-
*
|
|
396
|
+
* Apply parser with fallback value
|
|
346
397
|
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
398
|
+
* If parser throws, returns fallback instead.
|
|
399
|
+
* Useful for optional environment variables with complex parsing.
|
|
400
|
+
*
|
|
401
|
+
* @param parser - Parser to attempt
|
|
402
|
+
* @param fallback - Fallback value if parsing fails
|
|
403
|
+
* @returns Parser function
|
|
349
404
|
*
|
|
350
405
|
* @example
|
|
351
406
|
* ```typescript
|
|
352
|
-
* const
|
|
407
|
+
* const config = getEnvVar('CONFIG_JSON', {
|
|
408
|
+
* validator: withFallback(parseJson, { host: 'localhost', port: 3000 }),
|
|
409
|
+
* });
|
|
353
410
|
* ```
|
|
354
411
|
*/
|
|
355
|
-
declare function
|
|
412
|
+
declare function withFallback<T>(parser: Parser<T>, fallback: T): Parser<T>;
|
|
356
413
|
/**
|
|
357
|
-
*
|
|
414
|
+
* Make parser optional
|
|
358
415
|
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
* @param
|
|
362
|
-
* @returns
|
|
416
|
+
* Returns undefined for empty strings instead of throwing.
|
|
417
|
+
*
|
|
418
|
+
* @param parser - Parser to make optional
|
|
419
|
+
* @returns Parser function that returns T | undefined
|
|
363
420
|
*
|
|
364
421
|
* @example
|
|
365
422
|
* ```typescript
|
|
366
|
-
* const
|
|
367
|
-
* validator: (
|
|
423
|
+
* const redisUrl = getEnvVar('REDIS_URL', {
|
|
424
|
+
* validator: optional(parseRedisUrl),
|
|
368
425
|
* });
|
|
426
|
+
* // Empty string → undefined
|
|
427
|
+
* // Valid URL → parsed URL
|
|
428
|
+
* // Invalid URL → throws
|
|
369
429
|
* ```
|
|
370
430
|
*/
|
|
371
|
-
declare function
|
|
431
|
+
declare function optional<T>(parser: Parser<T>): Parser<T | undefined>;
|
|
432
|
+
|
|
372
433
|
/**
|
|
373
|
-
*
|
|
434
|
+
* Environment Variable Schema Definition System
|
|
374
435
|
*
|
|
375
|
-
*
|
|
376
|
-
* @param caseInsensitive - Whether to perform case-insensitive comparison
|
|
377
|
-
* @returns Validator function
|
|
436
|
+
* 환경변수에 메타데이터를 정의하여 중앙 관리, 문서화, 검증을 지원합니다.
|
|
378
437
|
*
|
|
379
438
|
* @example
|
|
380
439
|
* ```typescript
|
|
381
|
-
* const
|
|
382
|
-
*
|
|
383
|
-
*
|
|
440
|
+
* const schema = defineEnvSchema({
|
|
441
|
+
* DATABASE_URL: envUrl({
|
|
442
|
+
* description: 'Database connection',
|
|
443
|
+
* required: true,
|
|
444
|
+
* validator: parsePostgresUrl,
|
|
445
|
+
* sensitive: true,
|
|
446
|
+
* })
|
|
384
447
|
* });
|
|
385
448
|
* ```
|
|
449
|
+
*
|
|
450
|
+
* @module env/schema
|
|
451
|
+
*/
|
|
452
|
+
/**
|
|
453
|
+
* 환경변수 스키마 정의
|
|
454
|
+
*/
|
|
455
|
+
interface EnvVarSchema<T = string> {
|
|
456
|
+
/** 환경변수 키 */
|
|
457
|
+
key: string;
|
|
458
|
+
/** 설명 (목적, 사용처) */
|
|
459
|
+
description: string;
|
|
460
|
+
/** 타입 */
|
|
461
|
+
type: 'string' | 'number' | 'boolean' | 'url' | 'enum' | 'json';
|
|
462
|
+
/** 필수 여부 */
|
|
463
|
+
required?: boolean;
|
|
464
|
+
/** 기본값 */
|
|
465
|
+
default?: T;
|
|
466
|
+
/** 검증/변환 함수 */
|
|
467
|
+
validator?: (value: string) => T;
|
|
468
|
+
/** Fallback 환경변수 키들 (backward compatibility) */
|
|
469
|
+
fallbackKeys?: string[];
|
|
470
|
+
/** 최소 길이 (문자열 타입) */
|
|
471
|
+
minLength?: number;
|
|
472
|
+
/** 민감정보 여부 (로깅 시 마스킹) */
|
|
473
|
+
sensitive?: boolean;
|
|
474
|
+
/** 예시 값들 (타입과 일치해야 함) */
|
|
475
|
+
examples?: T[];
|
|
476
|
+
/**
|
|
477
|
+
* Next.js 프로세스에서 사용 여부
|
|
478
|
+
*
|
|
479
|
+
* - true: .env.local에 존재해야 함 (Next.js 서버 컴포넌트에서 접근 가능)
|
|
480
|
+
* - false: .env.server.local에만 존재해야 함 (SPFN 서버에서만 접근)
|
|
481
|
+
*
|
|
482
|
+
* @default NEXT_PUBLIC_* 이면 true, 아니면 false
|
|
483
|
+
*/
|
|
484
|
+
nextjs?: boolean;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* 스키마 컬렉션 타입
|
|
488
|
+
*/
|
|
489
|
+
type EnvSchemaCollection = Record<string, EnvVarSchema<any>>;
|
|
490
|
+
/**
|
|
491
|
+
* Helper type: Check if field has default value
|
|
492
|
+
*/
|
|
493
|
+
type HasDefault<T> = T extends {
|
|
494
|
+
default: any;
|
|
495
|
+
} ? true : false;
|
|
496
|
+
/**
|
|
497
|
+
* Helper type: Check if field is explicitly required
|
|
386
498
|
*/
|
|
387
|
-
|
|
499
|
+
type IsRequired<T> = T extends {
|
|
500
|
+
required: true;
|
|
501
|
+
} ? true : false;
|
|
388
502
|
/**
|
|
389
|
-
*
|
|
503
|
+
* Helper type: Check if field should be required (has default OR required: true)
|
|
504
|
+
*/
|
|
505
|
+
type ShouldBeRequired<T> = HasDefault<T> extends true ? true : IsRequired<T>;
|
|
506
|
+
/**
|
|
507
|
+
* 스키마로부터 타입 추출
|
|
508
|
+
*
|
|
509
|
+
* required: true 또는 default가 있는 필드 → 필수
|
|
510
|
+
* required: false 또는 미지정 → optional (| undefined)
|
|
511
|
+
*/
|
|
512
|
+
type InferEnvType<T extends EnvSchemaCollection> = {
|
|
513
|
+
[K in keyof T as ShouldBeRequired<T[K]> extends true ? K : never]: T[K] extends EnvVarSchema<infer U> ? U : string;
|
|
514
|
+
} & {
|
|
515
|
+
[K in keyof T as ShouldBeRequired<T[K]> extends true ? never : K]?: T[K] extends EnvVarSchema<infer U> ? U | undefined : string | undefined;
|
|
516
|
+
};
|
|
517
|
+
/**
|
|
518
|
+
* 스키마 정의 헬퍼 (타입 추론 지원)
|
|
390
519
|
*
|
|
391
|
-
*
|
|
392
|
-
* @param pattern - Regular expression pattern
|
|
393
|
-
* @returns True if value matches pattern, false otherwise
|
|
520
|
+
* Automatically fills in the `key` property from object keys.
|
|
394
521
|
*
|
|
395
522
|
* @example
|
|
396
523
|
* ```typescript
|
|
397
|
-
* const
|
|
398
|
-
*
|
|
524
|
+
* const schema = defineEnvSchema({
|
|
525
|
+
* DATABASE_URL: envString({ description: 'Database URL', required: true })
|
|
399
526
|
* });
|
|
527
|
+
* // Automatically adds key: 'DATABASE_URL'
|
|
400
528
|
* ```
|
|
401
529
|
*/
|
|
402
|
-
declare function
|
|
530
|
+
declare function defineEnvSchema<T extends Record<string, any>>(schema: T): {
|
|
531
|
+
[K in keyof T]: T[K] & {
|
|
532
|
+
key: K;
|
|
533
|
+
};
|
|
534
|
+
};
|
|
403
535
|
/**
|
|
404
|
-
*
|
|
536
|
+
* 문자열 스키마 헬퍼
|
|
405
537
|
*
|
|
406
|
-
* @
|
|
407
|
-
*
|
|
538
|
+
* @example
|
|
539
|
+
* ```typescript
|
|
540
|
+
* const schema = {
|
|
541
|
+
* API_KEY: {
|
|
542
|
+
* ...envString({
|
|
543
|
+
* description: 'API authentication key',
|
|
544
|
+
* required: true,
|
|
545
|
+
* sensitive: true,
|
|
546
|
+
* }),
|
|
547
|
+
* key: 'API_KEY',
|
|
548
|
+
* }
|
|
549
|
+
* };
|
|
550
|
+
* ```
|
|
551
|
+
*/
|
|
552
|
+
declare function envString<T extends Omit<EnvVarSchema, 'key' | 'type'>>(options: T): T & {
|
|
553
|
+
type: 'string';
|
|
554
|
+
};
|
|
555
|
+
/**
|
|
556
|
+
* 숫자 스키마 헬퍼
|
|
408
557
|
*
|
|
409
558
|
* @example
|
|
410
559
|
* ```typescript
|
|
411
|
-
* const
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
560
|
+
* const schema = {
|
|
561
|
+
* PORT: {
|
|
562
|
+
* ...envNumber({
|
|
563
|
+
* description: 'Server port',
|
|
564
|
+
* default: 3000,
|
|
565
|
+
* validator: createNumberParser({ min: 1, max: 65535 }),
|
|
566
|
+
* }),
|
|
567
|
+
* key: 'PORT',
|
|
568
|
+
* }
|
|
569
|
+
* };
|
|
570
|
+
* ```
|
|
571
|
+
*/
|
|
572
|
+
declare function envNumber<T extends Omit<EnvVarSchema<number>, 'key' | 'type'>>(options: T): T & {
|
|
573
|
+
type: 'number';
|
|
574
|
+
validator: (value: string) => number;
|
|
575
|
+
};
|
|
576
|
+
/**
|
|
577
|
+
* Boolean 스키마 헬퍼
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* ```typescript
|
|
581
|
+
* const schema = {
|
|
582
|
+
* DEBUG: {
|
|
583
|
+
* ...envBoolean({
|
|
584
|
+
* description: 'Enable debug mode',
|
|
585
|
+
* default: false,
|
|
586
|
+
* }),
|
|
587
|
+
* key: 'DEBUG',
|
|
588
|
+
* }
|
|
589
|
+
* };
|
|
415
590
|
* ```
|
|
416
591
|
*/
|
|
417
|
-
declare function
|
|
592
|
+
declare function envBoolean<T extends Omit<EnvVarSchema<boolean>, 'key' | 'type'>>(options: T): T & {
|
|
593
|
+
type: 'boolean';
|
|
594
|
+
validator: (value: string) => boolean;
|
|
595
|
+
};
|
|
418
596
|
/**
|
|
419
|
-
*
|
|
597
|
+
* URL 스키마 헬퍼
|
|
420
598
|
*
|
|
421
|
-
* @
|
|
422
|
-
*
|
|
599
|
+
* @example
|
|
600
|
+
* ```typescript
|
|
601
|
+
* const schema = {
|
|
602
|
+
* DATABASE_URL: {
|
|
603
|
+
* ...envUrl({
|
|
604
|
+
* description: 'Database connection URL',
|
|
605
|
+
* required: true,
|
|
606
|
+
* validator: parsePostgresUrl,
|
|
607
|
+
* }),
|
|
608
|
+
* key: 'DATABASE_URL',
|
|
609
|
+
* }
|
|
610
|
+
* };
|
|
611
|
+
* ```
|
|
612
|
+
*/
|
|
613
|
+
declare function envUrl<T extends Omit<EnvVarSchema, 'key' | 'type'>>(options: T): T & {
|
|
614
|
+
type: 'url';
|
|
615
|
+
};
|
|
616
|
+
/**
|
|
617
|
+
* Enum 스키마 헬퍼
|
|
423
618
|
*
|
|
424
619
|
* @example
|
|
425
620
|
* ```typescript
|
|
426
|
-
* const
|
|
427
|
-
*
|
|
428
|
-
*
|
|
621
|
+
* const schema = {
|
|
622
|
+
* LOG_LEVEL: {
|
|
623
|
+
* ...envEnum(['debug', 'info', 'warn', 'error'] as const, {
|
|
624
|
+
* description: 'Logging level',
|
|
625
|
+
* default: 'info',
|
|
626
|
+
* }),
|
|
627
|
+
* key: 'LOG_LEVEL',
|
|
628
|
+
* }
|
|
629
|
+
* };
|
|
429
630
|
* ```
|
|
430
631
|
*/
|
|
431
|
-
declare function
|
|
632
|
+
declare function envEnum<T extends string, O extends Omit<EnvVarSchema<T>, 'key' | 'type' | 'validator'>>(allowed: readonly T[], options: O): O & {
|
|
633
|
+
type: 'enum';
|
|
634
|
+
validator: (val: string) => T;
|
|
635
|
+
};
|
|
432
636
|
/**
|
|
433
|
-
*
|
|
637
|
+
* JSON 스키마 헬퍼
|
|
434
638
|
*
|
|
435
|
-
* @
|
|
436
|
-
*
|
|
437
|
-
*
|
|
639
|
+
* @example
|
|
640
|
+
* ```typescript
|
|
641
|
+
* const schema = {
|
|
642
|
+
* CONFIG_JSON: {
|
|
643
|
+
* ...envJson<{ host: string; port: number }>({
|
|
644
|
+
* description: 'JSON configuration object',
|
|
645
|
+
* required: true,
|
|
646
|
+
* }),
|
|
647
|
+
* key: 'CONFIG_JSON',
|
|
648
|
+
* }
|
|
649
|
+
* };
|
|
650
|
+
* ```
|
|
651
|
+
*/
|
|
652
|
+
declare function envJson<T = any, O extends Omit<EnvVarSchema<T>, 'key' | 'type' | 'validator'> = Omit<EnvVarSchema<T>, 'key' | 'type' | 'validator'>>(options: O): O & {
|
|
653
|
+
type: 'json';
|
|
654
|
+
validator: (val: string) => T;
|
|
655
|
+
};
|
|
656
|
+
/**
|
|
657
|
+
* 환경변수가 클라이언트에서 접근 가능한지 확인
|
|
658
|
+
* (NEXT_PUBLIC_ 접두사로 판단)
|
|
659
|
+
*
|
|
660
|
+
* @param key - 환경변수 키
|
|
661
|
+
* @returns 클라이언트에서 접근 가능하면 true
|
|
438
662
|
*
|
|
439
663
|
* @example
|
|
440
664
|
* ```typescript
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
* });
|
|
665
|
+
* isClientAccessible('NEXT_PUBLIC_API_URL'); // true
|
|
666
|
+
* isClientAccessible('DATABASE_URL'); // false
|
|
444
667
|
* ```
|
|
445
668
|
*/
|
|
446
|
-
declare function
|
|
669
|
+
declare function isClientAccessible(key: string): boolean;
|
|
447
670
|
/**
|
|
448
|
-
*
|
|
671
|
+
* 환경변수가 서버 전용인지 확인
|
|
672
|
+
* (NEXT_PUBLIC_ 접두사가 없으면 서버 전용)
|
|
449
673
|
*
|
|
450
|
-
* @param
|
|
451
|
-
* @returns
|
|
674
|
+
* @param key - 환경변수 키
|
|
675
|
+
* @returns 서버 전용이면 true
|
|
452
676
|
*
|
|
453
677
|
* @example
|
|
454
678
|
* ```typescript
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
* validationError: 'DB_PASSWORD must be at least 8 characters',
|
|
458
|
-
* });
|
|
679
|
+
* isServerOnly('DATABASE_URL'); // true
|
|
680
|
+
* isServerOnly('NEXT_PUBLIC_API_URL'); // false
|
|
459
681
|
* ```
|
|
460
682
|
*/
|
|
461
|
-
declare function
|
|
683
|
+
declare function isServerOnly(key: string): boolean;
|
|
462
684
|
/**
|
|
463
|
-
*
|
|
685
|
+
* 스키마의 nextjs 옵션 값 결정
|
|
464
686
|
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
687
|
+
* 명시적으로 지정되지 않은 경우:
|
|
688
|
+
* - NEXT_PUBLIC_* → true
|
|
689
|
+
* - 그 외 → false
|
|
690
|
+
*
|
|
691
|
+
* @param schema - 환경변수 스키마
|
|
692
|
+
* @returns Next.js 프로세스에서 사용 가능 여부
|
|
693
|
+
*/
|
|
694
|
+
declare function isNextjsAccessible(schema: EnvVarSchema): boolean;
|
|
695
|
+
/**
|
|
696
|
+
* 스키마가 SPFN 서버 전용인지 확인
|
|
697
|
+
*
|
|
698
|
+
* @param schema - 환경변수 스키마
|
|
699
|
+
* @returns SPFN 서버에서만 사용되면 true
|
|
700
|
+
*/
|
|
701
|
+
declare function isSpfnServerOnly(schema: EnvVarSchema): boolean;
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* Environment Variable Registry
|
|
705
|
+
*
|
|
706
|
+
* 환경변수 스키마를 등록하고 타입 안전하게 접근할 수 있는 레지스트리
|
|
467
707
|
*
|
|
468
708
|
* @example
|
|
469
709
|
* ```typescript
|
|
470
|
-
* const
|
|
471
|
-
*
|
|
472
|
-
* validateNotEmpty,
|
|
473
|
-
* createNumberValidator({ min: 1, max: 65535, integer: true }),
|
|
474
|
-
* ]),
|
|
710
|
+
* const schema = defineEnvSchema({
|
|
711
|
+
* DATABASE_URL: envString({ description: 'Database URL', required: true })
|
|
475
712
|
* });
|
|
713
|
+
*
|
|
714
|
+
* const registry = createEnvRegistry(schema);
|
|
715
|
+
* const env = registry.validate(); // 검증 + env 반환
|
|
716
|
+
* console.log(env.DATABASE_URL);
|
|
476
717
|
* ```
|
|
718
|
+
*
|
|
719
|
+
* @module env/registry
|
|
477
720
|
*/
|
|
478
|
-
|
|
721
|
+
|
|
479
722
|
/**
|
|
480
|
-
*
|
|
723
|
+
* 환경변수 레지스트리
|
|
481
724
|
*
|
|
482
|
-
*
|
|
483
|
-
|
|
725
|
+
* 스키마 기반 환경변수 관리 및 검증
|
|
726
|
+
*/
|
|
727
|
+
declare class EnvRegistry<T extends EnvSchemaCollection = EnvSchemaCollection> {
|
|
728
|
+
private schemas;
|
|
729
|
+
private hasValidated;
|
|
730
|
+
constructor(schemas?: T);
|
|
731
|
+
/**
|
|
732
|
+
* 스키마 등록
|
|
733
|
+
*/
|
|
734
|
+
register(schema: EnvVarSchema): void;
|
|
735
|
+
/**
|
|
736
|
+
* 여러 스키마 등록
|
|
737
|
+
*/
|
|
738
|
+
registerMultiple(schemas: EnvSchemaCollection): void;
|
|
739
|
+
/**
|
|
740
|
+
* 검증 상태 리셋 (테스트용)
|
|
741
|
+
*/
|
|
742
|
+
reset(): void;
|
|
743
|
+
/**
|
|
744
|
+
* 환경변수 원시값 가져오기 (fallback 지원)
|
|
745
|
+
*/
|
|
746
|
+
private getRawValue;
|
|
747
|
+
/**
|
|
748
|
+
* 값에 validator 적용
|
|
749
|
+
*/
|
|
750
|
+
private applyValidator;
|
|
751
|
+
/**
|
|
752
|
+
* 스키마 검증 수행 (값 읽기 없이)
|
|
753
|
+
*
|
|
754
|
+
* @internal
|
|
755
|
+
*/
|
|
756
|
+
private validateSchemas;
|
|
757
|
+
/**
|
|
758
|
+
* SKIP_ENV_VALIDATION 환경변수 확인
|
|
759
|
+
*/
|
|
760
|
+
private shouldSkipValidation;
|
|
761
|
+
/**
|
|
762
|
+
* 실제 접근 시점에 환경변수 값 가져오기 및 검증
|
|
763
|
+
*
|
|
764
|
+
* @internal
|
|
765
|
+
*/
|
|
766
|
+
private getAndValidate;
|
|
767
|
+
/**
|
|
768
|
+
* 모든 환경변수를 명시적으로 검증 (SKIP_ENV_VALIDATION 무시)
|
|
769
|
+
*
|
|
770
|
+
* CLI에서 사용하기 위한 메서드로, 모든 required 환경변수를 강제 검증합니다.
|
|
771
|
+
*
|
|
772
|
+
* @returns 검증 결과 (errors, warnings)
|
|
773
|
+
*/
|
|
774
|
+
validateAll(): {
|
|
775
|
+
errors: Array<{
|
|
776
|
+
key: string;
|
|
777
|
+
message: string;
|
|
778
|
+
}>;
|
|
779
|
+
warnings: Array<{
|
|
780
|
+
key: string;
|
|
781
|
+
message: string;
|
|
782
|
+
}>;
|
|
783
|
+
};
|
|
784
|
+
/**
|
|
785
|
+
* 환경변수 검증 및 타입 안전한 env 객체 반환
|
|
786
|
+
*
|
|
787
|
+
* Proxy 기반으로 구현되어 실제 환경변수 접근 시점에 값을 읽고 검증합니다.
|
|
788
|
+
* 이를 통해 dotenv 로딩 타이밍과 무관하게 최신 환경변수 값을 가져올 수 있습니다.
|
|
789
|
+
*
|
|
790
|
+
* @returns 검증된 환경변수 객체 (Proxy)
|
|
791
|
+
* @throws {Error} 필수 변수 누락 또는 검증 실패 시
|
|
792
|
+
*
|
|
793
|
+
* @example
|
|
794
|
+
* ```typescript
|
|
795
|
+
* const registry = createEnvRegistry(schema);
|
|
796
|
+
* const env = registry.validate(); // 스키마만 검증
|
|
797
|
+
* // ... dotenv 로딩 ...
|
|
798
|
+
* console.log(env.DATABASE_URL); // 이 시점에 실제 값 읽기
|
|
799
|
+
* ```
|
|
800
|
+
*/
|
|
801
|
+
validate(): InferEnvType<T>;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* 환경변수 검증 결과
|
|
805
|
+
*/
|
|
806
|
+
interface EnvValidationResult {
|
|
807
|
+
valid: boolean;
|
|
808
|
+
errors: Array<{
|
|
809
|
+
key: string;
|
|
810
|
+
message: string;
|
|
811
|
+
}>;
|
|
812
|
+
warnings: Array<{
|
|
813
|
+
key: string;
|
|
814
|
+
message: string;
|
|
815
|
+
}>;
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* 레지스트리 생성 헬퍼
|
|
484
819
|
*
|
|
485
820
|
* @example
|
|
486
821
|
* ```typescript
|
|
487
|
-
* const
|
|
488
|
-
*
|
|
822
|
+
* const schema = defineEnvSchema({
|
|
823
|
+
* DATABASE_URL: envString({ description: 'Database URL', required: true })
|
|
489
824
|
* });
|
|
825
|
+
*
|
|
826
|
+
* const registry = createEnvRegistry(schema);
|
|
827
|
+
* const env = registry.validate();
|
|
490
828
|
* ```
|
|
491
829
|
*/
|
|
492
|
-
declare function
|
|
830
|
+
declare function createEnvRegistry<T extends EnvSchemaCollection>(schemas: T): EnvRegistry<T>;
|
|
493
831
|
/**
|
|
494
|
-
*
|
|
832
|
+
* 모든 환경변수를 명시적으로 검증 (SKIP_ENV_VALIDATION 무시)
|
|
833
|
+
*
|
|
834
|
+
* CLI `spfn env validate` 명령어에서 사용
|
|
495
835
|
*
|
|
496
|
-
* @param
|
|
497
|
-
* @returns
|
|
836
|
+
* @param registries - 검증할 레지스트리 배열
|
|
837
|
+
* @returns 검증 결과
|
|
498
838
|
*
|
|
499
839
|
* @example
|
|
500
840
|
* ```typescript
|
|
501
|
-
* const
|
|
502
|
-
*
|
|
503
|
-
*
|
|
841
|
+
* const result = validateAllEnv([coreRegistry, authRegistry]);
|
|
842
|
+
* if (!result.valid) {
|
|
843
|
+
* console.error('Missing env vars:', result.errors);
|
|
844
|
+
* process.exit(1);
|
|
845
|
+
* }
|
|
504
846
|
* ```
|
|
505
847
|
*/
|
|
506
|
-
declare function
|
|
848
|
+
declare function validateAllEnv(registries: EnvRegistry<any>[]): EnvValidationResult;
|
|
849
|
+
|
|
850
|
+
/**
|
|
851
|
+
* Environment Types
|
|
852
|
+
*/
|
|
853
|
+
/**
|
|
854
|
+
* Node.js environment types
|
|
855
|
+
*/
|
|
856
|
+
type NodeEnv = 'local' | 'development' | 'staging' | 'production' | 'test';
|
|
507
857
|
|
|
508
|
-
export {
|
|
858
|
+
export { EnvRegistry, type EnvSchemaCollection, type EnvValidationResult, type EnvVarSchema, type InferEnvType, type NodeEnv, type Parser, chain, createArrayParser, createEnumParser, createEnvRegistry, createJsonParser, createNumberParser, createPasswordParser, createSecureSecretParser, createStringParser, createUrlParser, defineEnvSchema, envBoolean, envEnum, envJson, envNumber, envString, envUrl, isClientAccessible, isNextjsAccessible, isServerOnly, isSpfnServerOnly, optional, parseArray, parseBoolean, parseDecimal, parseEnum, parseInteger, parseJson, parseNumber, parsePostgresUrl, parseRedisUrl, parseString, parseUrl, validateAllEnv, withFallback };
|