commit 2 refactor

This commit is contained in:
Boki 2026-10-20 14:35:45 -04:00
parent 588f666943
commit 32e43c9243
310 changed files with 33318 additions and 31189 deletions

View file

@ -83,21 +83,21 @@ export function isSecret(value: unknown): value is SecretValue {
/**
* Redact secrets from an object
*/
export function redactSecrets<T extends Record<string, any>>(
export function redactSecrets<T extends Record<string, unknown>>(
obj: T,
secretPaths: string[] = []
): T {
const result = { ...obj };
const result = redactSecretValues(obj) as T;
// Redact known secret paths
for (const path of secretPaths) {
const keys = path.split('.');
let current: any = result;
let current: Record<string, unknown> = result;
for (let i = 0; i < keys.length - 1; i++) {
const key = keys[i];
if (key && current[key] && typeof current[key] === 'object') {
current = current[key];
current = current[key] as Record<string, unknown>;
} else {
break;
}
@ -110,7 +110,7 @@ export function redactSecrets<T extends Record<string, any>>(
}
// Recursively redact SecretValue instances
function redactSecretValues(obj: any): any {
function redactSecretValues(obj: unknown): unknown {
if (obj === null || obj === undefined) {
return obj;
}
@ -124,7 +124,7 @@ export function redactSecrets<T extends Record<string, any>>(
}
if (typeof obj === 'object') {
const result: any = {};
const result: Record<string, unknown> = {};
for (const [key, value] of Object.entries(obj)) {
result[key] = redactSecretValues(value);
}
@ -134,7 +134,7 @@ export function redactSecrets<T extends Record<string, any>>(
return obj;
}
return redactSecretValues(result);
return result;
}
/**

View file

@ -1,4 +1,5 @@
import { z } from 'zod';
import { defined } from '@stock-bot/invariants';
export interface ValidationResult {
valid: boolean;
@ -62,19 +63,19 @@ export function checkRequiredEnvVars(required: string[]): ValidationResult {
* Validate configuration completeness
*/
export function validateCompleteness(
config: Record<string, any>,
config: Record<string, unknown>,
required: string[]
): ValidationResult {
const errors: ValidationResult['errors'] = [];
for (const path of required) {
const keys = path.split('.');
let current: any = config;
let current: unknown = config;
let found = true;
for (const key of keys) {
if (current && typeof current === 'object' && key in current) {
current = current[key];
current = (current as Record<string, unknown>)[key];
} else {
found = false;
break;
@ -144,11 +145,11 @@ export function mergeSchemas<T extends z.ZodSchema[]>(
throw new Error('At least two schemas required for merge');
}
let result = schemas[0]!.and(schemas[1]!);
let result: z.ZodTypeAny = defined(schemas[0]).and(defined(schemas[1]));
for (let i = 2; i < schemas.length; i++) {
result = result.and(schemas[i]!) as any;
result = result.and(defined(schemas[i]));
}
return result as any;
return result as z.ZodIntersection<T[0], T[1]>;
}