@yumerijs/core 2.1.0 → 2.2.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/config.d.ts CHANGED
@@ -1,122 +1,31 @@
1
- /**
2
- * @time: 2025/05/24 12:18
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
- */
1
+ export declare function fallback<T>(schema: Schema<T>, config: T): T;
2
+ export declare class Schema<T = any> {
3
+ _type?: T;
4
+ type: string;
5
+ isRequired?: boolean;
22
6
  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>;
7
+ defaultValue?: any;
8
+ properties?: Record<string, Schema<any>>;
9
+ items?: Schema<any>;
10
+ enum?: T[];
11
+ constructor(definition: Omit<Schema<T>, '_type' | 'required' | 'default'> & {
12
+ enum?: T[];
51
13
  });
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;
14
+ static string(description?: string): Schema<string>;
15
+ static number(description?: string): Schema<number>;
16
+ static boolean(description?: string): Schema<boolean>;
17
+ static array<T>(inner: Schema<T>, description?: string): Schema<T[]>;
18
+ static object<T extends {}>(properties: {
19
+ [K in keyof T]: Schema<T[K]>;
20
+ }, description?: string): Schema<T>;
21
+ static extend<T extends {}, U extends {}>(base: Schema<T>, extension: {
22
+ [K in keyof U]: Schema<U[K]>;
23
+ }, description?: string): Schema<T & U>;
24
+ static enum<L extends string | number>(values: L[], description?: string): Schema<L>;
25
+ required(this: this): this;
26
+ default(this: this, value: T): this;
84
27
  }
