@yumerijs/core 2.2.1 → 2.2.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.
package/dist/context.d.ts CHANGED
@@ -28,6 +28,7 @@ export declare class Context {
28
28
  component: Components;
29
29
  renderer?: IRenderer;
30
30
  instance: any;
31
+ childpath: string;
31
32
  /** 插件名称 */
32
33
  pluginname: string;
33
34
  /**
@@ -47,7 +48,7 @@ export declare class Context {
47
48
  * @param path 路由路径
48
49
  * @returns Route 实例
49
50
  */
50
- route(path: string): Route;
51
+ route(routepath: string): Route;
51
52
  /**
52
53
  * 注册事件
53
54
  * @param name 事件名称
@@ -97,7 +98,7 @@ export declare class Context {
97
98
  * 注册子 Context
98
99
  * @param name 子 Context 名称
99
100
  */
100
- fork(name?: string): Context;
101
+ fork(name?: string, path?: string): Context;
101
102
  /**
102
103
  * 注册子插件
103
104
  * @param plugin 插件实例
package/dist/context.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Route } from './route.js';
2
+ import path from 'path';
2
3
  /**
3
4
  * 插件上下文对象
4
5
  * 每个插件一个 Context,用于管理插件注册的命令、路由、事件、组件和中间件
@@ -16,6 +17,7 @@ export class Context {
16
17
  component;
17
18
  renderer;
18
19
  instance;
20
+ childpath = '/';
19
21
  /** 插件名称 */
20
22
  pluginname;
21
23
  /**
@@ -43,13 +45,14 @@ export class Context {
43
45
  * @param path 路由路径
44
46
  * @returns Route 实例
45
47
  */
46
- route(path) {
47
- if (this.core.routes[path]) {
48
+ route(routepath) {
49
+ const realpath = path.join(this.childpath, routepath);
50
+ if (this.core.routes[realpath]) {
48
51
  this.core.logger.warn(`Plugin "${this.pluginname}" attempt to register route "${path}", but it has already been registered.`);
49
- return new Route(path, this);
52
+ return new Route(realpath, this);
50
53
  }
51
- this.routes.push(path);
52
- return this.core.route(path, this);
54
+ this.routes.push(realpath);
55
+ return this.core.route(realpath, this);
53
56
  }
54
57
  /**
55
58
  * 注册事件
@@ -134,8 +137,9 @@ export class Context {
134
137
  * 注册子 Context
135
138
  * @param name 子 Context 名称
136
139
  */
137
- fork(name = this.pluginname) {
140
+ fork(name = this.pluginname, path) {
138
141
  const ctx = new Context(this.core, name);
142
+ ctx.childpath = path;
139
143
  this.childContexts.push(ctx);
140
144
  return ctx;
141
145
  }
package/dist/core.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'events';
2
- import { Config } from './config.js';
2
+ import { Config, Schema } from './config.js';
3
3
  import { Logger } from './logger.js';
4
4
  import { Session } from './session.js';
5
5
  import { Middleware } from './middleware.js';
@@ -15,7 +15,7 @@ interface Plugin {
15
15
  depend: Array<string>;
16
16
  provide: Array<string>;
17
17
  }
18
- interface CoreOptions {
18
+ export interface CoreOptions {
19
19
  port: number;
20
20
  host: string;
21
21
  staticDir: string;
@@ -23,6 +23,7 @@ interface CoreOptions {
23
23
  enableWs: boolean;
24
24
  lang: string[];
25
25
  }
26
+ export declare const coreConfigSchema: Schema<CoreOptions>;
26
27
  export declare const enum PluginStatus {
27
28
  ENABLED = "enabled",
28
29
  DISABLED = "disabled",
package/dist/core.js CHANGED
@@ -1,8 +1,17 @@
1
1
  import { EventEmitter } from 'events';
2
+ import { Schema } from './config.js';
2
3
  import { Logger } from './logger.js';
3
4
  import { Route } from './route.js';
4
5
  import { Hook } from './hook.js';
5
6
  import { Server as CoreServer } from './server.js';
7
+ export const coreConfigSchema = Schema.object({
8
+ port: Schema.number('监听端口').default(14510),
9
+ host: Schema.string('监听地址').default('0.0.0.0'),
10
+ staticDir: Schema.string('静态目录').default('public'),
11
+ enableCors: Schema.boolean('启用跨域').default(false),
12
+ enableWs: Schema.boolean('启用 WebSocket').default(false),
13
+ lang: Schema.array(Schema.string(), '语言列表').default(['zh', 'en']),
14
+ });
6
15
  export class Core {
7
16
  emitter = new EventEmitter();
8
17
  components = {};
package/dist/session.js CHANGED
@@ -393,7 +393,7 @@ export class Session {
393
393
  if (!this.pluginContext) {
394
394
  throw new Error(`Cannot call 'renderView' because the session is not associated with a plugin context.`);
395
395
  }
396
- const renderer = this.pluginContext.renderer;
396
+ const renderer = this.pluginContext.renderer || null;
397
397
  const pluginName = this.pluginContext.pluginname;
398
398
  if (!renderer) {
399
399
  this.server.core.logger.error(`Renderer declared by plugin "${pluginName}" is not registered. Have you installed the renderer package (e.g., '@yumerijs/vue-renderer')?`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yumerijs/core",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Core module for yumeri",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",