@kotori-bot/loader 1.5.2-beta.1 → 1.6.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.
@@ -0,0 +1,15 @@
1
+ import { Api, Adapter as OriginAdapter } from '@kotori-bot/core';
2
+ import { WsRouteHandler } from '../types/server';
3
+ export declare namespace Adapter {
4
+ abstract class WebSocket<T extends Api = Api> extends OriginAdapter<T> {
5
+ private isSetup;
6
+ private destroyFn?;
7
+ protected destroy(): void;
8
+ protected setup(): void;
9
+ abstract handle<T extends object>(data: T): void;
10
+ connection?: (ws: Parameters<WsRouteHandler>[0], req: Parameters<WsRouteHandler>[1]) => void;
11
+ start(): void;
12
+ stop(): void;
13
+ }
14
+ }
15
+ export default Adapter;
@@ -0,0 +1,80 @@
1
+
2
+ /**
3
+ * @Package @kotori-bot/loader
4
+ * @Version 1.6.0-beta.1
5
+ * @Author Hotaru <biyuehuya@gmail.com>
6
+ * @Copyright 2024 Hotaru. All rights reserved.
7
+ * @License GPL-3.0
8
+ * @Link https://github.com/kotorijs/kotori
9
+ * @Date 2024/6/6 21:03:54
10
+ */
11
+
12
+ "use strict";
13
+ var __defProp = Object.defineProperty;
14
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
+ var __getOwnPropNames = Object.getOwnPropertyNames;
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
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/service/adapter.ts
32
+ var adapter_exports = {};
33
+ __export(adapter_exports, {
34
+ Adapter: () => Adapter,
35
+ default: () => adapter_default
36
+ });
37
+ module.exports = __toCommonJS(adapter_exports);
38
+ var import_core = require("@kotori-bot/core");
39
+ var Adapter;
40
+ ((Adapter2) => {
41
+ class WebSocket extends import_core.Adapter {
42
+ isSetup = false;
43
+ destroyFn;
44
+ destroy() {
45
+ if (!this.destroyFn) return;
46
+ this.destroyFn();
47
+ this.isSetup = false;
48
+ }
49
+ setup() {
50
+ if (this.isSetup) return;
51
+ this.ctx.inject("server");
52
+ this.destroyFn = this.ctx.server.wss(`/adapter/${this.identity}`, (ws, req) => {
53
+ if (this.connection) this.connection(ws, req);
54
+ ws.on("message", (raw) => {
55
+ let data;
56
+ try {
57
+ data = JSON.parse(raw.toString());
58
+ } catch (e) {
59
+ this.ctx.logger.error(`Data parse error: ${e instanceof Error ? e.message : e}`);
60
+ }
61
+ if (data) this.handle(data);
62
+ });
63
+ });
64
+ this.isSetup = true;
65
+ }
66
+ connection;
67
+ start() {
68
+ this.setup();
69
+ }
70
+ stop() {
71
+ this.destroy();
72
+ }
73
+ }
74
+ Adapter2.WebSocket = WebSocket;
75
+ })(Adapter || (Adapter = {}));
76
+ var adapter_default = Adapter;
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ Adapter
80
+ });
@@ -1,2 +1,29 @@
1
+
2
+ /**
3
+ * @Package @kotori-bot/loader
4
+ * @Version 1.6.0-beta.1
5
+ * @Author Hotaru <biyuehuya@gmail.com>
6
+ * @Copyright 2024 Hotaru. All rights reserved.
7
+ * @License GPL-3.0
8
+ * @Link https://github.com/kotorijs/kotori
9
+ * @Date 2024/6/6 21:03:54
10
+ */
11
+
1
12
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
13
+ var __defProp = Object.defineProperty;
14
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
+ var __getOwnPropNames = Object.getOwnPropertyNames;
16
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+
27
+ // src/service/database.ts
28
+ var database_exports = {};
29
+ module.exports = __toCommonJS(database_exports);
@@ -1,9 +1,9 @@
1
- import { Context, Service, createConfig, loadConfig, saveConfig } from '@kotori-bot/core';
1
+ import { Context, JsonMap, Service, createConfig, loadConfig, saveConfig } from '@kotori-bot/core';
2
2
  export declare class File extends Service {
3
3
  constructor(ctx: Context);
4
4
  getDir(): string;
5
5
  getFile(filename: string): string;
6
- load<T = Parameters<typeof saveConfig>[1]>(filename: string, type?: Parameters<typeof loadConfig>[1], init?: Parameters<typeof loadConfig>[2]): T;
6
+ load<O = undefined, T extends Parameters<typeof loadConfig>[1] = 'json'>(filename: string, type?: T, init?: T extends 'text' ? string : object): O extends undefined ? T extends "text" ? string : JsonMap : O;
7
7
  save(filename: string, data: Parameters<typeof saveConfig>[1], type?: Parameters<typeof saveConfig>[2]): void;
8
8
  create(filename: string, data?: Parameters<typeof createConfig>[1], type?: Parameters<typeof createConfig>[2]): void;
9
9
  }
