lakutata
Version:
An IoC-based universal application framework.
239 lines (236 loc) • 9.46 kB
TypeScript
import { Module, Component, Container, DTO } from './TypeDef.internal.96.js';
import { CLIContext, HTTPContext, ServiceContext } from './TypeDef.internal.115.js';
import { JSONSchema, ActionPattern } from './TypeDef.internal.100.js';
import { ActionPatternMap, PatternManager, ActionDetails } from './TypeDef.internal.116.js';
import { Controller, AccessControlRule, AccessControl } from './TypeDef.internal.117.js';
import { IBaseObjectConstructor } from './TypeDef.internal.118.js';
type CLIEntrypoint = (module: Module, cliMap: CLIMap, handler: CLIEntrypointHandler, registerDestroy: EntrypointDestroyerRegistrar) => void;
type HTTPEntrypoint = (module: Module, routeMap: HTTPRouteMap, handler: HTTPEntrypointHandler, registerDestroy: EntrypointDestroyerRegistrar) => void;
type ServiceEntrypoint = (module: Module, handler: ServiceEntrypointHandler, registerDestroy: EntrypointDestroyerRegistrar) => void;
type CLIMap = Map<string, JSONSchema>;
type HTTPRouteMap<HTTPMethods = string> = Map<string, Set<HTTPMethods>>;
type CLIEntrypointHandler<T = unknown> = (context: CLIContext, abortController?: AbortController) => Promise<T>;
type HTTPEntrypointHandler<T = unknown> = (context: HTTPContext, abortController?: AbortController) => Promise<T>;
type ServiceEntrypointHandler<T = unknown> = (context: ServiceContext, abortController?: AbortController) => Promise<T>;
type EntrypointDestroyer = () => void | Promise<void>;
type EntrypointDestroyerRegistrar = (destroyer: EntrypointDestroyer) => void;
type EntrypointOptions = {
controllers: IBaseObjectConstructor<Controller>[];
rules?: IBaseObjectConstructor<AccessControlRule>[];
cliActionGroups?: Record<string, string>;
cli?: CLIEntrypoint | CLIEntrypoint[];
httpActionGroups?: Record<string, string>;
http?: HTTPEntrypoint | HTTPEntrypoint[];
serviceActionGroups?: Record<string, string>;
service?: ServiceEntrypoint | ServiceEntrypoint[];
};
interface BaseActionInfo {
readonly id: string;
readonly acl: boolean;
readonly name: string;
readonly description: string;
readonly groups: string[];
readonly controller: string;
readonly method: string;
readonly jsonSchema: JSONSchema;
}
interface HTTPActionInfo extends BaseActionInfo {
readonly route: string;
}
interface ServiceActionInfo extends BaseActionInfo {
readonly pattern: ActionPattern;
}
interface CLIActionInfo extends BaseActionInfo {
readonly command: string;
}
interface ActionGroupInfo<T extends BaseActionInfo> {
readonly id: string;
readonly name: string;
actions: T[];
}
interface EntrypointActions<T extends BaseActionInfo> {
readonly groups: ActionGroupInfo<T>[];
readonly actions: T[];
}
/**
* Build cli entrypoint
* @param entrypoint
* @constructor
*/
declare const BuildCLIEntrypoint: (entrypoint: CLIEntrypoint) => CLIEntrypoint;
/**
* Build http entrypoint
* @param entrypoint
* @constructor
*/
declare const BuildHTTPEntrypoint: (entrypoint: HTTPEntrypoint) => HTTPEntrypoint;
/**
* Build service entrypoint
* @param entrypoint
* @constructor
*/
declare const BuildServiceEntrypoint: (entrypoint: ServiceEntrypoint) => ServiceEntrypoint;
/**
* Build entrypoints options for Entrypoint component
* @param options
* @constructor
*/
declare const BuildEntrypoints: (options: EntrypointOptions) => EntrypointOptions;
/**
* Entrypoint Component
*/
declare class Entrypoint extends Component {
protected readonly CLIActionPatternMap: ActionPatternMap;
protected readonly HTTPActionPatternMap: ActionPatternMap;
protected readonly ServiceActionPatternMap: ActionPatternMap;
protected readonly CLIActionPatternManager: PatternManager;
protected readonly HTTPActionPatternManager: PatternManager;
protected readonly ServiceActionPatternManager: PatternManager;
protected readonly entrypointDestroyers: EntrypointDestroyer[];
protected readonly httpActionInfoMap: Map<string, HTTPActionInfo>;
protected readonly serviceActionInfoMap: Map<string, ServiceActionInfo>;
protected readonly cliActionInfoMap: Map<string, CLIActionInfo>;
protected readonly accessControl: IBaseObjectConstructor<AccessControl>;
protected readonly controllers: IBaseObjectConstructor<Controller>[];
protected readonly rules: IBaseObjectConstructor<AccessControlRule>[];
protected readonly cliActionGroups: Record<string, string>;
protected readonly httpActionGroups: Record<string, string>;
protected readonly serviceActionGroups: Record<string, string>;
protected readonly cli?: CLIEntrypoint | CLIEntrypoint[];
protected readonly http?: HTTPEntrypoint | HTTPEntrypoint[];
protected readonly service?: ServiceEntrypoint | ServiceEntrypoint[];
/**
* Initializer
* @protected
*/
protected init(): Promise<void>;
/**
* Http action info getter
* @constructor
* @protected
*/
protected get HTTP_ACTIONS(): HTTPActionInfo[];
/**
* Service action info getter
* @constructor
* @protected
*/
protected get SERVICE_ACTIONS(): ServiceActionInfo[];
/**
* Cli action info getter
* @constructor
* @protected
*/
protected get CLI_ACTIONS(): CLIActionInfo[];
/**
* Destroyer
* @protected
*/
protected destroy(): Promise<void>;
/**
* Get entrypoint actions
* @param type
* @protected
*/
protected getEntrypointActions<T extends BaseActionInfo>(type: 'http' | 'cli' | 'service'): EntrypointActions<T>;
/**
* Find invalid action group ids
* @param actionInfoMap
* @param type
* @protected
*/
protected findInvalidActionGroupIds(actionInfoMap: Map<string, BaseActionInfo>, type: 'cli' | 'http' | 'service'): string[];
/**
* Find duplicate action names
* @protected
* @param actionInfoMap
*/
protected findDuplicateActionNames(actionInfoMap: Map<string, BaseActionInfo>): string[];
/**
* Run access control
* @param rules
* @param runtimeContainer
* @param context
* @param input
* @param details
* @protected
*/
protected runAccessControl(rules: IBaseObjectConstructor<AccessControlRule>[], runtimeContainer: Container, context: CLIContext | HTTPContext | ServiceContext, input: Record<string, any>, details: ActionDetails): Promise<void>;
/**
* Run controller's method and return its result (without AbortController)
* @param details
* @param context
* @param dtoConstructor
* @protected
*/
protected runControllerMethodWithoutAbortController<DTOConstructor extends typeof DTO = typeof DTO>(details: ActionDetails, context: CLIContext | HTTPContext | ServiceContext, dtoConstructor: DTOConstructor): Promise<unknown>;
/**
* Run controller's method and return its result (with AbortController)
* @param details
* @param context
* @param dtoConstructor
* @param abortController
* @protected
*/
protected runControllerMethodWithAbortController<DTOConstructor extends typeof DTO = typeof DTO>(details: ActionDetails, context: CLIContext | HTTPContext | ServiceContext, dtoConstructor: DTOConstructor, abortController: AbortController): Promise<unknown>;
/**
* Run controller's method and return its result
* @param details
* @param context
* @param dtoConstructor
* @param abortController
* @protected
*/
protected runControllerMethod<DTOConstructor extends typeof DTO = typeof DTO>(details: ActionDetails, context: CLIContext | HTTPContext | ServiceContext, dtoConstructor: DTOConstructor, abortController?: AbortController): Promise<unknown>;
/**
* Register
* @param eps
* @param registerFunc
* @protected
*/
protected register<T>(eps: any | any[] | undefined, registerFunc: (entrypoint: T) => void): void;
/**
* Register CLI entrypoint
* @param entrypoint
* @protected
*/
protected registerCLIEntrypoint(entrypoint: CLIEntrypoint): void;
/**
* Register http entrypoint
* @param entrypoint
* @protected
*/
protected registerHTTPEntrypoint(entrypoint: HTTPEntrypoint): void;
/**
* Register service entrypoint
* @param entrypoint
* @protected
*/
protected registerServiceEntrypoint(entrypoint: ServiceEntrypoint): void;
/**
* Get HTTP action groups
*/
getHttpActionGroups(): Record<string, string>;
/**
* Get Service action groups
*/
getServiceActionGroups(): Record<string, string>;
/**
* Get CLI action groups
*/
getCliActionGroups(): Record<string, string>;
/**
* Get entrypoint HTTP actions
*/
getHttpActions(): EntrypointActions<HTTPActionInfo>;
/**
* Get entrypoint Service actions
*/
getServiceActions(): EntrypointActions<ServiceActionInfo>;
/**
* Get entrypoint CLI actions
*/
getCliActions(): EntrypointActions<CLIActionInfo>;
}
export { BuildCLIEntrypoint, BuildEntrypoints, BuildHTTPEntrypoint, BuildServiceEntrypoint, Entrypoint };
export type { ActionGroupInfo, BaseActionInfo, CLIActionInfo, CLIEntrypoint, CLIEntrypointHandler, CLIMap, EntrypointActions, EntrypointDestroyer, EntrypointDestroyerRegistrar, EntrypointOptions, HTTPActionInfo, HTTPEntrypoint, HTTPEntrypointHandler, HTTPRouteMap, ServiceActionInfo, ServiceEntrypoint, ServiceEntrypointHandler };