@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
package/lib/cli/deploy_util.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import { NodeSSH } from 'node-ssh';
|
|
4
|
-
import { dedent } from 'vtils';
|
|
5
|
-
export class DeployUtil {
|
|
6
|
-
static async deploy(options) {
|
|
7
|
-
const pkgContent = await fs.readJson(path.join(options.cwd, 'package.json'));
|
|
8
|
-
const appFile = path.join(options.cwd, `temp${options.channel ? `/${options.channel}` : ''}/app.${pkgContent.version}.tgz`);
|
|
9
|
-
if (!(await fs.pathExists(appFile))) {
|
|
10
|
-
throw new Error('请先构建');
|
|
11
|
-
}
|
|
12
|
-
const ssh = new NodeSSH();
|
|
13
|
-
await ssh.connect({
|
|
14
|
-
host: options.host,
|
|
15
|
-
username: options.user,
|
|
16
|
-
privateKey: options.key,
|
|
17
|
-
password: options.pass
|
|
18
|
-
});
|
|
19
|
-
const appName = pkgContent.name;
|
|
20
|
-
const appDir = `./${appName}`;
|
|
21
|
-
await ssh.execCommand(dedent`
|
|
22
|
-
set -ex
|
|
23
|
-
mkdir -p ./app_files/${appName}/${options.channel || 'dist'}
|
|
24
|
-
mkdir -p ${appDir}
|
|
25
|
-
`, {
|
|
26
|
-
cwd: options.dir,
|
|
27
|
-
onStdout: buf => console.log(buf.toString()),
|
|
28
|
-
onStderr: buf => console.log(buf.toString())
|
|
29
|
-
});
|
|
30
|
-
const remoteAppFile = `${options.dir}/app_files/${appName}/${options.channel || 'dist'}/${path.basename(appFile)}`;
|
|
31
|
-
await ssh.putFile(appFile, remoteAppFile);
|
|
32
|
-
await ssh.execCommand(dedent`
|
|
33
|
-
set -ex
|
|
34
|
-
tar -zxf ${remoteAppFile} -C ${appDir}
|
|
35
|
-
cd "${appDir}/${options.channel || 'dist'}"
|
|
36
|
-
[ -f no_install.lock ] && yarn_disable_self_update_check=true tyn
|
|
37
|
-
${options.cmd || ''}
|
|
38
|
-
pm2 startOrReload pm2.config.js
|
|
39
|
-
`, {
|
|
40
|
-
cwd: options.dir,
|
|
41
|
-
onStdout: buf => console.log(buf.toString()),
|
|
42
|
-
onStderr: buf => console.log(buf.toString())
|
|
43
|
-
});
|
|
44
|
-
ssh.dispose();
|
|
45
|
-
}
|
|
46
|
-
static async deployEnv(options) {
|
|
47
|
-
const ssh = new NodeSSH();
|
|
48
|
-
await ssh.connect({
|
|
49
|
-
host: options.host,
|
|
50
|
-
username: options.user,
|
|
51
|
-
privateKey: options.key,
|
|
52
|
-
password: options.pass
|
|
53
|
-
});
|
|
54
|
-
await ssh.execCommand(dedent`
|
|
55
|
-
set -ex
|
|
56
|
-
curl --silent --header "Content-Type: application/json" \\
|
|
57
|
-
--request "POST" \\
|
|
58
|
-
--data ${JSON.stringify(JSON.stringify({
|
|
59
|
-
token: options.token,
|
|
60
|
-
type: 'updateEnv',
|
|
61
|
-
data: options.env
|
|
62
|
-
}))} \\
|
|
63
|
-
"http://localhost:${options.port}/$"
|
|
64
|
-
`, {
|
|
65
|
-
onStdout: buf => console.log(buf.toString()),
|
|
66
|
-
onStderr: buf => console.log(buf.toString())
|
|
67
|
-
});
|
|
68
|
-
ssh.dispose();
|
|
69
|
-
}
|
|
70
|
-
}
|
package/lib/cli/dev_util.d.ts
DELETED
package/lib/cli/dev_util.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import execa from 'execa';
|
|
3
|
-
import { ii } from 'vtils';
|
|
4
|
-
export class DevUtil {
|
|
5
|
-
static runFile(options) {
|
|
6
|
-
return options.runner === 'tsx' ? execa('node', ['-r', require.resolve("./css_register"), ii(() => {
|
|
7
|
-
const tsxPkgFile = require.resolve('tsx/package.json');
|
|
8
|
-
const tsxJsFile = tsxPkgFile.replace('/package.json', '/dist/cli.js');
|
|
9
|
-
const tsxCjsFile = tsxPkgFile.replace('/package.json', '/dist/cli.cjs');
|
|
10
|
-
const tsxMjsFile = tsxPkgFile.replace('/package.json', '/dist/cli.mjs');
|
|
11
|
-
return fs.existsSync(tsxCjsFile) ? tsxCjsFile : fs.existsSync(tsxMjsFile) ? tsxMjsFile : tsxJsFile;
|
|
12
|
-
}), options.file], {
|
|
13
|
-
cwd: options.cwd,
|
|
14
|
-
stdio: 'inherit'
|
|
15
|
-
}) : execa('node', ['-r', require.resolve("./esbuild_register"), '-r', require.resolve("./css_register"), options.file], {
|
|
16
|
-
cwd: options.cwd,
|
|
17
|
-
stdio: 'inherit'
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
package/lib/cli/env_util.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export interface ParsedEnv {
|
|
2
|
-
comment: string;
|
|
3
|
-
key: string;
|
|
4
|
-
value: any;
|
|
5
|
-
}
|
|
6
|
-
export declare class EnvUtil {
|
|
7
|
-
static NEWLINE: string;
|
|
8
|
-
static RE_INI_KEY_VAL: RegExp;
|
|
9
|
-
static RE_NEWLINES: RegExp;
|
|
10
|
-
static NEWLINES_MATCH: RegExp;
|
|
11
|
-
static COMMENT_MATCH: RegExp;
|
|
12
|
-
static getAllChannel(cwd: string, excludeChannels?: string[]): Promise<string[]>;
|
|
13
|
-
static chooseChannel(cwd: string, excludeChannels?: string[]): Promise<string | undefined>;
|
|
14
|
-
static withChannel(options: {
|
|
15
|
-
cwd: string;
|
|
16
|
-
channel?: string;
|
|
17
|
-
concurrency?: number;
|
|
18
|
-
cb: (channel: string | undefined) => any;
|
|
19
|
-
}): Promise<void>;
|
|
20
|
-
static getFile(env?: string, channel?: string, noBase?: boolean): string[];
|
|
21
|
-
static parseContent(src: string, _envItemMap?: Record<string, ParsedEnv>, _envValueMap?: Record<string, any>, channel?: string): ParsedEnv[];
|
|
22
|
-
static parseFile(options: {
|
|
23
|
-
cwd: string;
|
|
24
|
-
file: string[];
|
|
25
|
-
channel?: string;
|
|
26
|
-
}): Promise<ParsedEnv[]>;
|
|
27
|
-
static parseFileAsMap(options: {
|
|
28
|
-
cwd: string;
|
|
29
|
-
file: string[];
|
|
30
|
-
channel?: string;
|
|
31
|
-
}): Promise<Record<string, any>>;
|
|
32
|
-
static importFile(options: {
|
|
33
|
-
cwd: string;
|
|
34
|
-
file: string[];
|
|
35
|
-
channel?: string;
|
|
36
|
-
}): Promise<void>;
|
|
37
|
-
static makeTypes(envs: ParsedEnv[]): string;
|
|
38
|
-
static outputTypes(options: {
|
|
39
|
-
cwd: string;
|
|
40
|
-
file: string[];
|
|
41
|
-
outFile: string;
|
|
42
|
-
channel?: string;
|
|
43
|
-
}): Promise<void>;
|
|
44
|
-
private static getTypesFromValue;
|
|
45
|
-
}
|
package/lib/cli/env_util.js
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import globby from 'globby';
|
|
4
|
-
import { pinyin } from 'pinyin-pro';
|
|
5
|
-
import { asyncLimit, castArray, dedent, difference, escapeRegExp, get, isPlainObject, uniq } from 'vtils';
|
|
6
|
-
import { parse as yamlParse } from 'yaml';
|
|
7
|
-
export class EnvUtil {
|
|
8
|
-
static async getAllChannel(cwd, excludeChannels) {
|
|
9
|
-
const channelFiles = await globby(['.env@*'], {
|
|
10
|
-
cwd: cwd,
|
|
11
|
-
onlyFiles: true,
|
|
12
|
-
absolute: false
|
|
13
|
-
});
|
|
14
|
-
if (channelFiles.length === 0) {
|
|
15
|
-
return [];
|
|
16
|
-
}
|
|
17
|
-
let channels = uniq(channelFiles.map(channel => channel.split('@').pop().split('.')[0]));
|
|
18
|
-
if (excludeChannels?.length) {
|
|
19
|
-
channels = difference(channels, excludeChannels);
|
|
20
|
-
}
|
|
21
|
-
return channels;
|
|
22
|
-
}
|
|
23
|
-
static async chooseChannel(cwd, excludeChannels) {
|
|
24
|
-
const channels = await EnvUtil.getAllChannel(cwd, excludeChannels);
|
|
25
|
-
if (channels.length === 0) return undefined;
|
|
26
|
-
if (channels.length === 1) return channels[0];
|
|
27
|
-
const channelOptions = channels.sort((a, b) => a.localeCompare(b, 'zh-CN')).map(channel => {
|
|
28
|
-
const channelPinyin = pinyin(channel, {
|
|
29
|
-
type: 'string',
|
|
30
|
-
pattern: 'first',
|
|
31
|
-
toneType: 'none',
|
|
32
|
-
separator: '',
|
|
33
|
-
removeNonZh: false,
|
|
34
|
-
nonZh: 'consecutive'
|
|
35
|
-
}).toLowerCase();
|
|
36
|
-
return {
|
|
37
|
-
name: channel,
|
|
38
|
-
value: channel,
|
|
39
|
-
pinyin: channelPinyin,
|
|
40
|
-
description: `${channel}<${channelPinyin}>`
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
const {
|
|
45
|
-
default: autocomplete
|
|
46
|
-
} = await import('inquirer-autocomplete-standalone');
|
|
47
|
-
const selectedChannel = await autocomplete({
|
|
48
|
-
message: '请选择渠道',
|
|
49
|
-
source: async input => {
|
|
50
|
-
return !input ? channelOptions : channelOptions.filter(channelOption => {
|
|
51
|
-
return channelOption.pinyin.includes(input) || channelOption.name.includes(input);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
return selectedChannel || undefined;
|
|
56
|
-
}
|
|
57
|
-
static async withChannel(options) {
|
|
58
|
-
const successChannels = [];
|
|
59
|
-
const failedChannels = [];
|
|
60
|
-
if (options.channel?.startsWith('_')) {
|
|
61
|
-
const excludeChannels = options.channel.split('!')[1]?.split(',').filter(Boolean);
|
|
62
|
-
const channel = process.env.APP_CHANNEL || (await EnvUtil.chooseChannel(options.cwd, excludeChannels));
|
|
63
|
-
console.log(`========= ${channel} =========`);
|
|
64
|
-
try {
|
|
65
|
-
await options.cb(channel);
|
|
66
|
-
successChannels.push(channel);
|
|
67
|
-
} catch (err) {
|
|
68
|
-
console.error(err);
|
|
69
|
-
failedChannels.push(channel);
|
|
70
|
-
}
|
|
71
|
-
} else if (options.channel?.startsWith('@')) {
|
|
72
|
-
const excludeChannels = options.channel.split('!')[1]?.split(',').filter(Boolean);
|
|
73
|
-
const channels = await EnvUtil.getAllChannel(options.cwd, excludeChannels);
|
|
74
|
-
await Promise.all(channels.map(asyncLimit(async channel => {
|
|
75
|
-
console.log(`========= ${channel} =========`);
|
|
76
|
-
try {
|
|
77
|
-
await options.cb(channel);
|
|
78
|
-
successChannels.push(channel);
|
|
79
|
-
} catch (err) {
|
|
80
|
-
console.error(err);
|
|
81
|
-
failedChannels.push(channel);
|
|
82
|
-
}
|
|
83
|
-
}, {
|
|
84
|
-
concurrency: options.concurrency || 1
|
|
85
|
-
})));
|
|
86
|
-
} else {
|
|
87
|
-
if (options.channel) {
|
|
88
|
-
console.log(`========= ${options.channel} =========`);
|
|
89
|
-
}
|
|
90
|
-
try {
|
|
91
|
-
await options.cb(options.channel);
|
|
92
|
-
options.channel && successChannels.push(options.channel);
|
|
93
|
-
} catch (err) {
|
|
94
|
-
console.error(err);
|
|
95
|
-
options.channel && failedChannels.push(options.channel);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if (successChannels.length) {
|
|
99
|
-
console.log(`✅(${successChannels.length}):${JSON.stringify(successChannels)}`);
|
|
100
|
-
}
|
|
101
|
-
if (failedChannels.length) {
|
|
102
|
-
console.log(`❌(${failedChannels.length}):${JSON.stringify(failedChannels)}`);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
static getFile(env, channel, noBase) {
|
|
106
|
-
const file = ['.env_meta', ...(noBase ? [] : ['.env'])];
|
|
107
|
-
if (!noBase && channel) {
|
|
108
|
-
file.push(`.env@${channel}`);
|
|
109
|
-
}
|
|
110
|
-
if (env) {
|
|
111
|
-
file.push(`.env.${env}`);
|
|
112
|
-
if (channel) {
|
|
113
|
-
file.push(`.env@${channel}.${env}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return file;
|
|
117
|
-
}
|
|
118
|
-
static parseContent(src, _envItemMap, _envValueMap, channel) {
|
|
119
|
-
const envs = [];
|
|
120
|
-
const envObj = yamlParse(src);
|
|
121
|
-
if (channel) {
|
|
122
|
-
const channelEnvs = envObj.__CHANNEL__;
|
|
123
|
-
if (channelEnvs && Array.isArray(channelEnvs)) {
|
|
124
|
-
for (const channelEnv of channelEnvs) {
|
|
125
|
-
const channels = castArray(channelEnv._).flatMap(item => item.split(','));
|
|
126
|
-
if (channels.includes(channel)) {
|
|
127
|
-
delete channelEnv._;
|
|
128
|
-
Object.assign(envObj, channelEnv);
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
delete envObj.__CHANNEL__;
|
|
135
|
-
const inlineVars = value => {
|
|
136
|
-
if (Array.isArray(value)) {
|
|
137
|
-
return value.map(inlineVars);
|
|
138
|
-
}
|
|
139
|
-
if (isPlainObject(value)) {
|
|
140
|
-
return Object.keys(value).reduce((acc, key) => {
|
|
141
|
-
acc[key] = inlineVars(value[key]);
|
|
142
|
-
return acc;
|
|
143
|
-
}, {});
|
|
144
|
-
}
|
|
145
|
-
if (typeof value === 'string') {
|
|
146
|
-
return value.replace(/\{\{\s*(.+?)\s*\}\}/g, (_, key) => get(_envValueMap || envObj, key) || process.env[key] || '');
|
|
147
|
-
}
|
|
148
|
-
return value;
|
|
149
|
-
};
|
|
150
|
-
Object.keys(envObj).forEach(key => {
|
|
151
|
-
const value = inlineVars(envObj[key]);
|
|
152
|
-
const envItem = {
|
|
153
|
-
key: key,
|
|
154
|
-
value: value,
|
|
155
|
-
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() || ''
|
|
156
|
-
};
|
|
157
|
-
if (_envItemMap) {
|
|
158
|
-
_envItemMap[key] = envItem;
|
|
159
|
-
}
|
|
160
|
-
if (_envValueMap) {
|
|
161
|
-
_envValueMap[key] = value;
|
|
162
|
-
}
|
|
163
|
-
envs.push(envItem);
|
|
164
|
-
});
|
|
165
|
-
return envs;
|
|
166
|
-
}
|
|
167
|
-
static async parseFile(options) {
|
|
168
|
-
const envItemMap = {};
|
|
169
|
-
const envValueMap = {
|
|
170
|
-
APP_CHANNEL: options.channel
|
|
171
|
-
};
|
|
172
|
-
for (const file of options.file) {
|
|
173
|
-
const isEnvMeta = file === '.env_meta';
|
|
174
|
-
const envYmlFile = path.join(options.cwd, `${file}.yml`);
|
|
175
|
-
const envYamlFile = path.join(options.cwd, `${file}.yaml`);
|
|
176
|
-
const envFile = (await fs.pathExists(envYmlFile)) ? envYmlFile : (await fs.pathExists(envYamlFile)) ? envYamlFile : '';
|
|
177
|
-
if (envFile) {
|
|
178
|
-
const envContent = await fs.readFile(envFile, 'utf-8');
|
|
179
|
-
EnvUtil.parseContent(envContent, isEnvMeta ? undefined : envItemMap, envValueMap, options.channel);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return Object.values(envItemMap);
|
|
183
|
-
}
|
|
184
|
-
static async parseFileAsMap(options) {
|
|
185
|
-
const envsObj = {
|
|
186
|
-
APP_CHANNEL: options.channel
|
|
187
|
-
};
|
|
188
|
-
const envs = await EnvUtil.parseFile(options);
|
|
189
|
-
for (const env of envs) {
|
|
190
|
-
envsObj[env.key] = env.value;
|
|
191
|
-
}
|
|
192
|
-
return envsObj;
|
|
193
|
-
}
|
|
194
|
-
static async importFile(options) {
|
|
195
|
-
const envsObj = {
|
|
196
|
-
APP_CHANNEL: options.channel
|
|
197
|
-
};
|
|
198
|
-
const envs = await EnvUtil.parseFile(options);
|
|
199
|
-
for (const env of envs) {
|
|
200
|
-
envsObj[env.key] = env.value;
|
|
201
|
-
process.env[env.key] = env.value;
|
|
202
|
-
}
|
|
203
|
-
process.env.X_SERVER_ENVS = JSON.stringify({
|
|
204
|
-
...JSON.parse(process.env.X_SERVER_ENVS || '{}'),
|
|
205
|
-
...envsObj
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
static makeTypes(envs) {
|
|
209
|
-
return dedent`
|
|
210
|
-
declare namespace NodeJS {
|
|
211
|
-
interface ProcessEnv {
|
|
212
|
-
/**
|
|
213
|
-
* 当前环境
|
|
214
|
-
*/
|
|
215
|
-
NODE_ENV: 'development' | 'production';
|
|
216
|
-
/**
|
|
217
|
-
* 当前渠道
|
|
218
|
-
*/
|
|
219
|
-
APP_CHANNEL: string;
|
|
220
|
-
${envs.map(env => dedent`
|
|
221
|
-
${env.comment ? dedent`
|
|
222
|
-
/**
|
|
223
|
-
${env.comment.split(/[\r\n]+/g).map(line => `* ${line.trim()}`).join('\n*\n')}
|
|
224
|
-
*/
|
|
225
|
-
` : ''}
|
|
226
|
-
${env.key}: ${EnvUtil.getTypesFromValue(env.value)};
|
|
227
|
-
`).join('\n')}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
`;
|
|
231
|
-
}
|
|
232
|
-
static async outputTypes(options) {
|
|
233
|
-
const envs = await EnvUtil.parseFile(options);
|
|
234
|
-
const outFile = path.join(options.cwd, options.outFile);
|
|
235
|
-
const types = EnvUtil.makeTypes(envs);
|
|
236
|
-
await fs.outputFile(outFile, types);
|
|
237
|
-
}
|
|
238
|
-
static getTypesFromValue(value) {
|
|
239
|
-
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;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
EnvUtil.NEWLINE = '\n';
|
|
243
|
-
EnvUtil.RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*(.*)?\s*$/;
|
|
244
|
-
EnvUtil.RE_NEWLINES = /\\n/g;
|
|
245
|
-
EnvUtil.NEWLINES_MATCH = /\r\n|\n|\r/;
|
|
246
|
-
EnvUtil.COMMENT_MATCH = /^#\s*(.+?)\s*$/;
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
}
|
package/lib/cli/template_util.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import globby from 'globby';
|
|
4
|
-
import { generateManyIndex } from 'vscode-generate-index-standalone';
|
|
5
|
-
import { camelCase, dedent, snakeCase, upperFirst } from 'vtils';
|
|
6
|
-
export class TemplateUtil {
|
|
7
|
-
/**
|
|
8
|
-
* 初始化。
|
|
9
|
-
*/
|
|
10
|
-
static async init(cwd) {
|
|
11
|
-
await Promise.all([this.initHelperPackage(cwd), this.initTasks(cwd)]);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 初始化辅助包。
|
|
16
|
-
*/
|
|
17
|
-
static async initHelperPackage(cwd) {
|
|
18
|
-
const fromDir = path.join(__dirname, 'templates');
|
|
19
|
-
const toDir = path.join(cwd, 'node_modules/.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
|
-
// 对于 models.ts, 项目未使用数据库相关功能时不生成
|
|
30
|
-
if (fromFile.endsWith('models.ts') && !hasDb) {
|
|
31
|
-
await fs.writeFile(toFile, 'export {}');
|
|
32
|
-
} else {
|
|
33
|
-
let fromFileContent = await fs.readFile(fromFile, 'utf-8');
|
|
34
|
-
fromFileContent = fromFileContent.replaceAll('../../src', path.relative(toDir, `${cwd}/src`));
|
|
35
|
-
await fs.writeFile(toFile, fromFileContent);
|
|
36
|
-
}
|
|
37
|
-
}));
|
|
38
|
-
await generateManyIndex({
|
|
39
|
-
cwd: cwd,
|
|
40
|
-
patterns: ['node_modules/.x/*.ts'],
|
|
41
|
-
replaceFile: true
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 初始化任务。
|
|
47
|
-
*/
|
|
48
|
-
static async initTasks(cwd) {
|
|
49
|
-
const tasksDir = path.join(cwd, 'src/tasks');
|
|
50
|
-
const tasksIndexFile = path.join(tasksDir, 'index.ts');
|
|
51
|
-
if (!(await fs.pathExists(tasksIndexFile))) {
|
|
52
|
-
await fs.outputFile(tasksIndexFile, dedent`
|
|
53
|
-
// @index(['./**/*.ts', '!**/*.test.ts', '!**/_*'], f => \`export * from '\${f.path}'\`)
|
|
54
|
-
// @endindex
|
|
55
|
-
`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* 初始化模型。
|
|
61
|
-
*/
|
|
62
|
-
static async initModels(cwd) {
|
|
63
|
-
const modelsDir = path.join(cwd, 'src/models');
|
|
64
|
-
const indexFile = path.join(modelsDir, 'index.ts');
|
|
65
|
-
const indexFile2 = path.join(cwd, 'node_modules/.x/models.ts');
|
|
66
|
-
const prismaClientFile = path.join(cwd, 'node_modules/.x/prisma/internal/prismaNamespace.ts');
|
|
67
|
-
const prismaClientFileContent = await fs.readFile(prismaClientFile, 'utf8');
|
|
68
|
-
const modelNames = [...prismaClientFileContent.match(/(?<=const ModelName).+?(?=\})/s)[0].matchAll(/(\S+?):/g)].map(match => camelCase(match[1]));
|
|
69
|
-
await Promise.all(modelNames.map(async modelName => {
|
|
70
|
-
const model_name = snakeCase(modelName);
|
|
71
|
-
const ModelName = upperFirst(modelName);
|
|
72
|
-
const modelFile = path.join(modelsDir, `${model_name}.ts`);
|
|
73
|
-
if (!(await fs.pathExists(modelFile))) {
|
|
74
|
-
await fs.outputFile(modelFile, dedent`
|
|
75
|
-
import { ${ModelName}BaseModel } from '@jayfong/x-server'
|
|
76
|
-
|
|
77
|
-
export class ${ModelName}Model extends ${ModelName}BaseModel {}
|
|
78
|
-
|
|
79
|
-
export const ${modelName}Model = new ${ModelName}Model()
|
|
80
|
-
`);
|
|
81
|
-
}
|
|
82
|
-
}));
|
|
83
|
-
if (!(await fs.pathExists(indexFile))) {
|
|
84
|
-
await fs.outputFile(indexFile, dedent`
|
|
85
|
-
// @index(['./**/*.ts', '!**/*.test.ts', '!**/_*'], f => \`export * from '\${f.path}'\`)
|
|
86
|
-
// @endindex
|
|
87
|
-
`);
|
|
88
|
-
}
|
|
89
|
-
await generateManyIndex({
|
|
90
|
-
cwd: cwd,
|
|
91
|
-
patterns: [indexFile, indexFile2],
|
|
92
|
-
replaceFile: true
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
package/lib/core/ctx_storage.js
DELETED
package/lib/core/define_bus.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
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 {};
|
package/lib/core/define_bus.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'node:events';
|
|
2
|
-
class EventBus extends EventEmitter {
|
|
3
|
-
onReturnOff(event, listener) {
|
|
4
|
-
this.on(event, listener);
|
|
5
|
-
return () => this.off(event, listener);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export function defineBus() {
|
|
9
|
-
const eventEmitter = new EventBus();
|
|
10
|
-
return eventEmitter;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// strict-event-emitter-types
|
|
14
|
-
// https://github.com/bterlson/strict-event-emitter-types/blob/9ed45fc68a69f0b7f85ce4e5fe11ff53cc6a009e/src/index.ts
|
|
15
|
-
|
|
16
|
-
// the overridden signatures need to be assignment compatible, but
|
|
17
|
-
// due to how tuple types work[0] it's not possible to be assignment
|
|
18
|
-
// compatible anymore. This hack fixes it with a unique symbol that
|
|
19
|
-
// won't ever show up in parameter help etc.
|
|
20
|
-
//
|
|
21
|
-
// Unfortunately, this has the result of giving a poor error message when
|
|
22
|
-
// you mix up types.
|
|
23
|
-
// 0: https://github.com/Microsoft/TypeScript/issues/26013)
|
|
24
|
-
|
|
25
|
-
// TODO: Stash under a symbol key once TS compiler bug is fixed
|
|
26
|
-
|
|
27
|
-
// EventEmitter method overrides
|
package/lib/core/define_cron.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Handler } from "./handler";
|
|
2
|
-
export function defineHandler(options) {
|
|
3
|
-
const handler = new Handler({
|
|
4
|
-
...options,
|
|
5
|
-
requestMethod: 'POST'
|
|
6
|
-
});
|
|
7
|
-
return handler;
|
|
8
|
-
}
|
|
9
|
-
defineHandler.POST = defineHandler;
|
|
10
|
-
export function defineHandlerGET(options) {
|
|
11
|
-
const handler = new Handler({
|
|
12
|
-
...options,
|
|
13
|
-
requestMethod: 'GET'
|
|
14
|
-
});
|
|
15
|
-
return handler;
|
|
16
|
-
}
|
|
17
|
-
defineHandler.GET = defineHandlerGET;
|
|
18
|
-
export function defineHandlerFILE(options) {
|
|
19
|
-
const handler = new Handler({
|
|
20
|
-
...options,
|
|
21
|
-
requestMethod: 'FILE'
|
|
22
|
-
});
|
|
23
|
-
return handler;
|
|
24
|
-
}
|
|
25
|
-
defineHandler.FILE = defineHandlerFILE;
|
|
26
|
-
defineHandler.WS = options => {
|
|
27
|
-
const handler = new Handler({
|
|
28
|
-
...options,
|
|
29
|
-
requestMethod: 'WS'
|
|
30
|
-
});
|
|
31
|
-
return handler;
|
|
32
|
-
};
|
|
33
|
-
export function defineHandlerXML(options) {
|
|
34
|
-
const handler = new Handler({
|
|
35
|
-
...options,
|
|
36
|
-
requestMethod: 'XML'
|
|
37
|
-
});
|
|
38
|
-
return handler;
|
|
39
|
-
}
|
|
40
|
-
defineHandler.XML = defineHandlerXML;
|
|
41
|
-
export function defineHandlerANY(options) {
|
|
42
|
-
const handler = new Handler({
|
|
43
|
-
...options,
|
|
44
|
-
requestMethod: 'ANY'
|
|
45
|
-
});
|
|
46
|
-
return handler;
|
|
47
|
-
}
|
|
48
|
-
defineHandler.ANY = defineHandlerANY;
|
package/lib/core/define_hook.js
DELETED