fix: replace any types in logger and utilities (14 errors)

Phase 1 Batch 2: Logger & Simple Utilities

Replaced any types with proper TypeScript types across 3 files:

- logger.ts: Created LogContext type, added RequestEvent import from SvelteKit
  - Defined LogContext = Record<string, string | number | boolean | null | undefined>
  - Changed all context parameters from Record<string, any> to LogContext
  - Changed event parameter in createRequestLogger from any to RequestEvent

- extractEmbeds.ts: Used TiptapNode type from editor.ts
  - Changed content and node parameters from any to TiptapNode

- global.d.ts: Improved SVG module declarations
  - Changed *.svg from any to string (raw SVG content)
  - Changed *.svg?component from any to Component<any> (Svelte component)

Progress: 199 → 185 errors (91 → 77 any-type errors)
This commit is contained in:
Justin Edmund 2025-11-24 01:55:25 -08:00
parent 4212ec0f6f
commit 9da0232d45
3 changed files with 21 additions and 15 deletions

5
src/global.d.ts vendored
View file

@ -1,10 +1,11 @@
declare module '*.svg' {
const content: any
const content: string
export default content
}
declare module '*.svg?component' {
const content: any
import type { Component } from 'svelte'
const content: Component
export default content
}

View file

@ -1,13 +1,17 @@
import { dev } from '$app/environment'
import type { RequestEvent } from '@sveltejs/kit'
export type LogLevel = 'debug' | 'info' | 'warn' | 'error'
export type LogCategory = 'music' | 'api' | 'db' | 'media' | 'general'
// LogContext supports common log data types
export type LogContext = Record<string, string | number | boolean | null | undefined>
interface LogEntry {
level: LogLevel
message: string
timestamp: string
context?: Record<string, any>
context?: LogContext
error?: Error
category?: LogCategory
}
@ -67,7 +71,7 @@ class Logger {
private log(
level: LogLevel,
message: string,
context?: Record<string, any>,
context?: LogContext,
error?: Error,
category?: LogCategory
) {
@ -98,29 +102,29 @@ class Logger {
}
}
debug(message: string, context?: Record<string, any>, category?: LogCategory) {
debug(message: string, context?: LogContext, category?: LogCategory) {
this.log('debug', message, context, undefined, category)
}
info(message: string, context?: Record<string, any>, category?: LogCategory) {
info(message: string, context?: LogContext, category?: LogCategory) {
this.log('info', message, context, undefined, category)
}
warn(message: string, context?: Record<string, any>, category?: LogCategory) {
warn(message: string, context?: LogContext, category?: LogCategory) {
this.log('warn', message, context, undefined, category)
}
error(message: string, error?: Error, context?: Record<string, any>, category?: LogCategory) {
error(message: string, error?: Error, context?: LogContext, category?: LogCategory) {
this.log('error', message, context, error, category)
}
// Convenience method for music-related logs
music(level: LogLevel, message: string, context?: Record<string, any>) {
music(level: LogLevel, message: string, context?: LogContext) {
this.log(level, message, context, undefined, 'music')
}
// Log API requests
apiRequest(method: string, path: string, context?: Record<string, any>) {
apiRequest(method: string, path: string, context?: LogContext) {
this.info(`API Request: ${method} ${path}`, context)
}
@ -134,7 +138,7 @@ class Logger {
}
// Log database operations
dbQuery(operation: string, model: string, duration?: number, context?: Record<string, any>) {
dbQuery(operation: string, model: string, duration?: number, context?: LogContext) {
this.debug(`DB Query: ${operation} on ${model}`, {
...context,
duration: duration ? `${duration}ms` : undefined
@ -156,13 +160,12 @@ export const logger = new Logger()
// Middleware to log API requests
export function createRequestLogger() {
return (event: any) => {
return (event: RequestEvent) => {
const start = Date.now()
const { method, url } = event.request
const path = new URL(url).pathname
logger.apiRequest(method, path, {
headers: Object.fromEntries(event.request.headers),
ip: event.getClientAddress()
})

View file

@ -1,3 +1,5 @@
import type { TiptapNode } from '$lib/types/editor'
// Extract URL embeds from Tiptap content
export interface ExtractedEmbed {
type: 'urlEmbed' | 'youtube'
@ -10,7 +12,7 @@ export interface ExtractedEmbed {
videoId?: string
}
export function extractEmbeds(content: any): ExtractedEmbed[] {
export function extractEmbeds(content: TiptapNode): ExtractedEmbed[] {
if (!content || !content.content) return []
const embeds: ExtractedEmbed[] = []
@ -32,7 +34,7 @@ export function extractEmbeds(content: any): ExtractedEmbed[] {
}
// Recursive function to find embed nodes
const findEmbeds = (node: any) => {
const findEmbeds = (node: TiptapNode) => {
if (node.type === 'urlEmbed' && node.attrs?.url) {
const url = node.attrs.url
const isYouTube = /(?:youtube\.com|youtu\.be)/.test(url)