@zhin.js/core 1.0.17 → 1.0.18
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/CHANGELOG.md +11 -0
- package/REFACTORING_COMPLETE.md +178 -0
- package/REFACTORING_STATUS.md +263 -0
- package/lib/adapter.d.ts +44 -19
- package/lib/adapter.d.ts.map +1 -1
- package/lib/adapter.js +81 -50
- package/lib/adapter.js.map +1 -1
- package/lib/bot.d.ts +7 -12
- package/lib/bot.d.ts.map +1 -1
- package/lib/built/adapter-process.d.ts +36 -0
- package/lib/built/adapter-process.d.ts.map +1 -0
- package/lib/built/adapter-process.js +77 -0
- package/lib/built/adapter-process.js.map +1 -0
- package/lib/built/command.d.ts +46 -0
- package/lib/built/command.d.ts.map +1 -0
- package/lib/built/command.js +54 -0
- package/lib/built/command.js.map +1 -0
- package/lib/built/component.d.ts +42 -0
- package/lib/built/component.d.ts.map +1 -0
- package/lib/built/component.js +66 -0
- package/lib/built/component.js.map +1 -0
- package/lib/built/config.d.ts +31 -0
- package/lib/built/config.d.ts.map +1 -0
- package/lib/built/config.js +141 -0
- package/lib/built/config.js.map +1 -0
- package/lib/built/cron.d.ts +53 -0
- package/lib/built/cron.d.ts.map +1 -0
- package/lib/built/cron.js +79 -0
- package/lib/built/cron.js.map +1 -0
- package/lib/built/database.d.ts +17 -0
- package/lib/built/database.d.ts.map +1 -0
- package/lib/built/database.js +28 -0
- package/lib/built/database.js.map +1 -0
- package/lib/{permissions.d.ts → built/permission.d.ts} +5 -10
- package/lib/built/permission.d.ts.map +1 -0
- package/lib/{permissions.js → built/permission.js} +11 -10
- package/lib/built/permission.js.map +1 -0
- package/lib/command.d.ts +7 -7
- package/lib/command.d.ts.map +1 -1
- package/lib/command.js +5 -15
- package/lib/command.js.map +1 -1
- package/lib/component.d.ts.map +1 -1
- package/lib/component.js.map +1 -1
- package/lib/cron.d.ts +1 -0
- package/lib/cron.d.ts.map +1 -1
- package/lib/cron.js +2 -0
- package/lib/cron.js.map +1 -1
- package/lib/index.d.ts +11 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +14 -4
- package/lib/index.js.map +1 -1
- package/lib/jsx-runtime.d.ts +2 -2
- package/lib/message.d.ts +2 -2
- package/lib/message.d.ts.map +1 -1
- package/lib/plugin.d.ts +164 -51
- package/lib/plugin.d.ts.map +1 -1
- package/lib/plugin.js +521 -150
- package/lib/plugin.js.map +1 -1
- package/lib/prompt.d.ts +1 -1
- package/lib/prompt.d.ts.map +1 -1
- package/lib/prompt.js +2 -1
- package/lib/prompt.js.map +1 -1
- package/lib/types.d.ts +33 -33
- package/lib/types.d.ts.map +1 -1
- package/lib/utils.d.ts +16 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +166 -66
- package/lib/utils.js.map +1 -1
- package/package.json +15 -9
- package/src/adapter.ts +131 -80
- package/src/bot.ts +8 -13
- package/src/built/adapter-process.ts +77 -0
- package/src/built/command.ts +102 -0
- package/src/built/component.ts +111 -0
- package/src/built/config.ts +126 -0
- package/src/built/cron.ts +140 -0
- package/src/built/database.ts +38 -0
- package/src/{permissions.ts → built/permission.ts} +9 -12
- package/src/command.ts +11 -20
- package/src/component.ts +0 -1
- package/src/cron.ts +2 -0
- package/src/index.ts +15 -5
- package/src/message.ts +2 -2
- package/src/plugin.ts +671 -202
- package/src/prompt.ts +4 -3
- package/src/types.ts +41 -35
- package/src/utils.ts +418 -296
- package/test/minimal-bot.ts +31 -0
- package/test/stress-test.ts +123 -0
- package/tests/command.test.ts +47 -44
- package/ASYNC-JSX-SUPPORT.md +0 -173
- package/lib/app.d.ts +0 -191
- package/lib/app.d.ts.map +0 -1
- package/lib/app.js +0 -604
- package/lib/app.js.map +0 -1
- package/lib/config.d.ts +0 -54
- package/lib/config.d.ts.map +0 -1
- package/lib/config.js +0 -308
- package/lib/config.js.map +0 -1
- package/lib/log-transport.d.ts +0 -37
- package/lib/log-transport.d.ts.map +0 -1
- package/lib/log-transport.js +0 -136
- package/lib/log-transport.js.map +0 -1
- package/lib/permissions.d.ts.map +0 -1
- package/lib/permissions.js.map +0 -1
- package/src/app.ts +0 -772
- package/src/config.ts +0 -397
- package/src/log-transport.ts +0 -163
- package/tests/app.test.ts +0 -265
- package/tests/permissions.test.ts +0 -358
- package/tests/plugin.test.ts +0 -234
- package/tests/prompt.test.ts +0 -223
package/lib/adapter.js
CHANGED
|
@@ -1,79 +1,96 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import { segment } from "./utils.js";
|
|
1
3
|
/**
|
|
2
4
|
* Adapter类:适配器抽象,管理多平台Bot实例。
|
|
3
5
|
* 负责根据配置启动/关闭各平台机器人,统一异常处理。
|
|
4
6
|
*/
|
|
5
|
-
export class Adapter {
|
|
7
|
+
export class Adapter extends EventEmitter {
|
|
8
|
+
plugin;
|
|
6
9
|
name;
|
|
10
|
+
config;
|
|
7
11
|
/** 当前适配器下所有Bot实例,key为bot名称 */
|
|
8
12
|
bots = new Map();
|
|
9
|
-
#botFactory;
|
|
10
13
|
/**
|
|
11
14
|
* 构造函数
|
|
12
15
|
* @param name 适配器名称(如 'process'、'qq' 等)
|
|
13
16
|
* @param botFactory Bot工厂函数或构造器
|
|
14
17
|
*/
|
|
15
|
-
constructor(name,
|
|
18
|
+
constructor(plugin, name, config) {
|
|
19
|
+
super();
|
|
20
|
+
this.plugin = plugin;
|
|
16
21
|
this.name = name;
|
|
17
|
-
this
|
|
22
|
+
this.config = config;
|
|
23
|
+
this.on('call.recallMessage', async (bot_id, id) => {
|
|
24
|
+
const bot = this.bots.get(bot_id);
|
|
25
|
+
if (!bot)
|
|
26
|
+
throw new Error(`Bot ${bot_id} not found`);
|
|
27
|
+
this.logger.info(`${bot_id} recall ${id}`);
|
|
28
|
+
await bot.$recallMessage(id);
|
|
29
|
+
});
|
|
30
|
+
this.on('call.sendMessage', async (bot_id, options) => {
|
|
31
|
+
const fns = this.plugin.root.listeners('before.sendMessage');
|
|
32
|
+
for (const fn of fns) {
|
|
33
|
+
const result = await fn(options);
|
|
34
|
+
if (result)
|
|
35
|
+
options = result;
|
|
36
|
+
}
|
|
37
|
+
const bot = this.bots.get(bot_id);
|
|
38
|
+
if (!bot)
|
|
39
|
+
throw new Error(`Bot ${bot_id} not found`);
|
|
40
|
+
this.logger.info(`${bot_id} send ${options.type}(${options.id}):${segment.raw(options.content)}`);
|
|
41
|
+
return await bot.$sendMessage(options);
|
|
42
|
+
});
|
|
43
|
+
this.on('message.receive', (message) => {
|
|
44
|
+
this.logger.info(`${message.$bot} recv ${message.$channel.type}(${message.$channel.id}):${segment.raw(message.$content)}`);
|
|
45
|
+
this.plugin?.middleware(message, async () => { });
|
|
46
|
+
});
|
|
18
47
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
new
|
|
22
|
-
|
|
23
|
-
return bot;
|
|
48
|
+
get logger() {
|
|
49
|
+
if (!this.plugin)
|
|
50
|
+
throw new Error("Adapter is not associated with any plugin");
|
|
51
|
+
return this.plugin.logger;
|
|
24
52
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
bot = new this.#botFactory(config);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
bot = this.#botFactory(config);
|
|
41
|
-
}
|
|
42
|
-
try {
|
|
43
|
-
await bot.$connect();
|
|
44
|
-
plugin.logger.info(`bot ${config.name} of adapter ${this.name} connected`);
|
|
45
|
-
this.bots.set(config.name, bot);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
// 如果连接失败,确保错误正确传播
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
plugin.logger.info(`adapter ${this.name} mounted`);
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
// 确保错误正确传播
|
|
56
|
-
throw error;
|
|
53
|
+
binding(plugin) {
|
|
54
|
+
this.plugin = plugin;
|
|
55
|
+
}
|
|
56
|
+
async start() {
|
|
57
|
+
this.plugin.root.adapters.push(this.name);
|
|
58
|
+
if (!this.config?.length)
|
|
59
|
+
return;
|
|
60
|
+
for (const config of this.config) {
|
|
61
|
+
const bot = this.createBot(config);
|
|
62
|
+
await bot.$connect();
|
|
63
|
+
this.logger.debug(`bot ${bot.$id} of adapter ${this.name} connected`);
|
|
64
|
+
this.bots.set(bot.$id, bot);
|
|
57
65
|
}
|
|
66
|
+
this.logger.debug(`adapter ${this.name} started`);
|
|
58
67
|
}
|
|
59
68
|
/**
|
|
60
69
|
* 停止适配器,断开并移除所有Bot实例
|
|
61
70
|
* @param plugin 所属插件实例
|
|
62
71
|
*/
|
|
63
|
-
async
|
|
72
|
+
async stop() {
|
|
64
73
|
try {
|
|
65
|
-
for (const [
|
|
74
|
+
for (const [id, bot] of this.bots) {
|
|
66
75
|
try {
|
|
67
76
|
await bot.$disconnect();
|
|
68
|
-
|
|
69
|
-
this.bots.delete(name);
|
|
77
|
+
this.logger.debug(`bot ${id} of adapter ${this.name} disconnected`);
|
|
70
78
|
}
|
|
71
79
|
catch (error) {
|
|
72
80
|
// 如果断开连接失败,确保错误正确传播
|
|
73
81
|
throw error;
|
|
74
82
|
}
|
|
75
83
|
}
|
|
76
|
-
|
|
84
|
+
// 清理 bots Map
|
|
85
|
+
this.bots.clear();
|
|
86
|
+
// 从 adapters 数组中移除
|
|
87
|
+
const idx = this.plugin.root.adapters.indexOf(this.name);
|
|
88
|
+
if (idx !== -1) {
|
|
89
|
+
this.plugin.root.adapters.splice(idx, 1);
|
|
90
|
+
}
|
|
91
|
+
// 移除所有事件监听器
|
|
92
|
+
this.removeAllListeners();
|
|
93
|
+
this.logger.info(`adapter ${this.name} stopped`);
|
|
77
94
|
}
|
|
78
95
|
catch (error) {
|
|
79
96
|
// 确保错误正确传播
|
|
@@ -82,10 +99,24 @@ export class Adapter {
|
|
|
82
99
|
}
|
|
83
100
|
}
|
|
84
101
|
(function (Adapter) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
102
|
+
/**
|
|
103
|
+
* 适配器工厂注册表
|
|
104
|
+
* 灵感来源于 zhinjs/next 的 Adapter.Registry
|
|
105
|
+
*/
|
|
106
|
+
Adapter.Registry = new Map();
|
|
107
|
+
/**
|
|
108
|
+
* 注册适配器工厂
|
|
109
|
+
*
|
|
110
|
+
* @param name 适配器名称
|
|
111
|
+
* @param factory 适配器工厂函数
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* Adapter.register('icqq', IcqqAdapter);
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
function register(name, factory) {
|
|
118
|
+
Adapter.Registry.set(name, factory);
|
|
88
119
|
}
|
|
89
|
-
Adapter.
|
|
120
|
+
Adapter.register = register;
|
|
90
121
|
})(Adapter || (Adapter = {}));
|
|
91
122
|
//# sourceMappingURL=adapter.js.map
|
package/lib/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC;;;GAGG;AACH,MAAM,OAAgB,OAA6B,SAAQ,YAA+B;IAS/E;IACA;IACA;IAVT,8BAA8B;IACvB,IAAI,GAAmB,IAAI,GAAG,EAAa,CAAC;IACnD;;;;OAIG;IACH,YACS,MAAc,EACd,IAA2B,EAC3B,MAA8B;QAErC,KAAK,EAAE,CAAC;QAJD,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAuB;QAC3B,WAAM,GA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,OAAO,CAAC,CAAC;IAC9B,CAAC;IAFe,gBAAQ,WAEvB,CAAA;AACH,CAAC,EAzCgB,OAAO,KAAP,OAAO,QAyCvB"}
|
package/lib/bot.d.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import type { SendOptions } from "./types.js";
|
|
2
2
|
import { Message } from "./message.js";
|
|
3
|
+
import { Adapter, Adapters } from "./adapter.js";
|
|
3
4
|
/**
|
|
4
5
|
* Bot接口:所有平台机器人需实现的统一接口。
|
|
5
6
|
* 负责消息格式化、连接、断开、消息发送等。
|
|
6
7
|
* @template M 消息类型
|
|
7
8
|
* @template T 配置类型
|
|
8
9
|
*/
|
|
9
|
-
export interface Bot<
|
|
10
|
+
export interface Bot<Config extends object = {}, Event extends object = {}> {
|
|
11
|
+
$id: string;
|
|
10
12
|
/** 机器人配置 */
|
|
11
|
-
$config:
|
|
13
|
+
$config: Config;
|
|
12
14
|
/** 是否已连接 */
|
|
13
|
-
$connected
|
|
15
|
+
$connected: boolean;
|
|
14
16
|
/** 格式化平台消息为标准Message结构 */
|
|
15
|
-
$formatMessage(
|
|
17
|
+
$formatMessage(event: Event): Message<Event>;
|
|
16
18
|
/** 连接机器人 */
|
|
17
19
|
$connect(): Promise<void>;
|
|
18
20
|
/** 断开机器人 */
|
|
@@ -23,13 +25,6 @@ export interface Bot<M extends object = {}, T extends Bot.Config = Bot.Config> {
|
|
|
23
25
|
$sendMessage(options: SendOptions): Promise<string>;
|
|
24
26
|
}
|
|
25
27
|
export declare namespace Bot {
|
|
26
|
-
|
|
27
|
-
* Bot配置类型,所有平台机器人通用
|
|
28
|
-
*/
|
|
29
|
-
interface Config {
|
|
30
|
-
context: string;
|
|
31
|
-
name: string;
|
|
32
|
-
[key: string]: any;
|
|
33
|
-
}
|
|
28
|
+
type Config = Adapter.BotConfig<Adapters[keyof Adapters]>;
|
|
34
29
|
}
|
|
35
30
|
//# sourceMappingURL=bot.d.ts.map
|
package/lib/bot.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bot.d.ts","sourceRoot":"","sources":["../src/bot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC;;;;;GAKG;AACH,MAAM,WAAW,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"bot.d.ts","sourceRoot":"","sources":["../src/bot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACjD;;;;;GAKG;AACH,MAAM,WAAW,GAAG,CAAC,MAAM,SAAS,MAAM,GAAE,EAAE,EAAC,KAAK,SAAS,MAAM,GAAG,EAAE;IACtE,GAAG,EAAC,MAAM,CAAA;IACV,YAAY;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY;IACZ,UAAU,EAAE,OAAO,CAAC;IACpB,0BAA0B;IAC1B,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7C,YAAY;IACZ,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,YAAY;IACZ,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,WAAW;IACX,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,iBAAiB;IACjB,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACrD;AACD,yBAAiB,GAAG,CAAC;IACnB,KAAY,MAAM,GAAE,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,QAAQ,CAAC,CAAC,CAAA;CAChE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Adapter, Plugin, Bot, SendOptions, Message } from "@zhin.js/core";
|
|
2
|
+
export declare class ProcessBot implements Bot<{}, {
|
|
3
|
+
content: string;
|
|
4
|
+
ts: number;
|
|
5
|
+
}> {
|
|
6
|
+
adapter: ProcessAdapter;
|
|
7
|
+
$config: {};
|
|
8
|
+
$id: string;
|
|
9
|
+
get logger(): import("@zhin.js/logger").Logger;
|
|
10
|
+
$connected: boolean;
|
|
11
|
+
constructor(adapter: ProcessAdapter, $config?: {});
|
|
12
|
+
$listenInput: (data: Buffer<ArrayBufferLike>) => void;
|
|
13
|
+
connect(): Promise<void>;
|
|
14
|
+
disconnect(): Promise<void>;
|
|
15
|
+
$formatMessage(event: {
|
|
16
|
+
content: string;
|
|
17
|
+
ts: number;
|
|
18
|
+
}): Message<{
|
|
19
|
+
content: string;
|
|
20
|
+
ts: number;
|
|
21
|
+
}>;
|
|
22
|
+
$recallMessage(id: string): Promise<void>;
|
|
23
|
+
$sendMessage(options: SendOptions): Promise<string>;
|
|
24
|
+
$connect(): Promise<void>;
|
|
25
|
+
$disconnect(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export declare class ProcessAdapter extends Adapter<ProcessBot> {
|
|
28
|
+
constructor(plugin: Plugin);
|
|
29
|
+
createBot(): ProcessBot;
|
|
30
|
+
}
|
|
31
|
+
declare module '@zhin.js/core' {
|
|
32
|
+
interface RegisteredAdapters {
|
|
33
|
+
process: ProcessAdapter;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=adapter-process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-process.d.ts","sourceRoot":"","sources":["../../src/built/adapter-process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAe,WAAW,EAAe,OAAO,EAAW,MAAM,eAAe,CAAC;AAC9G,qBAAa,UAAW,YAAW,GAAG,CAAC,EAAE,EAAC;IAAC,OAAO,EAAC,MAAM,CAAC;IAAA,EAAE,EAAC,MAAM,CAAA;CAAC,CAAC;IAM9C,OAAO,EAAE,cAAc;IAAS,OAAO;IAL1D,GAAG,SAAkB;IACrB,IAAI,MAAM,qCAET;IACD,UAAU,UAAO;gBACE,OAAO,EAAE,cAAc,EAAS,OAAO,KAAG;IAG7D,YAAY,EAAC,CAAC,IAAI,EAAC,MAAM,CAAC,eAAe,CAAC,KAAG,IAAI,CAKhD;IACK,OAAO;IAEP,UAAU;IAEhB,cAAc,CAAC,KAAK,EAAE;QAAC,OAAO,EAAC,MAAM,CAAC;QAAA,EAAE,EAAC,MAAM,CAAA;KAAC,GAAG,OAAO,CAAC;QAAC,OAAO,EAAC,MAAM,CAAC;QAAA,EAAE,EAAC,MAAM,CAAA;KAAC,CAAC;IA+BhF,cAAc,CAAC,EAAE,EAAE,MAAM;IAEzB,YAAY,CAAC,OAAO,EAAE,WAAW;IAGjC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzB,WAAW;CAGpB;AACD,qBAAa,cAAe,SAAQ,OAAO,CAAC,UAAU,CAAC;gBACvC,MAAM,EAAE,MAAM;IAG1B,SAAS,IAAI,UAAU;CAG1B;AACD,OAAO,QAAQ,eAAe,CAAA;IAC1B,UAAU,kBAAkB;QACxB,OAAO,EAAC,cAAc,CAAA;KACzB;CACJ"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Adapter, Message } from "@zhin.js/core";
|
|
2
|
+
export class ProcessBot {
|
|
3
|
+
adapter;
|
|
4
|
+
$config;
|
|
5
|
+
$id = `${process.pid}`;
|
|
6
|
+
get logger() {
|
|
7
|
+
return this.adapter.logger;
|
|
8
|
+
}
|
|
9
|
+
$connected = false;
|
|
10
|
+
constructor(adapter, $config = {}) {
|
|
11
|
+
this.adapter = adapter;
|
|
12
|
+
this.$config = $config;
|
|
13
|
+
this.$listenInput = this.$listenInput.bind(this);
|
|
14
|
+
}
|
|
15
|
+
$listenInput = function (data) {
|
|
16
|
+
const content = data.toString().trim();
|
|
17
|
+
if (content) {
|
|
18
|
+
this.adapter.emit('message.receive', this.$formatMessage({ content, ts: Date.now() }));
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
async connect() {
|
|
22
|
+
}
|
|
23
|
+
async disconnect() {
|
|
24
|
+
}
|
|
25
|
+
$formatMessage(event) {
|
|
26
|
+
const base = {
|
|
27
|
+
$id: `${event.ts}`,
|
|
28
|
+
$adapter: 'process',
|
|
29
|
+
$bot: `${process.pid}`,
|
|
30
|
+
$sender: {
|
|
31
|
+
id: `${process.pid}`,
|
|
32
|
+
name: process.title,
|
|
33
|
+
},
|
|
34
|
+
$channel: {
|
|
35
|
+
id: `${process.pid}`,
|
|
36
|
+
type: 'private',
|
|
37
|
+
},
|
|
38
|
+
$content: [{ type: 'text', data: { text: event.content } }],
|
|
39
|
+
$raw: event.content,
|
|
40
|
+
$timestamp: event.ts,
|
|
41
|
+
$recall: async () => {
|
|
42
|
+
await this.$recallMessage(base.$id);
|
|
43
|
+
},
|
|
44
|
+
$reply: async (content) => {
|
|
45
|
+
return await this.$sendMessage({
|
|
46
|
+
context: 'process',
|
|
47
|
+
bot: base.$bot,
|
|
48
|
+
content,
|
|
49
|
+
id: base.$id,
|
|
50
|
+
type: base.$channel.type,
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
return Message.from(event, base);
|
|
55
|
+
}
|
|
56
|
+
async $recallMessage(id) {
|
|
57
|
+
}
|
|
58
|
+
async $sendMessage(options) {
|
|
59
|
+
return `${Date.now()}`;
|
|
60
|
+
}
|
|
61
|
+
async $connect() {
|
|
62
|
+
process.stdin.on('data', this.$listenInput);
|
|
63
|
+
this.$connected = true;
|
|
64
|
+
}
|
|
65
|
+
async $disconnect() {
|
|
66
|
+
process.stdin.removeListener('data', this.$listenInput);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export class ProcessAdapter extends Adapter {
|
|
70
|
+
constructor(plugin) {
|
|
71
|
+
super(plugin, 'process', [{}]);
|
|
72
|
+
}
|
|
73
|
+
createBot() {
|
|
74
|
+
return new ProcessBot(this);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=adapter-process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-process.js","sourceRoot":"","sources":["../../src/built/adapter-process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAsD,OAAO,EAAW,MAAM,eAAe,CAAC;AAC9G,MAAM,OAAO,UAAU;IAMA;IAAgC;IALnD,GAAG,GAAC,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACrB,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IACD,UAAU,GAAC,KAAK,CAAC;IACjB,YAAmB,OAAuB,EAAS,UAAQ,EAAE;QAA1C,YAAO,GAAP,OAAO,CAAgB;QAAS,YAAO,GAAP,OAAO,CAAG;QACzD,IAAI,CAAC,YAAY,GAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;IACD,YAAY,GAAsC,UAA0B,IAAI;QAC5E,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;QACvC,IAAI,OAAO,EAAE,CAAC;YACV,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,cAAc,CAAC,EAAC,OAAO,EAAC,EAAE,EAAC,IAAI,CAAC,GAAG,EAAE,EAAC,CAAC,CAAC,CAAC;QACvF,CAAC;IACL,CAAC,CAAA;IACD,KAAK,CAAC,OAAO;IACb,CAAC;IACD,KAAK,CAAC,UAAU;IAChB,CAAC;IACD,cAAc,CAAC,KAAiC;QAC5C,MAAM,IAAI,GAAa;YACnB,GAAG,EAAE,GAAG,KAAK,CAAC,EAAE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5C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IAC3B,CAAC;IACD,KAAK,CAAC,WAAW;QACb,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAC5D,CAAC;CACJ;AACD,MAAM,OAAO,cAAe,SAAQ,OAAmB;IACnD,YAAY,MAAc;QACtB,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACnC,CAAC;IACD,SAAS;QACL,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;CACJ"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command Context
|
|
3
|
+
* 管理所有插件注册的命令
|
|
4
|
+
*/
|
|
5
|
+
import { MessageCommand } from "../command.js";
|
|
6
|
+
import { Message } from "../message.js";
|
|
7
|
+
import { Context, Plugin } from "../plugin.js";
|
|
8
|
+
import type { RegisteredAdapter, AdapterMessage } from "../types.js";
|
|
9
|
+
/**
|
|
10
|
+
* CommandContext 扩展方法类型
|
|
11
|
+
*/
|
|
12
|
+
export interface CommandContextExtensions {
|
|
13
|
+
/** 添加命令 */
|
|
14
|
+
addCommand<T extends RegisteredAdapter>(command: MessageCommand<T>): () => void;
|
|
15
|
+
}
|
|
16
|
+
declare module "../plugin.js" {
|
|
17
|
+
namespace Plugin {
|
|
18
|
+
interface Extensions extends CommandContextExtensions {
|
|
19
|
+
}
|
|
20
|
+
interface Contexts {
|
|
21
|
+
command: CommandService;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 命令服务数据
|
|
27
|
+
*/
|
|
28
|
+
export interface CommandService {
|
|
29
|
+
/** 命令列表(保持顺序) */
|
|
30
|
+
readonly items: MessageCommand<RegisteredAdapter>[];
|
|
31
|
+
/** 按 pattern 索引 */
|
|
32
|
+
readonly byName: Map<string, MessageCommand<RegisteredAdapter>>;
|
|
33
|
+
/** 添加命令 */
|
|
34
|
+
add(command: MessageCommand<RegisteredAdapter>, pluginName: string): () => void;
|
|
35
|
+
/** 移除命令 */
|
|
36
|
+
remove(command: MessageCommand<RegisteredAdapter>): boolean;
|
|
37
|
+
/** 按名称获取 */
|
|
38
|
+
get(pattern: string): MessageCommand<RegisteredAdapter> | undefined;
|
|
39
|
+
/** 处理消息 */
|
|
40
|
+
handle(message: Message<AdapterMessage<RegisteredAdapter>>, plugin: Plugin): Promise<any>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 创建命令 Context
|
|
44
|
+
*/
|
|
45
|
+
export declare function createCommandService(): Context<'command', CommandContextExtensions>;
|
|
46
|
+
//# sourceMappingURL=command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/built/command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAa,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,WAAW;IACX,UAAU,CAAC,CAAC,SAAS,iBAAiB,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,CAAC;CACjF;AAGD,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,MAAM,CAAC;QACf,UAAU,UAAW,SAAQ,wBAAwB;SAAG;QACxD,UAAU,QAAQ;YAChB,OAAO,EAAE,cAAc,CAAC;SACzB;KACF;CACF;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,iBAAiB;IACjB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC,iBAAiB,CAAC,EAAE,CAAC;IACpD,mBAAmB;IACnB,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAChE,WAAW;IACX,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,iBAAiB,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,IAAI,CAAC;IAChF,WAAW;IACX,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC,iBAAiB,CAAC,GAAG,OAAO,CAAC;IAC5D,YAAY;IACZ,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAC;IACpE,WAAW;IACX,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CAC3F;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAAC,SAAS,EAAE,wBAAwB,CAAC,CAqDnF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { getPlugin } from "../plugin.js";
|
|
2
|
+
/**
|
|
3
|
+
* 创建命令 Context
|
|
4
|
+
*/
|
|
5
|
+
export function createCommandService() {
|
|
6
|
+
const items = [];
|
|
7
|
+
const byName = new Map();
|
|
8
|
+
const pluginMap = new Map();
|
|
9
|
+
const value = {
|
|
10
|
+
items,
|
|
11
|
+
byName,
|
|
12
|
+
add(command, pluginName) {
|
|
13
|
+
items.push(command);
|
|
14
|
+
byName.set(command.pattern, command);
|
|
15
|
+
pluginMap.set(command, pluginName);
|
|
16
|
+
return () => value.remove(command);
|
|
17
|
+
},
|
|
18
|
+
remove(command) {
|
|
19
|
+
const index = items.indexOf(command);
|
|
20
|
+
if (index !== -1) {
|
|
21
|
+
items.splice(index, 1);
|
|
22
|
+
byName.delete(command.pattern);
|
|
23
|
+
pluginMap.delete(command);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
},
|
|
28
|
+
get(pattern) {
|
|
29
|
+
return byName.get(pattern);
|
|
30
|
+
},
|
|
31
|
+
async handle(message, plugin) {
|
|
32
|
+
for (const command of items) {
|
|
33
|
+
const result = await command.handle(message, plugin);
|
|
34
|
+
if (result)
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
name: 'command',
|
|
42
|
+
description: '命令服务',
|
|
43
|
+
value,
|
|
44
|
+
extensions: {
|
|
45
|
+
addCommand(command) {
|
|
46
|
+
const plugin = getPlugin();
|
|
47
|
+
const dispose = value.add(command, plugin.name);
|
|
48
|
+
plugin.onDispose(dispose);
|
|
49
|
+
return dispose;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/built/command.ts"],"names":[],"mappings":"AAMA,OAAO,EAAmB,SAAS,EAAE,MAAM,cAAc,CAAC;AAuC1D;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,MAAM,KAAK,GAAwC,EAAE,CAAC;IACtD,MAAM,MAAM,GAAG,IAAI,GAAG,EAA6C,CAAC;IACpE,MAAM,SAAS,GAAG,IAAI,GAAG,EAA6C,CAAC;IAEvE,MAAM,KAAK,GAAmB;QAC5B,KAAK;QACL,MAAM;QAEN,GAAG,CAAC,OAAO,EAAE,UAAU;YACrB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACpB,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACrC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;YACnC,OAAO,GAAG,EAAE,CAA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
* Component Context
|
|
3
|
+
* 管理所有插件注册的组件
|
|
4
|
+
*/
|
|
5
|
+
import { Component } from "../component.js";
|
|
6
|
+
import { Context } from "../plugin.js";
|
|
7
|
+
/**
|
|
8
|
+
* ComponentContext 扩展方法类型
|
|
9
|
+
*/
|
|
10
|
+
export interface ComponentContextExtensions {
|
|
11
|
+
/** 添加组件 */
|
|
12
|
+
addComponent<T extends Component<any>>(component: T): () => void;
|
|
13
|
+
}
|
|
14
|
+
declare module "../plugin.js" {
|
|
15
|
+
namespace Plugin {
|
|
16
|
+
interface Extensions extends ComponentContextExtensions {
|
|
17
|
+
}
|
|
18
|
+
interface Contexts {
|
|
19
|
+
component: ComponentService;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 组件服务数据
|
|
25
|
+
*/
|
|
26
|
+
export interface ComponentService {
|
|
27
|
+
/** 按名称索引 */
|
|
28
|
+
readonly byName: Map<string, Component<any>>;
|
|
29
|
+
/** 添加组件 */
|
|
30
|
+
add(component: Component<any>, pluginName: string): () => void;
|
|
31
|
+
/** 获取所有组件名称 */
|
|
32
|
+
getAllNames(): string[];
|
|
33
|
+
/** 移除组件 */
|
|
34
|
+
remove(component: Component<any>): boolean;
|
|
35
|
+
/** 按名称获取 */
|
|
36
|
+
get(name: string): Component<any> | undefined;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 创建组件 Context
|
|
40
|
+
*/
|
|
41
|
+
export declare function createComponentService(): Context<'component', ComponentContextExtensions>;
|
|
42
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/built/component.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAoB,MAAM,iBAAiB,CAAC;AAE9D,OAAO,EAAE,OAAO,EAAqB,MAAM,cAAc,CAAC;AAI1D;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,WAAW;IACX,YAAY,CAAC,CAAC,SAAS,SAAS,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,MAAM,IAAI,CAAC;CAClE;AAGD,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,MAAM,CAAC;QACf,UAAU,UAAW,SAAQ,0BAA0B;SAAG;QAC1D,UAAU,QAAQ;YAChB,SAAS,EAAE,gBAAgB,CAAC;SAC7B;KACF;CACF;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY;IACZ,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7C,WAAW;IACX,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,IAAI,CAAC;IAC/D,eAAe;IACf,WAAW,IAAI,MAAM,EAAE,CAAC;IACxB,WAAW;IACX,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;IAC3C,YAAY;IACZ,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;CAC/C;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,CAAC,WAAW,EAAE,0BAA0B,CAAC,CA8DzF"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component Context
|
|
3
|
+
* 管理所有插件注册的组件
|
|
4
|
+
*/
|
|
5
|
+
import { renderComponents } from "../component.js";
|
|
6
|
+
import { getPlugin } from "../plugin.js";
|
|
7
|
+
/**
|
|
8
|
+
* 创建组件 Context
|
|
9
|
+
*/
|
|
10
|
+
export function createComponentService() {
|
|
11
|
+
const byName = new Map();
|
|
12
|
+
const pluginMap = new Map();
|
|
13
|
+
let listener;
|
|
14
|
+
let rootPlugin;
|
|
15
|
+
const value = {
|
|
16
|
+
byName,
|
|
17
|
+
add(component, pluginName) {
|
|
18
|
+
byName.set(component.name, component);
|
|
19
|
+
pluginMap.set(component, pluginName);
|
|
20
|
+
return () => value.remove(component);
|
|
21
|
+
},
|
|
22
|
+
getAllNames() {
|
|
23
|
+
return Array.from(byName.keys());
|
|
24
|
+
},
|
|
25
|
+
remove(component) {
|
|
26
|
+
if (byName.has(component.name)) {
|
|
27
|
+
byName.delete(component.name);
|
|
28
|
+
pluginMap.delete(component);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
},
|
|
33
|
+
get(name) {
|
|
34
|
+
return byName.get(name);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
name: 'component',
|
|
39
|
+
description: '组件服务',
|
|
40
|
+
value,
|
|
41
|
+
mounted(plugin) {
|
|
42
|
+
rootPlugin = plugin;
|
|
43
|
+
// 创建消息渲染监听器
|
|
44
|
+
listener = (options) => {
|
|
45
|
+
return renderComponents(byName, options);
|
|
46
|
+
};
|
|
47
|
+
plugin.root.on('before.sendMessage', listener);
|
|
48
|
+
return value;
|
|
49
|
+
},
|
|
50
|
+
dispose() {
|
|
51
|
+
if (listener && rootPlugin) {
|
|
52
|
+
rootPlugin.root.off('before.sendMessage', listener);
|
|
53
|
+
listener = undefined;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
extensions: {
|
|
57
|
+
addComponent(component) {
|
|
58
|
+
const plugin = getPlugin();
|
|
59
|
+
const dispose = value.add(component, plugin.name);
|
|
60
|
+
plugin.onDispose(dispose);
|
|
61
|
+
return dispose;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../src/built/component.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,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C,OAAO,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC3C,CAAC,CAAC;YACF,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC;YAC/C,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO;YACL,IAAI,QAAQ,IAAI,UAAU,EAAE,CAAC;gBAC3B,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC;gBACpD,QAAQ,GAAG,SAAS,CAAC;YACvB,CAAC;QACH,CAAC;QAED,UAAU,EAAE;YACV,YAAY,CAA2B,SAAY;gBACjD,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;gBAC3B,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;gBAClD,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;gBAC1B,OAAO,OAAO,CAAC;YACjB,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Schema } from "@zhin.js/schema";
|
|
2
|
+
export declare class ConfigLoader<T extends object> {
|
|
3
|
+
#private;
|
|
4
|
+
filename: string;
|
|
5
|
+
initial: T;
|
|
6
|
+
schema?: Schema<T> | undefined;
|
|
7
|
+
get data(): T;
|
|
8
|
+
get raw(): T;
|
|
9
|
+
get extension(): string;
|
|
10
|
+
constructor(filename: string, initial: T, schema?: Schema<T> | undefined);
|
|
11
|
+
load(): void;
|
|
12
|
+
save(fullPath: string): void;
|
|
13
|
+
}
|
|
14
|
+
export declare namespace ConfigLoader {
|
|
15
|
+
const supportedExtensions: string[];
|
|
16
|
+
function load<T extends object>(filename: string, initial?: T, schema?: Schema<T>): ConfigLoader<T>;
|
|
17
|
+
}
|
|
18
|
+
export declare class ConfigService {
|
|
19
|
+
configs: Map<string, ConfigLoader<any>>;
|
|
20
|
+
constructor();
|
|
21
|
+
load<T extends object>(filename: string, initial?: Partial<T>, schema?: Schema<T>): ConfigLoader<T>;
|
|
22
|
+
get<T extends object>(filename: string, initial?: Partial<T>, schema?: Schema<T>): T;
|
|
23
|
+
getRaw<T extends object>(filename: string, initial?: Partial<T>, schema?: Schema<T>): T;
|
|
24
|
+
/**
|
|
25
|
+
* 更新配置文件内容
|
|
26
|
+
* @param filename 配置文件名
|
|
27
|
+
* @param data 新的配置数据
|
|
28
|
+
*/
|
|
29
|
+
set<T extends object>(filename: string, data: T): void;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/built/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,qBAAa,YAAY,CAAC,CAAC,SAAS,MAAM;;IAWnB,QAAQ,EAAE,MAAM;IAAS,OAAO,EAAC,CAAC;IAAS,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IAThF,IAAI,IAAI,IAAI,CAAC,CAEZ;IACD,IAAI,GAAG,IAAI,CAAC,CAEX;IACD,IAAI,SAAS,WAEZ;gBACkB,QAAQ,EAAE,MAAM,EAAS,OAAO,EAAC,CAAC,EAAS,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,YAAA;IA+BhF,IAAI;IAsBJ,IAAI,CAAC,QAAQ,EAAE,MAAM;CAWxB;AACD,yBAAiB,YAAY,CAAA;IAClB,MAAM,mBAAmB,UAA6B,CAAC;IAC9D,SAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,mBAItF;CACJ;AACD,qBAAa,aAAa;IACtB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CA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