UNPKG

@rbac/rbac

Version:

Blazing Fast, Zero dependency, Hierarchical Role-Based Access Control for Node.js

26 lines (25 loc) 895 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.rolesSchema = exports.roleSchema = exports.roleOperationSchema = exports.whenSchema = void 0; const zod_1 = require("zod"); // Schema to validate the `when` property of a role operation exports.whenSchema = zod_1.z.union([ zod_1.z.boolean(), zod_1.z.promise(zod_1.z.boolean()), zod_1.z.function(), ]); // Schema for items in the `can` array exports.roleOperationSchema = zod_1.z.union([ zod_1.z.string(), zod_1.z.object({ name: zod_1.z.string(), when: exports.whenSchema, }), ]); // Schema for a single role definition exports.roleSchema = zod_1.z.object({ can: zod_1.z.array(exports.roleOperationSchema), inherits: zod_1.z.array(zod_1.z.string()).optional(), }); // Schema for the object with all roles exports.rolesSchema = zod_1.z.record(exports.roleSchema);