@yumerijs/core 1.1.0-alpha.1 → 1.1.0-alpha.2

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.
@@ -0,0 +1,133 @@
1
+ /**
2
+ * @time: 2025/03/24 12:26
3
+ * @author: FireGuo
4
+ * WindyPear-Team All right reserved
5
+ **/
6
+ /**
7
+ * 插件配置模式定义类
8
+ * 用于描述插件配置项的类型、默认值、描述等信息
9
+ */
10
+ export declare class ConfigSchema {
11
+ /**
12
+ * 配置项类型
13
+ */
14
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array';
15
+ /**
16
+ * 默认值
17
+ */
18
+ default?: any;
19
+ /**
20
+ * 配置项描述
21
+ */
22
+ description?: string;
23
+ /**
24
+ * 是否必需
25
+ */
26
+ required?: boolean;
27
+ /**
28
+ * 枚举值列表(可选项)
29
+ */
30
+ enum?: any[];
31
+ /**
32
+ * 数组项类型定义(当type为array时使用)
33
+ */
34
+ items?: ConfigSchema;
35
+ /**
36
+ * 对象属性定义(当type为object时使用)
37
+ */
38
+ properties?: Record<string, ConfigSchema>;
39
+ /**
40
+ * 创建配置模式对象
41
+ * @param type 配置项类型
42
+ * @param options 配置项选项
43
+ */
44
+ constructor(type: 'string' | 'number' | 'boolean' | 'object' | 'array', options?: {
45
+ default?: any;
46
+ description?: string;
47
+ required?: boolean;
48
+ enum?: any[];
49
+ items?: ConfigSchema;
50
+ properties?: Record<string, ConfigSchema>;
51
+ });
52
+ /**
53
+ * 创建字符串类型配置模式
54
+ * @param options 配置项选项
55
+ * @returns 配置模式对象
56
+ */
57
+ static string(options?: Omit<ConfigSchema, 'type' | 'items' | 'properties'>): ConfigSchema;
58
+ /**
59
+ * 创建数字类型配置模式
60
+ * @param options 配置项选项
61
+ * @returns 配置模式对象
62
+ */
63
+ static number(options?: Omit<ConfigSchema, 'type' | 'items' | 'properties'>): ConfigSchema;
64
+ /**
65
+ * 创建布尔类型配置模式
66
+ * @param options 配置项选项
67
+ * @returns 配置模式对象
68
+ */
69
+ static boolean(options?: Omit<ConfigSchema, 'type' | 'items' | 'properties'>): ConfigSchema;
70
+ /**
71
+ * 创建对象类型配置模式
72
+ * @param properties 对象属性定义
73
+ * @param options 配置项选项
74
+ * @returns 配置模式对象
75
+ */
76
+ static object(properties: Record<string, ConfigSchema>, options?: Omit<ConfigSchema, 'type' | 'items' | 'properties'>): ConfigSchema;
77
+ /**
78
+ * 创建数组类型配置模式
79
+ * @param items 数组项类型定义
80
+ * @param options 配置项选项
81
+ * @returns 配置模式对象
82
+ */
83
+ static array(items: ConfigSchema, options?: Omit<ConfigSchema, 'type' | 'items' | 'properties'>): ConfigSchema;
84
+ /**
85
+ * 验证值是否符合配置模式
86
+ * @param value 要验证的值
87
+ * @returns 验证结果,如果通过返回true,否则返回错误信息
88
+ */
89
+ validate(value: any): true | string;
90
+ }
91
+ export declare class Config {
92
+ /**
93
+ * 配置名称
94
+ */
95
+ name: string;
96
+ /**
97
+ * 配置内容
98
+ */
99
+ content: {
100
+ [name: string]: any;
101
+ };
102
+ /**
103
+ * 配置模式
104
+ */
105
+ schema?: Record<string, ConfigSchema>;
106
+ /**
107
+ * 创建配置对象
108
+ * @param name 配置名称
109
+ * @param content 配置内容
110
+ * @param schema 配置模式
111
+ */
112
+ constructor(name: string, content?: {
113
+ [name: string]: any;
114
+ }, schema?: Record<string, ConfigSchema>);
115
+ /**
116
+ * 获取配置项值
117
+ * @param key 配置项键名
118
+ * @param defaultValue 默认值
119
+ * @returns 配置项值
120
+ */
121
+ get<T>(key: string, defaultValue?: T): T;
122
+ /**
123
+ * 设置配置项值
124
+ * @param key 配置项键名
125
+ * @param value 配置项值
126
+ */
127
+ set(key: string, value: any): void;
128
+ /**
129
+ * 验证配置是否符合schema
130
+ * @returns 验证结果,如果通过返回true,否则返回错误信息
131
+ */
132
+ validate(): true | string;
133
+ }
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ /**
3
+ * @time: 2025/03/24 12:26
4
+ * @author: FireGuo
5
+ * WindyPear-Team All right reserved
6
+ **/
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.Config = exports.ConfigSchema = void 0;
9
+ /**
10
+ * 插件配置模式定义类
11
+ * 用于描述插件配置项的类型、默认值、描述等信息
12
+ */
13
+ class ConfigSchema {
14
+ /**
15
+ * 创建配置模式对象
16
+ * @param type 配置项类型
17
+ * @param options 配置项选项
18
+ */
19
+ constructor(type, options) {
20
+ this.type = type;
21
+ if (options) {
22
+ this.default = options.default;
23
+ this.description = options.description;
24
+ this.required = options.required;
25
+ this.enum = options.enum;
26
+ this.items = options.items;
27
+ this.properties = options.properties;
28
+ }
29
+ }
30
+ /**
31
+ * 创建字符串类型配置模式
32
+ * @param options 配置项选项
33
+ * @returns 配置模式对象
34
+ */
35
+ static string(options) {
36
+ return new ConfigSchema('string', options);
37
+ }
38
+ /**
39
+ * 创建数字类型配置模式
40
+ * @param options 配置项选项
41
+ * @returns 配置模式对象
42
+ */
43
+ static number(options) {
44
+ return new ConfigSchema('number', options);
45
+ }
46
+ /**
47
+ * 创建布尔类型配置模式
48
+ * @param options 配置项选项
49
+ * @returns 配置模式对象
50
+ */
51
+ static boolean(options) {
52
+ return new ConfigSchema('boolean', options);
53
+ }
54
+ /**
55
+ * 创建对象类型配置模式
56
+ * @param properties 对象属性定义
57
+ * @param options 配置项选项
58
+ * @returns 配置模式对象
59
+ */
60
+ static object(properties, options) {
61
+ return new ConfigSchema('object', { ...options, properties });
62
+ }
63
+ /**
64
+ * 创建数组类型配置模式
65
+ * @param items 数组项类型定义
66
+ * @param options 配置项选项
67
+ * @returns 配置模式对象
68
+ */
69
+ static array(items, options) {
70
+ return new ConfigSchema('array', { ...options, items });
71
+ }
72
+ /**
73
+ * 验证值是否符合配置模式
74
+ * @param value 要验证的值
75
+ * @returns 验证结果,如果通过返回true,否则返回错误信息
76
+ */
77
+ validate(value) {
78
+ // 检查必需项
79
+ if (this.required && value === undefined) {
80
+ return `Missing required value`;
81
+ }
82
+ // 如果值存在,检查类型
83
+ if (value !== undefined) {
84
+ // 类型检查
85
+ switch (this.type) {
86
+ case 'string':
87
+ if (typeof value !== 'string') {
88
+ return `Value should be string`;
89
+ }
90
+ break;
91
+ case 'number':
92
+ if (typeof value !== 'number') {
93
+ return `Value should be number`;
94
+ }
95
+ break;
96
+ case 'boolean':
97
+ if (typeof value !== 'boolean') {
98
+ return `Value should be boolean`;
99
+ }
100
+ break;
101
+ case 'object':
102
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
103
+ return `Value should be object`;
104
+ }
105
+ // 如果有属性定义,检查每个属性
106
+ if (this.properties) {
107
+ for (const key in this.properties) {
108
+ const propSchema = this.properties[key];
109
+ const propValue = value[key];
110
+ const propResult = propSchema.validate(propValue);
111
+ if (propResult !== true) {
112
+ return `Property ${key}: ${propResult}`;
113
+ }
114
+ }
115
+ }
116
+ break;
117
+ case 'array':
118
+ if (!Array.isArray(value)) {
119
+ return `Value should be array`;
120
+ }
121
+ // 如果有数组项定义,检查每个项
122
+ if (this.items) {
123
+ for (let i = 0; i < value.length; i++) {
124
+ const itemResult = this.items.validate(value[i]);
125
+ if (itemResult !== true) {
126
+ return `Item at index ${i}: ${itemResult}`;
127
+ }
128
+ }
129
+ }
130
+ break;
131
+ }
132
+ // 枚举值检查
133
+ if (this.enum && !this.enum.includes(value)) {
134
+ return `Value should be one of: ${this.enum.join(', ')}`;
135
+ }
136
+ }
137
+ return true;
138
+ }
139
+ }
140
+ exports.ConfigSchema = ConfigSchema;
141
+ class Config {
142
+ /**
143
+ * 创建配置对象
144
+ * @param name 配置名称
145
+ * @param content 配置内容
146
+ * @param schema 配置模式
147
+ */
148
+ constructor(name, content, schema) {
149
+ /**
150
+ * 配置名称
151
+ */
152
+ this.name = '';
153
+ /**
154
+ * 配置内容
155
+ */
156
+ this.content = {};
157
+ this.name = name;
158
+ this.content = content || {}; // 如果 content 是 undefined,则赋值为空对象
159
+ this.schema = schema;
160
+ }
161
+ /**
162
+ * 获取配置项值
163
+ * @param key 配置项键名
164
+ * @param defaultValue 默认值
165
+ * @returns 配置项值
166
+ */
167
+ get(key, defaultValue) {
168
+ if (this.content[key] !== undefined) {
169
+ return this.content[key];
170
+ }
171
+ // 如果有schema,尝试从schema中获取默认值
172
+ if (this.schema && this.schema[key] && this.schema[key].default !== undefined) {
173
+ return this.schema[key].default;
174
+ }
175
+ return defaultValue;
176
+ }
177
+ /**
178
+ * 设置配置项值
179
+ * @param key 配置项键名
180
+ * @param value 配置项值
181
+ */
182
+ set(key, value) {
183
+ this.content[key] = value;
184
+ }
185
+ /**
186
+ * 验证配置是否符合schema
187
+ * @returns 验证结果,如果通过返回true,否则返回错误信息
188
+ */
189
+ validate() {
190
+ if (!this.schema) {
191
+ return true; // 没有schema,视为验证通过
192
+ }
193
+ for (const key in this.schema) {
194
+ const schemaItem = this.schema[key];
195
+ const value = this.content[key];
196
+ const result = schemaItem.validate(value);
197
+ if (result !== true) {
198
+ return `Config ${key}: ${result}`;
199
+ }
200
+ }
201
+ return true;
202
+ }
203
+ }
204
+ exports.Config = Config;
205
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";AAAA;;;;IAII;;;AAEJ;;;GAGG;AACH,MAAa,YAAY;IAoCrB;;;;OAIG;IACH,YACE,IAA0D,EAC1D,OAOC;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QAEjB,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;YAC/B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;YACvC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;YACjC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;YACzB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;YAC3B,IAAI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W,EAAE,KAAU;QAC9B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACI,QAAQ;QACX,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACf,OAAO,IAAI,CAAC,CAAC,kBAAkB;QACnC,CAAC;QAED,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAC5B,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACpC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAEhC,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC1C,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;gBAClB,OAAO,UAAU,GAAG,KAAK,MAAM,EAAE,CAAC;YACtC,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA7ED,wBA6EC"}
@@ -0,0 +1,66 @@
1
+ import { Config } from './config';
2
+ import { Logger } from './logger';
3
+ import { Command } from './command';
4
+ import { Session } from './session';
5
+ import { Platform } from './platform';
6
+ interface Plugin {
7
+ apply: (core: Core, config: Config) => Promise<void>;
8
+ disable: (core: Core) => Promise<void>;
9
+ depend: Array<string>;
10
+ provide: Array<string>;
11
+ }
12
+ interface PluginLoader {
13
+ load(pluginName: string): Promise<Plugin>;
14
+ unloadPlugin(pluginName: string): Promise<void>;
15
+ checkPluginDependencies(pluginPath: string): Promise<boolean>;
16
+ installPluginDependencies(pluginName: string): Promise<void>;
17
+ logger: Logger;
18
+ }
19
+ export declare class Core {
20
+ plugins: {
21
+ [name: string]: Plugin & {
22
+ depend?: string[];
23
+ provide?: string[];
24
+ };
25
+ };
26
+ config: any;
27
+ platforms: Platform[];
28
+ private eventListeners;
29
+ private components;
30
+ commands: Record<string, Command>;
31
+ private pluginLoader;
32
+ private logger;
33
+ private providedComponents;
34
+ private pluginModules;
35
+ constructor(pluginLoader: PluginLoader);
36
+ loadConfig(configPath: string): Promise<void>;
37
+ getPluginConfig(pluginName: string): Promise<Config>;
38
+ loadPlugins(): Promise<void>;
39
+ /**
40
+ * 监听插件目录,实现热重载
41
+ * @param core Core实例
42
+ * @param pluginsDir 插件目录
43
+ */
44
+ watchPlugins(core: Core, pluginsDir?: string): void;
45
+ /**
46
+ * 重新加载插件
47
+ * @param pluginName 插件名称
48
+ * @param core Core实例
49
+ */
50
+ reloadPlugin(pluginName: string, core: Core): Promise<void>;
51
+ /**
52
+ * 卸载插件并触发事件
53
+ * @param pluginName 插件名称
54
+ * @param core Core实例
55
+ */
56
+ unloadPluginAndEmit(pluginName: string, core: Core): Promise<void>;
57
+ registerComponent(name: string, component: any): void;
58
+ getComponent(name: string): any;
59
+ unregisterComponent(name: string): void;
60
+ on(event: string, listener: (...args: any[]) => Promise<void>): void;
61
+ emit(event: string, ...args: any[]): Promise<void>;
62
+ command(name: string): Command;
63
+ executeCommand(name: string, session: any, ...args: any[]): Promise<Session | null>;
64
+ registerPlatform(platform: Platform): any;
65
+ }
66
+ export {};