lakutata
Version:
An IoC-based universal application framework.
308 lines (297 loc) • 10.7 kB
TypeScript
import './TypeDef.internal.30.js';
import { AnySchema, StringSchema, NumberSchema, BigIntSchema, BooleanSchema, DateSchema, ObjectSchema, ArraySchema, BinarySchema, FunctionSchema, SymbolSchema, AlternativesSchema, ReferenceOptions, Reference, ValidationOptions, LinkSchema } from './TypeDef.internal.121.js';
import { SchemaMap, SchemaLikeWithoutArray, SchemaLike, Schema } from './TypeDef.internal.129.js';
import { LoadObjectOptions, BootstrapOption, ModuleOptions, OverridableNamedObjectOptions, ApplicationOptions } from './TypeDef.internal.137.js';
import { Module, Application, DTO } from './TypeDef.internal.96.js';
import { BaseObject, BaseContext } from './TypeDef.internal.120.js';
import { IBaseObjectConstructor, IPatRun } from './TypeDef.internal.118.js';
import { AccessControlRuleHandler, Controller } from './TypeDef.internal.117.js';
import { ActionPattern, JSONSchema } from './TypeDef.internal.100.js';
declare class DataValidator {
/**
* 任意类型验证
* @constructor
*/
static Any<TSchema = any>(): AnySchema<TSchema>;
/**
* 字符串类型验证
* @constructor
*/
static String<TSchema = string>(): StringSchema<TSchema>;
/**
* 数字类型验证
* @constructor
*/
static Number<TSchema = number>(): NumberSchema<TSchema>;
/**
* 大数类型验证
* @constructor
*/
static BigInt<TSchema = bigint>(): BigIntSchema<TSchema>;
/**
* 布尔类型验证
* @constructor
*/
static Boolean<TSchema = boolean>(): BooleanSchema<TSchema>;
/**
* 日期类型验证
* @constructor
*/
static Date<TSchema = Date>(): DateSchema<TSchema>;
/**
* 对象类型验证
* @param schema
* @constructor
*/
static Object<TSchema = any, isStrict = false, T = TSchema>(schema?: SchemaMap<T, isStrict>): ObjectSchema<TSchema>;
/**
* 数组类型验证
* @param types
* @constructor
*/
static Array<TSchema = any[]>(...types: SchemaLikeWithoutArray[]): ArraySchema<TSchema>;
/**
* 二进制类型验证
* @constructor
*/
static Binary<TSchema = Buffer>(): BinarySchema<TSchema>;
/**
* 方法类型验证
* @constructor
*/
static Function<TSchema = Function>(): FunctionSchema<TSchema>;
/**
* 异步方法类型验证
* @constructor
*/
static AsyncFunction<TSchema = Function>(): FunctionSchema<TSchema>;
/**
* 类验证器
* @param inheritsFrom
* @constructor
*/
static Class<TSchema = Function>(inheritsFrom?: TSchema | (() => TSchema)): FunctionSchema<TSchema>;
/**
* Is object instanceOf a constructor
* @param constructor
* @constructor
*/
static InstanceOf<TSchema = Function>(constructor: TSchema): AnySchema<TSchema>;
/**
* 通配符匹配操作符字符串验证器
* @constructor
*/
static Glob<TSchema = string>(): StringSchema<TSchema>;
/**
* Cron表达式验证器
* @constructor
*/
static Cron<TSchema = string>(options?: {
alias?: boolean;
seconds?: boolean;
allowBlankDay?: boolean;
allowSevenAsSunday?: boolean;
}): StringSchema<TSchema>;
/**
* Http请求中Document类型数据验证器
* @constructor
*/
static HttpDocument<TSchema = string>(): StringSchema<TSchema>;
/**
* 符号类型验证
* @constructor
*/
static Symbol<TSchema = Symbol>(): SymbolSchema<TSchema>;
/**
* 可选参数类型验证
* @param types
* @constructor
*/
static Alternatives<TSchema = any>(...types: SchemaLike[]): AlternativesSchema<TSchema>;
/**
* 为已命名的键值生成引用
* @param key
* @param options
* @constructor
*/
static Ref(key: string, options?: ReferenceOptions): Reference;
/**
* 创建一个引用,当解析时,将其作为值数组用于与规则进行匹配。
* @param ref
* @param options
* @constructor
*/
static In(ref: string, options?: ReferenceOptions): Reference;
/**
* 对值进行模式验证,返回有效的对象,如果验证失败则抛出异常。
* @param value
* @param schema
* @param options
* @constructor
*/
static Attempt<TSchema extends Schema>(value: any, schema: TSchema, options?: ValidationOptions): TSchema extends Schema<infer Value> ? Value : never;
/**
* 创建关联验证关系,用于递归验证
* 绝对路径链接:/
* 相对路径链接:...
* @param ref
* @constructor
*/
static Link<TSchema extends Schema>(ref: string): LinkSchema<TSchema>;
}
/**
* Object Type
*/
declare enum ObjectType {
Unknown = "Unknown",
Object = "Object",
Provider = "Provider",
Controller = "Controller",
Component = "Component",
Module = "Module"
}
/**
* Module configurations loader
*/
declare class ModuleConfigLoader {
protected readonly $module: Module;
protected readonly $presetLoadOptionsSet: Set<LoadObjectOptions | typeof BaseObject | string>;
protected readonly $loadOptions: (LoadObjectOptions | typeof BaseObject | string)[];
protected readonly $bootstrap: BootstrapOption[];
/**
* Constructor
* @param module
* @param moduleOptions
* @param presetLoadOptions
*/
constructor(module: Module, moduleOptions: ModuleOptions, presetLoadOptions?: (LoadObjectOptions | typeof BaseObject | string)[]);
/**
* Validate constructor's object type
* @param expectObjectType
* @param target
* @protected
*/
protected validateObjectType<ClassConstructor extends IBaseObjectConstructor>(expectObjectType: ObjectType, target: ClassConstructor): ClassConstructor;
/**
* Process overridable named object options
* @param objectType
* @param options
* @protected
*/
protected processOverridableNamedObjectOptions(objectType: ObjectType, options?: OverridableNamedObjectOptions): void;
/**
* Load options for container.load()
*/
get loadOptions(): (LoadObjectOptions | typeof BaseObject | string)[];
/**
* Load bootstrap for module
*/
get bootstrap(): BootstrapOption[];
}
/**
* Application configurations loader
*/
declare class ApplicationConfigLoader extends ModuleConfigLoader {
/**
* Constructor
* @param app
* @param applicationOptions
* @param presetLoadOptions
*/
constructor(app: Application, applicationOptions: ApplicationOptions, presetLoadOptions?: (LoadObjectOptions | typeof BaseObject | string)[]);
}
declare class ActionOptions<T extends BaseContext<Record<string, any>>> extends DTO {
/**
* Whether enable access control for this action
*/
acl?: boolean;
/**
* Action name
*/
name?: string;
/**
* Action description
*/
description?: string;
/**
* Action group names
*/
groups?: string[];
/**
* Action rule callback
*/
rule?: AccessControlRuleHandler<T>;
}
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;
getActionInfo: () => ActionInfo;
} & ActionInfo;
type ActionInfo = {
id: string;
acl: boolean;
action: string;
name: string;
description: string;
groups: string[];
rule?: AccessControlRuleHandler<any>;
};
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 BeforeFunction<ClassPrototype extends Object, Method extends (...args: any[]) => unknown> = (this: ClassPrototype, ...args: Parameters<Method>) => Promise<Parameters<Method> | void> | Parameters<Method> | void;
type AfterFunction<ClassPrototype extends Object, Method extends (...args: any[]) => unknown> = (this: ClassPrototype, result: Awaited<ReturnType<Method>>) => Promise<ReturnType<Method> | void> | ReturnType<Method> | void;
type InjectionName = string | symbol | IBaseObjectConstructor<BaseObject>;
type InjectionTransformFunction = (injection: any) => any | Promise<any>;
export { ActionOptions, ApplicationConfigLoader, DataValidator, ModuleConfigLoader, PatternManager };
export type { ActionDetails, ActionPatternMap, AfterFunction, BeforeFunction, InjectionName, InjectionTransformFunction };