@x-9lab/xlab 1.6.1 → 2.0.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/@types/cluster.d.ts +15 -3
- package/@types/components/common/index.d.ts +1 -2
- package/@types/components/cron/index.d.ts +4 -4
- package/@types/components/log/index.d.ts +37 -2
- package/@types/config/index.d.ts +9 -5
- package/@types/custom.d.ts +25 -3
- package/@types/dot-file.d.ts +6 -0
- package/@types/global.d.ts +44 -56
- package/@types/index.d.ts +18 -0
- package/@types/init-env.d.ts +3 -1
- package/@types/middleware/handle-pre-dir.d.ts +1 -5
- package/@types/middleware/request-filter.d.ts +0 -1
- package/@types/middleware/service-mark.d.ts +1 -6
- package/@types/router.d.ts +25 -0
- package/@types/server.d.ts +28 -6
- package/MIGRATION.md +182 -0
- package/README.md +105 -86
- package/dist/@config/config.dev.js +7 -3
- package/dist/@config/config.js +7 -4
- package/dist/@config/config.sand.js +7 -3
- package/dist/bin/watch.js +36 -16
- package/dist/cluster.js +121 -44
- package/dist/components/assets/index.js +9 -5
- package/dist/components/cluster/index.js +17 -4
- package/dist/components/common/index.js +65 -45
- package/dist/components/cron/index.js +50 -27
- package/dist/components/header/index.js +32 -17
- package/dist/components/header/time.js +6 -2
- package/dist/components/index.js +1 -1
- package/dist/components/log/index.js +91 -87
- package/dist/components/mime/index.js +6 -2
- package/dist/components/return-code/index.js +33 -18
- package/dist/components/uuid/index.js +22 -13
- package/dist/config/getEnv.js +9 -5
- package/dist/config/index.js +98 -66
- package/dist/config/process-custom-config-files.js +26 -22
- package/dist/config/process-def-config-file.js +15 -11
- package/dist/custom.js +77 -28
- package/dist/default-x-config.js +9 -5
- package/dist/dot-file.js +42 -17
- package/dist/global.js +37 -31
- package/dist/index.js +100 -0
- package/dist/init-env.js +17 -9
- package/dist/middleware/@bin/html-filter.js +19 -7
- package/dist/middleware/bad-request.js +12 -8
- package/dist/middleware/compress.js +11 -7
- package/dist/middleware/cors.js +20 -7
- package/dist/middleware/fresh-filter.js +13 -7
- package/dist/middleware/handle-pre-dir.js +22 -17
- package/dist/middleware/request-filter.js +39 -25
- package/dist/middleware/service-mark.js +22 -25
- package/dist/middlewares.js +22 -20
- package/dist/router.js +174 -141
- package/dist/server.js +202 -93
- package/package.json +25 -29
- package/@types/business/utils/cookie/1.1.0/clean/index.d.ts +0 -3
- package/@types/business/utils/cookie/1.1.0/clean/js/index.d.ts +0 -2
- package/@types/components/cache/index.d.ts +0 -2
- package/@types/components/cache/lru.d.ts +0 -21
- package/@types/components/html-processor/index.d.ts +0 -9
- package/@types/components/injection/index.d.ts +0 -25
- package/@types/components/js-processor/index.d.ts +0 -5
- package/@types/components/md5/index.d.ts +0 -2
- package/@types/components/platform/index.d.ts +0 -21
- package/@types/components/proxy/index.d.ts +0 -26
- package/@types/components/querystring/index.d.ts +0 -25
- package/@types/components/redirect/index.d.ts +0 -11
- package/@types/components/request/helper.d.ts +0 -3
- package/@types/components/request/index.d.ts +0 -51
- package/@types/components/request/resolve-uri.d.ts +0 -6
- package/@types/components/version/index.d.ts +0 -26
- package/@types/env.d.ts +0 -1
package/dist/server.js
CHANGED
|
@@ -2,120 +2,229 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get app () {
|
|
13
|
+
return app;
|
|
14
|
+
},
|
|
15
|
+
get boot () {
|
|
16
|
+
return boot;
|
|
17
|
+
},
|
|
18
|
+
get default () {
|
|
19
|
+
return _default;
|
|
20
|
+
},
|
|
21
|
+
get exit () {
|
|
22
|
+
return exit;
|
|
23
|
+
},
|
|
24
|
+
get getApp () {
|
|
25
|
+
return getApp;
|
|
26
|
+
},
|
|
27
|
+
get shutdown () {
|
|
28
|
+
return shutdown;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const _log = require("./components/log");
|
|
32
|
+
const _cron = require("./components/cron");
|
|
33
|
+
const _defaultxconfig = /*#__PURE__*/ _interop_require_default(require("./default-x-config"));
|
|
34
|
+
const _dotfile = require("./dot-file");
|
|
35
|
+
const _config = /*#__PURE__*/ _interop_require_wildcard(require("./config"));
|
|
36
|
+
const _custom = require("./custom");
|
|
37
|
+
const _initenv = /*#__PURE__*/ _interop_require_default(require("./init-env"));
|
|
38
|
+
const _cluster = /*#__PURE__*/ _interop_require_wildcard(require("./cluster"));
|
|
39
|
+
const _router = /*#__PURE__*/ _interop_require_default(require("./router"));
|
|
40
|
+
const _middlewares = /*#__PURE__*/ _interop_require_default(require("./middlewares"));
|
|
41
|
+
const _badrequest = /*#__PURE__*/ _interop_require_default(require("./middleware/bad-request"));
|
|
42
|
+
const _utils = require("@x-drive/utils");
|
|
43
|
+
const _koastatic = /*#__PURE__*/ _interop_require_default(require("koa-static"));
|
|
44
|
+
const _koarouter = /*#__PURE__*/ _interop_require_default(require("koa-router"));
|
|
45
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
46
|
+
const _koa = /*#__PURE__*/ _interop_require_default(require("koa"));
|
|
47
|
+
function _interop_require_default(obj) {
|
|
23
48
|
return obj && obj.__esModule ? obj : {
|
|
24
49
|
default: obj
|
|
25
50
|
};
|
|
26
51
|
}
|
|
27
|
-
function
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
52
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
53
|
+
if (typeof WeakMap !== "function") return null;
|
|
54
|
+
var cacheBabelInterop = new WeakMap();
|
|
55
|
+
var cacheNodeInterop = new WeakMap();
|
|
56
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
57
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
58
|
+
})(nodeInterop);
|
|
59
|
+
}
|
|
60
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
61
|
+
if (!nodeInterop && obj && obj.__esModule) return obj;
|
|
62
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") return {
|
|
63
|
+
default: obj
|
|
64
|
+
};
|
|
65
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
66
|
+
if (cache && cache.has(obj)) return cache.get(obj);
|
|
67
|
+
var newObj = {
|
|
68
|
+
__proto__: null
|
|
69
|
+
};
|
|
70
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
71
|
+
for(var key in obj){
|
|
72
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
73
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
74
|
+
if (desc && (desc.get || desc.set)) Object.defineProperty(newObj, key, desc);
|
|
75
|
+
else newObj[key] = obj[key];
|
|
43
76
|
}
|
|
44
|
-
newObj.default = obj;
|
|
45
|
-
return newObj;
|
|
46
77
|
}
|
|
78
|
+
newObj.default = obj;
|
|
79
|
+
if (cache) cache.set(obj, newObj);
|
|
80
|
+
return newObj;
|
|
47
81
|
}
|
|
48
|
-
process.env.TZ = _config.default.timezone;
|
|
49
82
|
const logger = _log.globalLog.getLogger("system");
|
|
50
|
-
|
|
51
|
-
// 只在 master 上输出的日志
|
|
52
|
-
global.masterLog = _config.log;
|
|
53
|
-
// 服务实例
|
|
54
|
-
const app = new _koa.default();
|
|
55
|
-
/**
|
|
56
|
-
* 获取应用实例对象
|
|
57
|
-
* @deprecated v1.7.0 后将弃用,请直接从模块中引用
|
|
58
|
-
* @return 实例对象
|
|
59
|
-
*/ global.getApp = function() {
|
|
60
|
-
return app;
|
|
61
|
-
};
|
|
83
|
+
/**服务实例 */ const app = new _koa.default();
|
|
62
84
|
// 不输出X-Powered-By
|
|
63
85
|
// @ts-ignore
|
|
64
86
|
app.poweredBy = false;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
87
|
+
/**
|
|
88
|
+
* 获取应用实例对象
|
|
89
|
+
* @return 实例对象
|
|
90
|
+
*/ function getApp() {
|
|
91
|
+
return app;
|
|
68
92
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
93
|
+
/**http 服务实例, master fork 模式下为空 */ var server = null;
|
|
94
|
+
/**是否已启动 */ var booted = false;
|
|
95
|
+
/**是否正在退出 */ var shuttingDown = false;
|
|
96
|
+
/**
|
|
97
|
+
* 关闭 http 服务, 等待在途请求结束, 超时强制返回
|
|
98
|
+
* @param timeout 超时时间(毫秒)
|
|
99
|
+
*/ function closeServer(timeout) {
|
|
100
|
+
return new Promise(function(resolve) {
|
|
101
|
+
const timer = setTimeout(function() {
|
|
102
|
+
logger.warn(`等待在途请求结束超时(${timeout}ms), 强制关闭`);
|
|
103
|
+
resolve();
|
|
104
|
+
}, timeout);
|
|
105
|
+
server.close(function() {
|
|
106
|
+
clearTimeout(timer);
|
|
107
|
+
resolve();
|
|
108
|
+
});
|
|
109
|
+
// 主动断开空闲的 keep-alive 连接, 避免拖住 close 回调
|
|
110
|
+
if ((0, _utils.isExecutable)(server.closeIdleConnections)) {
|
|
111
|
+
server.closeIdleConnections();
|
|
112
|
+
}
|
|
113
|
+
});
|
|
80
114
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
115
|
+
/**
|
|
116
|
+
* 退出服务
|
|
117
|
+
|
|
118
|
+
* 停止定时任务 -> 通知 worker 退出(master) -> 等待在途请求 -> 执行 shutdown 钩子 -> 退出进程
|
|
119
|
+
* @param code 进程退出码
|
|
120
|
+
*/ async function shutdown(code = 0) {
|
|
121
|
+
if (shuttingDown) {
|
|
122
|
+
return;
|
|
84
123
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
124
|
+
shuttingDown = true;
|
|
125
|
+
const config = (0, _config.get)();
|
|
126
|
+
(0, _config.log)("system", `Shutting down (pid ${process.pid}) ...`);
|
|
127
|
+
try {
|
|
128
|
+
(0, _cron.kill)();
|
|
129
|
+
if (config.isMaster && config.workers) {
|
|
130
|
+
await (0, _cluster.shutdownWorkers)(config.shutdownTimeout);
|
|
91
131
|
}
|
|
132
|
+
if (server) {
|
|
133
|
+
await closeServer(config.shutdownTimeout || 10 * 1000);
|
|
134
|
+
}
|
|
135
|
+
await (0, _custom.runShutdown)();
|
|
136
|
+
} catch (e) {
|
|
137
|
+
logger.error("Shutdown error:", e);
|
|
92
138
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
(0, _cron).on(_path.default.resolve(process.cwd(), _defaultXConfig.default.businessDir, "cron"));
|
|
101
|
-
}
|
|
139
|
+
process.exit(code);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* 退出服务
|
|
143
|
+
* @deprecated 请使用 shutdown
|
|
144
|
+
*/ function exit() {
|
|
145
|
+
shutdown();
|
|
102
146
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
147
|
+
/**
|
|
148
|
+
* 启动服务
|
|
149
|
+
|
|
150
|
+
* 按固定顺序执行启动阶段:
|
|
151
|
+
* initEnv -> loadConfig -> dotFile -> custom(setup) -> middleware
|
|
152
|
+
* -> router -> static/badRequest -> cron -> listen -> custom(ready)
|
|
153
|
+
*/ async function boot() {
|
|
154
|
+
if (booted) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
booted = true;
|
|
158
|
+
// 1. 业务环境预处理(@server/@env)
|
|
159
|
+
(0, _initenv.default)();
|
|
160
|
+
// 2. 配置装载
|
|
161
|
+
const config = (0, _config.default)();
|
|
162
|
+
process.env.TZ = config.timezone;
|
|
163
|
+
// 3. .xlab 环境数据
|
|
164
|
+
(0, _dotfile.processDotFile)(config.env, logger);
|
|
165
|
+
// 4. 自定义初始化(setup 钩子)
|
|
166
|
+
if (config.custom) {
|
|
167
|
+
await (0, _custom.loadCustom)();
|
|
168
|
+
}
|
|
169
|
+
// 5. 中间件
|
|
170
|
+
(0, _middlewares.default)(app);
|
|
171
|
+
// 6. 业务路由
|
|
172
|
+
const koaRouter = new _koarouter.default();
|
|
173
|
+
app.use(koaRouter.routes());
|
|
174
|
+
(0, _router.default)(koaRouter);
|
|
175
|
+
// 7. 静态文件服务
|
|
176
|
+
var staticServeOpts = {};
|
|
177
|
+
if (config.isProd) {
|
|
178
|
+
staticServeOpts.maxage = config.staticMaxage;
|
|
179
|
+
}
|
|
180
|
+
staticServeOpts.setHeaders = function(res, filePath) {
|
|
181
|
+
if (config.isProd && config.staticHtmlFileMaxage && filePath.endsWith(".html")) {
|
|
182
|
+
res.setHeader("Cache-Control", `max-age=${config.staticHtmlFileMaxage}`);
|
|
183
|
+
}
|
|
184
|
+
if (config.staticCros) {
|
|
185
|
+
const { origin } = res.req.headers;
|
|
186
|
+
if (origin) {
|
|
187
|
+
res.setHeader("X-Cros-Static", origin);
|
|
188
|
+
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
189
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
app.use((0, _koastatic.default)(_path.default.resolve(process.cwd(), config.root), staticServeOpts));
|
|
194
|
+
// 8. 异常状态处理中间件
|
|
195
|
+
app.use(_badrequest.default);
|
|
196
|
+
// 9. 定时任务
|
|
197
|
+
if (config.enableCron) {
|
|
198
|
+
if (config.isMaster || config.enableWorkerCron) {
|
|
199
|
+
(0, _cron.on)(_path.default.resolve(process.cwd(), _defaultxconfig.default.businessDir, "cron"));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
// 10. 监听
|
|
203
|
+
server = (0, _cluster.default)(app);
|
|
204
|
+
// 11. 进程信号与异常处理
|
|
205
|
+
if (!config.isMaster) {
|
|
206
|
+
// master 异常退出(如被强杀)导致通道断开时, worker 自行优雅退出,
|
|
207
|
+
// 防止孤儿进程继续占用端口对外服务
|
|
208
|
+
process.on("disconnect", function() {
|
|
209
|
+
shutdown();
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
process.on("SIGTERM", function() {
|
|
213
|
+
shutdown();
|
|
214
|
+
}).on("SIGINT", function() {
|
|
215
|
+
shutdown();
|
|
216
|
+
}).on("uncaughtException", (err)=>{
|
|
106
217
|
logger.error(`uncaughtException:${err.message}\n`, err.stack);
|
|
107
218
|
}).on("unhandledRejection", (err)=>{
|
|
108
219
|
logger.error(`unhandledRejection:${err.message}\n`, err.stack);
|
|
109
220
|
});
|
|
221
|
+
// 12. ready 钩子
|
|
222
|
+
await (0, _custom.runReady)();
|
|
110
223
|
}
|
|
111
|
-
|
|
112
|
-
process.exit();
|
|
113
|
-
}
|
|
114
|
-
var _default = app;
|
|
115
|
-
exports.default = _default;
|
|
224
|
+
const _default = app;
|
|
116
225
|
if (require.main === module) {
|
|
117
|
-
boot()
|
|
226
|
+
boot().catch(function(err) {
|
|
227
|
+
logger.error("Boot failed:", err);
|
|
228
|
+
process.exit(1);
|
|
229
|
+
});
|
|
118
230
|
}
|
|
119
|
-
exports.app = app;
|
|
120
|
-
exports.boot = boot;
|
|
121
|
-
exports.exit = exit;
|
package/package.json
CHANGED
|
@@ -1,49 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-9lab/xlab",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "9lab 服务端模块",
|
|
5
|
-
"versionDesc": "
|
|
5
|
+
"versionDesc": "watch 退出信号级联与 worker 孤儿防护;移除 combo 中间件残留",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"dev": "swc src -
|
|
8
|
-
"compile": "swc src -
|
|
7
|
+
"dev": "swc src --copy-files --strip-leading-paths --config-file .swcrc -d dist -w",
|
|
8
|
+
"compile": "swc src --copy-files --strip-leading-paths --config-file .swcrc -d dist",
|
|
9
9
|
"build": "yarn compile && yarn gen-declaration",
|
|
10
10
|
"gen-declaration": "tsc --emitDeclarationOnly",
|
|
11
|
+
"test": "node --test",
|
|
11
12
|
"changelog": "changelog"
|
|
12
13
|
},
|
|
13
14
|
"engines": {
|
|
14
|
-
"node": "
|
|
15
|
+
"node": ">=20.0.0"
|
|
15
16
|
},
|
|
16
|
-
"main": "./dist/
|
|
17
|
-
"types": "./@types/
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./@types/index.d.ts",
|
|
18
19
|
"files": [
|
|
19
20
|
"dist",
|
|
20
|
-
"@types"
|
|
21
|
+
"@types",
|
|
22
|
+
"MIGRATION.md"
|
|
21
23
|
],
|
|
22
24
|
"dependencies": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"liftoff": "4.0.0",
|
|
27
|
-
"minimist": "1.2.6",
|
|
28
|
-
"koa-static": "5.0.0",
|
|
25
|
+
"@x-drive/utils": "1.1.32",
|
|
26
|
+
"koa": "3.2.1",
|
|
27
|
+
"koa-compress": "5.2.2",
|
|
29
28
|
"koa-router": "14.0.0",
|
|
30
|
-
"koa-
|
|
31
|
-
"
|
|
29
|
+
"koa-static": "5.0.0",
|
|
30
|
+
"liftoff": "5.0.1",
|
|
31
|
+
"log4js": "^6.9.1",
|
|
32
|
+
"minimist": "1.2.8"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"should": "11.2.1",
|
|
37
|
-
"nodemon": "2.0.12",
|
|
38
|
-
"chokidar": "3.5.3",
|
|
39
|
-
"@swc/cli": "0.1.57",
|
|
40
|
-
"typescript": "4.3.4",
|
|
41
|
-
"@swc/core": "1.2.171",
|
|
42
|
-
"@types/log4js": "2.3.5",
|
|
43
|
-
"@types/node": "16.11.40",
|
|
44
|
-
"@types/koa-static": "4.0.4",
|
|
35
|
+
"@swc/cli": "^0.7.7",
|
|
36
|
+
"@swc/core": "^1.13.2",
|
|
45
37
|
"@types/koa-router": "7.4.9",
|
|
46
|
-
"@
|
|
38
|
+
"@types/koa-static": "4.0.4",
|
|
39
|
+
"@types/node": "^20.19.0",
|
|
40
|
+
"@x-drive/changelog": "1.1.6",
|
|
41
|
+
"chokidar": "^3.6.0",
|
|
42
|
+
"typescript": "^5.9.2"
|
|
47
43
|
},
|
|
48
44
|
"bin": {
|
|
49
45
|
"xlab": "dist/bin/xlab"
|
|
@@ -52,4 +48,4 @@
|
|
|
52
48
|
"type": "git",
|
|
53
49
|
"url": "git+https://github.com/x-9lab/xlab.git"
|
|
54
50
|
}
|
|
55
|
-
}
|
|
51
|
+
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 生成或获取一个缓存实例
|
|
3
|
-
* @param cacheName 实例名称
|
|
4
|
-
* @param conf 缓存配置,仅在生成的时候有效
|
|
5
|
-
* @return 缓存实例
|
|
6
|
-
*/
|
|
7
|
-
declare function create(cacheName: string, conf: Record<string, XLab.JsonValue>): any;
|
|
8
|
-
export { create };
|
|
9
|
-
/**
|
|
10
|
-
* 获取一个缓存实例
|
|
11
|
-
* @param name 缓存名称
|
|
12
|
-
* @param conf 缓存配置
|
|
13
|
-
*/
|
|
14
|
-
declare function get(name: string, conf?: Record<string, XLab.JsonValue>): any;
|
|
15
|
-
export { get };
|
|
16
|
-
/**
|
|
17
|
-
* 获取当前缓存实例数量
|
|
18
|
-
* @return 缓存数量
|
|
19
|
-
*/
|
|
20
|
-
declare function len(): number;
|
|
21
|
-
export { len };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type Koa from "koa";
|
|
2
|
-
declare type RouteOption = Record<string, string | string[] | Function>;
|
|
3
|
-
interface HtmlProcessorOptions {
|
|
4
|
-
route?: RouteOption;
|
|
5
|
-
}
|
|
6
|
-
declare function htmlProcessor(pathname: string, options: HtmlProcessorOptions, context: Koa.Context): string;
|
|
7
|
-
declare function init(): void;
|
|
8
|
-
export { init };
|
|
9
|
-
export { htmlProcessor };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type Koa from "koa";
|
|
2
|
-
/**
|
|
3
|
-
* 数据注入方法
|
|
4
|
-
* @param html 待处理的字符串
|
|
5
|
-
* @param req 请求对象
|
|
6
|
-
* @return 处理完的字符串
|
|
7
|
-
*/
|
|
8
|
-
declare function inject(html: string, req: Koa.Context): string;
|
|
9
|
-
export { inject };
|
|
10
|
-
/**
|
|
11
|
-
* 添加一个字段到缓存对象
|
|
12
|
-
* @param key 字段名
|
|
13
|
-
* @param val 数据
|
|
14
|
-
* @return 存储的数据
|
|
15
|
-
*/
|
|
16
|
-
declare function add(key: string, val: XLab.JsonValue): any;
|
|
17
|
-
export { add };
|
|
18
|
-
/**
|
|
19
|
-
* 修改一个字段
|
|
20
|
-
* @param key 字段名
|
|
21
|
-
* @param val 数据
|
|
22
|
-
* @return 存储的数据
|
|
23
|
-
*/
|
|
24
|
-
declare function modify(key: string, val: XLab.JsonValue): boolean;
|
|
25
|
-
export { modify };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
interface IPlat {
|
|
2
|
-
/**平台类型,mobile 或 desktop */
|
|
3
|
-
is: string;
|
|
4
|
-
/**是否是微信 */
|
|
5
|
-
wechat?: boolean;
|
|
6
|
-
/**是否是支付宝 */
|
|
7
|
-
alipay?: boolean;
|
|
8
|
-
/**是否是微博 */
|
|
9
|
-
weibo?: boolean;
|
|
10
|
-
/**是否是 Windows 系统 */
|
|
11
|
-
win?: boolean;
|
|
12
|
-
/**是否是 Mac 系统 */
|
|
13
|
-
mac?: boolean;
|
|
14
|
-
/**是否是 Linux 系统 */
|
|
15
|
-
linux?: string;
|
|
16
|
-
/**操作系统信息 */
|
|
17
|
-
os?: string;
|
|
18
|
-
}
|
|
19
|
-
export type { IPlat };
|
|
20
|
-
declare function check(ua: string): IPlat;
|
|
21
|
-
export { check };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type Koa from "koa";
|
|
2
|
-
/**代理配置项 */
|
|
3
|
-
interface IProxyOption {
|
|
4
|
-
/**代理目标 */
|
|
5
|
-
target: string;
|
|
6
|
-
/**代理域名 */
|
|
7
|
-
host: string;
|
|
8
|
-
}
|
|
9
|
-
declare module "http" {
|
|
10
|
-
interface IncomingMessage {
|
|
11
|
-
/**代理类型 */
|
|
12
|
-
proxyType: string;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* 设置代理配置
|
|
17
|
-
* @param type 代理配置名称
|
|
18
|
-
* @param options 配置信息
|
|
19
|
-
*/
|
|
20
|
-
declare function set(type: string, options: IProxyOption | string): IProxyOption;
|
|
21
|
-
export { set };
|
|
22
|
-
/**
|
|
23
|
-
* web 代理
|
|
24
|
-
*/
|
|
25
|
-
declare function web(reqObj: Koa.Context, headers: any): Promise<unknown>;
|
|
26
|
-
export { web };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import qs from "querystring";
|
|
3
|
-
/**
|
|
4
|
-
* 将 URL 参数转换为字符串
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* query2string({"pf":"145","ss":"320x240"});
|
|
8
|
-
* query2string({"pf":"145","ss":"320x240"},["pf"]);
|
|
9
|
-
* query2string({"pf":"145","ss":"320x240"},{"fr":"android"});
|
|
10
|
-
* query2string({"pf":"145","ss":"320x240"},{"fr":"android"},["fr"]);
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
declare function query2string(...args: Array<XLab.JsonObject | string[]>): string;
|
|
14
|
-
export { query2string };
|
|
15
|
-
/**
|
|
16
|
-
* 字符串转成参数对象
|
|
17
|
-
* @param qString 参数字符串
|
|
18
|
-
* @return 处理完的对象
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* string2query("pf=145&ss=320x240");
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
declare function string2query(qString: string): qs.ParsedUrlQuery;
|
|
25
|
-
export { string2query };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { ParsedUrlQuery } from "querystring";
|
|
3
|
-
import type Koa from "koa";
|
|
4
|
-
declare function by302(context: Koa.Context, url: string): void;
|
|
5
|
-
export { by302 };
|
|
6
|
-
declare function byJS(context: Koa.Context, url: string, msg: string, origin: string): void;
|
|
7
|
-
export { byJS };
|
|
8
|
-
declare function byMeta(context: Koa.Context, url: string): void;
|
|
9
|
-
export { byMeta };
|
|
10
|
-
declare function makeRedirectUrl(query: ParsedUrlQuery, url: string): string;
|
|
11
|
-
export { makeRedirectUrl };
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { RequestInit, Response } from "node-fetch";
|
|
2
|
-
/**支持的返回数据类型 */
|
|
3
|
-
declare type IFetchType = "text" | "json" | "blob" | "buffer" | "arrayBuffer";
|
|
4
|
-
/**请求配置 */
|
|
5
|
-
interface IFetchConfig extends Partial<Omit<RequestInit, "body" | "method">> {
|
|
6
|
-
/**数据返回类型 */
|
|
7
|
-
type?: IFetchType;
|
|
8
|
-
/**是否强制同源 */
|
|
9
|
-
sameOrigin?: boolean;
|
|
10
|
-
/**请求自动重试次数 */
|
|
11
|
-
retry?: number;
|
|
12
|
-
/**自动重试间隔时间 */
|
|
13
|
-
retryDelay?: number;
|
|
14
|
-
/**是否自动追加随机数retry,默认 false */
|
|
15
|
-
random?: boolean;
|
|
16
|
-
/**数据返回时的钩子 */
|
|
17
|
-
onResponse?: (res?: Response) => Promise<unknown>;
|
|
18
|
-
}
|
|
19
|
-
export type { IFetchConfig };
|
|
20
|
-
/**给指定对象增加一个随机字符串 */
|
|
21
|
-
declare function setRandomStr(query: any): void;
|
|
22
|
-
export { setRandomStr };
|
|
23
|
-
/**设置默认 Headers */
|
|
24
|
-
declare function setDefHeaders(headers: Record<string, any>): void;
|
|
25
|
-
export { setDefHeaders };
|
|
26
|
-
/**
|
|
27
|
-
* 获取数据
|
|
28
|
-
* @param type 请求类型
|
|
29
|
-
* @param uri 请求地址
|
|
30
|
-
* @param query 请求参数
|
|
31
|
-
* @param data 发送数据
|
|
32
|
-
* @param config 请求配置
|
|
33
|
-
* @param needProcessConfig 是否需要处理配置
|
|
34
|
-
*/
|
|
35
|
-
declare function httpFetch<T = unknown>(type: string, uri: string, query?: Record<string, any>, data?: any, config?: IFetchConfig, retry?: number, needProcessConfig?: boolean): Promise<T>;
|
|
36
|
-
export { httpFetch as fetch };
|
|
37
|
-
/**
|
|
38
|
-
* 发起一个 get 请求
|
|
39
|
-
* @param uri 请求地址
|
|
40
|
-
* @param query 请求参数
|
|
41
|
-
*/
|
|
42
|
-
declare function requsetGet<T = unknown>(uri: string, query?: Record<string, any>, config?: IFetchConfig): Promise<T>;
|
|
43
|
-
export { requsetGet as get };
|
|
44
|
-
/**
|
|
45
|
-
* 发起一个 post 请求
|
|
46
|
-
* @param uri 请求地址
|
|
47
|
-
* @param query 请求参数
|
|
48
|
-
* @param data 请求数据
|
|
49
|
-
*/
|
|
50
|
-
declare function requestPost<T>(uri: string, query?: any, data?: any, config?: IFetchConfig): Promise<T>;
|
|
51
|
-
export { requestPost as post };
|