fixed all tests
This commit is contained in:
parent
08f713d98b
commit
bd26ecf3bc
11 changed files with 457 additions and 794 deletions
|
|
@ -199,31 +199,44 @@ export class ConfigManager<T = Record<string, unknown>> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Simple deep merge without circular reference handling
|
||||
* Deep merge with circular reference handling
|
||||
*/
|
||||
private merge(...objects: Record<string, unknown>[]): Record<string, unknown> {
|
||||
const result: Record<string, unknown> = {};
|
||||
const seen = new WeakSet();
|
||||
|
||||
const mergeRecursive = (...objs: Record<string, unknown>[]): Record<string, unknown> => {
|
||||
const result: Record<string, unknown> = {};
|
||||
|
||||
for (const obj of objects) {
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
if (value === null || value === undefined) {
|
||||
result[key] = value;
|
||||
} else if (
|
||||
typeof value === 'object' &&
|
||||
!Array.isArray(value) &&
|
||||
!(value instanceof Date) &&
|
||||
!(value instanceof RegExp)
|
||||
) {
|
||||
result[key] = this.merge(
|
||||
(result[key] as Record<string, unknown>) || {},
|
||||
value as Record<string, unknown>
|
||||
);
|
||||
} else {
|
||||
result[key] = value;
|
||||
for (const obj of objs) {
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
if (value === null || value === undefined) {
|
||||
result[key] = value;
|
||||
} else if (
|
||||
typeof value === 'object' &&
|
||||
!Array.isArray(value) &&
|
||||
!(value instanceof Date) &&
|
||||
!(value instanceof RegExp)
|
||||
) {
|
||||
// Check for circular reference
|
||||
if (seen.has(value)) {
|
||||
result[key] = '[Circular]';
|
||||
continue;
|
||||
}
|
||||
seen.add(value);
|
||||
|
||||
result[key] = mergeRecursive(
|
||||
(result[key] as Record<string, unknown>) || {},
|
||||
value as Record<string, unknown>
|
||||
);
|
||||
} else {
|
||||
result[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
};
|
||||
|
||||
return mergeRecursive(...objects);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,3 +24,26 @@ export function createAppConfig<T>(
|
|||
): ConfigManager<T> {
|
||||
return new ConfigManager<T>(options);
|
||||
}
|
||||
|
||||
// Export utilities
|
||||
export {
|
||||
SecretValue,
|
||||
secret,
|
||||
isSecret,
|
||||
isSecretEnvVar,
|
||||
COMMON_SECRET_PATTERNS,
|
||||
redactSecrets,
|
||||
wrapSecretEnvVars,
|
||||
secretSchema,
|
||||
secretStringSchema
|
||||
} from './utils/secrets';
|
||||
|
||||
export {
|
||||
checkRequiredEnvVars,
|
||||
createStrictSchema,
|
||||
formatValidationResult,
|
||||
mergeSchemas,
|
||||
validateConfig,
|
||||
validateCompleteness,
|
||||
type ValidationResult
|
||||
} from './utils/validation';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue