2.0.3 • Published 2 years ago

@types/koa-roles v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Installation

npm install --save @types/koa-roles

Summary

This package contains type definitions for koa-roles (https://github.com/koajs/koa-roles).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/koa-roles.

index.d.ts

// Type definitions for koa-roles 2.0
// Project: https://github.com/koajs/koa-roles
// Definitions by: Chris Wilkinson <https://github.com/thewilkybarkid>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 4.2

import Koa = require('koa');

declare class Roles<StateT extends Koa.DefaultStateExtends = Koa.DefaultState, ContextT extends Koa.DefaultContextExtends = Koa.DefaultContext, ResponseBodyT = unknown> {
    constructor(options?: Roles.Options<StateT, ContextT, ResponseBodyT>);

    can(action: string): Koa.Middleware<StateT, ContextT, ResponseBodyT>;

    use(fn: Roles.Handler<StateT, ContextT, ResponseBodyT>): void;
    use<Action extends string>(action: Action, fn: Roles.Handler<StateT, ContextT, ResponseBodyT, Action>): void;

    middleware(): Koa.Middleware<StateT, ContextT, ResponseBodyT>;
}

declare namespace Roles {
    type Handler<
        StateT extends Koa.DefaultStateExtends = Koa.DefaultState,
        ContextT extends Koa.DefaultContextExtends = Koa.DefaultContext,
        ResponseBodyT = unknown,
        Action extends string = string
    > = (ctx: Koa.ParameterizedContext<StateT, ContextT, ResponseBodyT>, action: Action) => boolean | Promise<boolean>;

    interface Options<StateT extends Koa.DefaultStateExtends = Koa.DefaultState, ContextT extends Koa.DefaultContextExtends = Koa.DefaultContext, ResponseBodyT = unknown> {
        failureHandler?: (ctx: Koa.ParameterizedContext<StateT, ContextT, ResponseBodyT>, action: string) => void;
        userProperty?: string;
    }
}

export = Roles;

Additional Details

  • Last updated: Fri, 12 Nov 2021 22:31:49 GMT
  • Dependencies: @types/koa
  • Global values: none

Credits

These definitions were written by Chris Wilkinson.

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

4 years ago