85
- export declare class Config {
86
- /**
87
- * 配置名称
88
- */
89
- name: string;
90
- /**
91
- * 配置内容
92
- */
93
- content: {
94
- [name: string]: any;
95
- };
96
- /**
97
- * 配置模式
98
- */
99
- schema?: Record<string, ConfigSchema>;
100
- /**
101
- * 创建配置对象
102
- * @param name 配置名称
103
- * @param content 配置内容
104
- * @param schema 配置模式
105
- */
106
- constructor(name: string, content?: {
107
- [name: string]: any;
108
- }, schema?: Record<string, ConfigSchema>);
109
- /**
110
- * 获取配置项值
111
- * @param key 配置项键名
112
- * @param defaultValue 默认值
113
- * @returns 配置项值
114
- */
115
- get<T>(key: string, defaultValue?: T): T;
116
- /**
117
- * 设置配置项值
118
- * @param key 配置项键名
119
- * @param value 配置项值
120
- */
121
- set(key: string, value: any): void;
28
+ export { Schema as ConfigSchema };
29
+ export interface Config {
30
+ [key: string]: any;
122
31
  }
package/dist/config.js CHANGED
@@ -1,151 +1,78 @@
1
- "use strict";
2
- /**
3
- * @time: 2025/05/24 12:18
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
- */
1
+ function isNullable(value) {
2
+ return value === null || value === undefined;
3
+ }
4
+ export function fallback(schema, config) {
5
+ if (!schema)
6
+ return config;
7
+ let result = config;
8
+ if (isNullable(result)) {
9
+ result = schema.defaultValue;
10
+ }
11
+ if (schema.type === 'object') {
12
+ if (typeof result !== 'object' || result === null) {
13
+ result = {};
14
+ }
15
+ for (const key in schema.properties) {
16
+ const innerSchema = schema.properties[key];
17
+ result[key] = fallback(innerSchema, result[key]);
18
+ }
19
+ }
20
+ else if (schema.type === 'array' && schema.items) {
21
+ if (!Array.isArray(result)) {
22
+ result = [];
23
+ }
24
+ result = result.map((item) => fallback(schema.items, item));
25
+ }
26
+ return result;
27
+ }
28
+ export class Schema {
29
+ _type; // Phantom type
17
30
  type;
18
- /**
19
- * 默认值
20
- */
21
- default;
22
- /**
23
- * 配置项描述
24
- */
31
+ isRequired;
25
32
  description;
26
- /**
27
- * 是否必需
28
- */
29
- required;
30
- /**
31
- * 枚举值列表(可选项)
32
- */
33
- enum;
34
- /**
35
- * 数组项类型定义(当type为array时使用)
36
- */
37
- items;
38
- /**
39
- * 对象属性定义(当type为object时使用)
40
- */
33
+ defaultValue;
41
34
  properties;
42
- /**
43
- * 创建配置模式对象
44
- * @param type 配置项类型
45
- * @param options 配置项选项
46
- */
47
- constructor(type, options) {
48
- this.type = type;
49
- if (options) {
50
- this.default = options.default;
51
- this.description = options.description;
52
- this.required = options.required;
53
- this.enum = options.enum;
54
- this.items = options.items;
55
- this.properties = options.properties;
56
- }
35
+ items;
36
+ enum;
37
+ constructor(definition) {
38
+ this.type = definition.type;
39
+ this.isRequired = definition.isRequired;
40
+ this.description = definition.description;
41
+ this.defaultValue = definition.defaultValue;
42
+ this.properties = definition.properties;
43
+ this.items = definition.items;
44
+ this.enum = definition.enum;
57
45
  }
58
- /**
59
- * 创建字符串类型配置模式
60
- * @param options 配置项选项
61
- * @returns 配置模式对象
62
- */
63
- static string(options) {
64
- return new ConfigSchema('string', options);
46
+ static string(description) {
47
+ return new Schema({ type: 'string', description });
65
48
  }
66
- /**
67
- * 创建数字类型配置模式
68
- * @param options 配置项选项
69
- * @returns 配置模式对象
70
- */
71
- static number(options) {
72
- return new ConfigSchema('number', options);
49
+ static number(description) {
50
+ return new Schema({ type: 'number', description });
73
51
  }
74
- /**
75
- * 创建布尔类型配置模式
76
- * @param options 配置项选项
77
- * @returns 配置模式对象
78
- */
79
- static boolean(options) {
80
- return new ConfigSchema('boolean', options);
52
+ static boolean(description) {
53
+ return new Schema({ type: 'boolean', description });
81
54
  }
82
- /**
83
- * 创建对象类型配置模式
84
- * @param properties 对象属性定义
85
- * @param options 配置项选项
86
- * @returns 配置模式对象
87
- */
88
- static object(properties, options) {
89
- return new ConfigSchema('object', { ...options, properties });
55
+ static array(inner, description) {
56
+ return new Schema({ type: 'array', items: inner, description });
90
57
  }
91
- /**
92
- * 创建数组类型配置模式
93
- * @param items 数组项类型定义
94
- * @param options 配置项选项
95
- * @returns 配置模式对象
96
- */
97
- static array(items, options) {
98
- return new ConfigSchema('array', { ...options, items });
58
+ static object(properties, description) {
59
+ return new Schema({ type: 'object', properties, description });
99
60
  }
100
- }
101
- exports.ConfigSchema = ConfigSchema;
102
- class Config {
103
- /**
104
- * 配置名称
105
- */
106
- name = '';
107
- /**
108
- * 配置内容
109
- */
110
- content = {};
111
- /**
112
- * 配置模式
113
- */
114
- schema;
115
- /**
116
- * 创建配置对象
117
- * @param name 配置名称
118
- * @param content 配置内容
119
- * @param schema 配置模式
120
- */
121
- constructor(name, content, schema) {
122
- this.name = name;
123
- this.content = content || {}; // 如果 content 是 undefined,则赋值为空对象
124
- this.schema = schema;
61
+ static extend(base, extension, description) {
62
+ const combinedProperties = { ...base.properties, ...extension };
63
+ return new Schema({ type: 'object', properties: combinedProperties, description: description || base.description });
125
64
  }
126
- /**
127
- * 获取配置项值
128
- * @param key 配置项键名
129
- * @param defaultValue 默认值
130
- * @returns 配置项值
131
- */
132
- get(key, defaultValue) {
133
- if (this.content[key] !== undefined) {
134
- return this.content[key];
135
- }
136
- // 如果有schema,尝试从schema中获取默认值
137
- if (this.schema && this.schema[key] && this.schema[key].default !== undefined) {
138
- return this.schema[key].default;
139
- }
140
- return defaultValue;
65
+ static enum(values, description) {
66
+ const type = typeof values[0] === 'string' ? 'string' : typeof values[0] === 'number' ? 'number' : 'string'; // Infer type based on first value
67
+ return new Schema({ type, enum: values, description });
68
+ }
69
+ required() {
70
+ this.isRequired = true;
71
+ return this;
141
72
  }
142
- /**
143
- * 设置配置项值
144
- * @param key 配置项键名
145
- * @param value 配置项值
146
- */
147
- set(key, value) {
148
- this.content[key] = value;
73
+ default(value) {
74
+ this.defaultValue = value;
75
+ return this;
149
76
  }
150
77
  }
151
- exports.Config = Config;
78
+ export { Schema as ConfigSchema };
package/dist/context.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- import { Core } from './core';
2
- import { Route } from './route';
3
- import { HookHandler } from './hook';
4
- import { Middleware } from './middleware';
5
- import { Config } from './config';
1
+ import { Core } from './core.js';
2
+ import { Route } from './route.js';
3
+ import { HookHandler } from './hook.js';
4
+ import { Middleware } from './middleware.js';
6
5
  interface Plugin {
7
- apply: (ctx: Context, config: Config) => Promise<void>;
6
+ apply: (ctx: Context, config: any) => any;
8
7
  disable: (ctx: Context) => Promise<void>;
9
8
  depend: Array<string>;
10
9
  provide: Array<string>;
@@ -102,7 +101,7 @@ export declare class Context {
102
101
  * @param plugin 插件实例
103
102
  * @param config 插件配置
104
103
  */
105
- apply(plugin: Plugin, config: Config): Promise<void>;
104
+ apply(plugin: Plugin, config: any): Promise<void>;
106
105
  /**
107
106
  * 注册 i18n
108
107
  * @param content 内容(可以是嵌套对象或单个key)
package/dist/context.js CHANGED
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Context = void 0;
4
- const route_1 = require("./route");
1
+ import { Route } from './route.js';
5
2
  /**
6
3
  * 插件上下文对象
7
4
  * 每个插件一个 Context,用于管理插件注册的命令、路由、事件、组件和中间件
8
5
  */
9
- class Context {
6
+ export class Context {
10
7
  core;
11
8
  routes = [];
12
9
  eventlisteners = [];
@@ -48,7 +45,7 @@ class Context {
48
45
  route(path) {
49
46
  if (this.core.routes[path]) {
50
47
  this.core.logger.warn(`Plugin "${this.pluginname}" attempt to register route "${path}", but it has already been registered.`);
51
- return new route_1.Route(path, this);
48
+ return new Route(path, this);
52
49
  }
53
50
  this.routes.push(path);
54
51
  return this.core.route(path, this);
@@ -232,4 +229,3 @@ class Context {
232
229
  this.childContexts = [];
233
230
  }
234
231
  }
235
- exports.Context = Context;
package/dist/core.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { EventEmitter } from 'events';
2
- import { Config } from './config';
3
- import { Logger } from './logger';
4
- import { Session } from './session';
5
- import { Middleware } from './middleware';
6
- import { Route } from './route';
7
- import { Context } from './context';
8
- import { HookHandler, Hook } from './hook';
9
- import { Server as CoreServer } from './server';
10
- import { I18n } from './i18n';
2
+ import { Config } from './config.js';
3
+ import { Logger } from './logger.js';
4
+ import { Session } from './session.js';
5
+ import { Middleware } from './middleware.js';
6
+ import { Route } from './route.js';
7
+ import { Context } from './context.js';
8
+ import { HookHandler, Hook } from './hook.js';
9
+ import { Server as CoreServer } from './server.js';
10
+ import { I18n } from './i18n.js';
11
11
  import { IRenderer } from '@yumerijs/types';
12
12
  interface Plugin {
13
13
  apply: (ctx: Context, config: Config) => Promise<void>;
package/dist/core.js CHANGED
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Core = void 0;
4
- const events_1 = require("events");
5
- const logger_1 = require("./logger");
6
- const route_1 = require("./route");
7
- const hook_1 = require("./hook");
8
- const server_1 = require("./server");
9
- class Core {
10
- emitter = new events_1.EventEmitter();
1
+ import { EventEmitter } from 'events';
2
+ import { Logger } from './logger.js';
3
+ import { Route } from './route.js';
4
+ import { Hook } from './hook.js';
5
+ import { Server as CoreServer } from './server.js';
6
+ export class Core {
7
+ emitter = new EventEmitter();
11
8
  components = {};
12
9
  routes = {};
13
- logger = new logger_1.Logger('core');
10
+ logger = new Logger('core');
14
11
  globalMiddlewares = {};
15
12
  hooks = {};
16
13
  coreConfig;
@@ -23,7 +20,7 @@ class Core {
23
20
  this.coreConfig = coreConfig || {};
24
21
  this.loader = loader;
25
22
  if (setCore)
26
- logger_1.Logger.setCore(this);
23
+ Logger.setCore(this);
27
24
  }
28
25
  addRenderer(renderer) {
29
26
  if (this.renderers.has(renderer.name)) {
@@ -35,7 +32,7 @@ class Core {
35
32
  return this.pluginRenderers.get(pluginName);
36
33
  }
37
34
  async runCore() {
38
- this.server = new server_1.Server(this, {
35
+ this.server = new CoreServer(this, {
39
36
  port: this.coreConfig.port || 14510,
40
37
  host: this.coreConfig.host || '0.0.0.0',
41
38
  enableCors: this.coreConfig.enableCors || false,
@@ -93,13 +90,13 @@ class Core {
93
90
  return this;
94
91
  }
95
92
  route(path, context) {
96
- const route = new route_1.Route(path, context);
93
+ const route = new Route(path, context);
97
94
  this.routes[path] = route;
98
95
  return route;
99
96
  }
100
97
  hook(name, hookname, callback) {
101
98
  if (!this.hooks[name]) {
102
- this.hooks[name] = new hook_1.Hook(name);
99
+ this.hooks[name] = new Hook(name);
103
100
  }
104
101
  this.hooks[name].add(hookname, callback);
105
102
  }
@@ -196,4 +193,3 @@ class Core {
196
193
  return false;
197
194
  }
198
195
  }
199
- exports.Core = Core;
package/dist/hook.js CHANGED
@@ -1,15 +1,12 @@
1
- "use strict";
2
1
  /**
3
2
  * @time: 2025/08/14 18:33
4
3
  * @author: FireGuo
5
4
  * WindyPear-Team All right reserved
6
5
  **/
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.Hook = void 0;
9
6
  /**
10
7
  * Hook 类
11
8
  */
12
- class Hook {
9
+ export class Hook {
13
10
  name;
14
11
  handlers = {};
15
12
  /**
@@ -48,4 +45,3 @@ class Hook {
48
45
  return result;
49
46
  }
50
47
  }
51
- exports.Hook = Hook;
package/dist/i18n.js CHANGED
@@ -1,12 +1,9 @@
1
- "use strict";
2
1
  /**
3
2
  * @time: 2025/10/28 22:13
4
3
  * @author: FireGuo
5
4
  * WindyPear-Team All right reserved
6
5
  **/
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.I18n = void 0;
9
- class I18n {
6
+ export class I18n {
10
7
  data = {};
11
8
  fallback;
12
9
  constructor(fallback = ['en']) {
@@ -77,4 +74,3 @@ class I18n {
77
74
  return this.data;
78
75
  }
79
76
  }
80
- exports.I18n = I18n;
package/dist/index.d.ts CHANGED
@@ -3,12 +3,12 @@
3
3
  * @author: FireGuo
4
4
  * WindyPear-Team All right reserved
5
5
  **/
6
- export * from './core';
7
- export * from './session';
8
- export * from './route';
9
- export * from './config';
10
- export * from './logger';
11
- export * from './context';
12
- export * from './hook';
13
- export * from './middleware';
14
- export * from './i18n';
6
+ export * from './core.js';
7
+ export * from './session.js';
8
+ export * from './route.js';
9
+ export * from './config.js';
10
+ export * from './logger.js';
11
+ export * from './context.js';
12
+ export * from './hook.js';
13
+ export * from './middleware.js';
14
+ export * from './i18n.js';
package/dist/index.js CHANGED
@@ -1,30 +1,14 @@
1
- "use strict";
2
1
  /**
3
2
  * @time: 2025/08/14 09:48
4
3
  * @author: FireGuo
5
4
  * WindyPear-Team All right reserved
6
5
  **/
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- __exportStar(require("./core"), exports);
23
- __exportStar(require("./session"), exports);
24
- __exportStar(require("./route"), exports);
25
- __exportStar(require("./config"), exports);
26
- __exportStar(require("./logger"), exports);
27
- __exportStar(require("./context"), exports);
28
- __exportStar(require("./hook"), exports);
29
- __exportStar(require("./middleware"), exports);
30
- __exportStar(require("./i18n"), exports);
6
+ export * from './core.js';
7
+ export * from './session.js';
8
+ export * from './route.js';
9
+ export * from './config.js';
10
+ export * from './logger.js';
11
+ export * from './context.js';
12
+ export * from './hook.js';
13
+ export * from './middleware.js';
14
+ export * from './i18n.js';
package/dist/logger.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * @author: FireGuo
4
4
  * WindyPear-Team All right reserved
5
5
  **/
6
- import { Core } from './core';
6
+ import { Core } from './core.js';
7
7
  export declare class Logger {
8
8
  private title;
9
9
  private titleColor;
package/dist/logger.js CHANGED
@@ -1,16 +1,12 @@
1
- "use strict";
2
1
  /**
3
2
  * @time: 2025/08/14 09:48
4
3
  * @author: FireGuo
5
4
  * WindyPear-Team All right reserved
6
5
  **/
7
- var __importDefault = (this && this.__importDefault) || function (mod) {
8
- return (mod && mod.__esModule) ? mod : { "default": mod };
9
- };
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.Logger = void 0;
12
- const picocolors_1 = __importDefault(require("picocolors"));
13
- class Logger {
6
+ import * as pcc from 'picocolors';
7
+ const { createColors } = pcc;
8
+ const pc = createColors();
9
+ export class Logger {
14
10
  title;
15
11
  titleColor;
16
12
  static coreInstance = null;
@@ -27,10 +23,10 @@ class Logger {
27
23
  }
28
24
  getColorByName(name) {
29
25
  const availableColors = [
30
- picocolors_1.default.red, picocolors_1.default.green, picocolors_1.default.yellow, picocolors_1.default.blue,
31
- picocolors_1.default.magenta, picocolors_1.default.cyan, picocolors_1.default.white,
32
- picocolors_1.default.redBright, picocolors_1.default.greenBright, picocolors_1.default.yellowBright,
33
- picocolors_1.default.blueBright, picocolors_1.default.magentaBright, picocolors_1.default.cyanBright
26
+ pc.red, pc.green, pc.yellow, pc.blue,
27
+ pc.magenta, pc.cyan, pc.white,
28
+ pc.redBright, pc.greenBright, pc.yellowBright,
29
+ pc.blueBright, pc.magentaBright, pc.cyanBright
34
30
  ];
35
31
  // Simple hash function to ensure consistent color for the same title
36
32
  let hash = 0;
@@ -46,9 +42,9 @@ class Logger {
46
42
  `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')}`;
47
43
  }
48
44
  log(level, ...args) {
49
- const levelColor = level === 'E' ? picocolors_1.default.red : level === 'W' ? picocolors_1.default.yellow : picocolors_1.default.cyan;
45
+ const levelColor = level === 'E' ? pc.red : level === 'W' ? pc.yellow : pc.cyan;
50
46
  const timestamp = this.getTimestamp();
51
- console.log(`${picocolors_1.default.gray(timestamp)} [${levelColor(level)}] ${this.titleColor(this.title)}`, ...args);
47
+ console.log(`${pc.gray(timestamp)} [${levelColor(level)}] ${this.titleColor(this.title)}`, ...args);
52
48
  Logger.coreInstance?.emit('log', { level, message: args.join(' '), timestamp });
53
49
  Logger.logs.push({ level, message: args.join(' '), timestamp });
54
50
  }
@@ -56,4 +52,3 @@ class Logger {
56
52
  warn(...args) { this.log('W', ...args); }
57
53
  error(...args) { this.log('E', ...args); }
58
54
  }
59
- exports.Logger = Logger;
@@ -3,5 +3,5 @@
3
3
  * @author: FireGuo
4
4
  * WindyPear-Team All right reserved
5
5
  **/
6
- import { Session } from './session';
6
+ import { Session } from './session.js';
7
7
  export type Middleware = (session: Session, next: () => Promise<void>) => Promise<void>;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/dist/route.d.ts CHANGED
@@ -3,10 +3,10 @@
3
3
  * @author: FireGuo
4
4
  * WindyPear-Team All right reserved
5
5
  **/
6
- import { Session } from './session';
7
- import { Middleware } from './middleware';
6
+ import { Session } from './session.js';
7
+ import { Middleware } from './middleware.js';
8
8
  import { WebSocketServer } from 'ws';
9
- import { Context } from './context';
9
+ import { Context } from './context.js';
10
10
  export type RouteHandler = (session: Session, queryParams: URLSearchParams, ...pathParams: string[]) => Promise<void> | void;
11
11
  /**
12
12
  * Route class using segment-based matching (no fragile capture-group-index mapping).
package/dist/route.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Route = void 0;
4
- const ws_1 = require("ws");
1
+ import { WebSocketServer } from 'ws';
5
2
  function parsePatternToSegments(pattern) {
6
3
  // Normalize: remove leading/trailing slashes for consistent splitting
7
4
  const norm = pattern.replace(/^\/+|\/+$/g, '');
@@ -33,7 +30,7 @@ function parsePatternToSegments(pattern) {
33
30
  * :param* (zero or more segments)
34
31
  * - honors "no trailing slash" expectation (we normalize input)
35
32
  */
36
- class Route {
33
+ export class Route {
37
34
  path;
38
35
  segments;
39
36
  paramsInfo;
@@ -234,9 +231,8 @@ class Route {
234
231
  */
235
232
  wsOn(event, handler) {
236
233
  if (!this.ws)
237
- this.ws = new ws_1.WebSocketServer({ noServer: true });
234
+ this.ws = new WebSocketServer({ noServer: true });
238
235
  this.ws.on(event, handler);
239
236
  return this;
240
237
  }
241
238
  }
242
- exports.Route = Route;
package/dist/server.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Core } from './core';
1
+ import { Core } from './core.js';
2
2
  export interface ServerConfig {
3
3
  port: number;
4
4
  host: string;
package/dist/server.js CHANGED
@@ -1,55 +1,16 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.Server = void 0;
40
- const logger_1 = require("./logger");
41
- const session_1 = require("./session");
42
- const http_1 = __importDefault(require("http"));
43
- const fs = __importStar(require("fs"));
44
- const path = __importStar(require("path"));
45
- const url_1 = require("url");
46
- const mime = __importStar(require("mime-types"));
47
- const types_1 = require("@yumerijs/types");
48
- const logger = new logger_1.Logger('server');
1
+ import { Logger } from './logger.js';
2
+ import { Session } from './session.js';
3
+ import http from 'http';
4
+ import * as fs from 'fs';
5
+ import * as path from 'path';
6
+ import { URL } from 'url';
7
+ import * as mime from 'mime-types';
8
+ import { resolveVirtualAsset } from '@yumerijs/types';
9
+ const logger = new Logger('server');
49
10
  function isStream(value) {
50
11
  return value && typeof value.pipe === "function";
51
12
  }
52
- class Server {
13
+ export class Server {
53
14
  core;
54
15
  port;
55
16
  host;
@@ -67,7 +28,7 @@ class Server {
67
28
  return this.staticDir;
68
29
  }
69
30
  createSession(ip, cookies, res, req, pathname, pluginContext, extra = {}) {
70
- const session = new session_1.Session(ip, cookies, this, req, res, pathname, undefined, pluginContext);
31
+ const session = new Session(ip, cookies, this, req, res, pathname, undefined, pluginContext);
71
32
  Object.assign(session.properties, extra);
72
33
  session.protocol = extra.protocol ?? 'http';
73
34
  return session;
@@ -101,7 +62,7 @@ class Server {
101
62
  });
102
63
  }
103
64
  async start() {
104
- this.httpServer = http_1.default.createServer(async (req, res) => {
65
+ this.httpServer = http.createServer(async (req, res) => {
105
66
  if (req.method === 'OPTIONS' && this.enableCors) {
106
67
  res.writeHead(204, {
107
68
  'Access-Control-Allow-Origin': '*',
@@ -111,13 +72,13 @@ class Server {
111
72
  res.end();
112
73
  return;
113
74
  }
114
- const url = new url_1.URL(req.url || '/', `http://${req.headers.host}`);
75
+ const url = new URL(req.url || '/', `http://${req.headers.host}`);
115
76
  const pathname = url.pathname;
116
77
  const queryParams = url.searchParams;
117
78
  const ip = this.getClientIP(req);
118
79
  const cookies = this.parseCookies(req);
119
80
  if (req.method === 'GET' || req.method === 'HEAD') {
120
- const virtualAsset = await (0, types_1.resolveVirtualAsset)(pathname);
81
+ const virtualAsset = await resolveVirtualAsset(pathname);
121
82
  if (virtualAsset) {
122
83
  const headers = virtualAsset.headers || {};
123
84
  headers['Content-Type'] = headers['Content-Type'] || virtualAsset.contentType || 'application/octet-stream';
@@ -191,7 +152,7 @@ class Server {
191
152
  }
192
153
  });
193
154
  this.httpServer.on('upgrade', async (req, socket, head) => {
194
- const url = new url_1.URL(req.url || '/', `http://${req.headers.host}`);
155
+ const url = new URL(req.url || '/', `http://${req.headers.host}`);
195
156
  const pathname = url.pathname;
196
157
  const queryParams = url.searchParams;
197
158
  const ip = this.getClientIP(req);
@@ -229,4 +190,3 @@ class Server {
229
190
  this.httpServer.close(() => logger.info('Server stopped'));
230
191
  }
231
192
  }
232
- exports.Server = Server;
package/dist/session.d.ts CHANGED
@@ -3,10 +3,10 @@
3
3
  * @author: FireGuo
4
4
  * WindyPear-Team All right reserved
5
5
  **/
6
- import { Server } from './server';
6
+ import { Server } from './server.js';
7
7
  import { IncomingMessage, ServerResponse } from 'http';
8
8
  import { Stream } from "stream";
9
- import { Context } from './context';
9
+ import { Context } from './context.js';
10
10
  type ParsedParams = Record<string, string | string[] | undefined>;
11
11
  type MissingMode = 'keep-template' | 'keep-key' | 'remove';
12
12
  export interface Client {
package/dist/session.js CHANGED
@@ -1,51 +1,12 @@
1
- "use strict";
2
1
  /**
3
2
  * @time: 2025/03/26 12:36
4
3
  * @author: FireGuo
5
4
  * WindyPear-Team All right reserved
6
5
  **/
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || (function () {
24
- var ownKeys = function(o) {
25
- ownKeys = Object.getOwnPropertyNames || function (o) {
26
- var ar = [];
27
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
- return ar;
29
- };
30
- return ownKeys(o);
31
- };
32
- return function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- })();
40
- var __importDefault = (this && this.__importDefault) || function (mod) {
41
- return (mod && mod.__esModule) ? mod : { "default": mod };
42
- };
43
- Object.defineProperty(exports, "__esModule", { value: true });
44
- exports.Session = void 0;
45
- const crypto_1 = __importDefault(require("crypto"));
46
- const formidable = __importStar(require("formidable"));
47
- const fs_1 = __importDefault(require("fs"));
48
- class Session {
6
+ import crypto from 'crypto';
7
+ import * as formidable from 'formidable';
8
+ import fs from 'fs';
9
+ export class Session {
49
10
  ip;
50
11
  cookie;
51
12
  query;
@@ -241,7 +202,7 @@ class Session {
241
202
  }
242
203
  // MD5 加密
243
204
  md5(str) {
244
- const hash = crypto_1.default.createHash('md5');
205
+ const hash = crypto.createHash('md5');
245
206
  hash.update(str);
246
207
  return hash.digest('hex');
247
208
  }
@@ -359,13 +320,13 @@ class Session {
359
320
  file(path, option) {
360
321
  if (this.client.headers['If-Modified-Since']) {
361
322
  const modified = new Date(this.client.headers['If-Modified-Since']);
362
- const moditime = fs_1.default.statSync(path).mtime;
323
+ const moditime = fs.statSync(path).mtime;
363
324
  if (modified.getTime() === moditime.getTime()) {
364
325
  this.status = 304;
365
326
  return;
366
327
  }
367
328
  }
368
- const etag = crypto_1.default.createHash(option.etagType || 'md5').update(fs_1.default.readFileSync(path)).digest('hex');
329
+ const etag = crypto.createHash(option.etagType || 'md5').update(fs.readFileSync(path)).digest('hex');
369
330
  if (this.client.headers['If-None-Match']) {
370
331
  if (option.etag) {
371
332
  if (this.client.headers['If-None-Match'] === etag) {
@@ -375,13 +336,13 @@ class Session {
375
336
  }
376
337
  }
377
338
  this.setCache({
378
- modified: fs_1.default.statSync(path).mtime,
339
+ modified: fs.statSync(path).mtime,
379
340
  etag,
380
341
  maxAge: option.maxAge,
381
342
  smaxAge: option.smaxAge,
382
343
  cacheControl: 'public'
383
344
  });
384
- this.response(fs_1.default.createReadStream(path), 'stream');
345
+ this.response(fs.createReadStream(path), 'stream');
385
346
  }
386
347
  /**
387
348
  * 发送普通文件
@@ -391,10 +352,10 @@ class Session {
391
352
  sendFile(path, isStream = false) {
392
353
  if (isStream) {
393
354
  this.setMime('application/octet-stream');
394
- this.response(fs_1.default.createReadStream(path), 'stream');
355
+ this.response(fs.createReadStream(path), 'stream');
395
356
  }
396
357
  else {
397
- this.response(fs_1.default.readFileSync(path), 'buffer');
358
+ this.response(fs.readFileSync(path), 'buffer');
398
359
  }
399
360
  }
400
361
  /**
@@ -457,4 +418,3 @@ class Session {
457
418
  }
458
419
  }
459
420
  }
460
- exports.Session = Session;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yumerijs/core",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Core module for yumeri",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",