@morojs/moro 1.5.5 → 1.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/config/config-manager.d.ts +44 -0
- package/dist/core/config/config-manager.js +114 -0
- package/dist/core/config/config-manager.js.map +1 -0
- package/dist/core/config/config-sources.d.ts +21 -0
- package/dist/core/config/config-sources.js +314 -0
- package/dist/core/config/config-sources.js.map +1 -0
- package/dist/core/config/config-validator.d.ts +21 -0
- package/dist/core/config/config-validator.js +737 -0
- package/dist/core/config/config-validator.js.map +1 -0
- package/dist/core/config/file-loader.d.ts +0 -5
- package/dist/core/config/file-loader.js +0 -171
- package/dist/core/config/file-loader.js.map +1 -1
- package/dist/core/config/index.d.ts +39 -10
- package/dist/core/config/index.js +66 -29
- package/dist/core/config/index.js.map +1 -1
- package/dist/core/config/schema.js +22 -31
- package/dist/core/config/schema.js.map +1 -1
- package/dist/core/config/utils.d.ts +9 -2
- package/dist/core/config/utils.js +19 -32
- package/dist/core/config/utils.js.map +1 -1
- package/dist/core/framework.d.ts +2 -7
- package/dist/core/framework.js +12 -5
- package/dist/core/framework.js.map +1 -1
- package/dist/core/http/http-server.d.ts +12 -0
- package/dist/core/http/http-server.js +56 -0
- package/dist/core/http/http-server.js.map +1 -1
- package/dist/core/http/router.d.ts +12 -0
- package/dist/core/http/router.js +114 -36
- package/dist/core/http/router.js.map +1 -1
- package/dist/core/logger/index.d.ts +1 -1
- package/dist/core/logger/index.js +2 -1
- package/dist/core/logger/index.js.map +1 -1
- package/dist/core/logger/logger.d.ts +9 -1
- package/dist/core/logger/logger.js +36 -3
- package/dist/core/logger/logger.js.map +1 -1
- package/dist/core/routing/index.d.ts +20 -0
- package/dist/core/routing/index.js +109 -11
- package/dist/core/routing/index.js.map +1 -1
- package/dist/moro.d.ts +7 -20
- package/dist/moro.js +97 -192
- package/dist/moro.js.map +1 -1
- package/dist/types/config.d.ts +39 -2
- package/dist/types/core.d.ts +22 -39
- package/dist/types/logger.d.ts +4 -0
- package/package.json +1 -1
- package/src/core/config/config-manager.ts +133 -0
- package/src/core/config/config-sources.ts +384 -0
- package/src/core/config/config-validator.ts +1035 -0
- package/src/core/config/file-loader.ts +0 -233
- package/src/core/config/index.ts +77 -32
- package/src/core/config/schema.ts +22 -31
- package/src/core/config/utils.ts +22 -29
- package/src/core/framework.ts +18 -11
- package/src/core/http/http-server.ts +66 -0
- package/src/core/http/router.ts +127 -38
- package/src/core/logger/index.ts +1 -0
- package/src/core/logger/logger.ts +43 -4
- package/src/core/routing/index.ts +116 -12
- package/src/moro.ts +105 -225
- package/src/types/config.ts +40 -2
- package/src/types/core.ts +32 -43
- package/src/types/logger.ts +6 -0
- package/dist/core/config/loader.d.ts +0 -7
- package/dist/core/config/loader.js +0 -269
- package/dist/core/config/loader.js.map +0 -1
- package/dist/core/config/validation.d.ts +0 -17
- package/dist/core/config/validation.js +0 -131
- package/dist/core/config/validation.js.map +0 -1
- package/src/core/config/loader.ts +0 -633
- package/src/core/config/validation.ts +0 -140
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
// Configuration Validation Functions
|
|
2
|
-
// Validation for config system with simple TypeScript functions
|
|
3
|
-
|
|
4
|
-
export class ConfigValidationError extends Error {
|
|
5
|
-
constructor(
|
|
6
|
-
public field: string,
|
|
7
|
-
public value: unknown,
|
|
8
|
-
message: string
|
|
9
|
-
) {
|
|
10
|
-
super(`Configuration validation failed for '${field}': ${message}`);
|
|
11
|
-
this.name = 'ConfigValidationError';
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Type-safe validation functions for configuration
|
|
16
|
-
export function validatePort(value: unknown, field = 'port'): number {
|
|
17
|
-
const num = Number(value);
|
|
18
|
-
if (isNaN(num) || num < 1 || num > 65535) {
|
|
19
|
-
throw new ConfigValidationError(field, value, 'Must be a number between 1 and 65535');
|
|
20
|
-
}
|
|
21
|
-
return num;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function validateBoolean(value: unknown, field = 'boolean'): boolean {
|
|
25
|
-
if (value === 'true' || value === true) return true;
|
|
26
|
-
if (value === 'false' || value === false) return false;
|
|
27
|
-
if (value === '1' || value === 1) return true;
|
|
28
|
-
if (value === '0' || value === 0) return false;
|
|
29
|
-
throw new ConfigValidationError(field, value, 'Must be a boolean (true/false) or numeric (1/0)');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function validateNumber(
|
|
33
|
-
value: unknown,
|
|
34
|
-
field = 'number',
|
|
35
|
-
options: { min?: number; max?: number } = {}
|
|
36
|
-
): number {
|
|
37
|
-
const num = Number(value);
|
|
38
|
-
if (isNaN(num)) {
|
|
39
|
-
throw new ConfigValidationError(field, value, 'Must be a valid number');
|
|
40
|
-
}
|
|
41
|
-
if (options.min !== undefined && num < options.min) {
|
|
42
|
-
throw new ConfigValidationError(field, value, `Must be at least ${options.min}`);
|
|
43
|
-
}
|
|
44
|
-
if (options.max !== undefined && num > options.max) {
|
|
45
|
-
throw new ConfigValidationError(field, value, `Must be at most ${options.max}`);
|
|
46
|
-
}
|
|
47
|
-
return num;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function validateString(value: unknown, field = 'string'): string {
|
|
51
|
-
if (typeof value !== 'string') {
|
|
52
|
-
throw new ConfigValidationError(field, value, 'Must be a string');
|
|
53
|
-
}
|
|
54
|
-
return value;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function validateUrl(value: unknown, field = 'url'): string {
|
|
58
|
-
const str = validateString(value, field);
|
|
59
|
-
try {
|
|
60
|
-
new URL(str);
|
|
61
|
-
return str;
|
|
62
|
-
} catch {
|
|
63
|
-
throw new ConfigValidationError(field, value, 'Must be a valid URL');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function validateEnum<T extends string>(
|
|
68
|
-
value: unknown,
|
|
69
|
-
validValues: readonly T[],
|
|
70
|
-
field = 'enum'
|
|
71
|
-
): T {
|
|
72
|
-
const str = validateString(value, field);
|
|
73
|
-
if (!validValues.includes(str as T)) {
|
|
74
|
-
throw new ConfigValidationError(field, value, `Must be one of: ${validValues.join(', ')}`);
|
|
75
|
-
}
|
|
76
|
-
return str as T;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function validateStringArray(value: unknown, field = 'string array'): string[] {
|
|
80
|
-
if (!Array.isArray(value)) {
|
|
81
|
-
// Try to parse comma-separated string
|
|
82
|
-
if (typeof value === 'string') {
|
|
83
|
-
return value
|
|
84
|
-
.split(',')
|
|
85
|
-
.map(s => s.trim())
|
|
86
|
-
.filter(s => s.length > 0);
|
|
87
|
-
}
|
|
88
|
-
throw new ConfigValidationError(field, value, 'Must be an array or comma-separated string');
|
|
89
|
-
}
|
|
90
|
-
return value.map((item, index) => validateString(item, `${field}[${index}]`));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function validateOptional<T>(
|
|
94
|
-
value: unknown,
|
|
95
|
-
validator: (value: unknown, field: string) => T,
|
|
96
|
-
field: string
|
|
97
|
-
): T | undefined {
|
|
98
|
-
if (value === undefined || value === null || value === '') {
|
|
99
|
-
return undefined;
|
|
100
|
-
}
|
|
101
|
-
return validator(value, field);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Coercion helpers for environment variables
|
|
105
|
-
export function coerceEnvValue(value: string): unknown {
|
|
106
|
-
// Handle common patterns in environment variables
|
|
107
|
-
|
|
108
|
-
// Null/undefined
|
|
109
|
-
if (value === '' || value === 'null' || value === 'undefined') {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Boolean
|
|
114
|
-
if (value === 'true' || value === 'false') {
|
|
115
|
-
return value === 'true';
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Number (but not if it starts with 0 - could be port, zip code, etc.)
|
|
119
|
-
if (/^-?\d+(\.\d+)?$/.test(value) && !value.startsWith('0')) {
|
|
120
|
-
const num = Number(value);
|
|
121
|
-
if (!isNaN(num)) {
|
|
122
|
-
return num;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// JSON (for complex objects/arrays)
|
|
127
|
-
if (
|
|
128
|
-
(value.startsWith('{') && value.endsWith('}')) ||
|
|
129
|
-
(value.startsWith('[') && value.endsWith(']'))
|
|
130
|
-
) {
|
|
131
|
-
try {
|
|
132
|
-
return JSON.parse(value);
|
|
133
|
-
} catch {
|
|
134
|
-
// Not valid JSON, treat as string
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Return as string for all other cases
|
|
139
|
-
return value;
|
|
140
|
-
}
|