agentframework
Version:
TypeScript that scales
201 lines (161 loc) • 8.36 kB
TypeScript
/*! Copyright 2016-2024 Ling Zhang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
interface Design {
readonly version: number;
readonly kind: number;
readonly name: string;
readonly declaringType: Function;
readonly type: Function | undefined;
}
interface Annotation {
readonly v: number;
readonly a?: ReadonlyArray<any>;
readonly m?: ReadonlyMap<string, any>;
}
interface Parameter extends Annotation {
}
interface Property extends Annotation {
readonly target: object | Function;
descriptor?: PropertyDescriptor;
parameters?: ReadonlyMap<number, Parameter>;
}
interface Type extends Property {
readonly prototype: object;
properties?: ReadonlyMap<string | symbol, Property>;
}
declare function AddAttributeToProperty(attribute: object, target: object | Function, key: string | symbol, descriptor?: PropertyDescriptor): void;
declare function AddAttributeToPropertyParameter(attribute: object, target: object | Function, key: string | symbol, parameterIndex: number): void;
declare function AddAttributeToConstructor(attribute: object, target: object | Function): void;
declare function AddAttributeToConstructorParameter(attribute: object, target: object | Function, parameterIndex: number): void;
interface Arguments {
[index: number]: any;
length: number;
}
interface Class<T extends object> extends Function {
readonly prototype: T;
}
interface Filter<T = object> {
(value: T, filterCriteria?: any): boolean;
}
interface MemberInfo extends Design {
readonly annotation: Annotation | undefined;
readonly ownAttributes: ReadonlyArray<object> | undefined;
readonly ownInterceptors: ReadonlyArray<object> | undefined;
addAttribute<A4 extends object>(attribute: A4): void;
hasOwnAttribute<A1 extends object>(type?: Class<A1>): boolean;
getOwnAttribute<A2 extends object>(type: Class<A2>): A2 | undefined;
getOwnAttributes<A3 extends object>(type?: Class<A3>): ReadonlyArray<A3>;
findOwnAttributes<A5 extends object>(filter: Filter, filterCriteria?: any): ReadonlyArray<A5>;
hasOwnInterceptor(): boolean;
}
interface ParameterInfo extends MemberInfo {
readonly key: string | symbol;
readonly index: number;
}
interface PropertyInfo extends MemberInfo {
readonly key: string | symbol;
readonly annotation: Property | undefined;
readonly descriptor: PropertyDescriptor | undefined;
readonly parameterTypes: ReadonlyArray<any> | undefined;
readonly intercepted: boolean;
parameter(index: number): ParameterInfo;
hasParameter(): boolean;
getParameter(index: number): ParameterInfo | undefined;
getParameters(): ReadonlyArray<ParameterInfo>;
hasInterceptor(): boolean;
}
interface TypeInfo extends PropertyInfo {
readonly typeAnnotation: Type | undefined;
readonly static: TypeInfo;
readonly prototype: TypeInfo;
readonly base: TypeInfo | null | undefined;
readonly version: number;
property(key: PropertyKey): PropertyInfo;
hasOwnProperties(): boolean;
getOwnProperties(): ReadonlyArray<PropertyInfo>;
getOwnProperty(key: PropertyKey): PropertyInfo | undefined;
getProperty(key: PropertyKey): PropertyInfo | undefined;
findOwnProperties(filter: Filter<PropertyInfo>, filterCriteria?: any): ReadonlyArray<PropertyInfo>;
findProperties(filter: Filter<PropertyInfo>, filterCriteria?: any): ReadonlyMap<TypeInfo, ReadonlyArray<PropertyInfo>>;
findTypes(filter?: Filter<TypeInfo>, filterCriteria?: any): ReadonlyArray<TypeInfo>;
}
interface Invocation<T extends Design = Design> {
readonly design: T;
invoke<T>(params: Arguments, receiver: unknown): T;
}
interface Interceptor<T extends Design = Design> {
intercept(target: Invocation<T>, params: Arguments, receiver: unknown): unknown;
}
interface Attribute extends Object {
beforeDecorate?(target: object | Function, key?: string | symbol, descriptor?: PropertyDescriptor | number): boolean;
readonly interceptor?: Interceptor;
}
interface TypeInvocation extends Invocation<TypeInfo> {
}
interface PropertyInvocation extends Invocation<PropertyInfo> {
}
interface ParameterInvocation extends Invocation<ParameterInfo> {
}
interface TypeInterceptor extends Interceptor<TypeInfo> {
}
interface PropertyInterceptor extends Interceptor<PropertyInfo> {
}
interface ParameterInterceptor extends Interceptor<ParameterInfo> {
}
interface TypeAttribute extends Attribute {
beforeDecorate?(target: Function): boolean;
readonly interceptor?: TypeInterceptor;
}
interface PropertyAttribute extends Attribute {
beforeDecorate?(target: object, key: string | symbol): boolean;
readonly interceptor?: PropertyInterceptor;
}
interface ParameterAttribute extends Attribute {
beforeDecorate?(target: Function, key: undefined, index: number): boolean;
readonly interceptor?: ParameterInterceptor;
}
declare class MemberKinds {
static None: number;
static Static: number;
static Class: number;
static Property: number;
static Parameter: number;
static StaticClass: number;
static StaticProperty: number;
static ClassParameter: number;
static StaticClassParameter: number;
static PropertyParameter: number;
static StaticPropertyParameter: number;
static Any: number;
}
declare function decorateClass<T extends Attribute>(attribute: T): (target: Function) => void;
declare function decorateAgent<T extends Attribute>(attribute: T): (target: Function) => void;
declare function decorateMember<T extends Attribute>(attribute: T): (target: object | Function, targetKey: string | symbol, descriptor?: PropertyDescriptor) => void;
declare function decorateParameter<T extends ParameterAttribute>(attribute: T): (target: object | Function, targetKey: string | symbol | undefined, parameterIndex: number) => void;
type VariableDecorator = (target: Object, propertyKey?: string | symbol, parameterIndex?: PropertyDescriptor | number) => void;
declare function decorateVariable<T extends Attribute>(attribute: T): VariableDecorator;
declare function Reflector(target: Function | object): TypeInfo;
declare function agent(): ClassDecorator;
declare function singleton<T extends Function>(type?: T): VariableDecorator;
declare function transit<T extends Function>(type?: T): VariableDecorator;
declare function SetCustomInterceptor(attribute: Function, custom: Function, meta?: unknown): void;
declare function GetCustomInterceptor(attribute: Function): [Function, unknown?] | undefined;
declare function RemoveCustomInterceptor(attribute: Function): void;
declare function initializable(key?: string | symbol): ClassDecorator;
type InitializerHandler = () => void;
type StaticInitializerHandler = (target: TypeInvocation, params: Arguments, receiver: Function) => object;
declare const Initializer: unique symbol;
declare class AgentFrameworkError extends Error {
}
declare function IsAgent(target: Function | object): boolean;
declare function GetAgentType<T extends Function>(agent: T): T | undefined;
declare function CreateAgent<T extends Function>(type: T): T;
export { AddAttributeToConstructor, AddAttributeToConstructorParameter, AddAttributeToProperty, AddAttributeToPropertyParameter, AgentFrameworkError, Arguments, Attribute, Class, CreateAgent, Design, Filter, GetAgentType, GetCustomInterceptor, Initializer, InitializerHandler, Interceptor, Invocation, IsAgent, MemberInfo, MemberKinds, ParameterAttribute, ParameterInfo, ParameterInterceptor, ParameterInvocation, PropertyAttribute, PropertyInfo, PropertyInterceptor, PropertyInvocation, Reflector, RemoveCustomInterceptor, SetCustomInterceptor, StaticInitializerHandler, TypeAttribute, TypeInfo, TypeInterceptor, TypeInvocation, VariableDecorator, agent, decorateAgent, decorateClass, decorateMember, decorateParameter, decorateVariable, initializable, singleton, transit };