// ───────────────────────────────────────────── // Type guards de primitivos // ───────────────────────────────────────────── import type {CurrencyValue, MediaRef, MetadataField, MetadataFieldType} from "@/mtas/lib/types.ts"; export function isCurrencyValue(v: unknown): v is CurrencyValue { if (typeof v !== 'object' || v === null) return false; const c = v as Record; return typeof c['amount'] === 'number' && typeof c['currency'] === 'string' && c['currency'].length > 0; } export function isMediaRef(v: unknown): v is MediaRef { if (typeof v !== 'object' || v === null) return false; const m = v as Record; return typeof m['url'] === 'string' && m['url'].length > 0; } export function isValidUrl(value: string): boolean { try { new URL(value); return true; } catch { return false; } } const KNOWN_TYPES: MetadataFieldType[] = [ 'string','number','boolean','ling','date','datetime', 'url','currency','image','video','audio','pdf','file','group', ]; export function isMetadataField(v: unknown): v is MetadataField { if (typeof v !== 'object' || v === null) return false; const f = v as Record; return KNOWN_TYPES.includes(f['type'] as MetadataFieldType); }