lakutata
Version:
An IoC-based universal application framework.
73 lines (68 loc) • 3.27 kB
TypeScript
import { Provider, Container } from './TypeDef.internal.96.js';
import { CLIContext, HTTPContext, ServiceContext } from './TypeDef.internal.115.js';
import { BaseContext, BaseObject, ContextType } from './TypeDef.internal.120.js';
import { HTTPActionInfo, ServiceActionInfo, CLIActionInfo, BaseActionInfo } from './TypeDef.internal.114.js';
import { Exception } from './TypeDef.internal.102.js';
import { ActionDetails } from './TypeDef.internal.116.js';
import { ActionPattern } from './TypeDef.internal.100.js';
import { IBaseObjectConstructor } from './TypeDef.internal.118.js';
import { FunctionSchema } from './TypeDef.internal.121.js';
/**
* For action decorator
*/
type ControllerProperty<ClassPrototype extends Controller> = Exclude<keyof ClassPrototype, keyof Controller>;
/**
* Controller base class
*/
declare class Controller extends Provider {
/**
* Context, possible be cli context, http context or service context
* @protected
*/
protected readonly context: CLIContext | HTTPContext | ServiceContext;
}
type AccessControlRuleHandler<T extends BaseContext<Record<string, any>>> = (context: T, input?: ActionPattern<any>) => Promise<boolean>;
declare abstract class AccessControlRule<T extends BaseContext<Record<string, any>> = BaseContext<Record<string, any>>> extends BaseObject {
protected readonly context: T;
protected readonly input: ActionPattern<any>;
protected readonly actions: HTTPActionInfo[] | ServiceActionInfo[] | CLIActionInfo[];
protected readonly targetAction: HTTPActionInfo | ServiceActionInfo | CLIActionInfo;
abstract get supportContextTypes(): ContextType[];
/**
* Rule handler
*/
abstract rule(): Promise<boolean>;
}
declare class AccessControl extends BaseObject {
protected readonly runtimeContainer: Container;
protected readonly actions: HTTPActionInfo[] | ServiceActionInfo[] | CLIActionInfo[];
protected readonly target: HTTPActionInfo | ServiceActionInfo | CLIActionInfo;
protected readonly context: CLIContext | HTTPContext | ServiceContext;
protected readonly input: Record<string, any>;
protected readonly allowCallback: () => void;
protected readonly denyCallback: (error?: Error | Exception) => void;
protected readonly rules: (IBaseObjectConstructor<AccessControlRule> | AccessControlRuleHandler<any>)[];
protected readonly accessControlRuleConstructorDTO: FunctionSchema<typeof AccessControlRule>;
/**
* Initializer
* @protected
*/
protected init(): Promise<void>;
/**
* Match rules
* @protected
*/
protected match(): Promise<boolean>;
/**
* Run access control and return result
* @param rules
* @param runtimeContainer
* @param context
* @param input
* @param details
* @param getActionsCallback
*/
static run(rules: IBaseObjectConstructor<AccessControlRule>[], runtimeContainer: Container, context: CLIContext | HTTPContext | ServiceContext, input: Record<string, any>, details: ActionDetails, getActionsCallback: (type: ContextType) => BaseActionInfo[]): Promise<[boolean, Error | Exception]>;
}
export { AccessControl, AccessControlRule, Controller };
export type { AccessControlRuleHandler, ControllerProperty };