UNPKG

@xcons/widget

Version:

XCon Studio widget utilities with advanced template rendering, reactive binding system and registry pattern support

115 lines (114 loc) 2.99 kB
/** * Service lifecycle scopes */ export type ServiceScope = 'singleton' | 'transient' | 'scoped'; /** * Service token types */ export type ServiceToken<T = any> = string | symbol | ServiceConstructor<T>; /** * Service constructor interface */ export interface ServiceConstructor<T = any> { new (...args: any[]): T; prototype: T; } /** * Service configuration options */ export interface ServiceConfig { scope?: ServiceScope; token?: ServiceToken; factory?: (...args: any[]) => any; dependencies?: ServiceToken[]; } /** * Service metadata stored on constructors */ export interface ServiceMetadata { target: ServiceConstructor; token: ServiceToken; scope: ServiceScope; dependencies: ServiceToken[]; factory?: (...args: any[]) => any; } /** * Service instance wrapper */ export interface ServiceInstance { instance: any; scope: ServiceScope; token: ServiceToken; created: number; lastAccessed: number; } /** * Service provider interface */ export interface ServiceProvider<T = any> { token: ServiceToken<T>; useClass?: ServiceConstructor<T>; useFactory?: (...args: any[]) => T; useValue?: T; dependencies?: ServiceToken[]; scope?: ServiceScope; } /** * Injection context */ export interface InjectionContext { token: ServiceToken; target?: ServiceConstructor; propertyKey?: string | symbol; parameterIndex?: number; } /** * Service registry interface */ export interface IServiceRegistry { registerService<T>(target: ServiceConstructor<T>, config?: ServiceConfig): void; registerProvider<T>(provider: ServiceProvider<T>): void; hasService(token: ServiceToken): boolean; getService<T>(token: ServiceToken<T>): T; createInstance<T>(target: ServiceConstructor<T>): T; clearScope(scope: ServiceScope): void; clear(): void; } /** * Service injector interface */ export interface IServiceInjector { inject<T>(token: ServiceToken<T>): T; injectAll<T>(tokens: ServiceToken<T>[]): T[]; canInject(token: ServiceToken): boolean; } /** * Service error types */ export declare class ServiceError extends Error { token?: ServiceToken | undefined; cause?: Error | undefined; constructor(message: string, token?: ServiceToken | undefined, cause?: Error | undefined); } export declare class CircularDependencyError extends ServiceError { constructor(token: ServiceToken, dependencyChain: ServiceToken[]); } export declare class ServiceNotFoundError extends ServiceError { constructor(token: ServiceToken); } /** * Service lifecycle hooks interface */ export interface OnServiceInit { onServiceInit(): void | Promise<void>; } export interface OnServiceDestroy { onServiceDestroy(): void | Promise<void>; } /** * Service lifecycle hooks */ export interface ServiceLifecycle extends OnServiceInit, OnServiceDestroy { onServiceInit(): void | Promise<void>; onServiceDestroy(): void | Promise<void>; }