40 lines · 1.3 KB · TypeScript
RawDownload
import { ServerSettings } from "@t3tools/contracts";import { Schema } from "effect";import { fromLenientJson } from "./schemaJson"; const ServerSettingsJson = fromLenientJson(ServerSettings); export interface PersistedServerObservabilitySettings {  readonly otlpTracesUrl: string | undefined;  readonly otlpMetricsUrl: string | undefined;} export function normalizePersistedServerSettingString(  value: string | null | undefined,): string | undefined {  const trimmed = value?.trim();  return trimmed && trimmed.length > 0 ? trimmed : undefined;} export function extractPersistedServerObservabilitySettings(input: {  readonly observability?: {    readonly otlpTracesUrl?: string;    readonly otlpMetricsUrl?: string;  };}): PersistedServerObservabilitySettings {  return {    otlpTracesUrl: normalizePersistedServerSettingString(input.observability?.otlpTracesUrl),    otlpMetricsUrl: normalizePersistedServerSettingString(input.observability?.otlpMetricsUrl),  };} export function parsePersistedServerObservabilitySettings(  raw: string,): PersistedServerObservabilitySettings {  try {    const decoded = Schema.decodeUnknownSync(ServerSettingsJson)(raw);    return extractPersistedServerObservabilitySettings(decoded);  } catch {    return { otlpTracesUrl: undefined, otlpMetricsUrl: undefined };  }}