All files / realm/blong-access/adapter/db account.ts

100% Statements 33/33
83.33% Branches 5/6
100% Functions 4/4
100% Lines 33/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 341x 1x 1x 1x 593x 593x 1x 1x 1x 58x 58x 58x 58x 1x 1x 1x 42x 42x 1x 1x 1x 153x 153x 153x 153x 153x 1x 1x 1x 1x 1x 1x 1x  
import crypto from 'node:crypto';
 
/** Convert a UUID string to a BINARY(16) Buffer for MySQL. */
export function uuidBuf(uuid: string): Buffer {
    return Buffer.from(uuid.replace(/-/g, ''), 'hex');
}
 
/** Read a BINARY(16) value from MySQL and return a hex string. */
export function bufToUuid(buf: Buffer | string): string {
    if (typeof buf === 'string') return buf;
    const hex = buf.toString('hex');
    return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
}
 
/** Generate a random UUID v4 string. */
export function newUuid(): string {
    return crypto.randomUUID();
}
 
/** Split a comma-separated string of names, trimming whitespace and filtering empty entries. */
export function splitNames(value: string): string[] {
    return value
        .split(',')
        .map(s => s.trim())
        .filter(Boolean);
}
 
/**
 * Shared account/credential helpers for the access realm — UUID conversion and
 * role-name splitting.  Imported directly by the `access.db` handlers (plain
 * module, not a handler itself).  Password hashing lives in `password.ts`
 * (config-driven library).
 */