lakutata
Version:
An IoC-based universal application framework.
194 lines (188 loc) • 8.56 kB
TypeScript
import '../vendor/TypeDef.2.js';
import { I as IBaseObjectConstructor, M as Module, C as Component } from '../vendor/TypeDef.3.js';
import { C as Controller, a as CLIContext, H as HTTPContext, S as ServiceContext } from '../vendor/TypeDef.14.js';
export { B as BaseContext, b as ContextType, c as ControllerProperty } from '../vendor/TypeDef.14.js';
import { A as ActionPattern } from '../vendor/TypeDef.9.js';
import { D as DTO, J as JSONSchema } from '../vendor/TypeDef.5.js';
import { I as IPatRun } from '../vendor/TypeDef.7.js';
import { E as Exception } from '../vendor/TypeDef.8.js';
import 'node:http';
type ActionPatternMap = Map<ActionPattern, ActionDetails>;
type ActionDetails<ClassPrototype extends Controller = Controller, DTOConstructor extends typeof DTO = typeof DTO> = {
pattern: ActionPattern;
constructor: IBaseObjectConstructor<ClassPrototype>;
method: string | number | symbol;
dtoConstructor: DTOConstructor;
jsonSchema: JSONSchema;
};
type PatternManagerOptions = {
globMatch?: boolean;
};
declare class PatternManager implements IPatRun {
#private;
constructor(options?: PatternManagerOptions);
/**
* Register a pattern, and the object that will be returned if an input matches.
* Both keys and values are considered to be strings.
* Other types are converted to strings.
* @param pattern
* @param obj
*/
add(pattern: Record<string, any>, obj: any): this;
/**
* Remove this pattern, and it's object, from the matcher.
* @param pattern
*/
remove(pattern: Record<string, any>): this;
/**
* Return the unique match for this subject, or null if not found.
* The properties of the subject are matched against the patterns previously added, and the most specifc pattern wins.
* Unknown properties in the subject are ignored.
* You can optionally provide a second boolean parameter, exact. If true, then all properties of the subject must match.
*
* If the optional third boolean parameter collect is true, then find returns an array of all sub matches
* (i.e. run find on each element of the power set of the subject pattern elements, and collate in breadth first order).
* Thus, {a:1,b:2} will generate {a:1},{b:2},{a:1,b:2} searches.
* If exact is true, only increasing sub patterns in lexicographical order are chosen.
* Thus, {a:1,b:2} will generate {a:1},{a:1,b:2}, omitting {b:2}. (You probably want to set exact to false!).
* @param subject
* @param exact
*/
find(subject: Record<string, any>, exact?: boolean): any;
/**
* Return the list of registered patterns that contain this partial pattern.
* You can use wildcards for property values.
* Omitted values are not equivalent to a wildcard of "*", you must specify each property explicitly.
* @param partialPattern
*/
list(partialPattern?: Record<string, any> | undefined): {
match: Record<string, any>;
data: any;
}[];
/**
* Generate a string representation of the decision tree for debugging.
*/
toJSON(): string;
}
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>[];
cli?: CLIEntrypoint | CLIEntrypoint[];
http?: HTTPEntrypoint | HTTPEntrypoint[];
service?: ServiceEntrypoint | ServiceEntrypoint[];
};
/**
* 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 controllers: IBaseObjectConstructor<Controller>[];
protected readonly cli?: CLIEntrypoint | CLIEntrypoint[];
protected readonly http?: HTTPEntrypoint | HTTPEntrypoint[];
protected readonly service?: ServiceEntrypoint | ServiceEntrypoint[];
/**
* Initializer
* @protected
*/
protected init(): Promise<void>;
/**
* Destroyer
* @protected
*/
protected destroy(): 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;
}
declare class ControllerActionNotFoundException extends Exception {
errno: string | number;
}
export { BuildCLIEntrypoint, BuildEntrypoints, BuildHTTPEntrypoint, BuildServiceEntrypoint, CLIContext, Controller, ControllerActionNotFoundException, Entrypoint, HTTPContext, ServiceContext };
export type { CLIEntrypoint, CLIEntrypointHandler, CLIMap, EntrypointDestroyer, EntrypointDestroyerRegistrar, EntrypointOptions, HTTPEntrypoint, HTTPEntrypointHandler, HTTPRouteMap, ServiceEntrypoint, ServiceEntrypointHandler };