@jayfong/x-server 2.119.0 → 3.1.1
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 +75 -0
- package/lib/cli/api_generator.mjs +334 -0
- package/lib/cli/build_util.d.mts +15 -0
- package/lib/cli/build_util.mjs +101 -0
- package/lib/cli/cli.d.mts +1 -0
- package/lib/cli/cli.mjs +345 -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 +9 -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/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 -2
- 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 +106 -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 +82 -32
- 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,207 @@
|
|
|
1
|
+
import { asyncLimit, castArray, dedent, difference, escapeRegExp, get, isPlainObject, uniq } from "vtils";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import { globby } from "globby";
|
|
5
|
+
import { pinyin } from "pinyin-pro";
|
|
6
|
+
import { parse } from "yaml";
|
|
7
|
+
// src/cli/env_util.ts
|
|
8
|
+
var EnvUtil = class EnvUtil {
|
|
9
|
+
static NEWLINE = "\n";
|
|
10
|
+
static RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*(.*)?\s*$/;
|
|
11
|
+
static RE_NEWLINES = /\\n/g;
|
|
12
|
+
static NEWLINES_MATCH = /\r\n|\n|\r/;
|
|
13
|
+
static COMMENT_MATCH = /^#\s*(.+?)\s*$/;
|
|
14
|
+
static async getAllChannel(cwd, excludeChannels) {
|
|
15
|
+
const channelFiles = await globby([".env@*"], {
|
|
16
|
+
cwd,
|
|
17
|
+
onlyFiles: true,
|
|
18
|
+
absolute: false
|
|
19
|
+
});
|
|
20
|
+
if (channelFiles.length === 0) return [];
|
|
21
|
+
let channels = uniq(channelFiles.map((channel) => channel.split("@").pop().split(".")[0]));
|
|
22
|
+
if (excludeChannels?.length) channels = difference(channels, excludeChannels);
|
|
23
|
+
return channels;
|
|
24
|
+
}
|
|
25
|
+
static async chooseChannel(cwd, excludeChannels) {
|
|
26
|
+
const channels = await EnvUtil.getAllChannel(cwd, excludeChannels);
|
|
27
|
+
if (channels.length === 0) return void 0;
|
|
28
|
+
if (channels.length === 1) return channels[0];
|
|
29
|
+
const channelOptions = channels.sort((a, b) => a.localeCompare(b, "zh-CN")).map((channel) => {
|
|
30
|
+
const channelPinyin = pinyin(channel, {
|
|
31
|
+
type: "string",
|
|
32
|
+
pattern: "first",
|
|
33
|
+
toneType: "none",
|
|
34
|
+
separator: "",
|
|
35
|
+
removeNonZh: false,
|
|
36
|
+
nonZh: "consecutive"
|
|
37
|
+
}).toLowerCase();
|
|
38
|
+
return {
|
|
39
|
+
name: channel,
|
|
40
|
+
value: channel,
|
|
41
|
+
pinyin: channelPinyin,
|
|
42
|
+
description: `${channel}<${channelPinyin}>`
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
const { default: autocomplete } = await import("inquirer-autocomplete-standalone");
|
|
46
|
+
return await autocomplete({
|
|
47
|
+
message: "请选择渠道",
|
|
48
|
+
source: async (input) => {
|
|
49
|
+
return !input ? channelOptions : channelOptions.filter((channelOption) => {
|
|
50
|
+
return channelOption.pinyin.includes(input) || channelOption.name.includes(input);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}) || void 0;
|
|
54
|
+
}
|
|
55
|
+
static async withChannel(options) {
|
|
56
|
+
const successChannels = [];
|
|
57
|
+
const failedChannels = [];
|
|
58
|
+
if (options.channel?.startsWith("_")) {
|
|
59
|
+
const excludeChannels = options.channel.split("!")[1]?.split(",").filter(Boolean);
|
|
60
|
+
const channel = process.env.APP_CHANNEL || await EnvUtil.chooseChannel(options.cwd, excludeChannels);
|
|
61
|
+
console.log(`========= ${channel} =========`);
|
|
62
|
+
try {
|
|
63
|
+
await options.cb(channel);
|
|
64
|
+
successChannels.push(channel);
|
|
65
|
+
} catch (err) {
|
|
66
|
+
console.error(err);
|
|
67
|
+
failedChannels.push(channel);
|
|
68
|
+
}
|
|
69
|
+
} else if (options.channel?.startsWith("@")) {
|
|
70
|
+
const excludeChannels = options.channel.split("!")[1]?.split(",").filter(Boolean);
|
|
71
|
+
const channels = await EnvUtil.getAllChannel(options.cwd, excludeChannels);
|
|
72
|
+
await Promise.all(channels.map(asyncLimit(async (channel) => {
|
|
73
|
+
console.log(`========= ${channel} =========`);
|
|
74
|
+
try {
|
|
75
|
+
await options.cb(channel);
|
|
76
|
+
successChannels.push(channel);
|
|
77
|
+
} catch (err) {
|
|
78
|
+
console.error(err);
|
|
79
|
+
failedChannels.push(channel);
|
|
80
|
+
}
|
|
81
|
+
}, { concurrency: options.concurrency || 1 })));
|
|
82
|
+
} else {
|
|
83
|
+
if (options.channel) console.log(`========= ${options.channel} =========`);
|
|
84
|
+
try {
|
|
85
|
+
await options.cb(options.channel);
|
|
86
|
+
options.channel && successChannels.push(options.channel);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
console.error(err);
|
|
89
|
+
options.channel && failedChannels.push(options.channel);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (successChannels.length) console.log(`✅(${successChannels.length}):${JSON.stringify(successChannels)}`);
|
|
93
|
+
if (failedChannels.length) console.log(`❌(${failedChannels.length}):${JSON.stringify(failedChannels)}`);
|
|
94
|
+
}
|
|
95
|
+
static getFile(env, channel, noBase) {
|
|
96
|
+
const file = [".env_meta", ...noBase ? [] : [".env"]];
|
|
97
|
+
if (!noBase && channel) file.push(`.env@${channel}`);
|
|
98
|
+
if (env) {
|
|
99
|
+
file.push(`.env.${env}`);
|
|
100
|
+
if (channel) file.push(`.env@${channel}.${env}`);
|
|
101
|
+
}
|
|
102
|
+
return file;
|
|
103
|
+
}
|
|
104
|
+
static parseContent(src, _envItemMap, _envValueMap, channel) {
|
|
105
|
+
const envs = [];
|
|
106
|
+
const envObj = parse(src);
|
|
107
|
+
if (channel) {
|
|
108
|
+
const channelEnvs = envObj.__CHANNEL__;
|
|
109
|
+
if (channelEnvs && Array.isArray(channelEnvs)) {
|
|
110
|
+
for (const channelEnv of channelEnvs) if (castArray(channelEnv._).flatMap((item) => item.split(",")).includes(channel)) {
|
|
111
|
+
delete channelEnv._;
|
|
112
|
+
Object.assign(envObj, channelEnv);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
delete envObj.__CHANNEL__;
|
|
118
|
+
const inlineVars = (value) => {
|
|
119
|
+
if (Array.isArray(value)) return value.map(inlineVars);
|
|
120
|
+
if (isPlainObject(value)) return Object.keys(value).reduce((acc, key) => {
|
|
121
|
+
acc[key] = inlineVars(value[key]);
|
|
122
|
+
return acc;
|
|
123
|
+
}, {});
|
|
124
|
+
if (typeof value === "string") return value.replace(/\{\{\s*(.+?)\s*\}\}/g, (_, key) => get(_envValueMap || envObj, key) || process.env[key] || "");
|
|
125
|
+
return value;
|
|
126
|
+
};
|
|
127
|
+
Object.keys(envObj).forEach((key) => {
|
|
128
|
+
const value = inlineVars(envObj[key]);
|
|
129
|
+
const envItem = {
|
|
130
|
+
key,
|
|
131
|
+
value,
|
|
132
|
+
comment: src.match(new RegExp(`((#\\s*(.+?)\\s*[\\r\\n]+)+)\\s*${escapeRegExp(key)}:`))?.[1].split(/(\r\n){2,}|\r{2,}|\n{2,}/g).pop()?.replace(/^#/gm, "").trim() || ""
|
|
133
|
+
};
|
|
134
|
+
if (_envItemMap) _envItemMap[key] = envItem;
|
|
135
|
+
if (_envValueMap) _envValueMap[key] = value;
|
|
136
|
+
envs.push(envItem);
|
|
137
|
+
});
|
|
138
|
+
return envs;
|
|
139
|
+
}
|
|
140
|
+
static async parseFile(options) {
|
|
141
|
+
const envItemMap = {};
|
|
142
|
+
const envValueMap = { APP_CHANNEL: options.channel };
|
|
143
|
+
for (const file of options.file) {
|
|
144
|
+
const isEnvMeta = file === ".env_meta";
|
|
145
|
+
const envYmlFile = path.join(options.cwd, `${file}.yml`);
|
|
146
|
+
const envYamlFile = path.join(options.cwd, `${file}.yaml`);
|
|
147
|
+
const envFile = await fs.pathExists(envYmlFile) ? envYmlFile : await fs.pathExists(envYamlFile) ? envYamlFile : "";
|
|
148
|
+
if (envFile) {
|
|
149
|
+
const envContent = await fs.readFile(envFile, "utf-8");
|
|
150
|
+
EnvUtil.parseContent(envContent, isEnvMeta ? void 0 : envItemMap, envValueMap, options.channel);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return Object.values(envItemMap);
|
|
154
|
+
}
|
|
155
|
+
static async parseFileAsMap(options) {
|
|
156
|
+
const envsObj = { APP_CHANNEL: options.channel };
|
|
157
|
+
const envs = await EnvUtil.parseFile(options);
|
|
158
|
+
for (const env of envs) envsObj[env.key] = env.value;
|
|
159
|
+
return envsObj;
|
|
160
|
+
}
|
|
161
|
+
static async importFile(options) {
|
|
162
|
+
const envsObj = { APP_CHANNEL: options.channel };
|
|
163
|
+
const envs = await EnvUtil.parseFile(options);
|
|
164
|
+
for (const env of envs) {
|
|
165
|
+
envsObj[env.key] = env.value;
|
|
166
|
+
process.env[env.key] = env.value;
|
|
167
|
+
}
|
|
168
|
+
process.env.X_SERVER_ENVS = JSON.stringify({
|
|
169
|
+
...JSON.parse(process.env.X_SERVER_ENVS || "{}"),
|
|
170
|
+
...envsObj
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
static makeTypes(envs) {
|
|
174
|
+
return dedent`
|
|
175
|
+
declare namespace NodeJS {
|
|
176
|
+
interface ProcessEnv {
|
|
177
|
+
/**
|
|
178
|
+
* 当前环境
|
|
179
|
+
*/
|
|
180
|
+
NODE_ENV: 'development' | 'production';
|
|
181
|
+
/**
|
|
182
|
+
* 当前渠道
|
|
183
|
+
*/
|
|
184
|
+
APP_CHANNEL: string;
|
|
185
|
+
${envs.map((env) => dedent`
|
|
186
|
+
${env.comment ? dedent`
|
|
187
|
+
/**
|
|
188
|
+
${env.comment.split(/[\r\n]+/g).map((line) => `* ${line.trim()}`).join("\n*\n")}
|
|
189
|
+
*/
|
|
190
|
+
` : ""}
|
|
191
|
+
${env.key}: ${EnvUtil.getTypesFromValue(env.value)};
|
|
192
|
+
`).join("\n")}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
`;
|
|
196
|
+
}
|
|
197
|
+
static async outputTypes(options) {
|
|
198
|
+
const envs = await EnvUtil.parseFile(options);
|
|
199
|
+
const outFile = path.join(options.cwd, options.outFile);
|
|
200
|
+
const types = EnvUtil.makeTypes(envs);
|
|
201
|
+
await fs.outputFile(outFile, types);
|
|
202
|
+
}
|
|
203
|
+
static getTypesFromValue(value) {
|
|
204
|
+
return Array.isArray(value) ? `Array<${value[0] ? EnvUtil.getTypesFromValue(value[0]) : "any"}>` : isPlainObject(value) ? Object.keys(value).length ? `{${Object.keys(value).map((key) => `'${key}':${EnvUtil.getTypesFromValue(value[key])}`).join(",")}}` : `Record<any, any>` : typeof value;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
export { EnvUtil };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class TemplateUtil {
|
|
2
|
+
/**
|
|
3
|
+
* 初始化。
|
|
4
|
+
*/
|
|
5
|
+
static init(cwd: string): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* 初始化辅助包。
|
|
8
|
+
*/
|
|
9
|
+
static initHelperPackage(cwd: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* 初始化任务。
|
|
12
|
+
*/
|
|
13
|
+
static initTasks(cwd: string): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* 初始化模型。
|
|
16
|
+
*/
|
|
17
|
+
static initModels(cwd: string): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { camelCase, dedent, snakeCase, upperFirst } from "vtils";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import { generateManyIndex } from "vscode-generate-index-standalone";
|
|
5
|
+
import { globby } from "globby";
|
|
6
|
+
// src/cli/template_util.ts
|
|
7
|
+
var TemplateUtil = class {
|
|
8
|
+
/**
|
|
9
|
+
* 初始化。
|
|
10
|
+
*/
|
|
11
|
+
static async init(cwd) {
|
|
12
|
+
await Promise.all([this.initHelperPackage(cwd), this.initTasks(cwd)]);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 初始化辅助包。
|
|
16
|
+
*/
|
|
17
|
+
static async initHelperPackage(cwd) {
|
|
18
|
+
const fromDir = path.join(import.meta.dirname, "templates");
|
|
19
|
+
const toDir = path.join(cwd, "node_modules/@a/x");
|
|
20
|
+
const hasDb = await fs.pathExists(path.join(cwd, "src/db/schema.prisma"));
|
|
21
|
+
const fromFiles = await globby("*", {
|
|
22
|
+
cwd: fromDir,
|
|
23
|
+
onlyFiles: true,
|
|
24
|
+
absolute: true
|
|
25
|
+
});
|
|
26
|
+
await fs.ensureDir(toDir);
|
|
27
|
+
await Promise.all(fromFiles.map(async (fromFile) => {
|
|
28
|
+
const toFile = fromFile.replace(fromDir, toDir);
|
|
29
|
+
if (fromFile.endsWith("models.ts") && !hasDb) await fs.writeFile(toFile, "export {}");
|
|
30
|
+
else {
|
|
31
|
+
let fromFileContent = await fs.readFile(fromFile, "utf-8");
|
|
32
|
+
fromFileContent = fromFileContent.replaceAll("../../src", path.relative(toDir, `${cwd}/src`));
|
|
33
|
+
await fs.writeFile(toFile, fromFileContent);
|
|
34
|
+
}
|
|
35
|
+
}));
|
|
36
|
+
await generateManyIndex({
|
|
37
|
+
cwd,
|
|
38
|
+
patterns: ["node_modules/@a/x/*.ts"],
|
|
39
|
+
replaceFile: true
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 初始化任务。
|
|
44
|
+
*/
|
|
45
|
+
static async initTasks(cwd) {
|
|
46
|
+
const tasksDir = path.join(cwd, "src/tasks");
|
|
47
|
+
const tasksIndexFile = path.join(tasksDir, "index.ts");
|
|
48
|
+
if (!await fs.pathExists(tasksIndexFile)) await fs.outputFile(tasksIndexFile, dedent`
|
|
49
|
+
// @index(['./**/*.ts', '!**/*.test.ts', '!**/_*'], f => \`export * from '\${f.path}'\`)
|
|
50
|
+
// @endindex
|
|
51
|
+
`);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 初始化模型。
|
|
55
|
+
*/
|
|
56
|
+
static async initModels(cwd) {
|
|
57
|
+
const modelsDir = path.join(cwd, "src/models");
|
|
58
|
+
const indexFile = path.join(modelsDir, "index.ts");
|
|
59
|
+
const indexFile2 = path.join(cwd, "node_modules/@a/x/models.ts");
|
|
60
|
+
const prismaClientFile = path.join(cwd, "node_modules/@a/x/prisma/internal/prismaNamespace.ts");
|
|
61
|
+
const modelNames = [...(await fs.readFile(prismaClientFile, "utf8")).match(/(?<=const ModelName).+?(?=\})/s)[0].matchAll(/(\S+?):/g)].map((match) => camelCase(match[1]));
|
|
62
|
+
await Promise.all(modelNames.map(async (modelName) => {
|
|
63
|
+
const model_name = snakeCase(modelName);
|
|
64
|
+
const ModelName = upperFirst(modelName);
|
|
65
|
+
const modelFile = path.join(modelsDir, `${model_name}.ts`);
|
|
66
|
+
if (!await fs.pathExists(modelFile)) await fs.outputFile(modelFile, dedent`
|
|
67
|
+
import { ${ModelName}BaseModel } from '@jayfong/x-server'
|
|
68
|
+
|
|
69
|
+
export class ${ModelName}Model extends ${ModelName}BaseModel {}
|
|
70
|
+
|
|
71
|
+
export const ${modelName}Model = new ${ModelName}Model()
|
|
72
|
+
`);
|
|
73
|
+
}));
|
|
74
|
+
if (!await fs.pathExists(indexFile)) await fs.outputFile(indexFile, dedent`
|
|
75
|
+
// @index(['./**/*.ts', '!**/*.test.ts', '!**/_*'], f => \`export * from '\${f.path}'\`)
|
|
76
|
+
// @endindex
|
|
77
|
+
`);
|
|
78
|
+
await generateManyIndex({
|
|
79
|
+
cwd,
|
|
80
|
+
patterns: [indexFile, indexFile2],
|
|
81
|
+
replaceFile: true
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
export { TemplateUtil };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// @index(['../../src/crons/**/*.ts', '!**/_*', '!**/_*/**', '!**/*.test.*'], (f, _) => `import '${f.path}'`)
|
|
1
|
+
// @index(['../../src/crons/**/*.ts', '!**/_*', '!**/_*/**', '!**/*.test.*'], (f, _) => `import '${f.path}${f.ext}'`)
|
|
2
2
|
// @endindex
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
// @index(['../../src/handlers/**/*.ts', '!**/_*', '!**/_*/**', '!**/*.test.*'], (f, _) => `export * as __${_.pascal(f.path.replace('/src/handlers/', ''))}__ from '${f.path}'`)
|
|
1
|
+
// @index(['../../src/handlers/**/*.ts', '!**/_*', '!**/_*/**', '!**/*.test.*'], (f, _) => `export * as __${_.pascal(f.path.replace('/src/handlers/', ''))}__ from '${f.path}${f.ext}'`)
|
|
2
2
|
|
|
3
3
|
// @endindex
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// @index(['../../src/hooks/**/*.ts', '!**/_*', '!**/_*/**', '!**/*.test.*'], (f, _) => `import '${f.path}'`)
|
|
1
|
+
// @index(['../../src/hooks/**/*.ts', '!**/_*', '!**/_*/**', '!**/*.test.*'], (f, _) => `import '${f.path}${f.ext}'`)
|
|
2
2
|
// @endindex
|
|
@@ -3,7 +3,7 @@ import { URL } from 'node:url';
|
|
|
3
3
|
import { x } from '@jayfong/x-server';
|
|
4
4
|
import { PrismaMariaDb } from '@prisma/adapter-mariadb';
|
|
5
5
|
import { isNumeric, mapValues } from 'vtils';
|
|
6
|
-
import { type Prisma, PrismaClient } from './prisma/client';
|
|
6
|
+
import { type Prisma, PrismaClient } from './prisma/client.ts';
|
|
7
7
|
|
|
8
8
|
const dbUri = new URL(process.env.DATABASE_URL!);
|
|
9
9
|
const adapter = new PrismaMariaDb({
|
|
@@ -76,12 +76,12 @@ function _makeBaseModel<TModelName extends ModelName>(name: TModelName) {
|
|
|
76
76
|
|
|
77
77
|
public getModel = <T extends ModelName>(
|
|
78
78
|
name: T,
|
|
79
|
-
): typeof import('../../src/models')[`${T}Model`] => {
|
|
79
|
+
): typeof import('../../src/models/index.ts')[`${T}Model`] => {
|
|
80
80
|
return this.transactionClient
|
|
81
|
-
? require('../../src/models')[`${name}Model`].transactionify(
|
|
81
|
+
? require('../../src/models/index.ts')[`${name}Model`].transactionify(
|
|
82
82
|
this.transactionClient,
|
|
83
83
|
)
|
|
84
|
-
: require('../../src/models')[`${name}Model`];
|
|
84
|
+
: require('../../src/models/index.ts')[`${name}Model`];
|
|
85
85
|
};
|
|
86
86
|
};
|
|
87
87
|
}
|
|
@@ -89,7 +89,7 @@ function _makeBaseModel<TModelName extends ModelName>(name: TModelName) {
|
|
|
89
89
|
// @index('./prisma/internal/prismaNamespace.ts', /(?<=const ModelName).+?(?=\})/s, /(\S+?):/g, (m, _) => `export const ${m[1]}BaseModel = _makeBaseModel('${_.camel(m[1])}')`)
|
|
90
90
|
// @endindex
|
|
91
91
|
|
|
92
|
-
export * from './prisma/client';
|
|
92
|
+
export * from './prisma/client.ts';
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
95
|
* @deprecated 使用 runInTransaction 代替
|
|
@@ -97,12 +97,12 @@ export * from './prisma/client';
|
|
|
97
97
|
export const startTransaction = <T>(
|
|
98
98
|
cb: (
|
|
99
99
|
models: {
|
|
100
|
-
[K in ModelName]: typeof import('../../src/models')[`${K}Model`];
|
|
100
|
+
[K in ModelName]: typeof import('../../src/models/index.ts')[`${K}Model`];
|
|
101
101
|
},
|
|
102
102
|
) => Promise<T>,
|
|
103
103
|
): Promise<T> => {
|
|
104
104
|
return prismaClient.$transaction(async _tx => {
|
|
105
|
-
const _models = require('../../src/models');
|
|
105
|
+
const _models = require('../../src/models/index.ts');
|
|
106
106
|
const _cache = Object.create(null);
|
|
107
107
|
return cb({
|
|
108
108
|
// @index('./prisma/internal/prismaNamespace.ts', /(?<=const ModelName).+?(?=\})/s, /(\S+?):/g, (m, _) => `get ${_.camel(m[1])}() { return _cache.${_.camel(m[1])} || (_cache.${_.camel(m[1])} = _models.${_.camel(m[1])}Model.transactionify(_tx)) }, `)
|
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
2
|
+
"name": "@a/x",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./crons": "./crons.ts",
|
|
7
|
+
"./handlers": "./handlers.ts",
|
|
8
|
+
"./hooks": "./hooks.ts",
|
|
9
|
+
"./models": "./models.ts",
|
|
10
|
+
"./routes": "./routes.ts",
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
}
|
|
3
13
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Handler, XServer } from '@jayfong/x-server';
|
|
2
|
-
import * as handlers from './handlers';
|
|
2
|
+
import * as handlers from './handlers.ts';
|
|
3
3
|
|
|
4
4
|
const basePathWithHandlers: Array<[string, Record<string, Handler>]> = [
|
|
5
5
|
// @index(['../../src/handlers/**/*.ts', '!**/_*', '!**/_*/**', '!**/*.test.*'], (f, _) => `['${(f.path+'/').replace(/@dev/g, '').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}', handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__ as any],`)
|
|
@@ -52,7 +52,7 @@ export const routes: XServer.Route[] = basePathWithHandlers.reduce<
|
|
|
52
52
|
XServer.Route[]
|
|
53
53
|
>((res, item) => {
|
|
54
54
|
const validHandlerNames = Object.keys(item[1]).filter(
|
|
55
|
-
name => !name.startsWith('_') && name !== 'default',
|
|
55
|
+
name => !name.startsWith('_') && name !== 'default' && name !== 'module.exports',
|
|
56
56
|
);
|
|
57
57
|
for (const handlerName of validHandlerNames) {
|
|
58
58
|
const path = item[1][handlerName].options.requestPath || handlerName;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
declare class EventBus extends EventEmitter {
|
|
3
|
+
onReturnOff(event: string, listener: (...args: any[]) => any): () => any;
|
|
4
|
+
}
|
|
5
|
+
export declare function defineBus<T extends Record<string, any>>(): StrictEventEmitter<EventBus, T, T, "addEventListener" | "removeEventListener", "on" | "addListener" | "removeListener" | "once" | "emit" | "off" | "onReturnOff">;
|
|
6
|
+
declare const assignmentCompatibilityHack: unique symbol;
|
|
7
|
+
interface TypeRecord<T, U, V> {
|
|
8
|
+
' _emitterType'?: T;
|
|
9
|
+
' _eventsType'?: U;
|
|
10
|
+
' _emitType'?: V;
|
|
11
|
+
}
|
|
12
|
+
type InnerEEMethodReturnType<T, TValue, FValue> = T extends ((...args: any[]) => any) ? ReturnType<T> extends void | undefined ? FValue : TValue : FValue;
|
|
13
|
+
type EEMethodReturnType<T, S extends string, TValue, FValue = void> = S extends keyof T ? InnerEEMethodReturnType<T[S], TValue, FValue> : FValue;
|
|
14
|
+
type ListenerType<T> = [T] extends [(...args: infer U) => any] ? U : [T] extends [void] ? [] : [T];
|
|
15
|
+
type OverriddenMethods<TEmitter, TEventRecord, TEmitRecord = TEventRecord> = {
|
|
16
|
+
on<P extends keyof TEventRecord, T>(this: T, event: P, listener: (...args: ListenerType<TEventRecord[P]>) => void): EEMethodReturnType<TEmitter, 'on', T>;
|
|
17
|
+
on(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;
|
|
18
|
+
addListener<P extends keyof TEventRecord, T>(this: T, event: P, listener: (...args: ListenerType<TEventRecord[P]>) => void): EEMethodReturnType<TEmitter, 'addListener', T>;
|
|
19
|
+
addListener(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;
|
|
20
|
+
addEventListener<P extends keyof TEventRecord, T>(this: T, event: P, listener: (...args: ListenerType<TEventRecord[P]>) => void): EEMethodReturnType<TEmitter, 'addEventListener', T>;
|
|
21
|
+
addEventListener(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;
|
|
22
|
+
removeListener<P extends keyof TEventRecord, T>(this: T, event: P, listener: (...args: any[]) => any): EEMethodReturnType<TEmitter, 'removeListener', T>;
|
|
23
|
+
removeListener(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;
|
|
24
|
+
removeEventListener<P extends keyof TEventRecord, T>(this: T, event: P, listener: (...args: any[]) => any): EEMethodReturnType<TEmitter, 'removeEventListener', T>;
|
|
25
|
+
removeEventListener(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;
|
|
26
|
+
once<P extends keyof TEventRecord, T>(this: T, event: P, listener: (...args: ListenerType<TEventRecord[P]>) => void): EEMethodReturnType<TEmitter, 'once', T>;
|
|
27
|
+
once(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;
|
|
28
|
+
emit<P extends keyof TEmitRecord, T>(this: T, event: P, ...args: ListenerType<TEmitRecord[P]>): EEMethodReturnType<TEmitter, 'emit', T>;
|
|
29
|
+
emit(event: typeof assignmentCompatibilityHack, ...args: any[]): void;
|
|
30
|
+
off<P extends keyof TEventRecord, T>(this: T, event: P, listener: (...args: ListenerType<TEventRecord[P]>) => void): EEMethodReturnType<TEmitter, 'off', T>;
|
|
31
|
+
off(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): void;
|
|
32
|
+
onReturnOff<P extends keyof TEventRecord, T>(this: T, event: P, listener: (...args: ListenerType<TEventRecord[P]>) => void): () => any;
|
|
33
|
+
onReturnOff(event: typeof assignmentCompatibilityHack, listener: (...args: any[]) => any): () => any;
|
|
34
|
+
};
|
|
35
|
+
type OverriddenKeys = keyof OverriddenMethods<any, any, any>;
|
|
36
|
+
type StrictEventEmitter<TEmitterType, TEventRecord, TEmitRecord = TEventRecord, UnneededMethods extends Exclude<OverriddenKeys, keyof TEmitterType> = Exclude<OverriddenKeys, keyof TEmitterType>, NeededMethods extends Exclude<OverriddenKeys, UnneededMethods> = Exclude<OverriddenKeys, UnneededMethods>> = TypeRecord<TEmitterType, TEventRecord, TEmitRecord> & Pick<TEmitterType, Exclude<keyof TEmitterType, OverriddenKeys>> & Pick<OverriddenMethods<TEmitterType, TEventRecord, TEmitRecord>, NeededMethods>;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
// src/core/define_bus.ts
|
|
3
|
+
var EventBus = class extends EventEmitter {
|
|
4
|
+
onReturnOff(event, listener) {
|
|
5
|
+
this.on(event, listener);
|
|
6
|
+
return () => this.off(event, listener);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
function defineBus() {
|
|
10
|
+
return new EventBus();
|
|
11
|
+
}
|
|
12
|
+
export { defineBus };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare function defineCron(options: XCron.Options): XCron.Cron;
|
|
1
|
+
import { XCron } from "./types.mjs";
|
|
2
|
+
export declare function defineCron(options: XCron.Options): XCron.Cron;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { Handler } from "./handler.mjs";
|
|
2
|
+
import { XHandler } from "./types.mjs";
|
|
3
|
+
import { FirstParameter } from "vtils/types";
|
|
4
4
|
export declare function defineHandler<TFn extends (...args: any[]) => Promise<any>, TReqData = FirstParameter<TFn>, TResData = Awaited<ReturnType<TFn>>>(options: XHandler.Options<TReqData, TResData, 'POST'>): Handler<TReqData, TResData, 'POST'>;
|
|
5
5
|
export declare function defineHandler<TReqData extends any = void, TResData extends any = void>(options: XHandler.Options<TReqData, TResData, 'POST'>): Handler<TReqData, TResData, 'POST'>;
|
|
6
6
|
export declare namespace defineHandler {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
var POST: typeof defineHandler;
|
|
8
|
+
var GET: typeof defineHandlerGET;
|
|
9
|
+
var FILE: typeof defineHandlerFILE;
|
|
10
|
+
var WS: <TReqData extends Record<string, [any, any]>>(options: XHandler.Options<{ [K in keyof TReqData]: {
|
|
11
|
+
request: TReqData[K][0];
|
|
12
|
+
response: TReqData[K][1];
|
|
13
|
+
}; }, void, "WS">) => Handler<{ [K in keyof TReqData]: {
|
|
14
|
+
request: TReqData[K][0];
|
|
15
|
+
response: TReqData[K][1];
|
|
16
|
+
}; }, void, "WS", import("vtils/types").RequiredDeep<{ [K in keyof TReqData]: {
|
|
17
|
+
request: TReqData[K][0];
|
|
18
|
+
response: TReqData[K][1];
|
|
19
|
+
}; }>>;
|
|
20
|
+
var XML: typeof defineHandlerXML;
|
|
21
|
+
var ANY: typeof defineHandlerANY;
|
|
22
22
|
}
|
|
23
23
|
export declare function defineHandlerGET<TFn extends (...args: any[]) => Promise<any>, TReqData = FirstParameter<TFn>, TResData = Awaited<ReturnType<TFn>>>(options: XHandler.Options<TReqData, TResData, 'GET'>): Handler<TReqData, TResData, 'GET'>;
|
|
24
24
|
export declare function defineHandlerGET<TReqData extends any = void, TResData extends any = void>(options: XHandler.Options<TReqData, TResData, 'GET'>): Handler<TReqData, TResData, 'GET'>;
|
|
@@ -27,4 +27,4 @@ export declare function defineHandlerFILE<TReqData extends any = void, TResData
|
|
|
27
27
|
export declare function defineHandlerXML<TFn extends (...args: any[]) => Promise<any>, TReqData = FirstParameter<TFn>, TResData = Awaited<ReturnType<TFn>>>(options: XHandler.Options<TReqData, TResData, 'XML'>): Handler<TReqData, TResData, 'XML'>;
|
|
28
28
|
export declare function defineHandlerXML<TReqData extends any = void, TResData extends any = void>(options: XHandler.Options<TReqData, TResData, 'XML'>): Handler<TReqData, TResData, 'XML'>;
|
|
29
29
|
export declare function defineHandlerANY<TFn extends (...args: any[]) => Promise<any>, TReqData = FirstParameter<TFn>, TResData = Awaited<ReturnType<TFn>>>(options: XHandler.Options<TReqData, TResData, 'ANY'>): Handler<TReqData, TResData, 'ANY'>;
|
|
30
|
-
export declare function defineHandlerANY<TReqData extends any = void, TResData extends any = void>(options: XHandler.Options<TReqData, TResData, 'ANY'>): Handler<TReqData, TResData, 'ANY'>;
|
|
30
|
+
export declare function defineHandlerANY<TReqData extends any = void, TResData extends any = void>(options: XHandler.Options<TReqData, TResData, 'ANY'>): Handler<TReqData, TResData, 'ANY'>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Handler } from "./handler.mjs";
|
|
2
|
+
// src/core/define_handler.ts
|
|
3
|
+
function defineHandler(options) {
|
|
4
|
+
return new Handler({
|
|
5
|
+
...options,
|
|
6
|
+
requestMethod: "POST"
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
defineHandler.POST = defineHandler;
|
|
10
|
+
function defineHandlerGET(options) {
|
|
11
|
+
return new Handler({
|
|
12
|
+
...options,
|
|
13
|
+
requestMethod: "GET"
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
defineHandler.GET = defineHandlerGET;
|
|
17
|
+
function defineHandlerFILE(options) {
|
|
18
|
+
return new Handler({
|
|
19
|
+
...options,
|
|
20
|
+
requestMethod: "FILE"
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
defineHandler.FILE = defineHandlerFILE;
|
|
24
|
+
defineHandler.WS = (options) => {
|
|
25
|
+
return new Handler({
|
|
26
|
+
...options,
|
|
27
|
+
requestMethod: "WS"
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
function defineHandlerXML(options) {
|
|
31
|
+
return new Handler({
|
|
32
|
+
...options,
|
|
33
|
+
requestMethod: "XML"
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
defineHandler.XML = defineHandlerXML;
|
|
37
|
+
function defineHandlerANY(options) {
|
|
38
|
+
return new Handler({
|
|
39
|
+
...options,
|
|
40
|
+
requestMethod: "ANY"
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
defineHandler.ANY = defineHandlerANY;
|
|
44
|
+
export { defineHandler, defineHandlerANY, defineHandlerFILE, defineHandlerGET, defineHandlerXML };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { XTask } from "./types.mjs";
|
|
2
2
|
export declare function defineTask<T>(options: XTask.TaskOptions<T>): XTask.Task<T>;
|
|
3
3
|
export declare function defineSliceTask<T>(options: XTask.SliceTaskOptions<T, any>): XTask.SliceTaskNoKey<T>;
|
|
4
|
-
export declare function defineSliceTask<T, K extends string | number>(options: XTask.SliceTaskOptions<T, K>): XTask.SliceTask<T, K>;
|
|
4
|
+
export declare function defineSliceTask<T, K extends string | number>(options: XTask.SliceTaskOptions<T, K>): XTask.SliceTask<T, K>;
|