You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte-kit-vice/src/arts/sium/diagnostics.ts

73 lines
1.9 KiB

import {
LogLevel,
createCatalogDiagnostics,
type DiagnosticCatalog,
type DiagnosticEvent,
type Diagnostics,
type Logger
} from '$libs/logger';
import { SIUM_MODULE, SIUM_DIAGNOSTIC_EVENTS, SIUM_LOG_MSG_VALIDATION_FAILED } from './consts';
import { SIUM_LOG_MSG_RESOLVE_FALLBACK } from './errors';
import type { Issue } from './core';
export type SiumDiagnosticType =
(typeof SIUM_DIAGNOSTIC_EVENTS)[keyof typeof SIUM_DIAGNOSTIC_EVENTS];
export interface SiumDiagnosticMeta {
readonly message?: string;
readonly error?: unknown;
readonly issueCount?: number;
readonly issues?: ReadonlyArray<{
readonly path: ReadonlyArray<string | number>;
readonly code: string;
readonly message: string;
readonly params?: Record<string, unknown>;
}>;
}
export type SiumDiagnosticEvent = DiagnosticEvent<SiumDiagnosticType, SiumDiagnosticMeta>;
export type SiumDiagnostics = Diagnostics<SiumDiagnosticEvent>;
const SIUM_DIAGNOSTIC_LOGS: DiagnosticCatalog<SiumDiagnosticEvent> = {
[SIUM_DIAGNOSTIC_EVENTS.VALIDATION_FAILED]: {
level: LogLevel.DEBUG,
message: SIUM_LOG_MSG_VALIDATION_FAILED
},
[SIUM_DIAGNOSTIC_EVENTS.RESOLVE_FALLBACK]: {
level: LogLevel.WARN,
message: SIUM_LOG_MSG_RESOLVE_FALLBACK
}
};
export function issueDiagnosticMeta(issues: ReadonlyArray<Issue>): SiumDiagnosticMeta {
return {
issueCount: issues.length,
issues: issues.map((entry) => ({
path: [...entry.path],
code: entry.code,
message: entry.message,
...(entry.params === undefined ? {} : { params: entry.params })
}))
};
}
export function createSiumDiagnostics(logger?: Logger): SiumDiagnostics {
return createCatalogDiagnostics({
logger,
defaultCategory: SIUM_MODULE,
catalog: SIUM_DIAGNOSTIC_LOGS
});
}
export function emitSiumDiagnostic(
diagnostics: SiumDiagnostics,
type: SiumDiagnosticType,
meta: SiumDiagnosticMeta
): void {
diagnostics.emit({
artifact: SIUM_MODULE,
type,
meta
});
}

Powered by TurnKey Linux.