app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

private-handles.ts (591B)


      1 // Local handles identify records; callers must separately resolve the active owner.
      2 export function canonicalLocalId(value: unknown): string | undefined {
      3   return typeof value === 'string' &&
      4     value.length === 36 &&
      5     /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(
      6       value
      7     )
      8     ? value
      9     : undefined;
     10 }
     11 
     12 // Explicit local creation only. No import/render operation creates a handle.
     13 export function newLocalId(): string | undefined {
     14   try {
     15     return canonicalLocalId(globalThis.crypto.randomUUID());
     16   } catch {
     17     return undefined;
     18   }
     19 }