@jayfong/x-server 2.119.0 → 3.0.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/lib/_virtual/_rolldown/runtime.mjs +4 -0
- package/lib/cli/api_generator.d.mts +74 -0
- package/lib/cli/api_generator.mjs +310 -0
- package/lib/cli/build_util.d.mts +17 -0
- package/lib/cli/build_util.mjs +156 -0
- package/lib/cli/cli.d.mts +1 -0
- package/lib/cli/cli.mjs +355 -0
- package/lib/cli/css_register.d.mts +1 -0
- package/lib/cli/css_register.mjs +7 -0
- package/lib/cli/deploy_util.d.mts +23 -0
- package/lib/cli/deploy_util.mjs +70 -0
- package/lib/cli/dev_util.d.mts +7 -0
- package/lib/cli/dev_util.mjs +25 -0
- package/lib/cli/env_util.d.mts +45 -0
- package/lib/cli/env_util.mjs +207 -0
- package/lib/cli/esbuild_register.d.mts +1 -0
- package/lib/cli/esbuild_register.mjs +7 -0
- package/lib/cli/template_util.d.mts +18 -0
- package/lib/cli/template_util.mjs +85 -0
- package/lib/cli/templates/crons.ts +1 -1
- package/lib/cli/templates/handlers.ts +1 -1
- package/lib/cli/templates/hooks.ts +1 -1
- package/lib/cli/templates/models.ts +7 -7
- package/lib/cli/templates/package.json +11 -1
- package/lib/cli/templates/routes.ts +2 -1
- package/lib/core/ctx_storage.d.mts +3 -0
- package/lib/core/ctx_storage.mjs +4 -0
- package/lib/core/define_bus.d.mts +37 -0
- package/lib/core/define_bus.mjs +12 -0
- package/lib/core/{define_cron.d.ts → define_cron.d.mts} +2 -2
- package/lib/core/define_cron.mjs +11 -0
- package/lib/core/{define_handler.d.ts → define_handler.d.mts} +19 -19
- package/lib/core/define_handler.mjs +44 -0
- package/lib/core/define_hook.d.mts +2 -0
- package/lib/core/define_hook.mjs +6 -0
- package/lib/core/define_server.d.mts +3 -0
- package/lib/core/define_server.mjs +8 -0
- package/lib/core/{define_task.d.ts → define_task.d.mts} +2 -2
- package/lib/core/define_task.mjs +102 -0
- package/lib/core/get_handler_url.d.mts +2 -0
- package/lib/core/get_handler_url.mjs +7 -0
- package/lib/core/handler.d.mts +16 -0
- package/lib/core/handler.mjs +132 -0
- package/lib/core/http_error.d.mts +2 -0
- package/lib/core/http_error.mjs +1 -0
- package/lib/core/http_header.d.mts +856 -0
- package/lib/core/http_header.mjs +860 -0
- package/lib/core/http_method.d.mts +3 -0
- package/lib/core/http_method.mjs +10 -0
- package/lib/core/http_redirect.d.mts +5 -0
- package/lib/core/http_redirect.mjs +10 -0
- package/lib/core/server.d.mts +20 -0
- package/lib/core/server.mjs +186 -0
- package/lib/core/types.d.mts +256 -0
- package/lib/exports.d.mts +46 -0
- package/lib/exports.mjs +46 -0
- package/lib/index.d.mts +48 -0
- package/lib/index.mjs +45 -0
- package/lib/plugins/base.d.mts +4 -0
- package/lib/plugins/compress.d.mts +12 -0
- package/lib/plugins/compress.mjs +15 -0
- package/lib/plugins/cookie.d.mts +12 -0
- package/lib/plugins/cookie.mjs +15 -0
- package/lib/plugins/cors.d.mts +22 -0
- package/lib/plugins/cors.mjs +34 -0
- package/lib/plugins/file_parser.d.mts +15 -0
- package/lib/plugins/file_parser.mjs +24 -0
- package/lib/plugins/form_body_parser.d.mts +12 -0
- package/lib/plugins/form_body_parser.mjs +15 -0
- package/lib/plugins/ws_parser.d.mts +12 -0
- package/lib/plugins/ws_parser.mjs +15 -0
- package/lib/plugins/xml_parser.d.mts +19 -0
- package/lib/plugins/xml_parser.mjs +40 -0
- package/lib/services/ai.d.mts +31 -0
- package/lib/services/ai.mjs +44 -0
- package/lib/services/base.d.mts +4 -0
- package/lib/services/base.mjs +1 -0
- package/lib/services/cache.d.mts +165 -0
- package/lib/services/cache.mjs +323 -0
- package/lib/services/captcha.d.mts +65 -0
- package/lib/services/captcha.mjs +61 -0
- package/lib/services/{crypto.js → crypto.d.mts} +19 -78
- package/lib/services/crypto.mjs +141 -0
- package/lib/services/db_value.d.mts +60 -0
- package/lib/services/db_value.mjs +64 -0
- package/lib/services/dingtalk.d.mts +39 -0
- package/lib/services/dingtalk.mjs +44 -0
- package/lib/services/dispose.d.mts +17 -0
- package/lib/services/dispose.mjs +18 -0
- package/lib/services/emoji.d.mts +10 -0
- package/lib/services/emoji.mjs +2025 -0
- package/lib/services/file_store.d.mts +49 -0
- package/lib/services/file_store.mjs +58 -0
- package/lib/services/html.d.mts +11 -0
- package/lib/services/html.mjs +12 -0
- package/lib/services/jwt.d.mts +33 -0
- package/lib/services/jwt.mjs +42 -0
- package/lib/services/log.d.mts +37 -0
- package/lib/services/log.mjs +99 -0
- package/lib/services/mail.d.mts +22 -0
- package/lib/services/mail.mjs +28 -0
- package/lib/services/pay.d.mts +123 -0
- package/lib/services/pay.mjs +157 -0
- package/lib/services/random.d.mts +27 -0
- package/lib/services/random.mjs +42 -0
- package/lib/services/rate_limit.d.mts +37 -0
- package/lib/services/rate_limit.mjs +40 -0
- package/lib/services/redis.d.mts +11 -0
- package/lib/services/redis.mjs +6 -0
- package/lib/services/sensitive_words.d.mts +29 -0
- package/lib/services/sensitive_words.mjs +37 -0
- package/lib/services/sms.d.mts +40 -0
- package/lib/services/sms.mjs +30238 -0
- package/lib/types/dto.d.mts +30 -0
- package/lib/types/dto.mjs +1 -0
- package/lib/x.d.mts +11 -0
- package/lib/x.mjs +21 -0
- package/lib/x_init.d.mts +1 -0
- package/lib/x_init.mjs +10 -0
- package/package.json +71 -16
- package/lib/_cjs/cli/api_generator.js +0 -458
- package/lib/_cjs/cli/build_util.js +0 -243
- package/lib/_cjs/cli/cli.js +0 -378
- package/lib/_cjs/cli/css_register.js +0 -7
- package/lib/_cjs/cli/deploy_util.js +0 -76
- package/lib/_cjs/cli/dev_util.js +0 -26
- package/lib/_cjs/cli/env_util.js +0 -252
- package/lib/_cjs/cli/esbuild_register.js +0 -7
- package/lib/_cjs/cli/template_util.js +0 -101
- package/lib/_cjs/cli/templates/crons.ts +0 -2
- package/lib/_cjs/cli/templates/handlers.ts +0 -3
- package/lib/_cjs/cli/templates/hooks.ts +0 -2
- package/lib/_cjs/cli/templates/models.ts +0 -123
- package/lib/_cjs/cli/templates/package.json +0 -3
- package/lib/_cjs/cli/templates/routes.ts +0 -68
- package/lib/_cjs/core/ctx_storage.js +0 -6
- package/lib/_cjs/core/define_bus.js +0 -31
- package/lib/_cjs/core/define_cron.js +0 -13
- package/lib/_cjs/core/define_handler.js +0 -56
- package/lib/_cjs/core/define_hook.js +0 -8
- package/lib/_cjs/core/define_server.js +0 -10
- package/lib/_cjs/core/define_task.js +0 -113
- package/lib/_cjs/core/get_handler_url.js +0 -11
- package/lib/_cjs/core/handler.js +0 -216
- package/lib/_cjs/core/http_error.js +0 -6
- package/lib/_cjs/core/http_header.js +0 -142
- package/lib/_cjs/core/http_method.js +0 -12
- package/lib/_cjs/core/http_redirect.js +0 -11
- package/lib/_cjs/core/server.js +0 -219
- package/lib/_cjs/core/types.js +0 -8
- package/lib/_cjs/exports.js +0 -273
- package/lib/_cjs/index.js +0 -15
- package/lib/_cjs/plugins/base.js +0 -3
- package/lib/_cjs/plugins/compress.js +0 -18
- package/lib/_cjs/plugins/cookie.js +0 -18
- package/lib/_cjs/plugins/cors.js +0 -38
- package/lib/_cjs/plugins/file_parser.js +0 -28
- package/lib/_cjs/plugins/form_body_parser.js +0 -18
- package/lib/_cjs/plugins/ws_parser.js +0 -18
- package/lib/_cjs/plugins/xml_parser.js +0 -48
- package/lib/_cjs/services/ai.js +0 -48
- package/lib/_cjs/services/base.js +0 -3
- package/lib/_cjs/services/cache.js +0 -400
- package/lib/_cjs/services/captcha.js +0 -78
- package/lib/_cjs/services/crypto.js +0 -175
- package/lib/_cjs/services/db_value.js +0 -77
- package/lib/_cjs/services/dingtalk.js +0 -51
- package/lib/_cjs/services/dispose.js +0 -23
- package/lib/_cjs/services/emoji.js +0 -2034
- package/lib/_cjs/services/file_store.js +0 -67
- package/lib/_cjs/services/html.js +0 -17
- package/lib/_cjs/services/jwt.js +0 -65
- package/lib/_cjs/services/log.js +0 -108
- package/lib/_cjs/services/mail.js +0 -31
- package/lib/_cjs/services/pay.js +0 -191
- package/lib/_cjs/services/random.js +0 -51
- package/lib/_cjs/services/rate_limit.js +0 -54
- package/lib/_cjs/services/redis.js +0 -12
- package/lib/_cjs/services/sensitive_words.js +0 -61
- package/lib/_cjs/services/sms.js +0 -84
- package/lib/_cjs/types/dto.js +0 -3
- package/lib/_cjs/x.js +0 -35
- package/lib/cli/api_generator.d.ts +0 -74
- package/lib/cli/api_generator.js +0 -452
- package/lib/cli/build_util.d.ts +0 -17
- package/lib/cli/build_util.js +0 -236
- package/lib/cli/cli.d.ts +0 -2
- package/lib/cli/cli.js +0 -374
- package/lib/cli/css_register.js +0 -5
- package/lib/cli/deploy_util.d.ts +0 -23
- package/lib/cli/deploy_util.js +0 -70
- package/lib/cli/dev_util.d.ts +0 -8
- package/lib/cli/dev_util.js +0 -20
- package/lib/cli/env_util.d.ts +0 -45
- package/lib/cli/env_util.js +0 -246
- package/lib/cli/esbuild_register.js +0 -5
- package/lib/cli/template_util.d.ts +0 -18
- package/lib/cli/template_util.js +0 -95
- package/lib/core/ctx_storage.d.ts +0 -3
- package/lib/core/ctx_storage.js +0 -2
- package/lib/core/define_bus.d.ts +0 -37
- package/lib/core/define_bus.js +0 -27
- package/lib/core/define_cron.js +0 -9
- package/lib/core/define_handler.js +0 -48
- package/lib/core/define_hook.d.ts +0 -2
- package/lib/core/define_hook.js +0 -4
- package/lib/core/define_server.d.ts +0 -3
- package/lib/core/define_server.js +0 -6
- package/lib/core/define_task.js +0 -107
- package/lib/core/get_handler_url.d.ts +0 -2
- package/lib/core/get_handler_url.js +0 -7
- package/lib/core/handler.d.ts +0 -16
- package/lib/core/handler.js +0 -209
- package/lib/core/http_error.d.ts +0 -2
- package/lib/core/http_error.js +0 -2
- package/lib/core/http_header.d.ts +0 -856
- package/lib/core/http_header.js +0 -139
- package/lib/core/http_method.d.ts +0 -3
- package/lib/core/http_method.js +0 -8
- package/lib/core/http_redirect.d.ts +0 -5
- package/lib/core/http_redirect.js +0 -6
- package/lib/core/server.d.ts +0 -20
- package/lib/core/server.js +0 -213
- package/lib/core/types.d.ts +0 -265
- package/lib/core/types.js +0 -4
- package/lib/exports.d.ts +0 -45
- package/lib/exports.js +0 -47
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -3
- package/lib/plugins/base.d.ts +0 -4
- package/lib/plugins/base.js +0 -1
- package/lib/plugins/compress.d.ts +0 -13
- package/lib/plugins/compress.js +0 -12
- package/lib/plugins/cookie.d.ts +0 -13
- package/lib/plugins/cookie.js +0 -12
- package/lib/plugins/cors.d.ts +0 -22
- package/lib/plugins/cors.js +0 -32
- package/lib/plugins/file_parser.d.ts +0 -16
- package/lib/plugins/file_parser.js +0 -22
- package/lib/plugins/form_body_parser.d.ts +0 -13
- package/lib/plugins/form_body_parser.js +0 -12
- package/lib/plugins/ws_parser.d.ts +0 -13
- package/lib/plugins/ws_parser.js +0 -12
- package/lib/plugins/xml_parser.d.ts +0 -19
- package/lib/plugins/xml_parser.js +0 -43
- package/lib/services/ai.d.ts +0 -31
- package/lib/services/ai.js +0 -43
- package/lib/services/base.d.ts +0 -4
- package/lib/services/base.js +0 -1
- package/lib/services/cache.d.ts +0 -173
- package/lib/services/cache.js +0 -394
- package/lib/services/captcha.d.ts +0 -65
- package/lib/services/captcha.js +0 -72
- package/lib/services/crypto.d.ts +0 -110
- package/lib/services/db_value.d.ts +0 -60
- package/lib/services/db_value.js +0 -72
- package/lib/services/dingtalk.d.ts +0 -39
- package/lib/services/dingtalk.js +0 -45
- package/lib/services/dispose.d.ts +0 -17
- package/lib/services/dispose.js +0 -17
- package/lib/services/emoji.d.ts +0 -10
- package/lib/services/emoji.js +0 -2029
- package/lib/services/file_store.d.ts +0 -49
- package/lib/services/file_store.js +0 -61
- package/lib/services/html.d.ts +0 -11
- package/lib/services/html.js +0 -12
- package/lib/services/jwt.d.ts +0 -34
- package/lib/services/jwt.js +0 -59
- package/lib/services/log.d.ts +0 -37
- package/lib/services/log.js +0 -102
- package/lib/services/mail.d.ts +0 -23
- package/lib/services/mail.js +0 -25
- package/lib/services/pay.d.ts +0 -123
- package/lib/services/pay.js +0 -185
- package/lib/services/random.d.ts +0 -27
- package/lib/services/random.js +0 -45
- package/lib/services/rate_limit.d.ts +0 -37
- package/lib/services/rate_limit.js +0 -49
- package/lib/services/redis.d.ts +0 -12
- package/lib/services/redis.js +0 -7
- package/lib/services/sensitive_words.d.ts +0 -29
- package/lib/services/sensitive_words.js +0 -56
- package/lib/services/sms.d.ts +0 -40
- package/lib/services/sms.js +0 -78
- package/lib/types/dto.d.ts +0 -86
- package/lib/types/dto.js +0 -1
- package/lib/x.d.ts +0 -17
- package/lib/x.js +0 -30
- /package/lib/{cli/css_register.d.ts → core/types.mjs} +0 -0
- /package/lib/{cli/esbuild_register.d.ts → plugins/base.mjs} +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { XServer } from "./types.mjs";
|
|
2
|
+
export declare class Server {
|
|
3
|
+
readonly options: XServer.Options;
|
|
4
|
+
private fastify;
|
|
5
|
+
private routes;
|
|
6
|
+
static options: XServer.Options;
|
|
7
|
+
constructor(options: XServer.Options);
|
|
8
|
+
start(): Promise<void>;
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
private prepareFastify;
|
|
11
|
+
private startFastify;
|
|
12
|
+
private prepareRoutes;
|
|
13
|
+
private applyHooks;
|
|
14
|
+
private applyServices;
|
|
15
|
+
private applyPlugins;
|
|
16
|
+
private applyRoutes;
|
|
17
|
+
private applyStatic;
|
|
18
|
+
private startCrons;
|
|
19
|
+
private applyAutoClose;
|
|
20
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { x } from "../x.mjs";
|
|
2
|
+
import { HttpError } from "./http_error.mjs";
|
|
3
|
+
import { HandlerMethodToHttpMethod } from "./http_method.mjs";
|
|
4
|
+
import { base64UrlDecode, castArray, keyBy, noop, rot13 } from "vtils";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import Fastify from "fastify";
|
|
7
|
+
import { cuid2 } from "vtils/x";
|
|
8
|
+
// src/core/server.ts
|
|
9
|
+
var Server = class Server {
|
|
10
|
+
options;
|
|
11
|
+
fastify;
|
|
12
|
+
routes = [];
|
|
13
|
+
static options = {};
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
Server.options = options;
|
|
17
|
+
process.on("unhandledRejection", (reason, promise) => {
|
|
18
|
+
console.error("未捕获的错误", reason, promise);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async start() {
|
|
22
|
+
this.applyServices();
|
|
23
|
+
await this.prepareFastify();
|
|
24
|
+
this.applyPlugins();
|
|
25
|
+
await this.prepareRoutes();
|
|
26
|
+
await this.applyRoutes();
|
|
27
|
+
await this.applyHooks();
|
|
28
|
+
await this.startFastify();
|
|
29
|
+
await this.startCrons();
|
|
30
|
+
await this.applyAutoClose();
|
|
31
|
+
}
|
|
32
|
+
async close() {
|
|
33
|
+
await this.fastify?.close();
|
|
34
|
+
}
|
|
35
|
+
async prepareFastify() {
|
|
36
|
+
this.fastify = await Fastify({
|
|
37
|
+
logger: process.env.NODE_ENV === "development" ? { transport: { target: "pino-pretty" } } : false,
|
|
38
|
+
trustProxy: true,
|
|
39
|
+
...this.options.fastifyOptions
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async startFastify() {
|
|
43
|
+
await this.fastify.listen({
|
|
44
|
+
host: this.options.host || "0.0.0.0",
|
|
45
|
+
port: this.options.port
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async prepareRoutes() {
|
|
49
|
+
const { routes } = await import("@a/x/routes");
|
|
50
|
+
this.routes = routes;
|
|
51
|
+
}
|
|
52
|
+
async applyHooks() {
|
|
53
|
+
await import("@a/x/hooks");
|
|
54
|
+
}
|
|
55
|
+
applyServices() {
|
|
56
|
+
x.register(...this.options.services || []);
|
|
57
|
+
}
|
|
58
|
+
applyPlugins() {
|
|
59
|
+
const plugins = this.options.plugins || [];
|
|
60
|
+
for (const plugin of plugins) plugin.register(this.fastify);
|
|
61
|
+
}
|
|
62
|
+
async applyRoutes() {
|
|
63
|
+
await this.fastify.register(async (fastify) => {
|
|
64
|
+
const appUrl = x.env.APP_URL.replace(/\/+$/, "");
|
|
65
|
+
const routeMap = keyBy(this.routes, (item) => item.path);
|
|
66
|
+
const handleRoute = async (item, req, res, path) => {
|
|
67
|
+
const handlerMethod = item.handler.options.requestMethod || "POST";
|
|
68
|
+
const isWS = handlerMethod === "WS";
|
|
69
|
+
const url = `${appUrl}${path ?? (isWS ? res.url : req.url)}`;
|
|
70
|
+
if (isWS) {
|
|
71
|
+
await item.handler.handle(void 0, {
|
|
72
|
+
traceId: cuid2(),
|
|
73
|
+
url,
|
|
74
|
+
headers: res.headers,
|
|
75
|
+
setHeader: noop,
|
|
76
|
+
redirect: noop,
|
|
77
|
+
ws: req,
|
|
78
|
+
req: res,
|
|
79
|
+
res: {}
|
|
80
|
+
});
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
let files = {};
|
|
84
|
+
if (handlerMethod === "FILE") {
|
|
85
|
+
const part = await req.file();
|
|
86
|
+
files = Object.keys(part.fields).reduce((res, name) => {
|
|
87
|
+
res[name] = castArray(part.fields[name]).map((item) => item.file ? item : item.value)[0];
|
|
88
|
+
return res;
|
|
89
|
+
}, {});
|
|
90
|
+
}
|
|
91
|
+
return await item.handler.handle(handlerMethod === "ANY" ? {} : {
|
|
92
|
+
...req.params,
|
|
93
|
+
...req.query,
|
|
94
|
+
...req.body,
|
|
95
|
+
...files
|
|
96
|
+
}, {
|
|
97
|
+
traceId: cuid2(),
|
|
98
|
+
url,
|
|
99
|
+
headers: req.headers,
|
|
100
|
+
setHeader: (k, v) => res.header(k, v),
|
|
101
|
+
redirect: (url, permanently) => res.redirect(url, permanently ? 301 : 302),
|
|
102
|
+
ws: void 0,
|
|
103
|
+
req,
|
|
104
|
+
res
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
for (const item of this.routes) {
|
|
108
|
+
const handlerOptions = item.handler.options;
|
|
109
|
+
const handlerMethod = handlerOptions.requestMethod || "POST";
|
|
110
|
+
const isWS = handlerMethod === "WS";
|
|
111
|
+
const serverMethod = isWS ? "GET" : HandlerMethodToHttpMethod[handlerMethod];
|
|
112
|
+
fastify.route({
|
|
113
|
+
method: handlerMethod === "ANY" ? [
|
|
114
|
+
"GET",
|
|
115
|
+
"HEAD",
|
|
116
|
+
"TRACE",
|
|
117
|
+
"DELETE",
|
|
118
|
+
"OPTIONS",
|
|
119
|
+
"PATCH",
|
|
120
|
+
"PUT",
|
|
121
|
+
"POST"
|
|
122
|
+
] : serverMethod,
|
|
123
|
+
url: item.path,
|
|
124
|
+
constraints: handlerOptions.requestHost ? { host: handlerOptions.requestHost } : void 0,
|
|
125
|
+
websocket: isWS,
|
|
126
|
+
handler: (req, res) => handleRoute(item, req, res)
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
this.applyStatic();
|
|
130
|
+
fastify.route({
|
|
131
|
+
method: "POST",
|
|
132
|
+
url: "/@",
|
|
133
|
+
handler: async (req, res) => {
|
|
134
|
+
let requestPath = req.headers["x-path"] || "";
|
|
135
|
+
if (!requestPath.startsWith("/")) {
|
|
136
|
+
const [_requestPath, _time] = base64UrlDecode(rot13(requestPath)).split("#");
|
|
137
|
+
if (!_time || Date.now() / 1e3 - Number(_time) > 300) throw new HttpError.Forbidden();
|
|
138
|
+
requestPath = _requestPath;
|
|
139
|
+
}
|
|
140
|
+
if (!requestPath || !routeMap[requestPath]) throw new HttpError.NotFound();
|
|
141
|
+
return handleRoute(routeMap[requestPath], req, res, requestPath);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
fastify.route({
|
|
145
|
+
method: "POST",
|
|
146
|
+
url: "/$",
|
|
147
|
+
handler: async (req) => {
|
|
148
|
+
const payload = req.body;
|
|
149
|
+
if (payload && typeof payload === "object" && x.env.APP_TOKEN && payload.token === x.env.APP_TOKEN) {
|
|
150
|
+
if (payload.type === "ping") return "ping:success";
|
|
151
|
+
else if (payload.type === "updateEnv") {
|
|
152
|
+
Object.assign(x.env, payload.data);
|
|
153
|
+
this.applyStatic();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
async applyStatic() {
|
|
161
|
+
if (Array.isArray(x.env.APP_STATIC_CONTENT)) {
|
|
162
|
+
const staticContent = x.env.APP_STATIC_CONTENT;
|
|
163
|
+
for (const item of staticContent) {
|
|
164
|
+
const methods = castArray(item.method);
|
|
165
|
+
if (!methods.some((method) => this.fastify.hasRoute({
|
|
166
|
+
method,
|
|
167
|
+
url: item.path
|
|
168
|
+
}))) this.fastify.route({
|
|
169
|
+
method: methods,
|
|
170
|
+
url: item.path,
|
|
171
|
+
handler: async (_req, res) => {
|
|
172
|
+
if (!item.contentType && typeof item.content === "string") res.header("Content-Type", "plain/text");
|
|
173
|
+
return item.content;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async startCrons() {
|
|
180
|
+
await import("@a/x/crons");
|
|
181
|
+
}
|
|
182
|
+
async applyAutoClose() {
|
|
183
|
+
x.dispose.add(() => this.close());
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
export { Server };
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { BasePlugin } from "../plugins/base.mjs";
|
|
2
|
+
import { BaseService } from "../services/base.mjs";
|
|
3
|
+
import { DisposeService } from "../services/dispose.mjs";
|
|
4
|
+
import { Handler } from "./handler.mjs";
|
|
5
|
+
import { CronJob } from "cron";
|
|
6
|
+
import { MsValue } from "vtils";
|
|
7
|
+
import * as vae from "vtils/vae";
|
|
8
|
+
import { FastifyReply, FastifyRequest, FastifyServerOptions } from "fastify";
|
|
9
|
+
import { Queue } from "bull";
|
|
10
|
+
import { MultipartFile } from "@fastify/multipart";
|
|
11
|
+
import { AsyncOrSync, LiteralUnion, OneOrMore, RequiredDeep } from "vtils/types";
|
|
12
|
+
import { IncomingHttpHeaders } from "node:http";
|
|
13
|
+
import { WebSocket } from "ws";
|
|
14
|
+
export declare namespace XServer {
|
|
15
|
+
type Mode = 'development' | 'production';
|
|
16
|
+
interface Route {
|
|
17
|
+
/**
|
|
18
|
+
* 路径
|
|
19
|
+
*/
|
|
20
|
+
path: string;
|
|
21
|
+
/**
|
|
22
|
+
* 处理器
|
|
23
|
+
*/
|
|
24
|
+
handler: Handler;
|
|
25
|
+
}
|
|
26
|
+
interface Options {
|
|
27
|
+
/**
|
|
28
|
+
* 监听主机
|
|
29
|
+
*/
|
|
30
|
+
host?: string;
|
|
31
|
+
/**
|
|
32
|
+
* 监听端口
|
|
33
|
+
*/
|
|
34
|
+
port: number;
|
|
35
|
+
/**
|
|
36
|
+
* 响应加密算法
|
|
37
|
+
*/
|
|
38
|
+
responseEncryptAlgorithm?: 'simple';
|
|
39
|
+
/**
|
|
40
|
+
* 响应加密密钥
|
|
41
|
+
*/
|
|
42
|
+
responseEncryptKey?: string;
|
|
43
|
+
/**
|
|
44
|
+
* 是否使用异步上下文
|
|
45
|
+
*
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
useAsyncContext?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* 透传给 Fastify 的选项
|
|
51
|
+
*/
|
|
52
|
+
fastifyOptions?: FastifyServerOptions;
|
|
53
|
+
/**
|
|
54
|
+
* 服务列表
|
|
55
|
+
*/
|
|
56
|
+
services?: BaseService[];
|
|
57
|
+
/**
|
|
58
|
+
* 插件列表
|
|
59
|
+
*/
|
|
60
|
+
plugins?: BasePlugin[];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export declare namespace XHandler {
|
|
64
|
+
type Method = 'GET' | 'POST' | 'FILE' | 'WS' | 'XML' | 'ANY';
|
|
65
|
+
interface ExtraContext {}
|
|
66
|
+
interface Context extends ExtraContext {
|
|
67
|
+
/**
|
|
68
|
+
* 当前请求的跟踪 ID
|
|
69
|
+
*/
|
|
70
|
+
traceId: string;
|
|
71
|
+
/**
|
|
72
|
+
* 当前请求的地址
|
|
73
|
+
*/
|
|
74
|
+
url: string;
|
|
75
|
+
/**
|
|
76
|
+
* 请求头
|
|
77
|
+
*/
|
|
78
|
+
headers: IncomingHttpHeaders;
|
|
79
|
+
/**
|
|
80
|
+
* 设置响应头
|
|
81
|
+
*/
|
|
82
|
+
setHeader: (key: string, value: string) => void;
|
|
83
|
+
/**
|
|
84
|
+
* HTTP 跳转
|
|
85
|
+
*
|
|
86
|
+
* 默认是临时跳转,状态码是 302,
|
|
87
|
+
* 可将第二个参数设为 true 表示永久跳转,状态码是 301
|
|
88
|
+
*/
|
|
89
|
+
redirect: (url: string, permanently?: boolean) => void;
|
|
90
|
+
/**
|
|
91
|
+
* WS
|
|
92
|
+
*/
|
|
93
|
+
ws: WebSocket;
|
|
94
|
+
/**
|
|
95
|
+
* Fastify Request
|
|
96
|
+
*/
|
|
97
|
+
req: FastifyRequest;
|
|
98
|
+
/**
|
|
99
|
+
* Fastify Response
|
|
100
|
+
*/
|
|
101
|
+
res: FastifyReply;
|
|
102
|
+
}
|
|
103
|
+
type Handle<TReqData extends any = void, TResData extends any = void, TReqMethod extends Method = Method> = (
|
|
104
|
+
/**
|
|
105
|
+
* 请求数据,WS 时为一个处理函数
|
|
106
|
+
*/
|
|
107
|
+
data: TReqMethod extends 'WS' ? <T extends keyof TReqData>(type: T, fn: (payload: {
|
|
108
|
+
data: TReqData[T]['request'];
|
|
109
|
+
send: (data: TReqData[T]['response']) => void;
|
|
110
|
+
dispose: DisposeService;
|
|
111
|
+
}) => any) => void : TReqData,
|
|
112
|
+
/**
|
|
113
|
+
* 请求上下文
|
|
114
|
+
*/
|
|
115
|
+
ctx: Context) => AsyncOrSync<TResData>;
|
|
116
|
+
interface ExtraOptions {}
|
|
117
|
+
interface Options<TReqData extends any = void, TResData extends any = void, TReqMethod extends Method = Method, TReqDataRequired = RequiredDeep<TReqData>> extends ExtraOptions {
|
|
118
|
+
/**
|
|
119
|
+
* 请求方法
|
|
120
|
+
*
|
|
121
|
+
* @default POST
|
|
122
|
+
*/
|
|
123
|
+
requestMethod?: TReqMethod;
|
|
124
|
+
/**
|
|
125
|
+
* 请求 Host
|
|
126
|
+
*/
|
|
127
|
+
requestHost?: string | RegExp;
|
|
128
|
+
/**
|
|
129
|
+
* 请求路径
|
|
130
|
+
*/
|
|
131
|
+
requestPath?: OneOrMore<string>;
|
|
132
|
+
/**
|
|
133
|
+
* 解析请求数据
|
|
134
|
+
*/
|
|
135
|
+
parseRequestData?: (data: any, ctx: Context) => any;
|
|
136
|
+
/**
|
|
137
|
+
* 是否打包返回数据
|
|
138
|
+
*
|
|
139
|
+
* @default false
|
|
140
|
+
*/
|
|
141
|
+
responseDataPack?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* 是否混淆返回数据
|
|
144
|
+
*
|
|
145
|
+
* @default false
|
|
146
|
+
*/
|
|
147
|
+
responseDataObfuscate?: boolean;
|
|
148
|
+
responseDataEncrypt?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* 响应的 Content-Type 头
|
|
151
|
+
*/
|
|
152
|
+
responseContentType?: LiteralUnion<'text/html', string>;
|
|
153
|
+
/**
|
|
154
|
+
* 请求数据验证结构(vae)
|
|
155
|
+
*/
|
|
156
|
+
requestDataSchemaVae?: vae.VaeSchemaOf<TReqDataRequired> | ((_: vae.VaeSchemaBuilder<TReqDataRequired>) => vae.VaeSchemaOf<TReqDataRequired> | vae.VaeObjectSchemaShapeOf<TReqDataRequired>);
|
|
157
|
+
/**
|
|
158
|
+
* 是否使用异步上下文
|
|
159
|
+
*
|
|
160
|
+
* @default 默认为服务的设置
|
|
161
|
+
*/
|
|
162
|
+
useAsyncContext?: boolean;
|
|
163
|
+
/**
|
|
164
|
+
* 并发控制
|
|
165
|
+
*/
|
|
166
|
+
concurrency?: number | {
|
|
167
|
+
/** 并发数量 */
|
|
168
|
+
count?: number;
|
|
169
|
+
/** 分组函数 */
|
|
170
|
+
groupBy?: (data: TReqData, ctx: Context) => string;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* 处理器
|
|
174
|
+
*/
|
|
175
|
+
handle: Handle<TReqData, TResData, TReqMethod>;
|
|
176
|
+
}
|
|
177
|
+
type Hook = (options: Options, ...args: Parameters<Handle>) => AsyncOrSync<void>;
|
|
178
|
+
}
|
|
179
|
+
export declare namespace XTask {
|
|
180
|
+
interface TaskOptions<T> {
|
|
181
|
+
/**
|
|
182
|
+
* 任务名称
|
|
183
|
+
*/
|
|
184
|
+
name: string;
|
|
185
|
+
/**
|
|
186
|
+
* 并发数量
|
|
187
|
+
*
|
|
188
|
+
* @default 1
|
|
189
|
+
*/
|
|
190
|
+
concurrency?: number;
|
|
191
|
+
/**
|
|
192
|
+
* 处理器
|
|
193
|
+
*/
|
|
194
|
+
handle: (data: T) => any;
|
|
195
|
+
}
|
|
196
|
+
interface Task<T> extends Queue<T> {}
|
|
197
|
+
type SliceTaskOptions<T, K> = {
|
|
198
|
+
/**
|
|
199
|
+
* 任务名称
|
|
200
|
+
*/
|
|
201
|
+
name: string;
|
|
202
|
+
/**
|
|
203
|
+
* 持续时长
|
|
204
|
+
*/
|
|
205
|
+
duration?: MsValue | ((key: K) => MsValue);
|
|
206
|
+
/**
|
|
207
|
+
* 阈值数量
|
|
208
|
+
*/
|
|
209
|
+
threshold?: number | ((key: K) => number);
|
|
210
|
+
/**
|
|
211
|
+
* 阈值数量超时时间
|
|
212
|
+
*/
|
|
213
|
+
thresholdTimeout?: MsValue | ((key: K) => MsValue);
|
|
214
|
+
/**
|
|
215
|
+
* 处理器
|
|
216
|
+
*/
|
|
217
|
+
handle: (data: T[], key: K) => any;
|
|
218
|
+
};
|
|
219
|
+
interface SliceTaskNoKey<T> {
|
|
220
|
+
add: (data: T, options?: {
|
|
221
|
+
duration?: MsValue;
|
|
222
|
+
threshold?: number;
|
|
223
|
+
thresholdTimeout?: MsValue;
|
|
224
|
+
}) => Promise<void>;
|
|
225
|
+
}
|
|
226
|
+
interface SliceTask<T, K> {
|
|
227
|
+
add: (data: T, options: {
|
|
228
|
+
key: K;
|
|
229
|
+
duration?: MsValue;
|
|
230
|
+
threshold?: number;
|
|
231
|
+
thresholdTimeout?: MsValue;
|
|
232
|
+
delay?: MsValue;
|
|
233
|
+
}) => Promise<void>;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
export declare namespace XCron {
|
|
237
|
+
interface Options {
|
|
238
|
+
/**
|
|
239
|
+
* 定时语法
|
|
240
|
+
*
|
|
241
|
+
* @see https://crontab.guru/
|
|
242
|
+
* @see https://crontab.cronhub.io/
|
|
243
|
+
*/
|
|
244
|
+
expression: string;
|
|
245
|
+
/**
|
|
246
|
+
* 是否初始化后执行一次
|
|
247
|
+
*/
|
|
248
|
+
runOnInit?: boolean;
|
|
249
|
+
/**
|
|
250
|
+
* 处理器
|
|
251
|
+
*/
|
|
252
|
+
handle: () => any;
|
|
253
|
+
}
|
|
254
|
+
interface Cron extends CronJob {}
|
|
255
|
+
}
|
|
256
|
+
export type XFile = MultipartFile;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ctxStorage } from "./core/ctx_storage.mjs";
|
|
2
|
+
import { defineBus } from "./core/define_bus.mjs";
|
|
3
|
+
import { defineCron } from "./core/define_cron.mjs";
|
|
4
|
+
import { defineHandler, defineHandlerANY, defineHandlerFILE, defineHandlerGET, defineHandlerXML } from "./core/define_handler.mjs";
|
|
5
|
+
import { defineHook } from "./core/define_hook.mjs";
|
|
6
|
+
import { defineServer } from "./core/define_server.mjs";
|
|
7
|
+
import { defineSliceTask, defineTask } from "./core/define_task.mjs";
|
|
8
|
+
import { getHandlerUrl } from "./core/get_handler_url.mjs";
|
|
9
|
+
import { Handler, HandlerMethodMap, HandlerPath, HandlerPayloadMap, HandlerResultMap } from "./core/handler.mjs";
|
|
10
|
+
import { HttpError } from "./core/http_error.mjs";
|
|
11
|
+
import { HttpRequestHeader, HttpResponseHeader } from "./core/http_header.mjs";
|
|
12
|
+
import { HandlerMethodToHttpMethod } from "./core/http_method.mjs";
|
|
13
|
+
import { HttpRedirect } from "./core/http_redirect.mjs";
|
|
14
|
+
import { Server } from "./core/server.mjs";
|
|
15
|
+
import { XCron, XFile, XHandler, XServer, XTask } from "./core/types.mjs";
|
|
16
|
+
import { BasePlugin } from "./plugins/base.mjs";
|
|
17
|
+
import { CompressPlugin, CompressPluginOptions } from "./plugins/compress.mjs";
|
|
18
|
+
import { CookiePlugin, CookiePluginOptions } from "./plugins/cookie.mjs";
|
|
19
|
+
import { CorsPlugin, CorsPluginOptions } from "./plugins/cors.mjs";
|
|
20
|
+
import { FileParserPlugin, FileParserPluginOptions, MultipartFile } from "./plugins/file_parser.mjs";
|
|
21
|
+
import { FormBodyParserPlugin, FormBodyParserPluginOptions } from "./plugins/form_body_parser.mjs";
|
|
22
|
+
import { WsParserPlugin, WsParserPluginOptions } from "./plugins/ws_parser.mjs";
|
|
23
|
+
import { XmlParserPlugin, XmlParserPluginOptions } from "./plugins/xml_parser.mjs";
|
|
24
|
+
import { AiService, AiServiceAskPayload, AiServiceAskResult, AiServiceOptions } from "./services/ai.mjs";
|
|
25
|
+
import { BaseService } from "./services/base.mjs";
|
|
26
|
+
import { CacheSerializer, CacheService, CacheServiceOptions } from "./services/cache.mjs";
|
|
27
|
+
import { CaptchaService, CaptchaServiceGenerateCharset, CaptchaServiceGenerateDataUrlResult, CaptchaServiceGenerateImageResult, CaptchaServiceGeneratePayload, CaptchaServiceGenerateResult, CaptchaServiceVerifyOptions } from "./services/captcha.mjs";
|
|
28
|
+
import { CryptoService } from "./services/crypto.mjs";
|
|
29
|
+
import { DbValueService, DbValueServiceJsonObjectOptions, DbValueServiceSimpleArrayOptions } from "./services/db_value.mjs";
|
|
30
|
+
import { DingtalkService, DingtalkServiceOptions, DingtalkServiceSendOptions } from "./services/dingtalk.mjs";
|
|
31
|
+
import { DisposeService, DisposeServiceOptions } from "./services/dispose.mjs";
|
|
32
|
+
import { EmojiService } from "./services/emoji.mjs";
|
|
33
|
+
import { FileStoreService, FileStoreServiceGetUploadUrlPayload, FileStoreServiceGetUploadUrlResult, FileStoreServiceOptions, FileStoreServiceUploadPayload, FileStoreServiceUploadResult } from "./services/file_store.mjs";
|
|
34
|
+
import { HtmlService } from "./services/html.mjs";
|
|
35
|
+
import { JwtService, JwtServiceJwtPayload, JwtServiceOptions } from "./services/jwt.mjs";
|
|
36
|
+
import { LogService, LogServiceDesc, LogServiceLevel, LogServiceLogItem, LogServicePayload, LogServiceWriter } from "./services/log.mjs";
|
|
37
|
+
import { MailService, MailServiceOptions, MailServiceSendOptions } from "./services/mail.mjs";
|
|
38
|
+
import { PayService, PayServiceGetOrderInfoPayload, PayServiceGetOrderInfoResult, PayServiceOptions, PayServicePrepareAlipayOptions, PayServicePrepareAlipayResult, PayServicePrepareWepayOptions, PayServicePrepareWepayResult, PayServiceVerifyNotifyDataResult } from "./services/pay.mjs";
|
|
39
|
+
import { RandomService } from "./services/random.mjs";
|
|
40
|
+
import { RateLimitService, RateLimitServiceLimitByCountOptions, RateLimitServiceLimitByCountOrFailOptions, RateLimitServiceLimitByManyCountOptions, RateLimitServiceLimitByManyCountOrFailOptions } from "./services/rate_limit.mjs";
|
|
41
|
+
import { RedisService, RedisServiceOptions } from "./services/redis.mjs";
|
|
42
|
+
import { SensitiveWordsService, SensitiveWordsServiceOptions } from "./services/sensitive_words.mjs";
|
|
43
|
+
import { SmsService, SmsServiceErrorType, SmsServiceOptions, SmsServiceProvider, SmsServiceSendPayload, SmsServiceSendResult } from "./services/sms.mjs";
|
|
44
|
+
import { MakeDtoExclude, MakeDtoExcludeWithPartial, MakeDtoExcludeWithRequired, MakeDtoExcludeWithRequiredAndPartial, MakeDtoInclude, MakeDtoIncludeWithPartial, MakeDtoIncludeWithRequired, MakeDtoIncludeWithRequiredAndPartial, MakeDtoPartial, MakeDtoPartialByExclude, MakeDtoRequired, MakeDtoRequiredByExclude, MakeDtoWithPagination } from "./types/dto.mjs";
|
|
45
|
+
import { X, x } from "./x.mjs";
|
|
46
|
+
export { AiService, AiServiceAskPayload, AiServiceAskResult, AiServiceOptions, BasePlugin, BaseService, CacheSerializer, CacheService, CacheServiceOptions, CaptchaService, CaptchaServiceGenerateCharset, CaptchaServiceGenerateDataUrlResult, CaptchaServiceGenerateImageResult, CaptchaServiceGeneratePayload, CaptchaServiceGenerateResult, CaptchaServiceVerifyOptions, CompressPlugin, CompressPluginOptions, CookiePlugin, CookiePluginOptions, CorsPlugin, CorsPluginOptions, CryptoService, DbValueService, DbValueServiceJsonObjectOptions, DbValueServiceSimpleArrayOptions, DingtalkService, DingtalkServiceOptions, DingtalkServiceSendOptions, DisposeService, DisposeServiceOptions, EmojiService, FileParserPlugin, FileParserPluginOptions, FileStoreService, FileStoreServiceGetUploadUrlPayload, FileStoreServiceGetUploadUrlResult, FileStoreServiceOptions, FileStoreServiceUploadPayload, FileStoreServiceUploadResult, FormBodyParserPlugin, FormBodyParserPluginOptions, Handler, type HandlerMethodMap, HandlerMethodToHttpMethod, type HandlerPath, type HandlerPayloadMap, type HandlerResultMap, HtmlService, HttpError, HttpRedirect, HttpRequestHeader, HttpResponseHeader, JwtService, JwtServiceJwtPayload, JwtServiceOptions, LogService, LogServiceDesc, LogServiceLevel, LogServiceLogItem, LogServicePayload, LogServiceWriter, MailService, MailServiceOptions, MailServiceSendOptions, MakeDtoExclude, MakeDtoExcludeWithPartial, MakeDtoExcludeWithRequired, MakeDtoExcludeWithRequiredAndPartial, MakeDtoInclude, MakeDtoIncludeWithPartial, MakeDtoIncludeWithRequired, MakeDtoIncludeWithRequiredAndPartial, MakeDtoPartial, MakeDtoPartialByExclude, MakeDtoRequired, MakeDtoRequiredByExclude, MakeDtoWithPagination, type MultipartFile, PayService, PayServiceGetOrderInfoPayload, PayServiceGetOrderInfoResult, PayServiceOptions, PayServicePrepareAlipayOptions, PayServicePrepareAlipayResult, PayServicePrepareWepayOptions, PayServicePrepareWepayResult, PayServiceVerifyNotifyDataResult, RandomService, RateLimitService, RateLimitServiceLimitByCountOptions, RateLimitServiceLimitByCountOrFailOptions, RateLimitServiceLimitByManyCountOptions, RateLimitServiceLimitByManyCountOrFailOptions, RedisService, RedisServiceOptions, SensitiveWordsService, SensitiveWordsServiceOptions, Server, SmsService, SmsServiceErrorType, SmsServiceOptions, SmsServiceProvider, SmsServiceSendPayload, SmsServiceSendResult, WsParserPlugin, WsParserPluginOptions, X, XCron, XFile, XHandler, XServer, XTask, XmlParserPlugin, XmlParserPluginOptions, ctxStorage, defineBus, defineCron, defineHandler, defineHandlerANY, defineHandlerFILE, defineHandlerGET, defineHandlerXML, defineHook, defineServer, defineSliceTask, defineTask, getHandlerUrl, x };
|
package/lib/exports.mjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ctxStorage } from "./core/ctx_storage.mjs";
|
|
2
|
+
import { defineBus } from "./core/define_bus.mjs";
|
|
3
|
+
import { defineCron } from "./core/define_cron.mjs";
|
|
4
|
+
import { defineHandler, defineHandlerANY, defineHandlerFILE, defineHandlerGET, defineHandlerXML } from "./core/define_handler.mjs";
|
|
5
|
+
import { defineHook } from "./core/define_hook.mjs";
|
|
6
|
+
import { defineServer } from "./core/define_server.mjs";
|
|
7
|
+
import { defineSliceTask, defineTask } from "./core/define_task.mjs";
|
|
8
|
+
import { getHandlerUrl } from "./core/get_handler_url.mjs";
|
|
9
|
+
import { Handler } from "./core/handler.mjs";
|
|
10
|
+
import { HttpError } from "./core/http_error.mjs";
|
|
11
|
+
import { HttpRequestHeader, HttpResponseHeader } from "./core/http_header.mjs";
|
|
12
|
+
import { HandlerMethodToHttpMethod } from "./core/http_method.mjs";
|
|
13
|
+
import { HttpRedirect } from "./core/http_redirect.mjs";
|
|
14
|
+
import { Server } from "./core/server.mjs";
|
|
15
|
+
import "./core/types.mjs";
|
|
16
|
+
import "./plugins/base.mjs";
|
|
17
|
+
import { CompressPlugin } from "./plugins/compress.mjs";
|
|
18
|
+
import { CookiePlugin } from "./plugins/cookie.mjs";
|
|
19
|
+
import { CorsPlugin } from "./plugins/cors.mjs";
|
|
20
|
+
import { FileParserPlugin } from "./plugins/file_parser.mjs";
|
|
21
|
+
import { FormBodyParserPlugin } from "./plugins/form_body_parser.mjs";
|
|
22
|
+
import { WsParserPlugin } from "./plugins/ws_parser.mjs";
|
|
23
|
+
import { XmlParserPlugin } from "./plugins/xml_parser.mjs";
|
|
24
|
+
import { AiService } from "./services/ai.mjs";
|
|
25
|
+
import "./services/base.mjs";
|
|
26
|
+
import { CacheService } from "./services/cache.mjs";
|
|
27
|
+
import { CaptchaService } from "./services/captcha.mjs";
|
|
28
|
+
import { CryptoService } from "./services/crypto.mjs";
|
|
29
|
+
import { DbValueService } from "./services/db_value.mjs";
|
|
30
|
+
import { DingtalkService } from "./services/dingtalk.mjs";
|
|
31
|
+
import { DisposeService } from "./services/dispose.mjs";
|
|
32
|
+
import { EmojiService } from "./services/emoji.mjs";
|
|
33
|
+
import { FileStoreService } from "./services/file_store.mjs";
|
|
34
|
+
import { HtmlService } from "./services/html.mjs";
|
|
35
|
+
import { JwtService } from "./services/jwt.mjs";
|
|
36
|
+
import { LogService } from "./services/log.mjs";
|
|
37
|
+
import { MailService } from "./services/mail.mjs";
|
|
38
|
+
import { PayService } from "./services/pay.mjs";
|
|
39
|
+
import { RandomService } from "./services/random.mjs";
|
|
40
|
+
import { RateLimitService } from "./services/rate_limit.mjs";
|
|
41
|
+
import { RedisService } from "./services/redis.mjs";
|
|
42
|
+
import { SensitiveWordsService } from "./services/sensitive_words.mjs";
|
|
43
|
+
import { SmsService } from "./services/sms.mjs";
|
|
44
|
+
import "./types/dto.mjs";
|
|
45
|
+
import { x } from "./x.mjs";
|
|
46
|
+
export { AiService, CacheService, CaptchaService, CompressPlugin, CookiePlugin, CorsPlugin, CryptoService, DbValueService, DingtalkService, DisposeService, EmojiService, FileParserPlugin, FileStoreService, FormBodyParserPlugin, Handler, HandlerMethodToHttpMethod, HtmlService, HttpError, HttpRedirect, HttpRequestHeader, HttpResponseHeader, JwtService, LogService, MailService, PayService, RandomService, RateLimitService, RedisService, SensitiveWordsService, Server, SmsService, WsParserPlugin, XmlParserPlugin, ctxStorage, defineBus, defineCron, defineHandler, defineHandlerANY, defineHandlerFILE, defineHandlerGET, defineHandlerXML, defineHook, defineServer, defineSliceTask, defineTask, getHandlerUrl, x };
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BasePlugin } from "./plugins/base.mjs";
|
|
2
|
+
import { BaseService } from "./services/base.mjs";
|
|
3
|
+
import { DisposeService, DisposeServiceOptions } from "./services/dispose.mjs";
|
|
4
|
+
import { Handler, HandlerMethodMap, HandlerPath, HandlerPayloadMap, HandlerResultMap } from "./core/handler.mjs";
|
|
5
|
+
import { XCron, XFile, XHandler, XServer, XTask } from "./core/types.mjs";
|
|
6
|
+
import { ctxStorage } from "./core/ctx_storage.mjs";
|
|
7
|
+
import { defineBus } from "./core/define_bus.mjs";
|
|
8
|
+
import { defineCron } from "./core/define_cron.mjs";
|
|
9
|
+
import { defineHandler, defineHandlerANY, defineHandlerFILE, defineHandlerGET, defineHandlerXML } from "./core/define_handler.mjs";
|
|
10
|
+
import { defineHook } from "./core/define_hook.mjs";
|
|
11
|
+
import { Server } from "./core/server.mjs";
|
|
12
|
+
import { defineServer } from "./core/define_server.mjs";
|
|
13
|
+
import { defineSliceTask, defineTask } from "./core/define_task.mjs";
|
|
14
|
+
import { getHandlerUrl } from "./core/get_handler_url.mjs";
|
|
15
|
+
import { HttpError } from "./core/http_error.mjs";
|
|
16
|
+
import { HttpRequestHeader, HttpResponseHeader } from "./core/http_header.mjs";
|
|
17
|
+
import { HandlerMethodToHttpMethod } from "./core/http_method.mjs";
|
|
18
|
+
import { HttpRedirect } from "./core/http_redirect.mjs";
|
|
19
|
+
import { CompressPlugin, CompressPluginOptions } from "./plugins/compress.mjs";
|
|
20
|
+
import { CookiePlugin, CookiePluginOptions } from "./plugins/cookie.mjs";
|
|
21
|
+
import { CorsPlugin, CorsPluginOptions } from "./plugins/cors.mjs";
|
|
22
|
+
import { FileParserPlugin, FileParserPluginOptions, MultipartFile } from "./plugins/file_parser.mjs";
|
|
23
|
+
import { FormBodyParserPlugin, FormBodyParserPluginOptions } from "./plugins/form_body_parser.mjs";
|
|
24
|
+
import { WsParserPlugin, WsParserPluginOptions } from "./plugins/ws_parser.mjs";
|
|
25
|
+
import { XmlParserPlugin, XmlParserPluginOptions } from "./plugins/xml_parser.mjs";
|
|
26
|
+
import { AiService, AiServiceAskPayload, AiServiceAskResult, AiServiceOptions } from "./services/ai.mjs";
|
|
27
|
+
import { CacheSerializer, CacheService, CacheServiceOptions } from "./services/cache.mjs";
|
|
28
|
+
import { CaptchaService, CaptchaServiceGenerateCharset, CaptchaServiceGenerateDataUrlResult, CaptchaServiceGenerateImageResult, CaptchaServiceGeneratePayload, CaptchaServiceGenerateResult, CaptchaServiceVerifyOptions } from "./services/captcha.mjs";
|
|
29
|
+
import { CryptoService } from "./services/crypto.mjs";
|
|
30
|
+
import { DbValueService, DbValueServiceJsonObjectOptions, DbValueServiceSimpleArrayOptions } from "./services/db_value.mjs";
|
|
31
|
+
import { DingtalkService, DingtalkServiceOptions, DingtalkServiceSendOptions } from "./services/dingtalk.mjs";
|
|
32
|
+
import { EmojiService } from "./services/emoji.mjs";
|
|
33
|
+
import { FileStoreService, FileStoreServiceGetUploadUrlPayload, FileStoreServiceGetUploadUrlResult, FileStoreServiceOptions, FileStoreServiceUploadPayload, FileStoreServiceUploadResult } from "./services/file_store.mjs";
|
|
34
|
+
import { HtmlService } from "./services/html.mjs";
|
|
35
|
+
import { JwtService, JwtServiceJwtPayload, JwtServiceOptions } from "./services/jwt.mjs";
|
|
36
|
+
import { LogService, LogServiceDesc, LogServiceLevel, LogServiceLogItem, LogServicePayload, LogServiceWriter } from "./services/log.mjs";
|
|
37
|
+
import { MailService, MailServiceOptions, MailServiceSendOptions } from "./services/mail.mjs";
|
|
38
|
+
import { PayService, PayServiceGetOrderInfoPayload, PayServiceGetOrderInfoResult, PayServiceOptions, PayServicePrepareAlipayOptions, PayServicePrepareAlipayResult, PayServicePrepareWepayOptions, PayServicePrepareWepayResult, PayServiceVerifyNotifyDataResult } from "./services/pay.mjs";
|
|
39
|
+
import { RandomService } from "./services/random.mjs";
|
|
40
|
+
import { RateLimitService, RateLimitServiceLimitByCountOptions, RateLimitServiceLimitByCountOrFailOptions, RateLimitServiceLimitByManyCountOptions, RateLimitServiceLimitByManyCountOrFailOptions } from "./services/rate_limit.mjs";
|
|
41
|
+
import { RedisService, RedisServiceOptions } from "./services/redis.mjs";
|
|
42
|
+
import { SensitiveWordsService, SensitiveWordsServiceOptions } from "./services/sensitive_words.mjs";
|
|
43
|
+
import { SmsService, SmsServiceErrorType, SmsServiceOptions, SmsServiceProvider, SmsServiceSendPayload, SmsServiceSendResult } from "./services/sms.mjs";
|
|
44
|
+
import { MakeDtoExclude, MakeDtoExcludeWithPartial, MakeDtoExcludeWithRequired, MakeDtoExcludeWithRequiredAndPartial, MakeDtoInclude, MakeDtoIncludeWithPartial, MakeDtoIncludeWithRequired, MakeDtoIncludeWithRequiredAndPartial, MakeDtoPartial, MakeDtoPartialByExclude, MakeDtoRequired, MakeDtoRequiredByExclude, MakeDtoWithPagination } from "./types/dto.mjs";
|
|
45
|
+
import { X, x } from "./x.mjs";
|
|
46
|
+
import "./exports.mjs";
|
|
47
|
+
export * from "@a/x/models";
|
|
48
|
+
export { AiService, AiServiceAskPayload, AiServiceAskResult, AiServiceOptions, BasePlugin, BaseService, CacheSerializer, CacheService, CacheServiceOptions, CaptchaService, CaptchaServiceGenerateCharset, CaptchaServiceGenerateDataUrlResult, CaptchaServiceGenerateImageResult, CaptchaServiceGeneratePayload, CaptchaServiceGenerateResult, CaptchaServiceVerifyOptions, CompressPlugin, CompressPluginOptions, CookiePlugin, CookiePluginOptions, CorsPlugin, CorsPluginOptions, CryptoService, DbValueService, DbValueServiceJsonObjectOptions, DbValueServiceSimpleArrayOptions, DingtalkService, DingtalkServiceOptions, DingtalkServiceSendOptions, DisposeService, DisposeServiceOptions, EmojiService, FileParserPlugin, FileParserPluginOptions, FileStoreService, FileStoreServiceGetUploadUrlPayload, FileStoreServiceGetUploadUrlResult, FileStoreServiceOptions, FileStoreServiceUploadPayload, FileStoreServiceUploadResult, FormBodyParserPlugin, FormBodyParserPluginOptions, Handler, type HandlerMethodMap, HandlerMethodToHttpMethod, type HandlerPath, type HandlerPayloadMap, type HandlerResultMap, HtmlService, HttpError, HttpRedirect, HttpRequestHeader, HttpResponseHeader, JwtService, JwtServiceJwtPayload, JwtServiceOptions, LogService, LogServiceDesc, LogServiceLevel, LogServiceLogItem, LogServicePayload, LogServiceWriter, MailService, MailServiceOptions, MailServiceSendOptions, MakeDtoExclude, MakeDtoExcludeWithPartial, MakeDtoExcludeWithRequired, MakeDtoExcludeWithRequiredAndPartial, MakeDtoInclude, MakeDtoIncludeWithPartial, MakeDtoIncludeWithRequired, MakeDtoIncludeWithRequiredAndPartial, MakeDtoPartial, MakeDtoPartialByExclude, MakeDtoRequired, MakeDtoRequiredByExclude, MakeDtoWithPagination, type MultipartFile, PayService, PayServiceGetOrderInfoPayload, PayServiceGetOrderInfoResult, PayServiceOptions, PayServicePrepareAlipayOptions, PayServicePrepareAlipayResult, PayServicePrepareWepayOptions, PayServicePrepareWepayResult, PayServiceVerifyNotifyDataResult, RandomService, RateLimitService, RateLimitServiceLimitByCountOptions, RateLimitServiceLimitByCountOrFailOptions, RateLimitServiceLimitByManyCountOptions, RateLimitServiceLimitByManyCountOrFailOptions, RedisService, RedisServiceOptions, SensitiveWordsService, SensitiveWordsServiceOptions, Server, SmsService, SmsServiceErrorType, SmsServiceOptions, SmsServiceProvider, SmsServiceSendPayload, SmsServiceSendResult, WsParserPlugin, WsParserPluginOptions, X, XCron, XFile, XHandler, XServer, XTask, XmlParserPlugin, XmlParserPluginOptions, ctxStorage, defineBus, defineCron, defineHandler, defineHandlerANY, defineHandlerFILE, defineHandlerGET, defineHandlerXML, defineHook, defineServer, defineSliceTask, defineTask, getHandlerUrl, x };
|