@@ -1,28 +1,66 @@
1
+
2
+ /**
3
+ * @Package @kotori-bot/loader
4
+ * @Version 1.6.0-beta.1
5
+ * @Author Hotaru <biyuehuya@gmail.com>
6
+ * @Copyright 2024 Hotaru. All rights reserved.
7
+ * @License GPL-3.0
8
+ * @Link https://github.com/kotorijs/kotori
9
+ * @Date 2024/6/6 21:03:54
10
+ */
11
+
1
12
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.File = void 0;
4
- const core_1 = require("@kotori-bot/core");
5
- const node_path_1 = require("node:path");
6
- class File extends core_1.Service {
7
- constructor(ctx) {
8
- super(ctx, {}, 'file');
9
- }
10
- getDir() {
11
- return (0, node_path_1.join)(this.ctx.baseDir.data, ...(this.ctx.identity ? this.ctx.identity.split('/') : []));
12
- }
13
- getFile(filename) {
14
- return (0, node_path_1.join)(this.getDir(), filename);
15
- }
16
- /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
17
- load(filename, type, init) {
18
- return (0, core_1.loadConfig)(this.getFile(filename), type, init);
19
- }
20
- save(filename, data, type) {
21
- (0, core_1.saveConfig)(this.getFile(filename), data, type);
22
- }
23
- create(filename, data, type) {
24
- (0, core_1.createConfig)(this.getFile(filename), data, type);
25
- }
26
- }
27
- exports.File = File;
28
- exports.default = File;
13
+ var __defProp = Object.defineProperty;
14
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
+ var __getOwnPropNames = Object.getOwnPropertyNames;
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
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/service/file.ts
32
+ var file_exports = {};
33
+ __export(file_exports, {
34
+ File: () => File,
35
+ default: () => file_default
36
+ });
37
+ module.exports = __toCommonJS(file_exports);
38
+ var import_core = require("@kotori-bot/core");
39
+ var import_node_path = require("path");
40
+ var File = class extends import_core.Service {
41
+ constructor(ctx) {
42
+ super(ctx, {}, "file");
43
+ }
44
+ getDir() {
45
+ return (0, import_node_path.join)(this.ctx.baseDir.data, ...this.ctx.identity ? this.ctx.identity.split("/") : []);
46
+ }
47
+ getFile(filename) {
48
+ return (0, import_node_path.join)(this.getDir(), filename);
49
+ }
50
+ /* eslint-disable @typescript-eslint/no-explicit-any */
51
+ load(filename, type, init) {
52
+ return (0, import_core.loadConfig)(this.getFile(filename), type, init);
53
+ }
54
+ /* eslint-enable @typescript-eslint/no-explicit-any */
55
+ save(filename, data, type) {
56
+ (0, import_core.saveConfig)(this.getFile(filename), data, type);
57
+ }
58
+ create(filename, data, type) {
59
+ (0, import_core.createConfig)(this.getFile(filename), data, type);
60
+ }
61
+ };
62
+ var file_default = File;
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ File
66
+ });
@@ -1,33 +1,63 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Context, Service } from '@kotori-bot/core';
3
- import { IncomingMessage } from 'node:http';
4
- import express from 'express';
5
- import Ws from 'ws';
4
+ import { IncomingMessage, ServerResponse } from 'node:http';
5
+ import { HttpRouteHandler, HttpRoutes, WsRouteHandler } from '../types/server';
6
6
  interface ServerConfig {
7
7
  port: number;
8
8
  }
