@virid/core 0.2.5 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,170 +1,139 @@
1
1
  type Newable<TInstance = unknown, TArgs extends unknown[] = any[]> = new (...args: TArgs) => TInstance;
2
2
  interface AppConfig {
3
- enableLog: boolean;
4
- }
5
- declare const defaultConfig: {
6
- enableLog: boolean;
7
- };
8
-
9
- interface SystemParams {
10
- priority?: number;
11
- messageClass?: Newable<BaseMessage> | null;
12
- }
13
- interface MessageMetadata {
14
- index: number;
15
- messageClass: Newable<BaseMessage>;
16
- single: boolean;
17
- }
18
- interface ObserverItem {
19
- propertyKey: string;
20
- callback: (oldVal: any, newVal: any) => void | BaseMessage | BaseMessage;
21
- }
22
- type ObserverMetadata = ObserverItem[];
23
- type SafeMetadata = Set<string>;
24
-
25
- type Middleware = (message: BaseMessage, next: () => void) => void;
26
- type ExecuteHook<T extends BaseMessage> = (message: [BaseMessage] extends [T] ? SingleMessage[] | EventMessage : T extends SingleMessage ? T[] : T, context: ExecuteHookContext, success: boolean) => void | Promise<void>;
27
- interface ExecuteHookContext {
28
- context: SystemContext;
29
- tick: number;
30
- payload: {
31
- [key: string]: any;
32
- };
33
- }
34
- interface SystemContext {
35
- params: any[];
36
- targetClass: any;
37
- methodName: string;
38
- originalMethod: (...args: any[]) => any;
39
- }
40
- interface SystemTask {
41
- fn: (...args: any[]) => any;
42
- priority: number;
43
- }
44
- type MessagePayload<T> = T extends SingleMessage ? T[] : T extends EventMessage ? T : T | T[];
45
- type MessageIdentifier<T> = (abstract new (...args: any[]) => T) | Newable<T>;
46
- type TickHook = (context: TickHookContext) => void | Promise<void>;
47
- interface TickHookContext {
48
- tick: number;
49
- timestamp: number;
50
- payload: {
51
- [key: string]: any;
52
- };
3
+ maxDepth?: number;
4
+ enableLog?: boolean;
5
+ manual?: boolean;
53
6
  }
7
+ declare const defaultConfig: AppConfig;
54
8
 
55
9
  declare abstract class BaseMessage {
56
10
  static send<T extends Newable<any>>(this: T, ...args: ConstructorParameters<T>): void;
57
11
  }
58
- /**
59
- * 可合并的信号基类
60
- */
61
12
  declare abstract class SingleMessage extends BaseMessage {
62
- private readonly __kind;
63
13
  constructor();
64
14
  }
65
- /**
66
- * 不可合并的消息基类
67
- */
68
15
  declare abstract class EventMessage extends BaseMessage {
69
- private readonly __kind;
70
16
  constructor();
71
17
  }
72
- /**
73
- * 基础错误消息:不可合并,必须被精准捕获
74
- */
75
18
  declare class ErrorMessage extends EventMessage {
76
19
  readonly error: Error;
77
20
  readonly context?: string | undefined;
78
21
  constructor(error: Error, context?: string | undefined);
79
22
  }
80
- /**
81
- * 基础警告消息:不可合并,必须被精准捕获
82
- */
83
23
  declare class WarnMessage extends EventMessage {
84
24
  readonly context: string;
85
25
  constructor(context: string);
86
26
  }
87
- /**
88
- * 基础信息消息:不可合并,必须被精准捕获
89
- */
90
27
  declare class InfoMessage extends EventMessage {
91
28
  readonly context: string;
92
29
  constructor(context: string);
93
30
  }
94
31
 
