Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

serverSettings.ts

40 lines1.3 KB

1import { ServerSettings } from "@t3tools/contracts";
2import { Schema } from "effect";
3import { fromLenientJson } from "./schemaJson";
4​
5const ServerSettingsJson = fromLenientJson(ServerSettings);
6​
7export interface PersistedServerObservabilitySettings {
8 readonly otlpTracesUrl: string | undefined;
9 readonly otlpMetricsUrl: string | undefined;
11​
12export function normalizePersistedServerSettingString(
13 value: string | null | undefined,
14): string | undefined {
15 const trimmed = value?.trim();
16 return trimmed && trimmed.length > 0 ? trimmed : undefined;
18​
19export function extractPersistedServerObservabilitySettings(input: {
20 readonly observability?: {
21 readonly otlpTracesUrl?: string;
22 readonly otlpMetricsUrl?: string;
23 };
24}): PersistedServerObservabilitySettings {
25 return {
26 otlpTracesUrl: normalizePersistedServerSettingString(input.observability?.otlpTracesUrl),
27 otlpMetricsUrl: normalizePersistedServerSettingString(input.observability?.otlpMetricsUrl),
28 };
30​
31export function parsePersistedServerObservabilitySettings(
32 raw: string,
33): PersistedServerObservabilitySettings {
34 try {
35 const decoded = Schema.decodeUnknownSync(ServerSettingsJson)(raw);
36 return extractPersistedServerObservabilitySettings(decoded);
37 } catch {
38 return { otlpTracesUrl: undefined, otlpMetricsUrl: undefined };
39 }