9
- type wsRouterCallback = (ws: Ws, req: IncomingMessage & {
10
- params: object;
11
- }) => void;
12
- export declare class Server extends Service<ServerConfig> {
9
+ interface BodyParserOptions {
10
+ inflate?: boolean | undefined;
11
+ limit?: number | string | undefined;
12
+ type?: string | string[] | ((req: IncomingMessage) => any) | undefined;
13
+ verify?(req: IncomingMessage, res: ServerResponse, buf: Buffer, encoding: string): void;
14
+ }
15
+ interface UrlencodedOptions extends BodyParserOptions {
16
+ extended?: boolean | undefined;
17
+ parameterLimit?: number | undefined;
18
+ }
19
+ interface ServeStaticOptions<R extends ServerResponse = ServerResponse> {
20
+ acceptRanges?: boolean | undefined;
21
+ cacheControl?: boolean | undefined;
22
+ dotfiles?: string | undefined;
23
+ etag?: boolean | undefined;
24
+ extensions?: string[] | false | undefined;
25
+ fallthrough?: boolean | undefined;
26
+ immutable?: boolean | undefined;
27
+ index?: boolean | string | string[] | undefined;
28
+ lastModified?: boolean | undefined;
29
+ maxAge?: number | string | undefined;
30
+ redirect?: boolean | undefined;
31
+ setHeaders?: ((res: R, path: string, stat: any) => any) | undefined;
32
+ }
33
+ interface RouterOptions {
34
+ caseSensitive?: boolean | undefined;
35
+ /**
36
+ * @default false
37
+ * @since 4.5.0
38
+ */
39
+ mergeParams?: boolean | undefined;
40
+ strict?: boolean | undefined;
41
+ }
42
+ export declare class Server extends Service<ServerConfig> implements HttpRoutes {
13
43
  private app;
14
44
  private server;
15
45
  private wsServer;
16
- private wsRouters;
46
+ private wsRoutes;
17
47
  constructor(ctx: Context, config: ServerConfig);
18
48
  start(): void;
19
49
  stop(): void;
20
- get: Server['app']['get'];
21
- post: Server['app']['post'];
22
- patch: Server['app']['patch'];
23
- put: Server['app']['put'];
24
- delete: Server['app']['delete'];
25
- all: Server['app']['all'];
26
- use: Server['app']['use'];
27
- router: typeof express.Router;
28
- json: (options?: object) => () => unknown;
29
- static: (path: string) => () => unknown;
30
- urlencoded: (options?: object) => () => unknown;
31
- wss(path: string, callback: wsRouterCallback): void;
50
+ get<P extends string>(path: P, ...callback: HttpRouteHandler<P>[]): void;
51
+ post<P extends string>(path: P, ...callback: HttpRouteHandler<P>[]): void;
52
+ patch<P extends string>(path: P, ...callback: HttpRouteHandler<P>[]): void;
53
+ put<P extends string>(path: P, ...callback: HttpRouteHandler<P>[]): void;
54
+ delete<P extends string>(path: P, ...callback: HttpRouteHandler<P>[]): void;
55
+ all<P extends string>(path: P, ...callback: HttpRouteHandler<P>[]): void;
56
+ use<P extends string>(path: P | HttpRouteHandler | HttpRoutes, ...callback: (HttpRouteHandler<P> | HttpRoutes)[]): void;
57
+ router: (options?: RouterOptions) => HttpRoutes;
58
+ json: (options?: BodyParserOptions) => HttpRouteHandler;
59
+ static: (root: string, options?: ServeStaticOptions) => HttpRouteHandler;
60
+ urlencoded: (options?: UrlencodedOptions) => HttpRouteHandler;
61
+ wss<P extends string>(path: P, callback: WsRouteHandler<P>): () => boolean;
32
62
  }
33
63
  export default Server;
@@ -1,93 +1,146 @@
1
+
2
+ /**
3
+ * @Package @kotori-bot/loader
4
+ * @Version 1.6.0-beta.1
5
+ * @Author Hotaru <biyuehuya@gmail.com>
6
+ * @Copyright 2024 Hotaru. All rights reserved.
7
+ * @License GPL-3.0
8
+ * @Link https://github.com/kotorijs/kotori
9
+ * @Date 2024/6/6 21:03:54
10
+ */
11
+
1
12
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ var __create = Object.create;
14
+ var __defProp = Object.defineProperty;
15
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
16
+ var __getOwnPropNames = Object.getOwnPropertyNames;
17
+ var __getProtoOf = Object.getPrototypeOf;
18
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, { get: all[name], enumerable: true });
4
22
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Server = void 0;
7
- const core_1 = require("@kotori-bot/core");
8
- const node_http_1 = require("node:http");
9
- const path_to_regexp_1 = require("path-to-regexp");
10
- const express_1 = __importDefault(require("express"));
11
- const ws_1 = __importDefault(require("ws"));
12
- class Server extends core_1.Service {
13
- app;
14
- server;
15
- wsServer;
16
- wsRouters = new Map();
17
- constructor(ctx, config) {
18
- super(ctx, config, 'server');
19
- this.app = (0, express_1.default)();
20
- this.app.use(express_1.default.json());
21
- this.app.use('/', (req, res, next) => {
22
- let isWebui = false;
23
- ctx[core_1.Symbols.modules].forEach((module) => {
24
- if (isWebui)
25
- return;
26
- if (module[0].pkg.name === '@kotori-bot/kotori-plugin-webui')
27
- isWebui = true;
28
- });
29
- if (isWebui || req.url !== '/') {
30
- next();
31
- return;
32
- }
33
- res.setHeader('Content-type', 'text/html');
34
- res.send(/* html */ `<h1>Welcome to kotori!</h1>`);
35
- });
36
- this.get = this.app.get.bind(this.app);
37
- this.post = this.app.post.bind(this.app);
38
- this.patch = this.app.patch.bind(this.app);
39
- this.put = this.app.put.bind(this.app);
40
- this.delete = this.app.delete.bind(this.app);
41
- this.use = this.app.use.bind(this.app);
42
- this.all = this.app.all.bind(this.app);
43
- this.server = (0, node_http_1.createServer)(this.app);
44
- this.wsServer = new ws_1.default.Server({ noServer: true });
45
- this.server.on('upgrade', (req, socket, head) => {
46
- this.wsServer.handleUpgrade(req, socket, head, (ws) => {
47
- this.wsServer.emit('connection', ws, req);
48
- });
49
- });
50
- this.wsServer.on('connection', (ws, req) => {
51
- let triggered = false;
52
- /* eslint-disable no-restricted-syntax,no-continue */
53
- for (const [template, callback] of this.wsRouters.entries()) {
54
- if (!req.url)
55
- continue;
56
- const result = (0, path_to_regexp_1.match)(template, { decode: decodeURIComponent })(req.url);
57
- if (!result)
58
- continue;
59
- if (!triggered)
60
- triggered = true;
61
- callback(ws, Object.assign(req, { params: result.params }));
62
- }
63
- /* eslint-enable no-restricted-syntax,no-continue */
64
- if (!triggered)
65
- ws.close(1002);
66
- });
67
- }
68
- start() {
69
- this.server.listen(this.config.port, () => {
70
- this.ctx.logger.label('server').info(`http server start at http://127.0.0.1:${this.config.port}`);
23
+ var __copyProps = (to, from, except, desc) => {
24
+ if (from && typeof from === "object" || typeof from === "function") {
25
+ for (let key of __getOwnPropNames(from))
26
+ if (!__hasOwnProp.call(to, key) && key !== except)
27
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
28
+ }
29
+ return to;
30
+ };
31
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
32
+ // If the importer is in node compatibility mode or this is not an ESM
33
+ // file that has been converted to a CommonJS file using a Babel-
34
+ // compatible transform (i.e. "__esModule" has not been set), then set
35
+ // "default" to the CommonJS "module.exports" for node compatibility.
36
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
+ mod
38
+ ));
39
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
+
41
+ // src/service/server.ts
42
+ var server_exports = {};
43
+ __export(server_exports, {
44
+ Server: () => Server,
45
+ default: () => server_default
46
+ });
47
+ module.exports = __toCommonJS(server_exports);
48
+ var import_core = require("@kotori-bot/core");
49
+ var import_node_http = require("http");
50
+ var import_path_to_regexp = require("path-to-regexp");
51
+ var import_express = __toESM(require("express"));
52
+ var import_ws = __toESM(require("ws"));
53
+ var Server = class extends import_core.Service {
54
+ app;
55
+ server;
56
+ wsServer;
57
+ wsRoutes = /* @__PURE__ */ new Map();
58
+ constructor(ctx, config) {
59
+ super(ctx, config, "server");
60
+ this.app = (0, import_express.default)();
61
+ this.app.use(import_express.default.json());
62
+ this.app.use("/", (req, res, next) => {
63
+ let isWebui = false;
64
+ ctx[import_core.Symbols.modules].forEach((module2) => {
65
+ if (isWebui) return;
66
+ if (module2[0].pkg.name === "@kotori-bot/kotori-plugin-webui") isWebui = true;
67
+ });
68
+ if (isWebui || req.url !== "/") {
69
+ next();
70
+ return;
71
+ }
72
+ res.setHeader("Content-type", "text/html");
73
+ res.send(
74
+ /* html */
75
+ `<h1>Welcome to kotori!</h1>`
76
+ );
77
+ });
78
+ this.server = (0, import_node_http.createServer)(this.app);
79
+ this.wsServer = new import_ws.default.Server({ noServer: true });
80
+ this.server.on("upgrade", (req, socket, head) => {
81
+ this.wsServer.handleUpgrade(req, socket, head, (ws) => {
82
+ this.wsServer.emit("connection", ws, req);
83
+ });
84
+ });
85
+ this.wsServer.on("connection", (ws, req) => {
86
+ let triggered = false;
87
+ for (const [template, list] of this.wsRoutes.entries()) {
88
+ if (!req.url) continue;
89
+ const result = (0, import_path_to_regexp.match)(template, { decode: decodeURIComponent })(req.url);
90
+ if (!result) continue;
91
+ if (!triggered) triggered = true;
92
+ list.forEach((callback) => {
93
+ callback(ws, Object.assign(req, { params: result.params }));
71
94
  });
72
- }
73
- stop() {
74
- this.wsServer.close();
75
- this.server.close();
76
- }
77
- get;
78
- post;
79
- patch;
80
- put;
81
- delete;
82
- all;
83
- use;
84
- router = express_1.default.Router;
85
- json = express_1.default.json;
86
- static = express_1.default.static;
87
- urlencoded = express_1.default.urlencoded;
88
- wss(path, callback) {
89
- this.wsRouters.set(path, callback);
90
- }
91
- }
92
- exports.Server = Server;
93
- exports.default = Server;
95
+ }
96
+ if (!triggered) ws.close(1002);
97
+ });
98
+ }
99
+ start() {
100
+ this.server.listen(this.config.port, () => {
101
+ this.ctx.logger.label("server").info(`http server start at http://127.0.0.1:${this.config.port}`);
102
+ this.ctx.logger.label("server").info(`websocket server start at ws://127.0.0.1:${this.config.port}`);
103
+ });
104
+ }
105
+ stop() {
106
+ this.wsServer.close();
107
+ this.server.close();
108
+ }
109
+ get(path, ...callback) {
110
+ this.app.get(path, ...callback);
111
+ }
112
+ post(path, ...callback) {
113
+ this.app.post(path, ...callback);
114
+ }
115
+ patch(path, ...callback) {
116
+ this.app.patch(path, ...callback);
117
+ }
118
+ put(path, ...callback) {
119
+ this.app.put(path, ...callback);
120
+ }
121
+ delete(path, ...callback) {
122
+ this.app.delete(path, ...callback);
123
+ }
124
+ all(path, ...callback) {
125
+ this.app.all(path, ...callback);
126
+ }
127
+ use(path, ...callback) {
128
+ if (typeof path === "string") this.app.use(path, ...callback);
129
+ else this.app.use("/", path, ...callback);
130
+ }
131
+ router = import_express.default.Router;
132
+ json = import_express.default.json;
133
+ static = import_express.default.static;
134
+ urlencoded = import_express.default.urlencoded;
135
+ wss(path, callback) {
136
+ const list = this.wsRoutes.get(path) || /* @__PURE__ */ new Set();
137
+ list.add(callback);
138
+ this.wsRoutes.set(path, list);
139
+ return () => list.delete(callback);
140
+ }
141
+ };
142
+ var server_default = Server;
143
+ // Annotate the CommonJS export names for ESM import in node:
144
+ 0 && (module.exports = {
145
+ Server
146
+ });
@@ -0,0 +1 @@
1
+ export * from './server';
@@ -0,0 +1,29 @@
1
+
2
+ /**
3
+ * @Package @kotori-bot/loader
4
+ * @Version 1.6.0-beta.1
5
+ * @Author Hotaru <biyuehuya@gmail.com>
6
+ * @Copyright 2024 Hotaru. All rights reserved.
7
+ * @License GPL-3.0
8
+ * @Link https://github.com/kotorijs/kotori
9
+ * @Date 2024/6/6 21:03:54
10
+ */
11
+
12
+ "use strict";
13
+ var __defProp = Object.defineProperty;
14
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
+ var __getOwnPropNames = Object.getOwnPropertyNames;
16
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+
27
+ // src/types/index.ts
28
+ var types_exports = {};
29
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1,6 @@
1
+ declare module '@kotori-bot/core' {
2
+ interface EventsMapping {
3
+ ready_module_decorators(pkgName: string): void;
4
+ }
5
+ }
6
+ export {};
@@ -0,0 +1,12 @@
1
+
2
+ /**
3
+ * @Package @kotori-bot/loader
4
+ * @Version 1.6.0-beta.1
5
+ * @Author Hotaru <biyuehuya@gmail.com>
6
+ * @Copyright 2024 Hotaru. All rights reserved.
7
+ * @License GPL-3.0
8
+ * @Link https://github.com/kotorijs/kotori
9
+ * @Date 2024/6/6 21:03:54
10
+ */
11
+
12
+ "use strict";
@@ -0,0 +1,27 @@
1
+ /// <reference types="node" />
2
+ import { NextFunction, Request, Response } from 'express';
3
+ import { IncomingMessage } from 'node:http';
4
+ import Ws from 'ws';
5
+ type RemoveTail<S extends string, Tail extends string> = S extends `${infer P}${Tail}` ? P : S;
6
+ type GetRouteParameter<S extends string> = RemoveTail<RemoveTail<RemoveTail<S, `/${string}`>, `-${string}`>, `.${string}`>;
7
+ interface ParamsDictionary {
8
+ [key: string]: string;
9
+ }
10
+ type RouteParameters<Route extends string> = string extends Route ? ParamsDictionary : Route extends `${string}(${string}` ? ParamsDictionary : Route extends `${string}:${infer Rest}` ? (GetRouteParameter<Rest> extends never ? ParamsDictionary : GetRouteParameter<Rest> extends `${infer ParamName}?` ? {
11
+ [P in ParamName]?: string;
12
+ } : {
13
+ [P in GetRouteParameter<Rest>]: string;
14
+ }) & (Rest extends `${GetRouteParameter<Rest>}${infer Next}` ? RouteParameters<Next> : unknown) : object;
15
+ export type HttpRouteHandler<P extends string = string> = (req: Request<RouteParameters<P>>, res: Response, next: NextFunction) => unknown;
16
+ type KeyList = 'get' | 'post' | 'patch' | 'put' | 'delete' | 'all';
17
+ export type WsRouteHandler<P extends string = ''> = (ws: Ws, req: IncomingMessage & {
18
+ params: RouteParameters<P>;
19
+ }) => void;
20
+ type HttpRoutesReflect = {
21
+ [K in KeyList]: <P extends string>(path: P, ...callback: HttpRouteHandler<P>[]) => unknown;
22
+ };
23
+ export interface HttpRoutes extends HttpRoutesReflect {
24
+ use<P extends string>(path: P, ...callback: (HttpRouteHandler<P> | HttpRoutes)[]): unknown;
25
+ use(...callback: (HttpRouteHandler | HttpRoutes)[]): unknown;
26
+ }
27
+ export {};