permix
Version:
Permix is a lightweight, framework-agnostic, type-safe permissions management library for JavaScript applications on the client and server sides.
32 lines (29 loc) • 1.34 kB
text/typescript
import { Context, MiddlewareHandler } from 'hono';
import { P as PermixDefinition, C as CheckContext, e as PermixRules, h as CheckFunctionParams, a as Permix } from '../shared/permix.CuefdCK4.mjs';
import { M as MaybePromise } from '../shared/permix.BDsgFWDK.mjs';
interface MiddlewareContext {
c: Context;
}
interface PermixOptions<T extends PermixDefinition> {
/**
* Custom error handler
*/
onForbidden?: (params: CheckContext<T> & {
c: Context;
}) => MaybePromise<Response>;
}
/**
* Create a middleware function that checks permissions for Hono routes.
*
* @link https://permix.letstri.dev/docs/integrations/hono
*/
declare function createPermix<Definition extends PermixDefinition>({ onForbidden, }?: PermixOptions<Definition>): {
setupMiddleware: (callback: (context: {
c: Context;
}) => PermixRules<Definition> | Promise<PermixRules<Definition>>) => MiddlewareHandler;
checkMiddleware: <K extends keyof Definition>(...params: CheckFunctionParams<Definition, K>) => MiddlewareHandler;
template: <T = void>(rules: PermixRules<Definition> | ((param: T) => PermixRules<Definition>)) => (param: T) => PermixRules<Definition>;
get: (c: Context) => Pick<Permix<Definition>, "check" | "dehydrate">;
};
export { createPermix };
export type { MiddlewareContext, PermixOptions };