k99 0.2.0 → 0.3.0-beta.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/LICENSE +1 -1
- package/README.md +8 -0
- package/README.zh.md +8 -0
- package/browser/package.json +8 -0
- package/browser/types.d.ts +20 -0
- package/cli/command/create.js +1 -2
- package/cli/command/index.js +1 -2
- package/cli/command/init.js +3 -5
- package/cli/command/start.js +9 -10
- package/cli/index.js +3 -4
- package/cli/opt/bind.js +1 -2
- package/cli/opt/index.js +1 -2
- package/cli/opt/listen.js +1 -2
- package/cli/opt/path.js +1 -2
- package/cli/opt/port.js +1 -2
- package/cli/opt/show-router.js +1 -2
- package/dist/k99.browser.js +3110 -0
- package/dist/k99.browser.min.js +6 -0
- package/dist/k99.esm.js +3082 -0
- package/dist/k99.esm.min.js +6 -0
- package/dist/k99.js +3104 -0
- package/dist/k99.mjs +3082 -0
- package/dist/k99Browser.browser.js +490 -0
- package/dist/k99Browser.browser.min.js +6 -0
- package/dist/k99Browser.esm.js +475 -0
- package/dist/k99Browser.esm.min.js +6 -0
- package/dist/k99Browser.js +484 -0
- package/dist/k99Browser.mjs +475 -0
- package/dist/k99Services.browser.js +145 -0
- package/dist/k99Services.browser.min.js +6 -0
- package/dist/k99Services.esm.js +136 -0
- package/dist/k99Services.esm.min.js +6 -0
- package/dist/k99Services.js +141 -0
- package/dist/k99Services.mjs +136 -0
- package/node/index.js +1386 -0
- package/node/index.mjs +1350 -0
- package/node/package.json +5 -0
- package/node/types.d.ts +166 -0
- package/package.json +77 -11
- package/services/package.json +8 -0
- package/services/types.d.ts +22 -0
- package/starter.js +0 -1
- package/types.d.ts +748 -0
- package/Container.d.ts +0 -92
- package/Container.js +0 -242
- package/Container.js.map +0 -1
- package/Controller/index.d.ts +0 -178
- package/Controller/index.js +0 -576
- package/Controller/index.js.map +0 -1
- package/Controller/patch/cookie.d.ts +0 -33
- package/Controller/patch/cookie.js +0 -168
- package/Controller/patch/cookie.js.map +0 -1
- package/Controller/patch/index.d.ts +0 -7
- package/Controller/patch/index.js +0 -26
- package/Controller/patch/index.js.map +0 -1
- package/Controller/patch/render.d.ts +0 -5
- package/Controller/patch/render.js +0 -24
- package/Controller/patch/render.js.map +0 -1
- package/ExitSignal.d.ts +0 -14
- package/ExitSignal.js +0 -29
- package/ExitSignal.js.map +0 -1
- package/Extension.d.ts +0 -56
- package/Extension.js +0 -93
- package/Extension.js.map +0 -1
- package/ExtensionContainer.d.ts +0 -55
- package/ExtensionContainer.js +0 -105
- package/ExtensionContainer.js.map +0 -1
- package/Plugin.d.ts +0 -52
- package/Plugin.js +0 -278
- package/Plugin.js.map +0 -1
- package/Preprocessor.d.ts +0 -86
- package/Preprocessor.js +0 -135
- package/Preprocessor.js.map +0 -1
- package/Router/assets.d.ts +0 -33
- package/Router/assets.js +0 -106
- package/Router/assets.js.map +0 -1
- package/Router/callback.d.ts +0 -9
- package/Router/callback.js +0 -152
- package/Router/callback.js.map +0 -1
- package/Router/extendsInterface.d.ts +0 -8
- package/Router/extendsInterface.js +0 -43
- package/Router/extendsInterface.js.map +0 -1
- package/Router/index.d.ts +0 -184
- package/Router/index.js +0 -615
- package/Router/index.js.map +0 -1
- package/Router/log.d.ts +0 -23
- package/Router/log.js +0 -120
- package/Router/log.js.map +0 -1
- package/Router/order.d.ts +0 -14
- package/Router/order.js +0 -71
- package/Router/order.js.map +0 -1
- package/Router/register.d.ts +0 -9
- package/Router/register.js +0 -252
- package/Router/register.js.map +0 -1
- package/Router/registerManager.d.ts +0 -22
- package/Router/registerManager.js +0 -102
- package/Router/registerManager.js.map +0 -1
- package/Router/scan.d.ts +0 -2
- package/Router/scan.js +0 -72
- package/Router/scan.js.map +0 -1
- package/Router/setHandleItem.d.ts +0 -3
- package/Router/setHandleItem.js +0 -94
- package/Router/setHandleItem.js.map +0 -1
- package/Router/settings.d.ts +0 -12
- package/Router/settings.js +0 -74
- package/Router/settings.js.map +0 -1
- package/Router/start.d.ts +0 -3
- package/Router/start.js +0 -270
- package/Router/start.js.map +0 -1
- package/Router/vars.d.ts +0 -10
- package/Router/vars.js +0 -40
- package/Router/vars.js.map +0 -1
- package/Service.d.ts +0 -12
- package/Service.js +0 -20
- package/Service.js.map +0 -1
- package/cli/command/create.d.ts +0 -7
- package/cli/command/create.js.map +0 -1
- package/cli/command/index.d.ts +0 -7
- package/cli/command/index.js.map +0 -1
- package/cli/command/init.d.ts +0 -6
- package/cli/command/init.js.map +0 -1
- package/cli/command/start.d.ts +0 -6
- package/cli/command/start.js.map +0 -1
- package/cli/index.d.ts +0 -2
- package/cli/index.js.map +0 -1
- package/cli/opt/bind.d.ts +0 -3
- package/cli/opt/bind.js.map +0 -1
- package/cli/opt/index.d.ts +0 -16
- package/cli/opt/index.js.map +0 -1
- package/cli/opt/listen.d.ts +0 -3
- package/cli/opt/listen.js.map +0 -1
- package/cli/opt/path.d.ts +0 -3
- package/cli/opt/path.js.map +0 -1
- package/cli/opt/port.d.ts +0 -3
- package/cli/opt/port.js.map +0 -1
- package/cli/opt/show-router.d.ts +0 -3
- package/cli/opt/show-router.js.map +0 -1
- package/index.d.ts +0 -354
- package/index.js +0 -155
- package/index.js.map +0 -1
- package/setOptions.d.ts +0 -12
- package/setOptions.js +0 -60
- package/setOptions.js.map +0 -1
- package/starter.d.ts +0 -2
- package/starter.js.map +0 -1
- package/symbols.d.ts +0 -13
- package/symbols.js +0 -31
- package/symbols.js.map +0 -1
- package/util/index.d.ts +0 -5
- package/util/index.js +0 -92
- package/util/index.js.map +0 -1
- package/util/stream.d.ts +0 -19
- package/util/stream.js +0 -66
- package/util/stream.js.map +0 -1
package/Router/assets.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var fsFn = _interopRequireWildcard(require("fs"));
|
|
9
|
-
|
|
10
|
-
var pathFn = _interopRequireWildcard(require("path"));
|
|
11
|
-
|
|
12
|
-
var _extendsInterface = _interopRequireDefault(require("./extendsInterface"));
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
17
|
-
|
|
18
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
-
|
|
20
|
-
/** 获取查询路径 */
|
|
21
|
-
function* getPaths(router, path, usePlugin) {
|
|
22
|
-
path = pathFn.join('.', path);
|
|
23
|
-
yield pathFn.resolve(router.runtime.path, router.runtime.assets, path);
|
|
24
|
-
|
|
25
|
-
if (!usePlugin) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const r = /^\/group\/([a-zA-Z][a-zA-Z0-9_-]*(?:\.[a-zA-Z][a-zA-Z0-9_-]*)*)(\/.*)$/.exec(path);
|
|
30
|
-
|
|
31
|
-
if (!r) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const plugin = router.plugin(r[1]);
|
|
36
|
-
|
|
37
|
-
if (!plugin) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
yield pathFn.join(plugin.path, r[2]);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function read(path, options) {
|
|
45
|
-
if (!['object', 'string'].includes(typeof options)) {
|
|
46
|
-
options = null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
for (const p of getPaths(this, path, true)) {
|
|
50
|
-
try {
|
|
51
|
-
return await new Promise((resolve, reject) => fsFn.readFile(p, options, (e, d) => e ? reject(e) : resolve(d)));
|
|
52
|
-
} catch {}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
throw new Error(`ENOENT: Cannot open file '${path}'`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async function unlink(path) {
|
|
59
|
-
for (const p of getPaths(this, path)) {
|
|
60
|
-
return new Promise(resolve => fsFn.unlink(p, e => resolve(!e)));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function write(path, data, options) {
|
|
67
|
-
if (!['object', 'string'].includes(typeof options)) {
|
|
68
|
-
options = null;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
for (const p of getPaths(this, path)) {
|
|
72
|
-
await new Promise(r => fsFn.mkdir(pathFn.dirname(p), {
|
|
73
|
-
recursive: true
|
|
74
|
-
}, () => r()));
|
|
75
|
-
return new Promise((resolve, reject) => fsFn.writeFile(p, data, options, e => e ? reject(e) : resolve(true)));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async function stat(path, options) {
|
|
82
|
-
if (!options || typeof options !== 'object') {
|
|
83
|
-
options = {
|
|
84
|
-
bigint: false
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
for (const p of getPaths(this, path)) {
|
|
89
|
-
return new Promise((resolve, reject) => fsFn.stat(p, options, (e, s) => e ? reject(e) : resolve(s)));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
throw new Error(`ENOENT: Cannot open file '${path}'`);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function Assets(router) {
|
|
96
|
-
return (0, _extendsInterface.default)(router, {
|
|
97
|
-
read,
|
|
98
|
-
unlink,
|
|
99
|
-
write,
|
|
100
|
-
stat
|
|
101
|
-
}, {});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
var _default = Assets;
|
|
105
|
-
exports.default = _default;
|
|
106
|
-
//# sourceMappingURL=assets.js.map
|
package/Router/assets.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/k99/Router/assets.ts"],"names":["getPaths","router","path","usePlugin","pathFn","join","resolve","runtime","assets","r","exec","plugin","read","options","includes","p","Promise","reject","fsFn","readFile","e","d","Error","unlink","write","data","mkdir","dirname","recursive","writeFile","stat","bigint","s","Assets"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;;;;;AAmBA;AACA,UAAUA,QAAV,CAAmBC,MAAnB,EAAmCC,IAAnC,EAAiDC,SAAjD,EAAsE;AACrED,EAAAA,IAAI,GAAIE,MAAM,CAACC,IAAP,CAAY,GAAZ,EAAkBH,IAAlB,CAAR;AACA,QAAME,MAAM,CAACE,OAAP,CAAeL,MAAM,CAACM,OAAP,CAAeL,IAA9B,EAAoCD,MAAM,CAACM,OAAP,CAAeC,MAAnD,EAA2DN,IAA3D,CAAN;;AACA,MAAI,CAACC,SAAL,EAAgB;AAAE;AAAS;;AAC3B,QAAMM,CAAC,GAAG,yEAAyEC,IAAzE,CAA8ER,IAA9E,CAAV;;AACA,MAAI,CAACO,CAAL,EAAQ;AAAE;AAAS;;AACnB,QAAME,MAAM,GAAGV,MAAM,CAACU,MAAP,CAAcF,CAAC,CAAC,CAAD,CAAf,CAAf;;AACA,MAAI,CAACE,MAAL,EAAa;AAAE;AAAS;;AACxB,QAAMP,MAAM,CAACC,IAAP,CAAYM,MAAM,CAACT,IAAnB,EAAyBO,CAAC,CA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;AAAvB,GAAhD,EAA+E,EAA/E,CAAP;AACA;;eAEcG,M","sourcesContent":["import * as fsFn from 'fs';\nimport * as pathFn from 'path';\nimport extendsInterface from './extendsInterface';\nimport Router from './index';\n\ninterface ISettings {\n\t/** 读取文件 */\n\tread(path: string, options?: { encoding?: null; flag?: string; } | null): Promise<Buffer>;\n\tread(path: string, options?: { encoding: string; flag?: string; } | string): Promise<string>;\n\tread(path: string, options?: { encoding: string | null; flag?: string; } | string | null): Promise<string | Buffer>;\n\t/** 删除文件 */\n\tunlink(path: string): Promise<boolean>;\n\t/** 写入文件 */\n\twrite(path: string, data: any, options?: fsFn.WriteFileOptions): Promise<boolean>;\n\t/** 获取文件信息 */\n\tstat(path: string, options?: { bigint: false }): Promise<fsFn.Stats>;\n\tstat(path: string, options: fsFn.BigIntOptions): Promise<fsFn.BigIntStats>;\n\tstat(path: string, options?: fsFn.StatOptions): Promise<fsFn.Stats | fsFn.BigIntStats>;\n}\n\ninterface Assets extends ISettings, extendsInterface {}\n/** 获取查询路径 */\nfunction *getPaths(router: Router, path: string, usePlugin?: boolean) {\n\tpath = pathFn.join('.', path);\n\tyield pathFn.resolve(router.runtime.path, router.runtime.assets, path);\n\tif (!usePlugin) { return; }\n\tconst r = /^\\/group\\/([a-zA-Z][a-zA-Z0-9_-]*(?:\\.[a-zA-Z][a-zA-Z0-9_-]*)*)(\\/.*)$/.exec(path);\n\tif (!r) { return; }\n\tconst plugin = router.plugin(r[1]);\n\tif (!plugin) { return; }\n\tyield pathFn.join(plugin.path, r[2]);\n}\nasync function read(this: Router, path: string, options?: { encoding?: null; flag?: string; } | null): Promise<Buffer>;\nasync function read(this: Router, path: string, options?: { encoding: string; flag?: string; } | string): Promise<string>;\nasync function read(this: Router, path: string, options?: { encoding?: string | null; flag?: string; } | string | null): Promise<string | Buffer>;\nasync function read(this: Router, path: string, options?: { encoding?: string | null; flag?: string; } | string | null): Promise<string | Buffer> {\n\tif (!['object', 'string'].includes(typeof options)) { options = null; }\n\tfor (const p of getPaths(this, path, true)) {\n\t\ttry {\n\t\t\treturn await new Promise((resolve, reject) => fsFn.readFile(p, options, (e, d) => e ? reject(e) : resolve(d)));\n\t\t} catch {}\n\t}\n\tthrow new Error(`ENOENT: Cannot open file '${ path }'`);\n}\nasync function unlink(this: Router, path: string): Promise<boolean> {\n\tfor (const p of getPaths(this, path)) {\n\t\treturn new Promise(resolve => fsFn.unlink(p, e => resolve(!e)));\n\t}\n\treturn false;\n}\nasync function write(this: Router, path: string, data: any, options?: fsFn.WriteFileOptions): Promise<boolean> {\n\tif (!['object', 'string'].includes(typeof options)) { options = null; }\n\tfor (const p of getPaths(this, path)) {\n\t\tawait new Promise(r => fsFn.mkdir(pathFn.dirname(p), { recursive: true }, () => r()));\n\t\treturn new Promise((resolve, reject) => fsFn.writeFile(p, data, options!, e => e ? reject(e) : resolve(true)));\n\t}\n\treturn false;\n}\n\nasync function stat(this: Router, path: string, options?: { bigint: false }): Promise<fsFn.Stats>;\nasync function stat(this: Router, path: string, options: fsFn.BigIntOptions): Promise<fsFn.BigIntStats>;\nasync function stat(this: Router, path: string, options?: fsFn.StatOptions): Promise<fsFn.Stats | fsFn.BigIntStats>;\nasync function stat(this: Router, path: string, options?: fsFn.StatOptions): Promise<fsFn.Stats | fsFn.BigIntStats> {\n\tif (!options || typeof options !== 'object') { options = { bigint: false }; }\n\tfor (const p of getPaths(this, path)) {\n\t\treturn new Promise((resolve, reject) => fsFn.stat(p, options!, (e, s) => e ? reject(e) : resolve(s)));\n\t}\n\tthrow new Error(`ENOENT: Cannot open file '${ path }'`);\n}\n\nfunction Assets(router: Router) {\n\treturn extendsInterface<ISettings, {}, Assets>(router, { read, unlink, write, stat }, {});\n}\n\nexport default Assets;\n"],"file":"assets.js"}
|
package/Router/callback.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
-
import { Http2ServerRequest, Http2ServerResponse } from 'http2';
|
|
4
|
-
import { K99Request, K99Response, HandleInfo } from '../index';
|
|
5
|
-
import Router from './index';
|
|
6
|
-
import { BaseRequest } from '../index';
|
|
7
|
-
export declare function parseRequest(request: K99Request): BaseRequest;
|
|
8
|
-
/** 查找请求的处理函数 */
|
|
9
|
-
export default function run(this: Router, list: HandleInfo[], request: K99Request | IncomingMessage | Http2ServerRequest, response: K99Response | ServerResponse | Http2ServerResponse, next?: () => void): Promise<void>;
|
package/Router/callback.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.parseRequest = parseRequest;
|
|
7
|
-
exports.default = run;
|
|
8
|
-
|
|
9
|
-
var _Controller = _interopRequireDefault(require("../Controller"));
|
|
10
|
-
|
|
11
|
-
var _ExitSignal = _interopRequireDefault(require("../ExitSignal"));
|
|
12
|
-
|
|
13
|
-
var _util = require("../util");
|
|
14
|
-
|
|
15
|
-
var urlFn = _interopRequireWildcard(require("url"));
|
|
16
|
-
|
|
17
|
-
var symbols = _interopRequireWildcard(require("../symbols"));
|
|
18
|
-
|
|
19
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
20
|
-
|
|
21
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
22
|
-
|
|
23
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
|
-
|
|
25
|
-
function parseRequest(request) {
|
|
26
|
-
const headers = Object.freeze(Object.assign({}, request.headers));
|
|
27
|
-
const rawHeaders = Object.freeze(Array.from(request.rawHeaders));
|
|
28
|
-
const method = request.method || '';
|
|
29
|
-
const url = request.url || '';
|
|
30
|
-
const urlInfo = urlFn.parse(url, true);
|
|
31
|
-
const pathname = request.pathname || urlInfo.pathname || '/';
|
|
32
|
-
const search = request.search || urlInfo.search || '';
|
|
33
|
-
const query = request.query || urlInfo.query || {};
|
|
34
|
-
const referer = headers.referer || '';
|
|
35
|
-
const host = headers.host || '';
|
|
36
|
-
const hostname = host.replace(/:.*/, '');
|
|
37
|
-
const port = host.replace(/.*:/, '');
|
|
38
|
-
const userAgent = headers['user-agent'] || '';
|
|
39
|
-
return {
|
|
40
|
-
method,
|
|
41
|
-
url,
|
|
42
|
-
pathname,
|
|
43
|
-
search,
|
|
44
|
-
query,
|
|
45
|
-
host,
|
|
46
|
-
hostname,
|
|
47
|
-
port,
|
|
48
|
-
headers,
|
|
49
|
-
rawHeaders,
|
|
50
|
-
referer,
|
|
51
|
-
userAgent
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/** 查找请求的处理函数 */
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
async function run(list, request, response, next) {
|
|
58
|
-
const info = parseRequest(request);
|
|
59
|
-
|
|
60
|
-
for (const item of Array.from(list)) {
|
|
61
|
-
// 匹配校验
|
|
62
|
-
if (item.methods.length && !item.methods.includes(info.method)) {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const params = item.match(info.pathname);
|
|
67
|
-
|
|
68
|
-
if (!params) {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const {
|
|
73
|
-
config,
|
|
74
|
-
test
|
|
75
|
-
} = item; // 有效性验证
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
if (typeof test === 'function' && !(await test(params))) {
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
} catch {
|
|
82
|
-
continue;
|
|
83
|
-
} // 预处理
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const throughData = new Map();
|
|
87
|
-
const preprocessors = this.preprocessor(info.pathname);
|
|
88
|
-
|
|
89
|
-
for (let preprocessor of preprocessors) {
|
|
90
|
-
try {
|
|
91
|
-
if (!(await (0, _util.relateMap)(Object.create(preprocessor), throughData, preprocessor).test(params))) {
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
} catch {
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const file = {
|
|
100
|
-
root: item.root,
|
|
101
|
-
absPath: item.absPath,
|
|
102
|
-
path: item.filePath,
|
|
103
|
-
scope: item.scope,
|
|
104
|
-
group: item.group
|
|
105
|
-
}; // 创建 Controller
|
|
106
|
-
|
|
107
|
-
let ThisController = item.controller || item.group;
|
|
108
|
-
|
|
109
|
-
if (!ThisController || typeof ThisController === 'string') {
|
|
110
|
-
ThisController = this.controller(ThisController);
|
|
111
|
-
} else if (!Object.prototype.isPrototypeOf.call(_Controller.default, _Controller.default)) {
|
|
112
|
-
ThisController = this.controller();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const controller = new ThisController(params, info, config, item.exports, file, this, request, response);
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
// 预处理
|
|
119
|
-
for (let Preprocessor of preprocessors) {
|
|
120
|
-
await (0, _util.relateMap)(new Preprocessor(controller), throughData, Preprocessor).exec();
|
|
121
|
-
} // 执行
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const result = await controller[symbols.exec](item.handle);
|
|
125
|
-
await controller[symbols.return](result);
|
|
126
|
-
} catch (e) {
|
|
127
|
-
if (e instanceof _ExitSignal.default) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
// 错误处理
|
|
133
|
-
await controller[symbols.catch](e);
|
|
134
|
-
} catch (e) {
|
|
135
|
-
console.error(e);
|
|
136
|
-
}
|
|
137
|
-
} finally {
|
|
138
|
-
// controller 的销毁与回收处理
|
|
139
|
-
await controller.destroy();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (typeof next === 'function') {
|
|
146
|
-
return next();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
response.statusCode = 404;
|
|
150
|
-
response.end('404');
|
|
151
|
-
}
|
|
152
|
-
//# sourceMappingURL=callback.js.map
|
package/Router/callback.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/k99/Router/callback.ts"],"names":["parseRequest","request","headers","Object","freeze","assign","rawHeaders","Array","from","method","url","urlInfo","urlFn","parse","pathname","search","query","referer","host","hostname","replace","port","userAgent","run","list","response","next","info","item","methods","length","includes","params","match","config","test","throughData","Map","preprocessors","preprocessor","create","file","root","absPath","path","filePath","scope","group","ThisController","controller","prototype","isPrototypeOf","call","Controller","exports","Preprocessor","exec","result","symbols","handle","return","e","ExitSignal","catch","console","error","destroy","statusCode","end"],"mappings":";;;;;;;;AAIA;;AAGA;;AACA;;AAGA;;AACA;;;;;;;;AAGO,SAASA,YAAT,CAAsBC,OAAtB,EAAwD;AAC9D,QAAMC,OAAO,GAAGC,MAAM,CAACC,MAAP,CAAcD,MAAM,CAACE,MAAP,CAAc,EAAd,EAAkBJ,OAAO,CAACC,OAA1B,CAAd,CAAhB;AACA,QAAMI,UAAU,GAAGH,MAAM,CAACC,MAAP,CAAcG,KAAK,CAACC,IAAN,CAAWP,OAAO,CAACK,UAAnB,CAAd,CAAnB;AACA,QAAMG,MAAM,GAAGR,OAAO,CAACQ,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iB,OAAX,EAAN;AACA;;AACD;AACA;;AACD,MAAI,OAAOxC,IAAP,KAAgB,UAApB,EAAgC;AAAE,WAAOA,IAAI,EAAX;AAAgB;;AAClDD,EAAAA,QAAQ,CAAC0C,UAAT,GAAsB,GAAtB;AACA1C,EAAAA,QAAQ,CAAC2C,GAAT,CAAa,KAAb;AACA","sourcesContent":["import { IncomingMessage, ServerResponse } from 'http';\nimport { Http2ServerRequest, Http2ServerResponse } from 'http2';\n\nimport { FileInfo, K99Request, K99Response, HandleInfo } from '../index';\nimport Controller, { Class as ControllerClass } from '../Controller';\n\nimport { Class as PreprocessorClass } from '../Preprocessor';\nimport ExitSignal from '../ExitSignal';\nimport { relateMap } from '../util';\nimport Router from './index';\n\nimport * as urlFn from 'url';\nimport * as symbols from '../symbols';\nimport { Method, BaseRequest } from '../index';\n\nexport function parseRequest(request: K99Request): BaseRequest {\n\tconst headers = Object.freeze(Object.assign({}, request.headers));\n\tconst rawHeaders = Object.freeze(Array.from(request.rawHeaders));\n\tconst method = request.method as Method || '';\n\tconst url = request.url || '';\n\tconst urlInfo = urlFn.parse(url, true);\n\tconst pathname = request.pathname || urlInfo.pathname || '/';\n\tconst search = request.search || urlInfo.search || '';\n\tconst query = request.query || urlInfo.query || {};\n\tconst referer = headers.referer || '';\n\tconst host = headers.host || '';\n\tconst hostname = host.replace(/:.*/, '');\n\tconst port = host.replace(/.*:/, '');\n\tconst userAgent = headers['user-agent'] || '';\n\treturn {\n\t\tmethod,\n\t\turl,\n\t\tpathname,\n\t\tsearch,\n\t\tquery,\n\t\thost,\n\t\thostname,\n\t\tport,\n\t\theaders,\n\t\trawHeaders,\n\t\treferer,\n\t\tuserAgent,\n\t};\n}\n\n/** 查找请求的处理函数 */\nexport default async function run(\n\tthis: Router,\n\tlist: HandleInfo[],\n\trequest: K99Request | IncomingMessage | Http2ServerRequest,\n\tresponse: K99Response | ServerResponse | Http2ServerResponse,\n\tnext?: () => void\n): Promise<void> {\n\tconst info = parseRequest(request);\n\tfor (const item of Array.from(list)) {\n\t\t// 匹配校验\n\t\tif (item.methods.length && !item.methods.includes(info.method!)) { continue; }\n\t\tconst params = item.match(info.pathname);\n\t\tif (!params) { continue; }\n\t\tconst { config, test } = item;\n\t\t// 有效性验证\n\t\ttry { if (typeof test === 'function' && !await test(params)) { continue; } } catch { continue; }\n\n\t\t// 预处理\n\t\tconst throughData = new Map<PreprocessorClass<any>, Map<any, any>>();\n\t\tconst preprocessors = this.preprocessor(info.pathname);\n\t\tfor (let preprocessor of preprocessors) {\n\t\t\ttry {\n\t\t\t\tif (!await relateMap(Object.create(preprocessor) as PreprocessorClass<any>, throughData, preprocessor).test(params)) { continue; }\n\t\t\t} catch { continue; }\n\t\t}\n\t\tconst file: FileInfo = {root: item.root, absPath: item.absPath, path: item.filePath, scope: item.scope, group: item.group};\n\t\t// 创建 Controller\n\t\tlet ThisController: ControllerClass<Controller> | string | undefined = item.controller || item.group;\n\t\tif (!ThisController || typeof ThisController === 'string') {\n\t\t\tThisController = this.controller(ThisController);\n\t\t} else if (!Object.prototype.isPrototypeOf.call(Controller, Controller)) {\n\t\t\tThisController = this.controller();\n\t\t}\n\t\tconst controller = new ThisController(params, info, config, item.exports, file, this, request, response);\n\t\ttry {\n\t\t\t// 预处理\n\t\t\tfor (let Preprocessor of preprocessors) {\n\t\t\t\tawait relateMap(new Preprocessor(controller), throughData, Preprocessor).exec();\n\t\t\t}\n\t\t\t// 执行\n\t\t\tconst result = await controller[symbols.exec](item.handle);\n\t\t\tawait controller[symbols.return](result);\n\t\t} catch (e) {\n\t\t\tif (e instanceof ExitSignal) { return; }\n\t\t\ttry {\n\t\t\t\t// 错误处理\n\t\t\t\tawait controller[symbols.catch](e);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(e);\n\t\t\t}\n\t\t} finally {\n\t\t\t// controller 的销毁与回收处理\n\t\t\tawait controller.destroy();\n\t\t}\n\t\treturn;\n\t}\n\tif (typeof next === 'function') { return next(); }\n\tresponse.statusCode = 404;\n\tresponse.end('404');\n}\n"],"file":"callback.js"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/** 自扩展接口 */
|
|
2
|
-
interface Interface {
|
|
3
|
-
(): string;
|
|
4
|
-
(path: string): this;
|
|
5
|
-
}
|
|
6
|
-
/** 自扩展接口 */
|
|
7
|
-
declare function Interface<T extends object, E extends object, R extends T & E & Interface = T & E & Interface, THIS = any>(that: THIS, interfaces: T, extendsInterfaces: E, path?: string, basePath?: string): R;
|
|
8
|
-
export default Interface;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var pathFn = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
11
|
-
|
|
12
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
-
|
|
14
|
-
function subinterface(interfaces, extendsInterfaces, basePath, path) {
|
|
15
|
-
if (path === undefined) {
|
|
16
|
-
return basePath;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return Interface(this, interfaces, extendsInterfaces, path, basePath);
|
|
20
|
-
}
|
|
21
|
-
/** 自扩展接口 */
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function Interface(that, interfaces, extendsInterfaces, path = '', basePath = '') {
|
|
25
|
-
basePath = pathFn.join('/', basePath, path);
|
|
26
|
-
const ret = subinterface.bind(that, interfaces, extendsInterfaces, basePath);
|
|
27
|
-
|
|
28
|
-
for (const k in interfaces) {
|
|
29
|
-
const v = interfaces[k];
|
|
30
|
-
ret[k] = typeof v === 'function' ? (path, ...p) => v.call(that, pathFn.join(basePath, path), ...p) : v;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
for (const k in extendsInterfaces) {
|
|
34
|
-
const v = extendsInterfaces[k];
|
|
35
|
-
ret[k] = typeof v === 'function' ? (...p) => v.call(that, ...p) : v;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return ret;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
var _default = Interface;
|
|
42
|
-
exports.default = _default;
|
|
43
|
-
//# sourceMappingURL=extendsInterface.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/k99/Router/extendsInterface.ts"],"names":["subinterface","interfaces","extendsInterfaces","basePath","path","undefined","Interface","that","pathFn","join","ret","bind","k","v","p","call"],"mappings":";;;;;;;AAAA;;;;;;AAQA,SAASA,YAAT,CAAmIC,UAAnI,EAAkJC,iBAAlJ,EAAwKC,QAAxK,EAA0LC,IAA1L,EAAqN;AACpN,MAAIA,IAAI,KAAKC,SAAb,EAAwB;AAAE,WAAOF,QAAP;AAAkB;;AAC5C,SAAOG,SAAS,CAAC,IAAD,EAAOL,UAAP,EAAmBC,iBAAnB,EAAsCE,IAAtC,EAA4CD,QAA5C,CAAhB;AACA;AACD;;;AACA,SAASG,SAAT,CACCC,IADD,EAECN,UAFD,EAGCC,iBAHD,EAICE,IAAY,GAAG,EAJhB,EAKCD,QAAgB,GAAG,EALpB,EAMK;AACJA,EAAAA,QAAQ,GAAGK,MAAM,CAACC,IAAP,CAAY,GAAZ,EAAiBN,QAAjB,EAA2BC,IAA3B,CAAX;AACA,QAAMM,GAAM,GAAGV,YAAY,CAACW,IAAb,CAA6DJ,IAA7D,EAAmEN,UAAnE,EAA+EC,iBAA/E,EAAkGC,QAAlG,CAAf;;AACA,OAAK,MAAMS,CAAX,IAAgBX,UAAhB,EAA4B;AAC3B,UAAMY,CAAC,GAAGZ,UAAU,CAACW,CAAD,CAApB;AACAF,IAAAA,GAAG,CAACE,CAAD,CAAH,GAAS,OAAOC,CAAP,KAAa,UAAb,GAA0B,CAACT,IAAD,EAAe,GAAGU,CAAlB,KAA+BD,CAAC,CAACE,IAAF,CAAOR,IAAP,EAAaC,MAAM,CAACC,IAAP,CAAYN,QAAZ,EAAsBC,IAAtB,CAAb,EAA0C,GAAGU,CAA7C,CAAzD,GAA2GD,CAApH;AACA;;AACD,OAAK,MAAMD,CAAX,IAAgBV,iBAAhB,EAAmC;AAClC,UAAMW,CAAC,GAAGX,iBAAiB,CAACU,CAAD,CAA3B;AACAF,IAAAA,GAAG,CAACE,CAAD,CAAH,GAAS,OAAOC,CAAP,KAAa,UAAb,GAA0B,CAAC,GAAGC,CAAJ,KAAiBD,CAAC,CAACE,IAAF,CAAOR,IAAP,EAAa,GAAGO,CAAhB,CAA3C,GAAgED,CAAzE;AACA;;AACD,SAAOH,GAAP;AACA;;eAEcJ,S","sourcesContent":["import * as pathFn from 'path';\n/** 自扩展接口 */\ninterface Interface {\n\t(): string;\n\t(path: string): this;\n}\nfunction subinterface<T extends object, E extends object, R extends T & E & Interface = T & E & Interface, THIS = any>(this: THIS, interfaces: T, extendsInterfaces: E, basePath: string): string;\nfunction subinterface<T extends object, E extends object, R extends T & E & Interface = T & E & Interface, THIS = any>(this: THIS, interfaces: T, extendsInterfaces: E, basePath: string, path: string): R;\nfunction subinterface<T extends object, E extends object, R extends T & E & Interface = T & E & Interface, THIS = any>(this: THIS, interfaces: T, extendsInterfaces: E, basePath: string, path?: string): string | R {\n\tif (path === undefined) { return basePath; }\n\treturn Interface(this, interfaces, extendsInterfaces, path, basePath) as R;\n}\n/** 自扩展接口 */\nfunction Interface<T extends object, E extends object, R extends T & E & Interface = T & E & Interface, THIS = any>(\n\tthat: THIS,\n\tinterfaces: T,\n\textendsInterfaces: E,\n\tpath: string = '',\n\tbasePath: string = ''\n): R {\n\tbasePath = pathFn.join('/', basePath, path);\n\tconst ret: R = subinterface.bind<THIS, T, E, string, [string?], string | R>(that, interfaces, extendsInterfaces, basePath) as Interface & any;\n\tfor (const k in interfaces) {\n\t\tconst v = interfaces[k];\n\t\tret[k] = typeof v === 'function' ? (path: string, ...p: any[]) => v.call(that, pathFn.join(basePath, path), ...p) : v as any;\n\t}\n\tfor (const k in extendsInterfaces) {\n\t\tconst v = extendsInterfaces[k];\n\t\tret[k] = typeof v === 'function' ? (...p: any[]) => v.call(that, ...p) : v as any;\n\t}\n\treturn ret;\n}\n\nexport default Interface;\n"],"file":"extendsInterface.js"}
|
package/Router/index.d.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
-
import { Http2ServerRequest, Http2ServerResponse } from 'http2';
|
|
4
|
-
import { Exports, Method, Handle, ResourceOption, HandleInfo, HandleOption, FileItem, AddOptions, ROptions, Register, K99Request, K99Response, RouterOptions, RouterRuntime, StartOption } from '../index';
|
|
5
|
-
import Controller, { Class as ControllerClass, Param as ControllerParam, Base as ControllerBase } from '../Controller';
|
|
6
|
-
import Service, { Class as ServiceClass, Param as ServiceParam } from '../Service';
|
|
7
|
-
import { Class as PreprocessorClass } from '../Preprocessor';
|
|
8
|
-
import Extension, { Class as ExtensionClass, Param as ExtensionParam, Base as ExtensionBase } from '../Extension';
|
|
9
|
-
import Plugin from '../Plugin';
|
|
10
|
-
import * as RegisterManager from './registerManager';
|
|
11
|
-
import Settings from './settings';
|
|
12
|
-
import Assets from './assets';
|
|
13
|
-
import Log from './log';
|
|
14
|
-
declare class Router {
|
|
15
|
-
/**
|
|
16
|
-
* 设置公共的文件注册器
|
|
17
|
-
* @param register 注册配置
|
|
18
|
-
*/
|
|
19
|
-
static setRegister(register: Register): boolean;
|
|
20
|
-
static start(opt?: StartOption): Promise<Router>;
|
|
21
|
-
constructor(path?: string, parent?: Router | RouterOptions);
|
|
22
|
-
/** 子路由 */
|
|
23
|
-
route(path: string): Router;
|
|
24
|
-
/** 获取指定路径的 Preprocessor 列表 */
|
|
25
|
-
preprocessor(path: string): PreprocessorClass<any>[];
|
|
26
|
-
/**
|
|
27
|
-
* 注册 Preprocessor
|
|
28
|
-
* @param path 所要注册到的路径
|
|
29
|
-
* @param preprocessor 所要注册的 Preprocessor
|
|
30
|
-
* @param options 注册选项
|
|
31
|
-
*/
|
|
32
|
-
preprocessor(path: string, preprocessor: PreprocessorClass<any>, options?: {
|
|
33
|
-
order?: number;
|
|
34
|
-
group?: string;
|
|
35
|
-
}): (() => void) | null;
|
|
36
|
-
/**
|
|
37
|
-
* 注册处理函数
|
|
38
|
-
* @param path 要注册的路径
|
|
39
|
-
* @param handle 要注册的处理函数
|
|
40
|
-
* @param options 选项
|
|
41
|
-
*/
|
|
42
|
-
verb(path: string, handle: Handle, options?: HandleOption): (() => void) | null;
|
|
43
|
-
/**
|
|
44
|
-
* 注册处理函数
|
|
45
|
-
* @param path 要注册的路径
|
|
46
|
-
* @param handle 要注册的处理函数
|
|
47
|
-
* @param methods 有效的 HTTP 请求方法
|
|
48
|
-
* @param options 选项
|
|
49
|
-
*/
|
|
50
|
-
verb(path: string, handle: Handle, methods: Method | Method[], options?: HandleOption): (() => void) | null;
|
|
51
|
-
/**
|
|
52
|
-
* 注册 HTTP GET 处理函数
|
|
53
|
-
* @param path 要注册的路径
|
|
54
|
-
* @param handle 要注册的处理函数
|
|
55
|
-
* @param options 选项
|
|
56
|
-
*/
|
|
57
|
-
get(path: string, handle: Handle, options?: HandleOption): (() => void) | null;
|
|
58
|
-
/**
|
|
59
|
-
* 注册 HTTP POST 处理函数
|
|
60
|
-
* @param path 要注册的路径
|
|
61
|
-
* @param handle 要注册的处理函数
|
|
62
|
-
* @param options 选项
|
|
63
|
-
*/
|
|
64
|
-
post(path: string, handle: Handle, options?: HandleOption): (() => void) | null;
|
|
65
|
-
/**
|
|
66
|
-
* 注册 HTTP PUT 处理函数
|
|
67
|
-
* @param path 要注册的路径
|
|
68
|
-
* @param handle 要注册的处理函数
|
|
69
|
-
* @param options 选项
|
|
70
|
-
*/
|
|
71
|
-
put(path: string, handle: Handle, options?: HandleOption): (() => void) | null;
|
|
72
|
-
/**
|
|
73
|
-
* 注册 HTTP DELETE 处理函数
|
|
74
|
-
* @param path 要注册的路径
|
|
75
|
-
* @param handle 要注册的处理函数
|
|
76
|
-
* @param options 选项
|
|
77
|
-
*/
|
|
78
|
-
delete(path: string, handle: Handle, options?: HandleOption): (() => void) | null;
|
|
79
|
-
/**
|
|
80
|
-
* 注册 HTTP HEAD 处理函数
|
|
81
|
-
* @param path 要注册的路径
|
|
82
|
-
* @param handle 要注册的处理函数
|
|
83
|
-
* @param options 选项
|
|
84
|
-
*/
|
|
85
|
-
head(path: string, handle: Handle, options?: HandleOption): (() => void) | null;
|
|
86
|
-
/**
|
|
87
|
-
* 注册 HTTP OPTIONS 处理函数
|
|
88
|
-
* @param path 要注册的路径
|
|
89
|
-
* @param handle 要注册的处理函数
|
|
90
|
-
* @param options 选项
|
|
91
|
-
*/
|
|
92
|
-
options(path: string, handle: Handle, options?: HandleOption): (() => void) | null;
|
|
93
|
-
/**
|
|
94
|
-
* 注册 HTTP 资源
|
|
95
|
-
* @param path 要注册的路径
|
|
96
|
-
* @param exports 要注册的资源
|
|
97
|
-
* @param options 选项
|
|
98
|
-
*/
|
|
99
|
-
resource(path: string, exports: Exports, options?: ResourceOption): () => void;
|
|
100
|
-
/**
|
|
101
|
-
* 注册 HTTP 处理函数集
|
|
102
|
-
* @param path 要注册的路径
|
|
103
|
-
* @param exports 要注册的处理函数集
|
|
104
|
-
* @param options 选项
|
|
105
|
-
*/
|
|
106
|
-
collection(path: string, exports: Exports, options?: ResourceOption): () => void;
|
|
107
|
-
/**
|
|
108
|
-
* 注册 HTTP 资源成员处理函数集
|
|
109
|
-
* @param path 要注册的路径
|
|
110
|
-
* @param exports 要注册的处理函数集
|
|
111
|
-
* @param options 选项
|
|
112
|
-
*/
|
|
113
|
-
member(path: string, exports: Exports, options?: ResourceOption): () => void;
|
|
114
|
-
/** 获取匹配路径的项目 */
|
|
115
|
-
match(path: string, method?: Method): Iterable<HandleInfo>;
|
|
116
|
-
[Symbol.iterator](): Generator<HandleInfo, void, undefined>;
|
|
117
|
-
/**
|
|
118
|
-
* 扫描指定路径,并将扫描到的文件进行注册
|
|
119
|
-
* @param root 要扫描的路径
|
|
120
|
-
* @param options 选项
|
|
121
|
-
*/
|
|
122
|
-
scan(root: string, { group, scope, order }?: AddOptions): Promise<void>;
|
|
123
|
-
/** 为当前路由设置注册器 */
|
|
124
|
-
setRegister(register: Register): boolean;
|
|
125
|
-
/** 注册文件 */
|
|
126
|
-
register(file: FileItem, opt?: ROptions): Promise<boolean>;
|
|
127
|
-
controller<T extends Controller>(id: string, controller: ControllerClass<T> | string): boolean;
|
|
128
|
-
controller<T extends Controller>(id?: string, nodefault?: false): ControllerClass<T>;
|
|
129
|
-
controller<T extends Controller>(id?: string, nodefault?: boolean): ControllerClass<T> | undefined;
|
|
130
|
-
service<T extends Service<any, any>>(id: string, service: ServiceClass<T> | string): boolean;
|
|
131
|
-
service<T extends Service<any, any>>(id?: string, nodefault?: false): ServiceClass<T>;
|
|
132
|
-
service<T extends Service<any, any>>(id?: string, nodefault?: boolean): ServiceClass<T> | undefined;
|
|
133
|
-
extension<T extends Extension<any, any>>(id: string, service: ExtensionClass<T> | string): boolean;
|
|
134
|
-
extension<T extends Extension<any, any>>(id?: string, nodefault?: false): ExtensionClass<T>;
|
|
135
|
-
extension<T extends Extension<any, any>>(id?: string, nodefault?: boolean): ExtensionClass<T> | undefined;
|
|
136
|
-
/** 获取安装的 */
|
|
137
|
-
plugin(id: string): Plugin | undefined;
|
|
138
|
-
/** 安装插件 */
|
|
139
|
-
plugin(plugin: Plugin): undefined;
|
|
140
|
-
/** 获取指定类型的顺序列表 */
|
|
141
|
-
order(type?: string): string[];
|
|
142
|
-
}
|
|
143
|
-
interface Router {
|
|
144
|
-
/** 运行时配置 */
|
|
145
|
-
readonly runtime: RouterRuntime;
|
|
146
|
-
/** 设置接口 */
|
|
147
|
-
readonly settings: Settings;
|
|
148
|
-
/** 资产接口 */
|
|
149
|
-
readonly assets: Assets;
|
|
150
|
-
/** 日志接口 */
|
|
151
|
-
readonly log: Log;
|
|
152
|
-
/** 工作路径 */
|
|
153
|
-
readonly cwd: string;
|
|
154
|
-
/** 注册器列表 */
|
|
155
|
-
readonly _registers: {
|
|
156
|
-
[key: string]: Register;
|
|
157
|
-
};
|
|
158
|
-
/** 设置的预处理器 */
|
|
159
|
-
readonly _preprocessors: {
|
|
160
|
-
[k: string]: {
|
|
161
|
-
preprocessor: PreprocessorClass<any>;
|
|
162
|
-
order: number;
|
|
163
|
-
group: string;
|
|
164
|
-
}[];
|
|
165
|
-
};
|
|
166
|
-
readonly _controllers: RegisterManager.ClassList<Controller, ControllerParam, ControllerBase<Controller>>;
|
|
167
|
-
readonly _services: RegisterManager.ClassList<Service<any, any>, ServiceParam>;
|
|
168
|
-
readonly _extensions: RegisterManager.ClassList<Extension<any, any>, ExtensionParam, ExtensionBase>;
|
|
169
|
-
readonly _plugins: {
|
|
170
|
-
[id: string]: Plugin;
|
|
171
|
-
};
|
|
172
|
-
readonly _orders: {
|
|
173
|
-
[key: string]: [string[], {
|
|
174
|
-
[key: string]: number;
|
|
175
|
-
}];
|
|
176
|
-
};
|
|
177
|
-
/** 路由列表 */
|
|
178
|
-
readonly _routes: HandleInfo[];
|
|
179
|
-
/** 当前路由路径 */
|
|
180
|
-
readonly path: string;
|
|
181
|
-
/** 连接的处理函数 */
|
|
182
|
-
callback(request: K99Request | IncomingMessage | Http2ServerRequest, response: K99Response | ServerResponse | Http2ServerResponse, next?: () => void): Promise<void>;
|
|
183
|
-
}
|
|
184
|
-
export default Router;
|