95
- declare class MessageInternal {
96
- private eventHub;
32
+ declare class MessageEngine {
97
33
  private dispatcher;
98
34
  private registry;
99
35
  private middlewares;
100
- constructor();
36
+ private manual;
37
+ constructor(maxDepth: number, manual: boolean);
101
38
  useMiddleware(mw: Middleware, front: boolean): void;
102
39
  onBeforeExecute<T extends BaseMessage>(type: MessageIdentifier<T>, hook: ExecuteHook<T>, front: boolean): void;
103
40
  onAfterExecute<T extends BaseMessage>(type: MessageIdentifier<T>, hook: ExecuteHook<T>, front: boolean): void;
104
41
  onBeforeTick(hook: TickHook, front: boolean): void;
105
42
  onAfterTick(hook: TickHook, front: boolean): void;
106
- /**
107
- * 消息进入系统的唯一入口
108
- */
43
+ tick(): void;
109
44
  dispatch(message: BaseMessage): void;
110
45
  private pipeline;
111
46
  register(messageClass: any, systemFn: (...args: any[]) => any, priority?: number): () => void;
112
47
  }
113
48
 
114
- /**
115
- * @description: 消息注册器 - 负责将系统函数或监听器与消息类型关联
116
- */
117
49
  declare class MessageRegistry {
118
50
  systemTaskMap: Map<any, SystemTask[]>;
119
51
  /**
120
- * 注册消息并返回一个卸载函数
121
- * 这种模式能完美适配 Controller 的生命周期销毁
52
+ * Register the message and corresponding system and return an uninstallation function
122
53
  */
123
54
  register(messageClass: any, systemFn: (...args: any[]) => any, priority?: number): () => void;
124
55
  }
125
56
 
126
- interface IMessagePublisher {
127
- dispatch(message: BaseMessage): void;
128
- }
129
- declare function activateInstance(instance: MessageInternal): void;
130
- declare const publisher: IMessagePublisher;
57
+ declare function activateInstance(instance: MessageEngine): void;
131
58
  declare class MessageWriter {
132
- /**
133
- * 核心入口:无论是类还是实例,统一交给 Internal 处理
134
- */
135
59
  static write<T extends BaseMessage, K extends Newable<T>>(target: K | T, ...args: ConstructorParameters<K>): void;
136
- /**
137
- * 快捷方式:系统内部常用
138
- */
139
60
  static error(e: Error, context?: string): void;
140
61
  static warn(context: string): void;
141
62
  static info(context: string): void;
142
63
  }
143
64
 
144
- declare const handleResult: (res: any) => void;
65
+ interface SystemParams {
66
+ priority?: number;
67
+ messageClass?: Newable<BaseMessage> | null;
68
+ }
69
+ interface MessageMetadata {
70
+ index: number;
71
+ messageClass: Newable<BaseMessage>;
72
+ single: boolean;
73
+ }
74
+ interface ObserverItem {
75
+ propertyKey: string;
76
+ callback: (oldVal: any, newVal: any) => void | BaseMessage | BaseMessage;
77
+ }
78
+ type ObserverMetadata = ObserverItem[];
79
+ type SafeMetadata = Set<string>;
80
+
81
+ type Middleware = (message: BaseMessage, next: () => void) => void;
82
+ type ExecuteHook<T extends BaseMessage> = (message: [BaseMessage] extends [T] ? SingleMessage[] | EventMessage : T extends SingleMessage ? T[] : T, context: ExecuteHookContext, success: boolean) => void | Promise<void>;
83
+ interface ExecuteHookContext {
84
+ context: SystemContext;
85
+ tick: number;
86
+ payload: {
87
+ [key: string]: any;
88
+ };
89
+ }
90
+ interface SystemContext {
91
+ params: any[];
92
+ targetClass: any;
93
+ methodName: string;
94
+ originalMethod: (...args: any[]) => any;
95
+ }
96
+ interface SystemConfig {
97
+ priority: number;
98
+ messageClass: Newable<BaseMessage>;
99
+ messageIdx: number;
100
+ batchMode: boolean;
101
+ }
102
+ interface SystemTask {
103
+ fn: (...args: any[]) => any;
104
+ priority: number;
105
+ }
106
+ type MessagePayload<T> = T extends SingleMessage ? T[] : T extends EventMessage ? T : T | T[];
107
+ type MessageIdentifier<T> = (abstract new (...args: any[]) => T) | Newable<T>;
108
+ type TickHook = (context: TickHookContext) => void | Promise<void>;
109
+ interface TickHookContext {
110
+ tick: number;
111
+ timestamp: number;
112
+ payload: {
113
+ [key: string]: any;
114
+ };
115
+ }
116
+
117
+ declare function handleResult(res: any): void;
145
118
  /**
146
- * @description: 系统装饰器
147
- * @param priority 优先级,数值越大越早执行
119
+ * System Decorator
120
+ * @param params Priority and MessageClass config
148
121
  */
149
122
  declare function System(params?: SystemParams): (target: any, key: string, descriptor: PropertyDescriptor) => void;
150
123
  /**
151
- * @description: 标记参数为 MessageReader 并锁定其消息类型
152
- */
153
- declare function Message<T extends BaseMessage>(messageClass: Newable<T>, single?: boolean): (target: any, key: string, index: number) => void;
154
- /**
155
- * @description: 标识controller或者组件的方法是否是安全的,可被其他controller直接调用
124
+ * Is the method used to identify the controller or component safe and can be directly called by other controllers
156
125
  */
157
126
  declare function Safe(): (target: any, key: string, _descriptor: PropertyDescriptor) => void;
158
127
  /**
159
- * @description: 标识Component里的这个属性被改了之后需要调用一个回调
128
+ * Observer Decorator
160
129
  */
161
130
  declare function Observer(callback: (oldVal: any, newVale: any) => void | BaseMessage | BaseMessage[]): (target: any, propertyKey: string) => void;
162
131
  /**
163
- * @description: 标记Controller身份
132
+ * Controller Decorator
164
133
  */
165
134
  declare function Controller(): (target: any) => void;
166
135
  /**
167
- * @description: 标记Component身份
136
+ * Component Decorator
168
137
  */
169
138
  declare function Component(): (target: any) => void;
170
139
 
@@ -182,53 +151,78 @@ declare const VIRID_METADATA: {
182
151
  declare class ViridContainer {
183
152
  private bindings;
184
153
  private singletonInstances;
185
- bind<T>(identifier: Newable<T>): {
186
- toSelf: () => {
187
- inSingletonScope: () => {
188
- onActivation: (fn: any) => void;
189
- };
190
- };
191
- };
192
- get<T>(identifier: Newable<T>, onActivate: (instance: T) => T): T;
154
+ private activationHooks;
155
+ /**
156
+ * Register an activation hook
157
+ * @param hook An activation hook
158
+ * @param front Is the hook order inserted from the front or added
159
+ */
160
+ addActivationHook(hook: (instance: any) => any, front: boolean): void;
161
+ /**
162
+ * Static binding component or controller
163
+ * @param identifier Constructor of components or controllers
164
+ */
165
+ bind<T>(identifier: Newable<T>): void;
166
+ /**
167
+ * Dynamically register a component
168
+ * @param instance Component instance
169
+ */
170
+ spawn(instance: object): void;
171
+ /**
172
+ * Obtain a Component or Controller instance
173
+ * @param identifier Constructor of components or controllers
174
+ */
175
+ get<T>(identifier: Newable<T>): T;
176
+ private handleActivation;
193
177
  }
194
178
 
195
179
  interface ViridPlugin<T = any> {
196
180
  name: string;
197
181
  install: (app: ViridApp, options: T) => void;
198
182
  }
199
- /**
200
- * 创建 virid 核心实例
201
- */
202
183
  declare class ViridApp {
203
184
  container: ViridContainer;
204
- private messageInternal;
205
- private activationHooks;
206
- addActivationHook(hook: (instance: any) => any): void;
185
+ engine: MessageEngine;
186
+ private installedPlugins;
187
+ constructor(maxDepth: number, manual: boolean);
188
+ /**
189
+ * Register an activation hook
190
+ * @param hook An activation hook
191
+ * @param front Is the hook order inserted from the front or added
192
+ */
193
+ onActivate(hook: (instance: any) => any, front?: boolean): void;
194
+ /**
195
+ * Opening a new tick
196
+ */
197
+ tick(): void;
198
+ /**
199
+ * Obtain a Component or Controller instance
200
+ * @param identifier Constructor of components or controllers
201
+ */
207
202
  get<T>(identifier: Newable<T>): T;
208
- private handleActivation;
209
203
  /**
210
- * 绑定多例 (Controller 通常是多例)
204
+ * Static binding component or controller
205
+ * @param identifier Constructor of components or controllers
211
206
  */
212
- bindController<T>(identifier: Newable<T>): {
213
- inSingletonScope: () => {
214
- onActivation: () => void;
215
- };
216
- };
207
+ bind<T>(identifier: Newable<T>): void;
217
208
  /**
218
- * 绑定单例 (Component 是单例)
209
+ * Dynamically register a component
210
+ * @param instance Component instance
219
211
  */
220
- bindComponent<T>(identifier: Newable<T>): {
221
- onActivation: () => void;
222
- };
212
+ spawn(instance: object): void;
223
213
  useMiddleware(mw: Middleware, front?: boolean): void;
224
214
  onBeforeExecute<T extends BaseMessage>(type: MessageIdentifier<T>, hook: ExecuteHook<T>, front?: boolean): void;
225
215
  onAfterExecute<T extends BaseMessage>(type: MessageIdentifier<T>, hook: ExecuteHook<T>, front?: boolean): void;
226
216
  onBeforeTick(hook: TickHook, front?: boolean): void;
227
217
  onAfterTick(hook: TickHook, front?: boolean): void;
228
- register(messageClass: any, systemFn: (...args: any[]) => any, priority?: number): () => void;
229
218
  use<T>(plugin: ViridPlugin<T>, options: T): this;
219
+ /**
220
+ * Register message to registrar
221
+ * @param systemFn System functions
222
+ */
223
+ register(systemFn: (...args: any[]) => any): () => void;
230
224
  }
231
225
 
232
226
  declare function createVirid(config?: AppConfig): ViridApp;
233
227
 
234
- export { type AppConfig, BaseMessage, Component, Controller, ErrorMessage, EventMessage, type ExecuteHook, type ExecuteHookContext, type IMessagePublisher, InfoMessage, Message, type MessageIdentifier, MessageInternal, type MessageMetadata, type MessagePayload, MessageRegistry, MessageWriter, type Middleware, type Newable, Observer, type ObserverItem, type ObserverMetadata, Safe, type SafeMetadata, SingleMessage, System, type SystemContext, type SystemParams, type SystemTask, type TickHook, type TickHookContext, VIRID_METADATA, ViridApp, type ViridPlugin, WarnMessage, activateInstance, bindObservers, createVirid, defaultConfig, handleResult, publisher };
228
+ export { type AppConfig, BaseMessage, Component, Controller, ErrorMessage, EventMessage, type ExecuteHook, type ExecuteHookContext, InfoMessage, MessageEngine, type MessageIdentifier, type MessageMetadata, type MessagePayload, MessageRegistry, MessageWriter, type Middleware, type Newable, Observer, type ObserverItem, type ObserverMetadata, Safe, type SafeMetadata, SingleMessage, System, type SystemConfig, type SystemContext, type SystemParams, type SystemTask, type TickHook, type TickHookContext, VIRID_METADATA, ViridApp, type ViridPlugin, WarnMessage, activateInstance, bindObservers, createVirid, defaultConfig, handleResult };
package/dist/index.d.ts CHANGED
@@ -1,170 +1,139 @@
1
1
  type Newable<TInstance = unknown, TArgs extends unknown[] = any[]> = new (...args: TArgs) => TInstance;
2
2
  interface AppConfig {
3
- enableLog: boolean;
4
- }
5
- declare const defaultConfig: {
6
- enableLog: boolean;
7
- };
8
-
9
- interface SystemParams {
10
- priority?: number;
11
- messageClass?: Newable<BaseMessage> | null;
12
- }
13
- interface MessageMetadata {
14
- index: number;
15
- messageClass: Newable<BaseMessage>;
16
- single: boolean;
17
- }
18
- interface ObserverItem {
19
- propertyKey: string;
20
- callback: (oldVal: any, newVal: any) => void | BaseMessage | BaseMessage;
21
- }
22
- type ObserverMetadata = ObserverItem[];
23
- type SafeMetadata = Set<string>;
24
-
25
- type Middleware = (message: BaseMessage, next: () => void) => void;
26
- type ExecuteHook<T extends BaseMessage> = (message: [BaseMessage] extends [T] ? SingleMessage[] | EventMessage : T extends SingleMessage ? T[] : T, context: ExecuteHookContext, success: boolean) => void | Promise<void>;
27
- interface ExecuteHookContext {
28
- context: SystemContext;
29
- tick: number;
30
- payload: {
31
- [key: string]: any;
32
- };
33
- }
34
- interface SystemContext {
35
- params: any[];
36
- targetClass: any;
37
- methodName: string;
38
- originalMethod: (...args: any[]) => any;
39
- }
40
- interface SystemTask {
41
- fn: (...args: any[]) => any;
42
- priority: number;
43
- }
44
- type MessagePayload<T> = T extends SingleMessage ? T[] : T extends EventMessage ? T : T | T[];
45
- type MessageIdentifier<T> = (abstract new (...args: any[]) => T) | Newable<T>;
46
- type TickHook = (context: TickHookContext) => void | Promise<void>;
47
- interface TickHookContext {
48
- tick: number;
49
- timestamp: number;
50
- payload: {
51
- [key: string]: any;
52
- };
3
+ maxDepth?: number;
4
+ enableLog?: boolean;
5
+ manual?: boolean;
53
6
  }
7
+ declare const defaultConfig: AppConfig;
54
8
 
55
9
  declare abstract class BaseMessage {
56
10
  static send<T extends Newable<any>>(this: T, ...args: ConstructorParameters<T>): void;
57
11
  }
58
- /**
59
- * 可合并的信号基类
60
- */
61
12
  declare abstract class SingleMessage extends BaseMessage {
62
- private readonly __kind;
63
13
  constructor();
64
14
  }
65
- /**
66
- * 不可合并的消息基类
67
- */
68
15
  declare abstract class EventMessage extends BaseMessage {
69
- private readonly __kind;
70
16
  constructor();
71
17
  }
72
- /**
73
- * 基础错误消息:不可合并,必须被精准捕获
74
- */
75
18
  declare class ErrorMessage extends EventMessage {
76
19
  readonly error: Error;
77
20
  readonly context?: string | undefined;
78
21
  constructor(error: Error, context?: string | undefined);
79
22
  }
80
- /**
81
- * 基础警告消息:不可合并,必须被精准捕获
82
- */
83
23
  declare class WarnMessage extends EventMessage {
84
24
  readonly context: string;
85
25
  constructor(context: string);
86
26
  }
87
- /**
88
- * 基础信息消息:不可合并,必须被精准捕获
89
- */
90
27
  declare class InfoMessage extends EventMessage {
91
28
  readonly context: string;
92
29
  constructor(context: string);
93
30
  }
94
31
 
95
- declare class MessageInternal {
96
- private eventHub;
32
+ declare class MessageEngine {
97
33
  private dispatcher;
98
34
  private registry;
99
35
  private middlewares;
100
- constructor();
36
+ private manual;
37
+ constructor(maxDepth: number, manual: boolean);
101
38
  useMiddleware(mw: Middleware, front: boolean): void;
102
39
  onBeforeExecute<T extends BaseMessage>(type: MessageIdentifier<T>, hook: ExecuteHook<T>, front: boolean): void;
103
40
  onAfterExecute<T extends BaseMessage>(type: MessageIdentifier<T>, hook: ExecuteHook<T>, front: boolean): void;
104
41
  onBeforeTick(hook: TickHook, front: boolean): void;
105
42
  onAfterTick(hook: TickHook, front: boolean): void;
106
- /**
107
- * 消息进入系统的唯一入口
108
- */
43
+ tick(): void;
109
44
  dispatch(message: BaseMessage): void;
110
45
  private pipeline;
111
46
  register(messageClass: any, systemFn: (...args: any[]) => any, priority?: number): () => void;
112
47
  }
113
48
 
114
- /**
115
- * @description: 消息注册器 - 负责将系统函数或监听器与消息类型关联
116
- */
117
49
  declare class MessageRegistry {
118
50
  systemTaskMap: Map<any, SystemTask[]>;
119
51
  /**
120
- * 注册消息并返回一个卸载函数
121
- * 这种模式能完美适配 Controller 的生命周期销毁
52
+ * Register the message and corresponding system and return an uninstallation function
122
53
  */
123
54
  register(messageClass: any, systemFn: (...args: any[]) => any, priority?: number): () => void;
124
55
  }
125
56
 
126
- interface IMessagePublisher {
127
- dispatch(message: BaseMessage): void;
128
- }
129
- declare function activateInstance(instance: MessageInternal): void;
130
- declare const publisher: IMessagePublisher;
57
+ declare function activateInstance(instance: MessageEngine): void;
131
58
  declare class MessageWriter {
132
- /**
133
- * 核心入口:无论是类还是实例,统一交给 Internal 处理
134
- */
135
59
  static write<T extends BaseMessage, K extends Newable<T>>(target: K | T, ...args: ConstructorParameters<K>): void;
136
- /**
137
- * 快捷方式:系统内部常用
138
- */
139
60
  static error(e: Error, context?: string): void;
140
61
  static warn(context: string): void;
141
62
  static info(context: string): void;
142
63
  }
143
64
 
144
- declare const handleResult: (res: any) => void;
65
+ interface SystemParams {
66
+ priority?: number;
67
+ messageClass?: Newable<BaseMessage> | null;
68
+ }
69
+ interface MessageMetadata {
70
+ index: number;
71
+ messageClass: Newable<BaseMessage>;
72
+ single: boolean;
73
+ }
74
+ interface ObserverItem {
75
+ propertyKey: string;
76
+ callback: (oldVal: any, newVal: any) => void | BaseMessage | BaseMessage;
77
+ }
78
+ type ObserverMetadata = ObserverItem[];
79
+ type SafeMetadata = Set<string>;
80
+
81
+ type Middleware = (message: BaseMessage, next: () => void) => void;
82
+ type ExecuteHook<T extends BaseMessage> = (message: [BaseMessage] extends [T] ? SingleMessage[] | EventMessage : T extends SingleMessage ? T[] : T, context: ExecuteHookContext, success: boolean) => void | Promise<void>;
83
+ interface ExecuteHookContext {
84
+ context: SystemContext;
85
+ tick: number;
86
+ payload: {
87
+ [key: string]: any;
88
+ };
89
+ }
90
+ interface SystemContext {
91
+ params: any[];
92
+ targetClass: any;
93
+ methodName: string;
94
+ originalMethod: (...args: any[]) => any;
95
+ }
96
+ interface SystemConfig {
97
+ priority: number;
98
+ messageClass: Newable<BaseMessage>;
99
+ messageIdx: number;
100
+ batchMode: boolean;
101
+ }
102
+ interface SystemTask {
103
+ fn: (...args: any[]) => any;
104
+ priority: number;
105
+ }
106
+ type MessagePayload<T> = T extends SingleMessage ? T[] : T extends EventMessage ? T : T | T[];
107
+ type MessageIdentifier<T> = (abstract new (...args: any[]) => T) | Newable<T>;
108
+ type TickHook = (context: TickHookContext) => void | Promise<void>;
109
+ interface TickHookContext {
110
+ tick: number;
111
+ timestamp: number;
112
+ payload: {
113
+ [key: string]: any;
114
+ };
115
+ }
116
+
117
+ declare function handleResult(res: any): void;
145
118
  /**
146
- * @description: 系统装饰器
147
- * @param priority 优先级,数值越大越早执行
119
+ * System Decorator
120
+ * @param params Priority and MessageClass config
148
121
  */
149
122
  declare function System(params?: SystemParams): (target: any, key: string, descriptor: PropertyDescriptor) => void;
150
123
  /**
151
- * @description: 标记参数为 MessageReader 并锁定其消息类型
152
- */
153
- declare function Message<T extends BaseMessage>(messageClass: Newable<T>, single?: boolean): (target: any, key: string, index: number) => void;
154
- /**
155
- * @description: 标识controller或者组件的方法是否是安全的,可被其他controller直接调用
124
+ * Is the method used to identify the controller or component safe and can be directly called by other controllers
156
125
  */
157
126
  declare function Safe(): (target: any, key: string, _descriptor: PropertyDescriptor) => void;
158
127
  /**
159
- * @description: 标识Component里的这个属性被改了之后需要调用一个回调
128
+ * Observer Decorator
160
129
  */
161
130
  declare function Observer(callback: (oldVal: any, newVale: any) => void | BaseMessage | BaseMessage[]): (target: any, propertyKey: string) => void;
162
131
  /**
163
- * @description: 标记Controller身份
132
+ * Controller Decorator
164
133
  */
165
134
  declare function Controller(): (target: any) => void;
166
135
  /**
167
- * @description: 标记Component身份
136
+ * Component Decorator
168
137
  */
169
138
  declare function Component(): (target: any) => void;
170
139
 
@@ -182,53 +151,78 @@ declare const VIRID_METADATA: {
182
151
  declare class ViridContainer {
183
152
  private bindings;
184
153
  private singletonInstances;
185
- bind<T>(identifier: Newable<T>): {
186
- toSelf: () => {
187
- inSingletonScope: () => {
188
- onActivation: (fn: any) => void;
189
- };
190
- };
191
- };
192
- get<T>(identifier: Newable<T>, onActivate: (instance: T) => T): T;
154
+ private activationHooks;
155
+ /**
156
+ * Register an activation hook
157
+ * @param hook An activation hook
158
+ * @param front Is the hook order inserted from the front or added
159
+ */
160
+ addActivationHook(hook: (instance: any) => any, front: boolean): void;
161
+ /**
162
+ * Static binding component or controller
163
+ * @param identifier Constructor of components or controllers
164
+ */
165
+ bind<T>(identifier: Newable<T>): void;
166
+ /**
167
+ * Dynamically register a component
168
+ * @param instance Component instance
169
+ */
170
+ spawn(instance: object): void;
171
+ /**
172
+ * Obtain a Component or Controller instance
173
+ * @param identifier Constructor of components or controllers
174
+ */
175
+ get<T>(identifier: Newable<T>): T;
176
+ private handleActivation;
193
177
  }
194
178
 
195
179
  interface ViridPlugin<T = any> {
196
180
  name: string;
197
181
  install: (app: ViridApp, options: T) => void;
198
182
  }
199
- /**
200
- * 创建 virid 核心实例
201
- */
202
183
  declare class ViridApp {
203
184
  container: ViridContainer;
204
- private messageInternal;
205
- private activationHooks;
206
- addActivationHook(hook: (instance: any) => any): void;
185
+ engine: MessageEngine;
186
+ private installedPlugins;
187
+ constructor(maxDepth: number, manual: boolean);
188
+ /**
189
+ * Register an activation hook
190
+ * @param hook An activation hook
191
+ * @param front Is the hook order inserted from the front or added
192
+ */
193
+ onActivate(hook: (instance: any) => any, front?: boolean): void;
194
+ /**
195
+ * Opening a new tick
196
+ */
197
+ tick(): void;
198
+ /**
199
+ * Obtain a Component or Controller instance
200
+ * @param identifier Constructor of components or controllers
201
+ */
207
202
  get<T>(identifier: Newable<T>): T;
208
- private handleActivation;
209
203
  /**
210
- * 绑定多例 (Controller 通常是多例)
204
+ * Static binding component or controller
205
+ * @param identifier Constructor of components or controllers
211
206
  */
212
- bindController<T>(identifier: Newable<T>): {
213
- inSingletonScope: () => {
214
- onActivation: () => void;
215
- };
216
- };
207
+ bind<T>(identifier: Newable<T>): void;
217
208
  /**
218
- * 绑定单例 (Component 是单例)
209
+ * Dynamically register a component
210
+ * @param instance Component instance
219
211
  */
220
- bindComponent<T>(identifier: Newable<T>): {
221
- onActivation: () => void;
222
- };
212
+ spawn(instance: object): void;
223
213
  useMiddleware(mw: Middleware, front?: boolean): void;
224
214
  onBeforeExecute<T extends BaseMessage>(type: MessageIdentifier<T>, hook: ExecuteHook<T>, front?: boolean): void;
225
215
  onAfterExecute<T extends BaseMessage>(type: MessageIdentifier<T>, hook: ExecuteHook<T>, front?: boolean): void;
226
216
  onBeforeTick(hook: TickHook, front?: boolean): void;
227
217
  onAfterTick(hook: TickHook, front?: boolean): void;
228
- register(messageClass: any, systemFn: (...args: any[]) => any, priority?: number): () => void;
229
218
  use<T>(plugin: ViridPlugin<T>, options: T): this;
219
+ /**
220
+ * Register message to registrar
221
+ * @param systemFn System functions
222
+ */
223
+ register(systemFn: (...args: any[]) => any): () => void;
230
224
  }
231
225
 
232
226
  declare function createVirid(config?: AppConfig): ViridApp;
233
227
 
234
- export { type AppConfig, BaseMessage, Component, Controller, ErrorMessage, EventMessage, type ExecuteHook, type ExecuteHookContext, type IMessagePublisher, InfoMessage, Message, type MessageIdentifier, MessageInternal, type MessageMetadata, type MessagePayload, MessageRegistry, MessageWriter, type Middleware, type Newable, Observer, type ObserverItem, type ObserverMetadata, Safe, type SafeMetadata, SingleMessage, System, type SystemContext, type SystemParams, type SystemTask, type TickHook, type TickHookContext, VIRID_METADATA, ViridApp, type ViridPlugin, WarnMessage, activateInstance, bindObservers, createVirid, defaultConfig, handleResult, publisher };
228
+ export { type AppConfig, BaseMessage, Component, Controller, ErrorMessage, EventMessage, type ExecuteHook, type ExecuteHookContext, InfoMessage, MessageEngine, type MessageIdentifier, type MessageMetadata, type MessagePayload, MessageRegistry, MessageWriter, type Middleware, type Newable, Observer, type ObserverItem, type ObserverMetadata, Safe, type SafeMetadata, SingleMessage, System, type SystemConfig, type SystemContext, type SystemParams, type SystemTask, type TickHook, type TickHookContext, VIRID_METADATA, ViridApp, type ViridPlugin, WarnMessage, activateInstance, bindObservers, createVirid, defaultConfig, handleResult };