bknd
Version:
Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.
34 lines (33 loc) • 1.59 kB
TypeScript
import { s, type ParseOptions, InvalidSchemaError, HttpStatus } from "bknd/utils";
export declare const permissionOptionsSchema: s.ObjectSchema<{
readonly description: s.Schema<s.ISchemaOptions, string | undefined, string | undefined>;
readonly filterable: s.Schema<s.ISchemaOptions, boolean | undefined, boolean | undefined>;
}, s.Merge<s.IObjectOptions & {
additionalProperties: false;
}>>;
export type TPermission = {
name: string;
description?: string;
filterable?: boolean;
context?: any;
};
export type PermissionOptions = s.Static<typeof permissionOptionsSchema>;
export type PermissionContext<P extends Permission<any, any, any, any>> = P extends Permission<any, any, infer Context, any> ? Context extends s.ObjectSchema ? s.Static<Context> : never : never;
export declare class InvalidPermissionContextError extends InvalidSchemaError {
name: string;
code: HttpStatus;
static from(e: InvalidSchemaError): InvalidPermissionContextError;
}
export declare class Permission<Name extends string = string, Options extends PermissionOptions = {}, Context extends s.ObjectSchema | undefined = undefined, ContextValue = Context extends s.ObjectSchema ? s.Static<Context> : undefined> {
name: Name;
options: Options;
context: Context;
constructor(name: Name, options?: Options, context?: Context);
isFilterable(): boolean;
parseContext(ctx: ContextValue, opts?: ParseOptions): ContextValue | s.Static<NonNullable<Context>> | undefined;
toJSON(): {
name: Name;
} & Options & {
context: Context;
};
}