refactor: bare structure for new backend architecture and runtime; no behavior changes yet

This commit is contained in:
Haileyesus
2026-03-12 14:17:12 +03:00
parent b54cdf8168
commit e67738c9fc
40 changed files with 10316 additions and 9 deletions

View File

@@ -0,0 +1,19 @@
export type AppErrorOptions = {
code?: string;
statusCode?: number;
details?: unknown;
};
export class AppError extends Error {
readonly code: string;
readonly statusCode: number;
readonly details?: unknown;
constructor(message: string, options: AppErrorOptions = {}) {
super(message);
this.name = 'AppError';
this.code = options.code ?? 'INTERNAL_ERROR';
this.statusCode = options.statusCode ?? 500;
this.details = options.details;
}
}

View File

@@ -0,0 +1,32 @@
type LoggerLevel = 'info' | 'warn' | 'error';
function formatMetadata(metadata?: Record<string, unknown>): string {
if (!metadata || Object.keys(metadata).length === 0) {
return '';
}
return ` ${JSON.stringify(metadata)}`;
}
function write(level: LoggerLevel, message: string, metadata?: Record<string, unknown>): void {
const prefix = `[server:${level}]`;
const formatted = `${prefix} ${message}${formatMetadata(metadata)}`;
if (level === 'error') {
console.error(formatted);
return;
}
if (level === 'warn') {
console.warn(formatted);
return;
}
console.log(formatted);
}
export const logger = {
info: (message: string, metadata?: Record<string, unknown>) => write('info', message, metadata),
warn: (message: string, metadata?: Record<string, unknown>) => write('warn', message, metadata),
error: (message: string, metadata?: Record<string, unknown>) => write('error', message, metadata),
};