@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
package/lib/core/http_header.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
// https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
|
|
2
|
-
/**
|
|
3
|
-
[...$0.querySelectorAll('tr')].map(v => v.querySelector('td:nth-child(1)').innerText.trim().split(',').map(name => name.replace(/\[.*?\]/g, '').trim()).map((name) => ({
|
|
4
|
-
name: name,
|
|
5
|
-
description: v.querySelector('td:nth-child(2)').innerText.replace(/\[.*?\]/g, '').trim(),
|
|
6
|
-
example: v.querySelector('td:nth-child(3)').innerText.trim(),
|
|
7
|
-
pascalName: name.replace(/\-/g, '_').toUpperCase()
|
|
8
|
-
}))).flat().map(item => `
|
|
9
|
-
${'/'}**
|
|
10
|
-
* ${item.description}
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ${item.example}
|
|
14
|
-
*${'/'}
|
|
15
|
-
${item.pascalName} = '${item.name}',
|
|
16
|
-
`).join('\n\n')
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
export let HttpRequestHeader = /*#__PURE__*/function (HttpRequestHeader) {
|
|
20
|
-
HttpRequestHeader["A_IM"] = "A-IM";
|
|
21
|
-
HttpRequestHeader["ACCEPT"] = "Accept";
|
|
22
|
-
HttpRequestHeader["ACCEPT_CHARSET"] = "Accept-Charset";
|
|
23
|
-
HttpRequestHeader["ACCEPT_DATETIME"] = "Accept-Datetime";
|
|
24
|
-
HttpRequestHeader["ACCEPT_ENCODING"] = "Accept-Encoding";
|
|
25
|
-
HttpRequestHeader["ACCEPT_LANGUAGE"] = "Accept-Language";
|
|
26
|
-
HttpRequestHeader["ACCESS_CONTROL_REQUEST_METHOD"] = "Access-Control-Request-Method";
|
|
27
|
-
HttpRequestHeader["ACCESS_CONTROL_REQUEST_HEADERS"] = "Access-Control-Request-Headers";
|
|
28
|
-
HttpRequestHeader["AUTHORIZATION"] = "Authorization";
|
|
29
|
-
HttpRequestHeader["CACHE_CONTROL"] = "Cache-Control";
|
|
30
|
-
HttpRequestHeader["CONNECTION"] = "Connection";
|
|
31
|
-
HttpRequestHeader["CONTENT_ENCODING"] = "Content-Encoding";
|
|
32
|
-
HttpRequestHeader["CONTENT_LENGTH"] = "Content-Length";
|
|
33
|
-
HttpRequestHeader["CONTENT_MD5"] = "Content-MD5";
|
|
34
|
-
HttpRequestHeader["CONTENT_TYPE"] = "Content-Type";
|
|
35
|
-
HttpRequestHeader["COOKIE"] = "Cookie";
|
|
36
|
-
HttpRequestHeader["DATE"] = "Date";
|
|
37
|
-
HttpRequestHeader["EXPECT"] = "Expect";
|
|
38
|
-
HttpRequestHeader["FORWARDED"] = "Forwarded";
|
|
39
|
-
HttpRequestHeader["FROM"] = "From";
|
|
40
|
-
HttpRequestHeader["HOST"] = "Host";
|
|
41
|
-
HttpRequestHeader["HTTP2_SETTINGS"] = "HTTP2-Settings";
|
|
42
|
-
HttpRequestHeader["IF_MATCH"] = "If-Match";
|
|
43
|
-
HttpRequestHeader["IF_MODIFIED_SINCE"] = "If-Modified-Since";
|
|
44
|
-
HttpRequestHeader["IF_NONE_MATCH"] = "If-None-Match";
|
|
45
|
-
HttpRequestHeader["IF_RANGE"] = "If-Range";
|
|
46
|
-
HttpRequestHeader["IF_UNMODIFIED_SINCE"] = "If-Unmodified-Since";
|
|
47
|
-
HttpRequestHeader["MAX_FORWARDS"] = "Max-Forwards";
|
|
48
|
-
HttpRequestHeader["ORIGIN"] = "Origin";
|
|
49
|
-
HttpRequestHeader["PRAGMA"] = "Pragma";
|
|
50
|
-
HttpRequestHeader["PROXY_AUTHORIZATION"] = "Proxy-Authorization";
|
|
51
|
-
HttpRequestHeader["RANGE"] = "Range";
|
|
52
|
-
HttpRequestHeader["REFERER"] = "Referer";
|
|
53
|
-
HttpRequestHeader["TE"] = "TE";
|
|
54
|
-
HttpRequestHeader["TRAILER"] = "Trailer";
|
|
55
|
-
HttpRequestHeader["TRANSFER_ENCODING"] = "Transfer-Encoding";
|
|
56
|
-
HttpRequestHeader["USER_AGENT"] = "User-Agent";
|
|
57
|
-
HttpRequestHeader["UPGRADE"] = "Upgrade";
|
|
58
|
-
HttpRequestHeader["VIA"] = "Via";
|
|
59
|
-
HttpRequestHeader["WARNING"] = "Warning";
|
|
60
|
-
HttpRequestHeader["UPGRADE_INSECURE_REQUESTS"] = "Upgrade-Insecure-Requests";
|
|
61
|
-
HttpRequestHeader["X_REQUESTED_WITH"] = "X-Requested-With";
|
|
62
|
-
HttpRequestHeader["DNT"] = "DNT";
|
|
63
|
-
HttpRequestHeader["X_FORWARDED_FOR"] = "X-Forwarded-For";
|
|
64
|
-
HttpRequestHeader["X_FORWARDED_HOST"] = "X-Forwarded-Host";
|
|
65
|
-
HttpRequestHeader["X_FORWARDED_PROTO"] = "X-Forwarded-Proto";
|
|
66
|
-
HttpRequestHeader["FRONT_END_HTTPS"] = "Front-End-Https";
|
|
67
|
-
HttpRequestHeader["X_HTTP_METHOD_OVERRIDE"] = "X-Http-Method-Override";
|
|
68
|
-
HttpRequestHeader["X_ATT_DEVICEID"] = "X-ATT-DeviceId";
|
|
69
|
-
HttpRequestHeader["X_WAP_PROFILE"] = "X-Wap-Profile";
|
|
70
|
-
HttpRequestHeader["PROXY_CONNECTION"] = "Proxy-Connection";
|
|
71
|
-
HttpRequestHeader["X_UIDH"] = "X-UIDH";
|
|
72
|
-
HttpRequestHeader["X_CSRF_TOKEN"] = "X-Csrf-Token";
|
|
73
|
-
HttpRequestHeader["X_REQUEST_ID"] = "X-Request-ID";
|
|
74
|
-
HttpRequestHeader["X_CORRELATION_ID"] = "X-Correlation-ID";
|
|
75
|
-
HttpRequestHeader["SAVE_DATA"] = "Save-Data";
|
|
76
|
-
return HttpRequestHeader;
|
|
77
|
-
}({});
|
|
78
|
-
export let HttpResponseHeader = /*#__PURE__*/function (HttpResponseHeader) {
|
|
79
|
-
HttpResponseHeader["ACCESS_CONTROL_ALLOW_ORIGIN"] = "Access-Control-Allow-Origin";
|
|
80
|
-
HttpResponseHeader["ACCESS_CONTROL_ALLOW_CREDENTIALS"] = "Access-Control-Allow-Credentials";
|
|
81
|
-
HttpResponseHeader["ACCESS_CONTROL_EXPOSE_HEADERS"] = "Access-Control-Expose-Headers";
|
|
82
|
-
HttpResponseHeader["ACCESS_CONTROL_MAX_AGE"] = "Access-Control-Max-Age";
|
|
83
|
-
HttpResponseHeader["ACCESS_CONTROL_ALLOW_METHODS"] = "Access-Control-Allow-Methods";
|
|
84
|
-
HttpResponseHeader["ACCESS_CONTROL_ALLOW_HEADERS"] = "Access-Control-Allow-Headers";
|
|
85
|
-
HttpResponseHeader["ACCEPT_PATCH"] = "Accept-Patch";
|
|
86
|
-
HttpResponseHeader["ACCEPT_RANGES"] = "Accept-Ranges";
|
|
87
|
-
HttpResponseHeader["AGE"] = "Age";
|
|
88
|
-
HttpResponseHeader["ALLOW"] = "Allow";
|
|
89
|
-
HttpResponseHeader["ALT_SVC"] = "Alt-Svc";
|
|
90
|
-
HttpResponseHeader["CACHE_CONTROL"] = "Cache-Control";
|
|
91
|
-
HttpResponseHeader["CONNECTION"] = "Connection";
|
|
92
|
-
HttpResponseHeader["CONTENT_DISPOSITION"] = "Content-Disposition";
|
|
93
|
-
HttpResponseHeader["CONTENT_ENCODING"] = "Content-Encoding";
|
|
94
|
-
HttpResponseHeader["CONTENT_LANGUAGE"] = "Content-Language";
|
|
95
|
-
HttpResponseHeader["CONTENT_LENGTH"] = "Content-Length";
|
|
96
|
-
HttpResponseHeader["CONTENT_LOCATION"] = "Content-Location";
|
|
97
|
-
HttpResponseHeader["CONTENT_MD5"] = "Content-MD5";
|
|
98
|
-
HttpResponseHeader["CONTENT_RANGE"] = "Content-Range";
|
|
99
|
-
HttpResponseHeader["CONTENT_TYPE"] = "Content-Type";
|
|
100
|
-
HttpResponseHeader["DATE"] = "Date";
|
|
101
|
-
HttpResponseHeader["DELTA_BASE"] = "Delta-Base";
|
|
102
|
-
HttpResponseHeader["ETAG"] = "ETag";
|
|
103
|
-
HttpResponseHeader["EXPIRES"] = "Expires";
|
|
104
|
-
HttpResponseHeader["IM"] = "IM";
|
|
105
|
-
HttpResponseHeader["LAST_MODIFIED"] = "Last-Modified";
|
|
106
|
-
HttpResponseHeader["LINK"] = "Link";
|
|
107
|
-
HttpResponseHeader["LOCATION"] = "Location";
|
|
108
|
-
HttpResponseHeader["P3P"] = "P3P";
|
|
109
|
-
HttpResponseHeader["PRAGMA"] = "Pragma";
|
|
110
|
-
HttpResponseHeader["PROXY_AUTHENTICATE"] = "Proxy-Authenticate";
|
|
111
|
-
HttpResponseHeader["PUBLIC_KEY_PINS"] = "Public-Key-Pins";
|
|
112
|
-
HttpResponseHeader["RETRY_AFTER"] = "Retry-After";
|
|
113
|
-
HttpResponseHeader["SERVER"] = "Server";
|
|
114
|
-
HttpResponseHeader["SET_COOKIE"] = "Set-Cookie";
|
|
115
|
-
HttpResponseHeader["STRICT_TRANSPORT_SECURITY"] = "Strict-Transport-Security";
|
|
116
|
-
HttpResponseHeader["TRAILER"] = "Trailer";
|
|
117
|
-
HttpResponseHeader["TRANSFER_ENCODING"] = "Transfer-Encoding";
|
|
118
|
-
HttpResponseHeader["TK"] = "Tk";
|
|
119
|
-
HttpResponseHeader["UPGRADE"] = "Upgrade";
|
|
120
|
-
HttpResponseHeader["VARY"] = "Vary";
|
|
121
|
-
HttpResponseHeader["VIA"] = "Via";
|
|
122
|
-
HttpResponseHeader["WARNING"] = "Warning";
|
|
123
|
-
HttpResponseHeader["WWW_AUTHENTICATE"] = "WWW-Authenticate";
|
|
124
|
-
HttpResponseHeader["X_FRAME_OPTIONS"] = "X-Frame-Options";
|
|
125
|
-
HttpResponseHeader["CONTENT_SECURITY_POLICY"] = "Content-Security-Policy";
|
|
126
|
-
HttpResponseHeader["X_CONTENT_SECURITY_POLICY"] = "X-Content-Security-Policy";
|
|
127
|
-
HttpResponseHeader["X_WEBKIT_CSP"] = "X-WebKit-CSP";
|
|
128
|
-
HttpResponseHeader["REFRESH"] = "Refresh";
|
|
129
|
-
HttpResponseHeader["STATUS"] = "Status";
|
|
130
|
-
HttpResponseHeader["TIMING_ALLOW_ORIGIN"] = "Timing-Allow-Origin";
|
|
131
|
-
HttpResponseHeader["X_CONTENT_DURATION"] = "X-Content-Duration";
|
|
132
|
-
HttpResponseHeader["X_CONTENT_TYPE_OPTIONS"] = "X-Content-Type-Options";
|
|
133
|
-
HttpResponseHeader["X_POWERED_BY"] = "X-Powered-By";
|
|
134
|
-
HttpResponseHeader["X_REQUEST_ID"] = "X-Request-ID";
|
|
135
|
-
HttpResponseHeader["X_CORRELATION_ID"] = "X-Correlation-ID";
|
|
136
|
-
HttpResponseHeader["X_UA_COMPATIBLE"] = "X-UA-Compatible";
|
|
137
|
-
HttpResponseHeader["X_XSS_PROTECTION"] = "X-XSS-Protection";
|
|
138
|
-
return HttpResponseHeader;
|
|
139
|
-
}({});
|
package/lib/core/http_method.js
DELETED
package/lib/core/server.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { XServer } from './types';
|
|
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
|
-
}
|
package/lib/core/server.js
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import process from 'node:process';
|
|
2
|
-
import Fastify from 'fastify';
|
|
3
|
-
import { base64UrlDecode, castArray, keyBy, noop, rot13 } from 'vtils';
|
|
4
|
-
import { cuid2 } from 'vtils/x';
|
|
5
|
-
import { x } from "../x";
|
|
6
|
-
import { HttpError } from "./http_error";
|
|
7
|
-
import { HandlerMethodToHttpMethod } from "./http_method";
|
|
8
|
-
export class Server {
|
|
9
|
-
constructor(options) {
|
|
10
|
-
this.options = options;
|
|
11
|
-
this.fastify = void 0;
|
|
12
|
-
this.routes = [];
|
|
13
|
-
Server.options = options;
|
|
14
|
-
process.on('unhandledRejection', (reason, promise) => {
|
|
15
|
-
console.error('未捕获的错误', reason, promise);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
async start() {
|
|
19
|
-
this.applyServices();
|
|
20
|
-
await this.prepareFastify();
|
|
21
|
-
this.applyPlugins();
|
|
22
|
-
await this.prepareRoutes();
|
|
23
|
-
await this.applyRoutes();
|
|
24
|
-
await this.applyHooks();
|
|
25
|
-
await this.startFastify();
|
|
26
|
-
await this.startCrons();
|
|
27
|
-
await this.applyAutoClose();
|
|
28
|
-
}
|
|
29
|
-
async close() {
|
|
30
|
-
await this.fastify?.close();
|
|
31
|
-
}
|
|
32
|
-
async prepareFastify() {
|
|
33
|
-
this.fastify = await Fastify({
|
|
34
|
-
logger: process.env.NODE_ENV === 'development' ? {
|
|
35
|
-
transport: {
|
|
36
|
-
target: 'pino-pretty'
|
|
37
|
-
}
|
|
38
|
-
} : false,
|
|
39
|
-
// 信任 X-Forwarded-For 头以获取正确的 IP,
|
|
40
|
-
// 否则通过 nginx 代理后 remoteAddr 将始终为 127.0.0.1
|
|
41
|
-
trustProxy: true,
|
|
42
|
-
...this.options.fastifyOptions
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
async startFastify() {
|
|
46
|
-
await this.fastify.listen({
|
|
47
|
-
host: this.options.host || '0.0.0.0',
|
|
48
|
-
port: this.options.port
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
async prepareRoutes() {
|
|
52
|
-
// @ts-ignore
|
|
53
|
-
const {
|
|
54
|
-
routes
|
|
55
|
-
} = await require('.x/routes');
|
|
56
|
-
this.routes = routes;
|
|
57
|
-
}
|
|
58
|
-
async applyHooks() {
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
await require('.x/hooks');
|
|
61
|
-
}
|
|
62
|
-
applyServices() {
|
|
63
|
-
x.register(...(this.options.services || []));
|
|
64
|
-
}
|
|
65
|
-
applyPlugins() {
|
|
66
|
-
const plugins = this.options.plugins || [];
|
|
67
|
-
for (const plugin of plugins) {
|
|
68
|
-
plugin.register(this.fastify);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
async applyRoutes() {
|
|
72
|
-
await this.fastify.register(async fastify => {
|
|
73
|
-
const appUrl = x.env.APP_URL.replace(/\/+$/, '');
|
|
74
|
-
const routeMap = keyBy(this.routes, item => item.path);
|
|
75
|
-
const handleRoute = async (item, req, res, path) => {
|
|
76
|
-
const handlerOptions = item.handler.options;
|
|
77
|
-
const handlerMethod = handlerOptions.requestMethod || 'POST';
|
|
78
|
-
const isWS = handlerMethod === 'WS';
|
|
79
|
-
const url = `${appUrl}${
|
|
80
|
-
// 结构:/test/sss?x=2
|
|
81
|
-
path ?? (isWS ? res.url : req.url)}`;
|
|
82
|
-
if (isWS) {
|
|
83
|
-
await item.handler.handle(undefined, {
|
|
84
|
-
traceId: cuid2(),
|
|
85
|
-
url: url,
|
|
86
|
-
headers: res.headers,
|
|
87
|
-
setHeader: noop,
|
|
88
|
-
redirect: noop,
|
|
89
|
-
ws: req,
|
|
90
|
-
req: res,
|
|
91
|
-
res: {}
|
|
92
|
-
});
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
let files = {};
|
|
96
|
-
if (handlerMethod === 'FILE') {
|
|
97
|
-
const part = await req.file();
|
|
98
|
-
files = Object.keys(part.fields).reduce((res, name) => {
|
|
99
|
-
res[name] = castArray(part.fields[name]).map(item => item.file ? item : item.value)[0];
|
|
100
|
-
return res;
|
|
101
|
-
}, {});
|
|
102
|
-
}
|
|
103
|
-
const data = await item.handler.handle(handlerMethod === 'ANY' ? {} : {
|
|
104
|
-
// @ts-ignore
|
|
105
|
-
...req.params,
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
...req.query,
|
|
108
|
-
// @ts-ignore
|
|
109
|
-
...req.body,
|
|
110
|
-
...files
|
|
111
|
-
}, {
|
|
112
|
-
traceId: cuid2(),
|
|
113
|
-
url,
|
|
114
|
-
headers: req.headers,
|
|
115
|
-
setHeader: (k, v) => res.header(k, v),
|
|
116
|
-
redirect: (url, permanently) => res.redirect(url, permanently ? 301 : 302),
|
|
117
|
-
ws: undefined,
|
|
118
|
-
req: req,
|
|
119
|
-
res: res
|
|
120
|
-
});
|
|
121
|
-
return data;
|
|
122
|
-
};
|
|
123
|
-
for (const item of this.routes) {
|
|
124
|
-
const handlerOptions = item.handler.options;
|
|
125
|
-
const handlerMethod = handlerOptions.requestMethod || 'POST';
|
|
126
|
-
const isWS = handlerMethod === 'WS';
|
|
127
|
-
const serverMethod = isWS ? 'GET' : HandlerMethodToHttpMethod[handlerMethod];
|
|
128
|
-
fastify.route({
|
|
129
|
-
method: handlerMethod === 'ANY' ? ['GET', 'HEAD', 'TRACE', 'DELETE', 'OPTIONS', 'PATCH', 'PUT', 'POST'] : serverMethod,
|
|
130
|
-
url: item.path,
|
|
131
|
-
constraints: handlerOptions.requestHost ? {
|
|
132
|
-
host: handlerOptions.requestHost
|
|
133
|
-
} : undefined,
|
|
134
|
-
websocket: isWS,
|
|
135
|
-
handler: (req, res) => handleRoute(item, req, res)
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// 静态文件服务
|
|
140
|
-
this.applyStatic();
|
|
141
|
-
|
|
142
|
-
// 接口统一入口
|
|
143
|
-
fastify.route({
|
|
144
|
-
method: 'POST',
|
|
145
|
-
url: '/@',
|
|
146
|
-
handler: async (req, res) => {
|
|
147
|
-
let requestPath = req.headers['x-path'] || '';
|
|
148
|
-
if (!requestPath.startsWith('/')) {
|
|
149
|
-
const [_requestPath, _time] = base64UrlDecode(rot13(requestPath)).split('#');
|
|
150
|
-
if (!_time || Date.now() / 1000 - Number(_time) > 5 * 60) {
|
|
151
|
-
throw new HttpError.Forbidden();
|
|
152
|
-
}
|
|
153
|
-
requestPath = _requestPath;
|
|
154
|
-
}
|
|
155
|
-
if (!requestPath || !routeMap[requestPath]) {
|
|
156
|
-
throw new HttpError.NotFound();
|
|
157
|
-
}
|
|
158
|
-
return handleRoute(routeMap[requestPath], req, res, requestPath);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
// 开发管理入口
|
|
163
|
-
fastify.route({
|
|
164
|
-
method: 'POST',
|
|
165
|
-
url: '/$',
|
|
166
|
-
handler: async req => {
|
|
167
|
-
const payload = req.body;
|
|
168
|
-
if (payload && typeof payload === 'object' && x.env.APP_TOKEN && payload.token === x.env.APP_TOKEN) {
|
|
169
|
-
if (payload.type === 'ping') {
|
|
170
|
-
return 'ping:success';
|
|
171
|
-
} else if (payload.type === 'updateEnv') {
|
|
172
|
-
Object.assign(x.env, payload.data);
|
|
173
|
-
|
|
174
|
-
// 更新静态文件服务
|
|
175
|
-
this.applyStatic();
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
async applyStatic() {
|
|
183
|
-
if (Array.isArray(x.env.APP_STATIC_CONTENT)) {
|
|
184
|
-
const staticContent = x.env.APP_STATIC_CONTENT;
|
|
185
|
-
for (const item of staticContent) {
|
|
186
|
-
const methods = castArray(item.method);
|
|
187
|
-
if (!methods.some(method => this.fastify.hasRoute({
|
|
188
|
-
method,
|
|
189
|
-
url: item.path
|
|
190
|
-
}))) {
|
|
191
|
-
this.fastify.route({
|
|
192
|
-
method: methods,
|
|
193
|
-
url: item.path,
|
|
194
|
-
handler: async (_req, res) => {
|
|
195
|
-
if (!item.contentType && typeof item.content === 'string') {
|
|
196
|
-
res.header('Content-Type', 'plain/text');
|
|
197
|
-
}
|
|
198
|
-
return item.content;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
async startCrons() {
|
|
206
|
-
// @ts-ignore
|
|
207
|
-
await require('.x/crons');
|
|
208
|
-
}
|
|
209
|
-
async applyAutoClose() {
|
|
210
|
-
x.dispose.add(() => this.close());
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
Server.options = {};
|
package/lib/core/types.d.ts
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import type { IncomingHttpHeaders } from 'node:http';
|
|
2
|
-
import type { MultipartFile } from '@fastify/multipart';
|
|
3
|
-
import type { Queue } from 'bull';
|
|
4
|
-
import type { CronJob } from 'cron';
|
|
5
|
-
import type { FastifyReply, FastifyRequest, FastifyServerOptions } from 'fastify';
|
|
6
|
-
import type { MsValue } from 'vtils';
|
|
7
|
-
import type { AsyncOrSync, LiteralUnion, OneOrMore, RequiredDeep } from 'vtils/types';
|
|
8
|
-
import type * as vae from 'vtils/vae';
|
|
9
|
-
import type { yup } from 'vtils/validator';
|
|
10
|
-
import type { WebSocket } from 'ws';
|
|
11
|
-
import type { BasePlugin } from '../plugins/base';
|
|
12
|
-
import type { BaseService } from '../services/base';
|
|
13
|
-
import type { DisposeService } from '../services/dispose';
|
|
14
|
-
import type { Handler } from './handler';
|
|
15
|
-
export declare namespace XServer {
|
|
16
|
-
type Mode = 'development' | 'production';
|
|
17
|
-
interface Route {
|
|
18
|
-
/**
|
|
19
|
-
* 路径
|
|
20
|
-
*/
|
|
21
|
-
path: string;
|
|
22
|
-
/**
|
|
23
|
-
* 处理器
|
|
24
|
-
*/
|
|
25
|
-
handler: Handler;
|
|
26
|
-
}
|
|
27
|
-
interface Options {
|
|
28
|
-
/**
|
|
29
|
-
* 监听主机
|
|
30
|
-
*/
|
|
31
|
-
host?: string;
|
|
32
|
-
/**
|
|
33
|
-
* 监听端口
|
|
34
|
-
*/
|
|
35
|
-
port: number;
|
|
36
|
-
/**
|
|
37
|
-
* 响应加密算法
|
|
38
|
-
*/
|
|
39
|
-
responseEncryptAlgorithm?: 'simple';
|
|
40
|
-
/**
|
|
41
|
-
* 响应加密密钥
|
|
42
|
-
*/
|
|
43
|
-
responseEncryptKey?: string;
|
|
44
|
-
/**
|
|
45
|
-
* 是否使用异步上下文
|
|
46
|
-
*
|
|
47
|
-
* @default false
|
|
48
|
-
*/
|
|
49
|
-
useAsyncContext?: boolean;
|
|
50
|
-
/**
|
|
51
|
-
* 透传给 Fastify 的选项
|
|
52
|
-
*/
|
|
53
|
-
fastifyOptions?: FastifyServerOptions;
|
|
54
|
-
/**
|
|
55
|
-
* 服务列表
|
|
56
|
-
*/
|
|
57
|
-
services?: BaseService[];
|
|
58
|
-
/**
|
|
59
|
-
* 插件列表
|
|
60
|
-
*/
|
|
61
|
-
plugins?: BasePlugin[];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
export declare namespace XHandler {
|
|
65
|
-
type Method = 'GET' | 'POST' | 'FILE' | 'WS' | 'XML' | 'ANY';
|
|
66
|
-
interface ExtraContext {
|
|
67
|
-
}
|
|
68
|
-
interface Context extends ExtraContext {
|
|
69
|
-
/**
|
|
70
|
-
* 当前请求的跟踪 ID
|
|
71
|
-
*/
|
|
72
|
-
traceId: string;
|
|
73
|
-
/**
|
|
74
|
-
* 当前请求的地址
|
|
75
|
-
*/
|
|
76
|
-
url: string;
|
|
77
|
-
/**
|
|
78
|
-
* 请求头
|
|
79
|
-
*/
|
|
80
|
-
headers: IncomingHttpHeaders;
|
|
81
|
-
/**
|
|
82
|
-
* 设置响应头
|
|
83
|
-
*/
|
|
84
|
-
setHeader: (key: string, value: string) => void;
|
|
85
|
-
/**
|
|
86
|
-
* HTTP 跳转
|
|
87
|
-
*
|
|
88
|
-
* 默认是临时跳转,状态码是 302,
|
|
89
|
-
* 可将第二个参数设为 true 表示永久跳转,状态码是 301
|
|
90
|
-
*/
|
|
91
|
-
redirect: (url: string, permanently?: boolean) => void;
|
|
92
|
-
/**
|
|
93
|
-
* WS
|
|
94
|
-
*/
|
|
95
|
-
ws: WebSocket;
|
|
96
|
-
/**
|
|
97
|
-
* Fastify Request
|
|
98
|
-
*/
|
|
99
|
-
req: FastifyRequest;
|
|
100
|
-
/**
|
|
101
|
-
* Fastify Response
|
|
102
|
-
*/
|
|
103
|
-
res: FastifyReply;
|
|
104
|
-
}
|
|
105
|
-
type Handle<TReqData extends any = void, TResData extends any = void, TReqMethod extends Method = Method> = (
|
|
106
|
-
/**
|
|
107
|
-
* 请求数据,WS 时为一个处理函数
|
|
108
|
-
*/
|
|
109
|
-
data: TReqMethod extends 'WS' ? <T extends keyof TReqData>(type: T, fn: (payload: {
|
|
110
|
-
data: TReqData[T]['request'];
|
|
111
|
-
send: (data: TReqData[T]['response']) => void;
|
|
112
|
-
dispose: DisposeService;
|
|
113
|
-
}) => any) => void : TReqData,
|
|
114
|
-
/**
|
|
115
|
-
* 请求上下文
|
|
116
|
-
*/
|
|
117
|
-
ctx: Context) => AsyncOrSync<TResData>;
|
|
118
|
-
interface ExtraOptions {
|
|
119
|
-
}
|
|
120
|
-
interface Options<TReqData extends any = void, TResData extends any = void, TReqMethod extends Method = Method, TReqDataRequired = RequiredDeep<TReqData>> extends ExtraOptions {
|
|
121
|
-
/**
|
|
122
|
-
* 请求方法
|
|
123
|
-
*
|
|
124
|
-
* @default POST
|
|
125
|
-
*/
|
|
126
|
-
requestMethod?: TReqMethod;
|
|
127
|
-
/**
|
|
128
|
-
* 请求 Host
|
|
129
|
-
*/
|
|
130
|
-
requestHost?: string | RegExp;
|
|
131
|
-
/**
|
|
132
|
-
* 请求路径
|
|
133
|
-
*/
|
|
134
|
-
requestPath?: OneOrMore<string>;
|
|
135
|
-
/**
|
|
136
|
-
* 解析请求数据
|
|
137
|
-
*/
|
|
138
|
-
parseRequestData?: (data: any, ctx: Context) => any;
|
|
139
|
-
/**
|
|
140
|
-
* 是否打包返回数据
|
|
141
|
-
*
|
|
142
|
-
* @default false
|
|
143
|
-
*/
|
|
144
|
-
responseDataPack?: boolean;
|
|
145
|
-
/**
|
|
146
|
-
* 是否混淆返回数据
|
|
147
|
-
*
|
|
148
|
-
* @default false
|
|
149
|
-
*/
|
|
150
|
-
responseDataObfuscate?: boolean;
|
|
151
|
-
responseDataEncrypt?: boolean;
|
|
152
|
-
/**
|
|
153
|
-
* 响应的 Content-Type 头
|
|
154
|
-
*/
|
|
155
|
-
responseContentType?: LiteralUnion<'text/html', string>;
|
|
156
|
-
/**
|
|
157
|
-
* 请求数据验证结构(yup)
|
|
158
|
-
*/
|
|
159
|
-
requestDataSchema?: (_: typeof yup) => yup.GetSchema<TReqDataRequired>;
|
|
160
|
-
/**
|
|
161
|
-
* 请求数据验证结构(vae)
|
|
162
|
-
*/
|
|
163
|
-
requestDataSchemaVae?: vae.VaeSchemaOf<TReqDataRequired> | ((_: vae.VaeSchemaBuilder<TReqDataRequired>) => vae.VaeSchemaOf<TReqDataRequired> | vae.VaeObjectSchemaShapeOf<TReqDataRequired>);
|
|
164
|
-
/**
|
|
165
|
-
* 是否使用异步上下文
|
|
166
|
-
*
|
|
167
|
-
* @default 默认为服务的设置
|
|
168
|
-
*/
|
|
169
|
-
useAsyncContext?: boolean;
|
|
170
|
-
/**
|
|
171
|
-
* 并发控制
|
|
172
|
-
*/
|
|
173
|
-
concurrency?: number | {
|
|
174
|
-
/** 并发数量 */
|
|
175
|
-
count?: number;
|
|
176
|
-
/** 分组函数 */
|
|
177
|
-
groupBy?: (data: TReqData, ctx: Context) => string;
|
|
178
|
-
};
|
|
179
|
-
/**
|
|
180
|
-
* 处理器
|
|
181
|
-
*/
|
|
182
|
-
handle: Handle<TReqData, TResData, TReqMethod>;
|
|
183
|
-
}
|
|
184
|
-
type Hook = (options: Options, ...args: Parameters<Handle>) => AsyncOrSync<void>;
|
|
185
|
-
}
|
|
186
|
-
export declare namespace XTask {
|
|
187
|
-
interface TaskOptions<T> {
|
|
188
|
-
/**
|
|
189
|
-
* 任务名称
|
|
190
|
-
*/
|
|
191
|
-
name: string;
|
|
192
|
-
/**
|
|
193
|
-
* 并发数量
|
|
194
|
-
*
|
|
195
|
-
* @default 1
|
|
196
|
-
*/
|
|
197
|
-
concurrency?: number;
|
|
198
|
-
/**
|
|
199
|
-
* 处理器
|
|
200
|
-
*/
|
|
201
|
-
handle: (data: T) => any;
|
|
202
|
-
}
|
|
203
|
-
interface Task<T> extends Queue<T> {
|
|
204
|
-
}
|
|
205
|
-
type SliceTaskOptions<T, K> = {
|
|
206
|
-
/**
|
|
207
|
-
* 任务名称
|
|
208
|
-
*/
|
|
209
|
-
name: string;
|
|
210
|
-
/**
|
|
211
|
-
* 持续时长
|
|
212
|
-
*/
|
|
213
|
-
duration?: MsValue | ((key: K) => MsValue);
|
|
214
|
-
/**
|
|
215
|
-
* 阈值数量
|
|
216
|
-
*/
|
|
217
|
-
threshold?: number | ((key: K) => number);
|
|
218
|
-
/**
|
|
219
|
-
* 阈值数量超时时间
|
|
220
|
-
*/
|
|
221
|
-
thresholdTimeout?: MsValue | ((key: K) => MsValue);
|
|
222
|
-
/**
|
|
223
|
-
* 处理器
|
|
224
|
-
*/
|
|
225
|
-
handle: (data: T[], key: K) => any;
|
|
226
|
-
};
|
|
227
|
-
interface SliceTaskNoKey<T> {
|
|
228
|
-
add: (data: T, options?: {
|
|
229
|
-
duration?: MsValue;
|
|
230
|
-
threshold?: number;
|
|
231
|
-
thresholdTimeout?: MsValue;
|
|
232
|
-
}) => Promise<void>;
|
|
233
|
-
}
|
|
234
|
-
interface SliceTask<T, K> {
|
|
235
|
-
add: (data: T, options: {
|
|
236
|
-
key: K;
|
|
237
|
-
duration?: MsValue;
|
|
238
|
-
threshold?: number;
|
|
239
|
-
thresholdTimeout?: MsValue;
|
|
240
|
-
delay?: MsValue;
|
|
241
|
-
}) => Promise<void>;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
export declare namespace XCron {
|
|
245
|
-
interface Options {
|
|
246
|
-
/**
|
|
247
|
-
* 定时语法
|
|
248
|
-
*
|
|
249
|
-
* @see https://crontab.guru/
|
|
250
|
-
* @see https://crontab.cronhub.io/
|
|
251
|
-
*/
|
|
252
|
-
expression: string;
|
|
253
|
-
/**
|
|
254
|
-
* 是否初始化后执行一次
|
|
255
|
-
*/
|
|
256
|
-
runOnInit?: boolean;
|
|
257
|
-
/**
|
|
258
|
-
* 处理器
|
|
259
|
-
*/
|
|
260
|
-
handle: () => any;
|
|
261
|
-
}
|
|
262
|
-
interface Cron extends CronJob {
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
export type XFile = MultipartFile;
|
package/lib/core/types.js
DELETED