@kotori-bot/loader 1.6.4 → 1.7.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/README.md CHANGED
@@ -1,26 +1,13 @@
1
- # @kotori-bot/core
1
+ # @kotori-bot/loader
2
2
 
3
- ```typescript
4
- interface Context {
5
- readonly baseDir: Runner['baseDir'];
6
- readonly options: Runner['options'];
7
- readonly [Symbols.modules]: Runner[typeof Symbols.modules];
8
- loadAll(): void;
9
- watcher(): void;
10
- logger: Logger;
11
- /* Service */
12
- server: Server;
13
- db: Database;
14
- file: File;
15
- }
16
- ```
3
+ It packed the `@kotori-bot/core` library, and provide logger, server routes, websocket connections, database supports and fully auto plugins loader!
17
4
 
18
5
  - Loader
19
- - Runner
20
- - Server
21
- - Database
6
+ - Server (base on express.js)
7
+ - Adapters (packed `@kotori-bot/core`'s Adapter, and provide websocket-reverse supports)
8
+ - Database (base on level-db)
22
9
  - File
23
- - log
10
+ - logger (from `@kotori-bot/logger`)
24
11
 
25
12
  ## Reference
26
13
 
package/lib/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- export * from './class/loader';
2
- export * from './constants';
3
- export * from './decorators';
1
+ export * from './loader';
4
2
  export * from './types';
5
3
  export * from './service/adapters';
6
4
  export * from '@kotori-bot/logger';
package/lib/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
 
2
2
  /**
3
3
  * @Package @kotori-bot/loader
4
- * @Version 1.6.4
5
- * @Author Hotaru <biyuehuya@gmail.com>
4
+ * @Version 1.7.0-rc.1
5
+ * @Author Arimura Sena <me@hotaru.icu>
6
6
  * @Copyright 2024 Hotaru. All rights reserved.
7
7
  * @License GPL-3.0
8
8
  * @Link https://github.com/kotorijs/kotori
9
- * @Date 2024/6/7 21:36:21
9
+ * @Date 2024/8/9 17:33:08
10
10
  */
11
11
 
12
12
  "use strict";
@@ -26,17 +26,13 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
26
26
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
27
  var src_exports = {};
28
28
  module.exports = __toCommonJS(src_exports);
29
- __reExport(src_exports, require("./class/loader"), module.exports);
30
- __reExport(src_exports, require("./constants"), module.exports);
31
- __reExport(src_exports, require("./decorators"), module.exports);
29
+ __reExport(src_exports, require("./loader"), module.exports);
32
30
  __reExport(src_exports, require("./types"), module.exports);
33
31
  __reExport(src_exports, require("./service/adapters"), module.exports);
34
32
  __reExport(src_exports, require("@kotori-bot/logger"), module.exports);
35
33
  // Annotate the CommonJS export names for ESM import in node:
36
34
  0 && (module.exports = {
37
- ...require("./class/loader"),
38
- ...require("./constants"),
39
- ...require("./decorators"),
35
+ ...require("./loader"),
40
36
  ...require("./types"),
41
37
  ...require("./service/adapters"),
42
38
  ...require("@kotori-bot/logger")
@@ -0,0 +1,15 @@
1
+ import { LoggerLevel } from '@kotori-bot/logger';
2
+ export declare const PLUGIN_PREFIX = "kotori-plugin-";
3
+ export declare const ADAPTER_PREFIX = "adapter-";
4
+ export declare const CONFIG_NAME = "kotori.toml";
5
+ export declare const BUILD_MODE: "build";
6
+ export declare const DEV_MODE: "dev";
7
+ export declare const CORE_MODULES: string[];
8
+ export declare const INTERNAL_PACKAGES: string[];
9
+ export declare const DEFAULT_LOADER_CONFIG: {
10
+ dirs: string[];
11
+ port: number;
12
+ dbPrefix: string;
13
+ level: LoggerLevel;
14
+ noColor: boolean;
15
+ };
@@ -1,12 +1,12 @@
1
1
 
2
2
  /**
3
3
  * @Package @kotori-bot/loader
4
- * @Version 1.6.4
5
- * @Author Hotaru <biyuehuya@gmail.com>
4
+ * @Version 1.7.0-rc.1
5
+ * @Author Arimura Sena <me@hotaru.icu>
6
6
  * @Copyright 2024 Hotaru. All rights reserved.
7
7
  * @License GPL-3.0
8
8
  * @Link https://github.com/kotorijs/kotori
9
- * @Date 2024/6/7 21:36:21
9
+ * @Date 2024/8/9 17:33:08
10
10
  */
11
11
 
12
12
  "use strict";
@@ -29,29 +29,20 @@ var __copyProps = (to, from, except, desc) => {
29
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
30
  var constants_exports = {};
31
31
  __export(constants_exports, {
32
- BUILD_CONFIG_NAME: () => BUILD_CONFIG_NAME,
33
- BUILD_FILE: () => BUILD_FILE,
32
+ ADAPTER_PREFIX: () => ADAPTER_PREFIX,
34
33
  BUILD_MODE: () => BUILD_MODE,
35
- CONFIG_EXT: () => CONFIG_EXT,
34
+ CONFIG_NAME: () => CONFIG_NAME,
36
35
  CORE_MODULES: () => CORE_MODULES,
37
- DEV_CODE_DIRS: () => DEV_CODE_DIRS,
38
- DEV_CONFIG_NAME: () => DEV_CONFIG_NAME,
39
- DEV_FILE: () => DEV_FILE,
40
- DEV_IMPORT: () => DEV_IMPORT,
36
+ DEFAULT_LOADER_CONFIG: () => DEFAULT_LOADER_CONFIG,
41
37
  DEV_MODE: () => DEV_MODE,
42
- SUPPORTS_HALF_VERSION: () => SUPPORTS_HALF_VERSION,
43
- SUPPORTS_VERSION: () => SUPPORTS_VERSION
38
+ INTERNAL_PACKAGES: () => INTERNAL_PACKAGES,
39
+ PLUGIN_PREFIX: () => PLUGIN_PREFIX
44
40
  });
45
41
  module.exports = __toCommonJS(constants_exports);
46
- const DEV_FILE = ".ts";
47
- const BUILD_FILE = ".js";
48
- const DEV_CODE_DIRS = "./src/";
49
- const DEV_IMPORT = `${DEV_CODE_DIRS}index.ts`;
50
- const CONFIG_EXT = [".toml", ".yml", ".yaml", ".json"];
51
- const BUILD_CONFIG_NAME = "kotori";
52
- const DEV_CONFIG_NAME = "kotori.dev";
53
- const SUPPORTS_VERSION = /(1\.1\.0)|(1\.2\.0)|(1\.(3|4|5|6|7|8|9)\.(.*))/;
54
- const SUPPORTS_HALF_VERSION = /(x\.x\.(.*?))/;
42
+ var import_logger = require("@kotori-bot/logger");
43
+ const PLUGIN_PREFIX = "kotori-plugin-";
44
+ const ADAPTER_PREFIX = "adapter-";
45
+ const CONFIG_NAME = "kotori.toml";
55
46
  const BUILD_MODE = "build";
56
47
  const DEV_MODE = "dev";
57
48
  const CORE_MODULES = [
@@ -59,18 +50,30 @@ const CORE_MODULES = [
59
50
  "@kotori-bot/kotori-plugin-filter"
60
51
  // '@kotori-bot/kotori-plugin-webui'
61
52
  ];
53
+ const INTERNAL_PACKAGES = [
54
+ "fluoro",
55
+ "kotori-bot",
56
+ "@kotori-bot/core",
57
+ "@kotori-bot/loader",
58
+ "@kotori-bot/logger",
59
+ "@kotori-bot/i18n",
60
+ "@kotori-bot/tools"
61
+ ];
62
+ const DEFAULT_LOADER_CONFIG = {
63
+ dirs: ["./node_modules/", "./node_modules/@kotori-bot/"],
64
+ port: 720,
65
+ dbPrefix: "romiChan",
66
+ level: import_logger.LoggerLevel.RECORD,
67
+ noColor: false
68
+ };
62
69
  // Annotate the CommonJS export names for ESM import in node:
63
70
  0 && (module.exports = {
64
- BUILD_CONFIG_NAME,
65
- BUILD_FILE,
71
+ ADAPTER_PREFIX,
66
72
  BUILD_MODE,
67
- CONFIG_EXT,
73
+ CONFIG_NAME,
68
74
  CORE_MODULES,
69
- DEV_CODE_DIRS,
70
- DEV_CONFIG_NAME,
71
- DEV_FILE,
72
- DEV_IMPORT,
75
+ DEFAULT_LOADER_CONFIG,
73
76
  DEV_MODE,
74
- SUPPORTS_HALF_VERSION,
75
- SUPPORTS_VERSION
77
+ INTERNAL_PACKAGES,
78
+ PLUGIN_PREFIX
76
79
  });
@@ -0,0 +1,2 @@
1
+ export * from './loader';
2
+ export * from './constants';
@@ -1,12 +1,12 @@
1
1
 
2
2
  /**
3
3
  * @Package @kotori-bot/loader
4
- * @Version 1.6.4
5
- * @Author Hotaru <biyuehuya@gmail.com>
4
+ * @Version 1.7.0-rc.1
5
+ * @Author Arimura Sena <me@hotaru.icu>
6
6
  * @Copyright 2024 Hotaru. All rights reserved.
7
7
  * @License GPL-3.0
8
8
  * @Link https://github.com/kotorijs/kotori
9
- * @Date 2024/6/7 21:36:21
9
+ * @Date 2024/8/9 17:33:08
10
10
  */
11
11
 
12
12
  "use strict";
@@ -14,10 +14,6 @@ var __defProp = Object.defineProperty;
14
14
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
15
  var __getOwnPropNames = Object.getOwnPropertyNames;
16
16
  var __hasOwnProp = Object.prototype.hasOwnProperty;
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
17
  var __copyProps = (to, from, except, desc) => {
22
18
  if (from && typeof from === "object" || typeof from === "function") {
23
19
  for (let key of __getOwnPropNames(from))
@@ -26,23 +22,14 @@ var __copyProps = (to, from, except, desc) => {
26
22
  }
27
23
  return to;
28
24
  };
25
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
29
26
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var plugin_exports = {};
31
- __export(plugin_exports, {
32
- KotoriPlugin: () => KotoriPlugin,
33
- default: () => plugin_default
34
- });
35
- module.exports = __toCommonJS(plugin_exports);
36
- class KotoriPlugin {
37
- ctx;
38
- config;
39
- constructor(ctx, config) {
40
- this.ctx = ctx;
41
- this.config = config;
42
- }
43
- }
44
- var plugin_default = KotoriPlugin;
27
+ var loader_exports = {};
28
+ module.exports = __toCommonJS(loader_exports);
29
+ __reExport(loader_exports, require("./loader"), module.exports);
30
+ __reExport(loader_exports, require("./constants"), module.exports);
45
31
  // Annotate the CommonJS export names for ESM import in node:
46
32
  0 && (module.exports = {
47
- KotoriPlugin
33
+ ...require("./loader"),
34
+ ...require("./constants")
48
35
  });
@@ -0,0 +1,122 @@
1
+ import { Tsu, Symbols, Core, type LocaleType, type ModuleConfig, Parser } from '@kotori-bot/core';
2
+ import Logger from '@kotori-bot/logger';
3
+ import { BUILD_MODE, DEV_MODE } from './constants';
4
+ import Server from '../service/server';
5
+ import Database from '../service/database';
6
+ import File from '../service/file';
7
+ interface BaseDir {
8
+ root: string;
9
+ data: string;
10
+ logs: string;
11
+ config: string;
12
+ }
13
+ interface Options {
14
+ mode: typeof BUILD_MODE | typeof DEV_MODE;
15
+ isDaemon: boolean;
16
+ }
17
+ export interface ModulePackage {
18
+ name: string;
19
+ version: string;
20
+ description: string;
21
+ main: string;
22
+ keywords: string[];
23
+ license: 'GPL-3.0';
24
+ author: string | string[];
25
+ peerDependencies: {
26
+ 'kotori-bot': string;
27
+ [propName: string]: string;
28
+ };
29
+ kotori: {
30
+ enforce?: 'pre' | 'post';
31
+ meta: {
32
+ language: LocaleType[];
33
+ };
34
+ };
35
+ }
36
+ export interface ModuleMeta {
37
+ pkg: ModulePackage;
38
+ files: string[];
39
+ main: string;
40
+ }
41
+ interface LoaderOptions {
42
+ mode: typeof DEV_MODE | typeof BUILD_MODE;
43
+ isDaemon?: boolean;
44
+ dir?: string;
45
+ config?: string;
46
+ port?: number;
47
+ dbPrefix?: string;
48
+ level?: number;
49
+ noColor?: boolean;
50
+ }
51
+ declare module '@kotori-bot/core' {
52
+ interface Context {
53
+ readonly baseDir: BaseDir;
54
+ readonly options: Options;
55
+ readonly [Symbols.modules]: Loader[typeof Symbols.modules];
56
+ logger: Logger;
57
+ server: Server;
58
+ db: Database;
59
+ file: File;
60
+ browser: object;
61
+ }
62
+ interface GlobalConfig {
63
+ dirs: string[];
64
+ port: number;
65
+ dbPrefix: string;
66
+ level: number;
67
+ noColor: boolean;
68
+ }
69
+ }
70
+ export declare const localeTypeSchema: import("@kotori-bot/core").UnionParser<[import("@kotori-bot/core").LiteralParser<"en_US">, import("@kotori-bot/core").LiteralParser<"ja_JP">, import("@kotori-bot/core").LiteralParser<"zh_TW">, import("@kotori-bot/core").AnyParser<any>]>;
71
+ export declare const globalLoaderConfigSchema: Parser<import("@kotori-bot/core").ObjectParserInfer<{
72
+ lang: Parser<any>;
73
+ commandPrefix: Parser<string>;
74
+ dirs: Parser<string[]>;
75
+ level: Parser<number>;
76
+ port: Parser<number>;
77
+ dbPrefix: Parser<string>;
78
+ noColor: Parser<boolean>;
79
+ }>>;
80
+ export declare const adapterConfigSchemaFactory: (lang: Tsu.infer<typeof localeTypeSchema>, commandPrefix: string) => import("@kotori-bot/core").ObjectParser<{
81
+ extends: import("@kotori-bot/core").StringParser;
82
+ master: import("@kotori-bot/core").UnionParser<[import("@kotori-bot/core").NumberParser, import("@kotori-bot/core").StringParser]>;
83
+ lang: Parser<any>;
84
+ commandPrefix: Parser<string>;
85
+ }>;
86
+ export declare const modulePackageSchema: import("@kotori-bot/core").ObjectParser<{
87
+ name: import("@kotori-bot/core").CustomParser<string>;
88
+ version: import("@kotori-bot/core").StringParser;
89
+ description: import("@kotori-bot/core").StringParser;
90
+ main: import("@kotori-bot/core").StringParser;
91
+ license: import("@kotori-bot/core").LiteralParser<"GPL-3.0">;
92
+ keywords: import("@kotori-bot/core").CustomParser<string[]>;
93
+ author: import("@kotori-bot/core").UnionParser<[import("@kotori-bot/core").StringParser, import("@kotori-bot/core").ArrayParser<import("@kotori-bot/core").StringParser>]>;
94
+ peerDependencies: import("@kotori-bot/core").ObjectParser<{
95
+ 'kotori-bot': import("@kotori-bot/core").StringParser;
96
+ }>;
97
+ kotori: Parser<import("@kotori-bot/core").ObjectParserInfer<{
98
+ enforce: Parser<"post" | "pre" | undefined>;
99
+ meta: Parser<import("@kotori-bot/core").ObjectParserInfer<{
100
+ language: Parser<any[]>;
101
+ }>>;
102
+ }>>;
103
+ }>;
104
+ export declare class Loader extends Core {
105
+ private loadRecord;
106
+ private isDev;
107
+ private format;
108
+ readonly baseDir: BaseDir;
109
+ readonly options: Options;
110
+ readonly [Symbols.modules]: Map<string, [ModuleMeta, ModuleConfig, Parser<unknown>?]>;
111
+ constructor(loaderOptions?: LoaderOptions);
112
+ run(onlyStart?: boolean): void;
113
+ private catchError;
114
+ private listenMessage;
115
+ private checkModuleFiles;
116
+ private loadEx;
117
+ private unloadEx;
118
+ private loadAllModules;
119
+ private loadAllAdapter;
120
+ private checkUpdate;
121
+ }
122
+ export default Loader;