/** * src/platform/resource-ref.ts * ============================= * Canonical SIAX resource references (Master-DoD §5): * * `::[@]` * * e.g. `st0re:artifact:art_x`, `aud0:evidence:ev_x`, `0pt:dataset:ds_x`, * `0pt:dataset:ds_x@3`. No product needs another product's DB primary key; * references are stable, resolvable through the owning capability, and * authorization happens at dereference (never here — this module is pure * parsing/formatting). */ export interface SiaxResourceRef { product: string; resourceType: string; resourceId: string; version?: string; } const REF_RE = /^([a-z0-9][a-z0-9-]*):([a-z0-9][a-z0-9_-]*):([^@\s:]+)(?:@([A-Za-z0-9._-]+))?$/; /** Format a canonical reference string. */ export function formatResourceRef(ref: SiaxResourceRef): string { const base = `${ref.product}:${ref.resourceType}:${ref.resourceId}`; return ref.version ? `${base}@${ref.version}` : base; } /** Parse a canonical reference string; returns undefined when malformed. */ export function parseResourceRef(raw: string): SiaxResourceRef | undefined { const m = REF_RE.exec(raw.trim()); if (!m) return undefined; return { product: m[1], resourceType: m[2], resourceId: m[3], ...(m[4] ? { version: m[4] } : {}) }; } /** True when `raw` is a canonical reference for the given product/type. */ export function isResourceRef(raw: string, product?: string, resourceType?: string): boolean { const ref = parseResourceRef(raw); if (!ref) return false; if (product && ref.product !== product) return false; if (resourceType && ref.resourceType !== resourceType) return false; return true; }