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

66.66% Statements 14/21
100% Branches 1/1
0% Functions 0/1
66.66% Lines 14/21

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 221x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x               7x  
import {type IMeta, handler} from '@feasibleone/blong';
 
/** Fields joined for display by `access.acl.find` / `.get` — never persisted. */
const VIRTUAL_FIELDS = ['principalName', 'actionName', 'targetName'];
 
/**
 * `access.acl.edit` — update an ACL rule.
 *
 * The write is the generic CRUD (`super.exec`); this handler only drops the
 * virtual display fields the editor round-trips, so they never reach the table.
 */
export default handler(() => ({
    async accessAclEdit(
        params: {acl?: Record<string, unknown>} & Record<string, unknown>,
        $meta: IMeta,
    ): Promise<unknown> {
        const acl = {...(params.acl ?? {})};
        for (const field of VIRTUAL_FIELDS) delete acl[field];
        return super.exec({...params, acl}, $meta);
    },
}));