UNPKG

@adonis-agora/authz-react

Version:

React/Inertia bindings for @adonis-agora/authz: AuthzProvider, useAuthz, useCan, <Can>, and a server-side buildAuthzShare() for the Inertia share.

32 lines • 1.82 kB
/** * Wildcard permission matcher — client-safe port of * `@adonis-agora/authz`'s `permission_matcher.ts`. Segment-based on `.`, * spatie/Laravel-style. Kept as a standalone copy (no server import) so the * `<Can>`/`useCan` client bundle never pulls in `@adonis-agora/authz`. * * Only the GRANTED (left) side may contain wildcards. The REQUIRED ability is * always treated literally — a check is never itself a pattern. * * Rules: * - `granted === required` → exact match. * - bare `granted === '*'` → matches anything. * - Split both on `.` and walk the granted segments: * - A trailing `*` matches ONE-OR-MORE remaining required segments. So * `posts.*` matches `posts.edit` and `posts.edit.draft`, but NOT the bare * `posts` (zero remaining segments fails). * - An interior `*` consumes exactly one required segment (fails if missing). * - A literal segment must equal the required segment exactly. * - After consuming all granted segments with no trailing-wildcard early-return, * the match holds only if both sides have the same number of segments. */ export declare function permissionMatches(granted: string, required: string): boolean; /** True when any granted pattern in the set matches the required ability. */ export declare function permissionSatisfied(granted: Iterable<string>, required: string): boolean; /** * {@link permissionSatisfied} for the hooks/components: the share's `permissions` * array is compiled once and reused by every `useCan`/`<Can>` that reads the same * array (one Inertia page = one array), so a list of N gates costs one compile plus * N hash lookups instead of N full scans with a `split` per grant. */ export declare function satisfiesShared(granted: readonly string[], required: string): boolean; //# sourceMappingURL=matcher.d.ts.map