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/index.js
DELETED
|
@@ -1,615 +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
|
-
var pathToRegexp = _interopRequireWildcard(require("path-to-regexp"));
|
|
11
|
-
|
|
12
|
-
var _index = require("../index");
|
|
13
|
-
|
|
14
|
-
var _Controller = _interopRequireDefault(require("../Controller"));
|
|
15
|
-
|
|
16
|
-
var _Service = _interopRequireDefault(require("../Service"));
|
|
17
|
-
|
|
18
|
-
var _Preprocessor = _interopRequireDefault(require("../Preprocessor"));
|
|
19
|
-
|
|
20
|
-
var _Extension = _interopRequireDefault(require("../Extension"));
|
|
21
|
-
|
|
22
|
-
var _Plugin = _interopRequireDefault(require("../Plugin"));
|
|
23
|
-
|
|
24
|
-
var _util = require("../util");
|
|
25
|
-
|
|
26
|
-
var RegisterManager = _interopRequireWildcard(require("./registerManager"));
|
|
27
|
-
|
|
28
|
-
var _register = require("./register");
|
|
29
|
-
|
|
30
|
-
var _callback = _interopRequireDefault(require("./callback"));
|
|
31
|
-
|
|
32
|
-
var _scan = _interopRequireDefault(require("./scan"));
|
|
33
|
-
|
|
34
|
-
var _order = require("./order");
|
|
35
|
-
|
|
36
|
-
var _start = _interopRequireDefault(require("./start"));
|
|
37
|
-
|
|
38
|
-
var _settings = _interopRequireDefault(require("./settings"));
|
|
39
|
-
|
|
40
|
-
var _assets = _interopRequireDefault(require("./assets"));
|
|
41
|
-
|
|
42
|
-
var _log = _interopRequireDefault(require("./log"));
|
|
43
|
-
|
|
44
|
-
var _setHandleItem = _interopRequireDefault(require("./setHandleItem"));
|
|
45
|
-
|
|
46
|
-
var _vars = require("./vars");
|
|
47
|
-
|
|
48
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
49
|
-
|
|
50
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
51
|
-
|
|
52
|
-
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; }
|
|
53
|
-
|
|
54
|
-
/** 去除路径开头与结尾的斜杠 */
|
|
55
|
-
function getBasePath(path) {
|
|
56
|
-
return path.replace(/^\/+|\/+$/g, '');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function initOptions(router, path, exports, {
|
|
60
|
-
controller,
|
|
61
|
-
group,
|
|
62
|
-
order,
|
|
63
|
-
root,
|
|
64
|
-
filePath,
|
|
65
|
-
absPath,
|
|
66
|
-
config
|
|
67
|
-
} = {}) {
|
|
68
|
-
// 默认配置
|
|
69
|
-
config = { ...config,
|
|
70
|
-
...exports.Config
|
|
71
|
-
}; // 默认顺序
|
|
72
|
-
|
|
73
|
-
order = typeof exports.Order === 'number' && isFinite(exports.Order) ? exports.Order : order; // 安装预处理器
|
|
74
|
-
|
|
75
|
-
router.preprocessor(path, exports.Preprocessor, {
|
|
76
|
-
group,
|
|
77
|
-
order
|
|
78
|
-
}); // 路径
|
|
79
|
-
|
|
80
|
-
path = getBasePath(path); // 公共选项
|
|
81
|
-
|
|
82
|
-
const options = {
|
|
83
|
-
controller: exports.Controller || controller,
|
|
84
|
-
group,
|
|
85
|
-
order,
|
|
86
|
-
root,
|
|
87
|
-
filePath,
|
|
88
|
-
absPath,
|
|
89
|
-
exports,
|
|
90
|
-
config
|
|
91
|
-
}; // 将自身添加到路由
|
|
92
|
-
|
|
93
|
-
(0, _setHandleItem.default)(router, path, exports, options);
|
|
94
|
-
return {
|
|
95
|
-
path,
|
|
96
|
-
options
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function getRuntime(options) {
|
|
101
|
-
if (options instanceof Router) {
|
|
102
|
-
return options.runtime;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const path = pathFn.resolve(options.path || process.cwd());
|
|
106
|
-
const settings = pathFn.relative(path, pathFn.resolve(path, options.settings || 'runtime/settings'));
|
|
107
|
-
const assets = pathFn.relative(path, pathFn.resolve(path, options.assets || 'runtime/assets'));
|
|
108
|
-
const log = pathFn.relative(path, pathFn.resolve(path, options.log || 'runtime/log'));
|
|
109
|
-
return {
|
|
110
|
-
path,
|
|
111
|
-
settings,
|
|
112
|
-
assets,
|
|
113
|
-
log
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
class Router {
|
|
118
|
-
/**
|
|
119
|
-
* 设置公共的文件注册器
|
|
120
|
-
* @param register 注册配置
|
|
121
|
-
*/
|
|
122
|
-
static setRegister(register) {
|
|
123
|
-
return (0, _register.setRegister)(register);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
static async start(opt = {}) {
|
|
127
|
-
const router = new Router();
|
|
128
|
-
return (0, _start.default)(router, opt);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
constructor(path = '', parent = {}) {
|
|
132
|
-
path = getBasePath(path);
|
|
133
|
-
path = path ? `/${path}` : '';
|
|
134
|
-
(0, _util.defineProperty)(this, 'runtime', getRuntime(parent));
|
|
135
|
-
(0, _util.defineProperty)(this, 'path', parent instanceof Router ? `${parent.path}${path}` : path);
|
|
136
|
-
(0, _util.defineProperty)(this, 'settings', parent instanceof Router ? parent.settings : (0, _settings.default)(this));
|
|
137
|
-
(0, _util.defineProperty)(this, 'assets', parent instanceof Router ? parent.assets : (0, _assets.default)(this));
|
|
138
|
-
(0, _util.defineProperty)(this, 'log', parent instanceof Router ? parent.log : (0, _log.default)(this));
|
|
139
|
-
(0, _util.defineProperty)(this, '_routes', parent instanceof Router ? parent._routes : []);
|
|
140
|
-
(0, _util.defineProperty)(this, '_registers', parent instanceof Router ? parent._registers : Object.create(null));
|
|
141
|
-
(0, _util.defineProperty)(this, '_preprocessors', parent instanceof Router ? parent._preprocessors : Object.create(null));
|
|
142
|
-
(0, _util.defineProperty)(this, '_controllers', parent instanceof Router ? parent._controllers : Object.create(null));
|
|
143
|
-
(0, _util.defineProperty)(this, '_services', parent instanceof Router ? parent._services : Object.create(null));
|
|
144
|
-
(0, _util.defineProperty)(this, '_extensions', parent instanceof Router ? parent._extensions : Object.create(null));
|
|
145
|
-
(0, _util.defineProperty)(this, '_plugins', parent instanceof Router ? parent._plugins : Object.create(null));
|
|
146
|
-
(0, _util.defineProperty)(this, '_orders', parent instanceof Router ? parent._orders : Object.create(null));
|
|
147
|
-
this.callback = _callback.default.bind(this, this._routes);
|
|
148
|
-
}
|
|
149
|
-
/** 子路由 */
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
route(path) {
|
|
153
|
-
return new Router(path, this);
|
|
154
|
-
}
|
|
155
|
-
/** 获取指定路径的 Preprocessor 列表 */
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
preprocessor(path, preprocessor, {
|
|
159
|
-
order = 0,
|
|
160
|
-
group = ''
|
|
161
|
-
} = {}) {
|
|
162
|
-
if (arguments.length <= 1) {
|
|
163
|
-
const list = [];
|
|
164
|
-
|
|
165
|
-
for (const findPath = [], paths = [...path.split('/').filter(Boolean), '']; paths.length; findPath.push(paths.shift())) {
|
|
166
|
-
const preprocessors = this._preprocessors[findPath.join('/')];
|
|
167
|
-
|
|
168
|
-
if (!preprocessors) {
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
list.push(...preprocessors.map(p => p.preprocessor));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return list;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (!preprocessor) {
|
|
179
|
-
return null;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (!Object.prototype.isPrototypeOf.call(_Preprocessor.default, preprocessor)) {
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const k = `${this.path}/${getBasePath(path)}`;
|
|
187
|
-
let list = this._preprocessors[k];
|
|
188
|
-
|
|
189
|
-
if (!list) {
|
|
190
|
-
list = this._preprocessors[k] = [];
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const item = {
|
|
194
|
-
order,
|
|
195
|
-
group,
|
|
196
|
-
preprocessor
|
|
197
|
-
};
|
|
198
|
-
list.push(item);
|
|
199
|
-
list.sort(({
|
|
200
|
-
order: a
|
|
201
|
-
}, {
|
|
202
|
-
order: b
|
|
203
|
-
}) => a - b);
|
|
204
|
-
return (0, _util.onceExec)(() => {
|
|
205
|
-
const index = list.indexOf(item);
|
|
206
|
-
|
|
207
|
-
if (index < 0) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
list.splice(index, 1);
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* 注册处理函数
|
|
216
|
-
* @param path 要注册的路径
|
|
217
|
-
* @param handle 要注册的处理函数
|
|
218
|
-
* @param options 选项
|
|
219
|
-
*/
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
verb(path, handle, methods, options) {
|
|
223
|
-
if (typeof handle !== 'function') {
|
|
224
|
-
return null;
|
|
225
|
-
} // 参数预处理
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (!Array.isArray(methods) && typeof methods === 'object') {
|
|
229
|
-
options = methods;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (typeof methods === 'string') {
|
|
233
|
-
methods = [methods];
|
|
234
|
-
} else if (!Array.isArray(methods)) {
|
|
235
|
-
methods = options ? options.methods || handle[_index.symbols.methods] : undefined;
|
|
236
|
-
methods = typeof methods === 'string' ? [methods] : Array.isArray(methods) ? methods : ['GET', 'POST', 'PUT', 'DELETE'];
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (!methods.length) {
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
path = `${this.path}/${getBasePath(path)}`;
|
|
244
|
-
let {
|
|
245
|
-
controller,
|
|
246
|
-
order = handle[_index.symbols.order] || 0,
|
|
247
|
-
test = handle[_index.symbols.test],
|
|
248
|
-
config = handle[_index.symbols.config] || {},
|
|
249
|
-
group = '',
|
|
250
|
-
exports = {},
|
|
251
|
-
root = '',
|
|
252
|
-
absPath = '',
|
|
253
|
-
filePath = '',
|
|
254
|
-
name = handle.name
|
|
255
|
-
} = options || {};
|
|
256
|
-
|
|
257
|
-
if (filePath && !absPath) {
|
|
258
|
-
absPath = root ? pathFn.resolve(root, pathFn.join('.', filePath)) : filePath;
|
|
259
|
-
} else if (!filePath && absPath) {
|
|
260
|
-
filePath = root ? pathFn.relative(root, absPath) : absPath;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const token = pathToRegexp.parse(path);
|
|
264
|
-
const regex = pathToRegexp.tokensToRegExp(token);
|
|
265
|
-
const names = token.filter(x => x && typeof x === 'object').map(t => typeof t === 'string' ? t : String(t.name));
|
|
266
|
-
const nameLength = names.length;
|
|
267
|
-
const item = {
|
|
268
|
-
controller,
|
|
269
|
-
root,
|
|
270
|
-
absPath,
|
|
271
|
-
filePath,
|
|
272
|
-
exports,
|
|
273
|
-
config,
|
|
274
|
-
handle,
|
|
275
|
-
group,
|
|
276
|
-
order,
|
|
277
|
-
path,
|
|
278
|
-
methods,
|
|
279
|
-
test,
|
|
280
|
-
name,
|
|
281
|
-
scope: [].concat(...token.map(t => typeof t === 'string' ? t.split('/') : [`:${t.name}`])).filter(Boolean),
|
|
282
|
-
|
|
283
|
-
match(path) {
|
|
284
|
-
const res = regex.exec(path);
|
|
285
|
-
|
|
286
|
-
if (!res) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const params = {};
|
|
291
|
-
|
|
292
|
-
for (let i = 0; i < nameLength; i++) {
|
|
293
|
-
params[names[i]] = res[i + 1];
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return params;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
};
|
|
300
|
-
const list = this._routes;
|
|
301
|
-
list.push(item);
|
|
302
|
-
list.sort(({
|
|
303
|
-
order: a
|
|
304
|
-
}, {
|
|
305
|
-
order: b
|
|
306
|
-
}) => a - b);
|
|
307
|
-
return (0, _util.onceExec)(() => {
|
|
308
|
-
const index = list.indexOf(item);
|
|
309
|
-
|
|
310
|
-
if (index < 0) {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
list.splice(index, 1);
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* 注册 HTTP GET 处理函数
|
|
319
|
-
* @param path 要注册的路径
|
|
320
|
-
* @param handle 要注册的处理函数
|
|
321
|
-
* @param options 选项
|
|
322
|
-
*/
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
get(path, handle, options) {
|
|
326
|
-
return this.verb(path, handle, { ...options,
|
|
327
|
-
methods: ['GET']
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* 注册 HTTP POST 处理函数
|
|
332
|
-
* @param path 要注册的路径
|
|
333
|
-
* @param handle 要注册的处理函数
|
|
334
|
-
* @param options 选项
|
|
335
|
-
*/
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
post(path, handle, options) {
|
|
339
|
-
return this.verb(path, handle, { ...options,
|
|
340
|
-
methods: ['POST']
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* 注册 HTTP PUT 处理函数
|
|
345
|
-
* @param path 要注册的路径
|
|
346
|
-
* @param handle 要注册的处理函数
|
|
347
|
-
* @param options 选项
|
|
348
|
-
*/
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
put(path, handle, options) {
|
|
352
|
-
return this.verb(path, handle, { ...options,
|
|
353
|
-
methods: ['PUT']
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* 注册 HTTP DELETE 处理函数
|
|
358
|
-
* @param path 要注册的路径
|
|
359
|
-
* @param handle 要注册的处理函数
|
|
360
|
-
* @param options 选项
|
|
361
|
-
*/
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
delete(path, handle, options) {
|
|
365
|
-
return this.verb(path, handle, { ...options,
|
|
366
|
-
methods: ['DELETE']
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* 注册 HTTP HEAD 处理函数
|
|
371
|
-
* @param path 要注册的路径
|
|
372
|
-
* @param handle 要注册的处理函数
|
|
373
|
-
* @param options 选项
|
|
374
|
-
*/
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
head(path, handle, options) {
|
|
378
|
-
return this.verb(path, handle, { ...options,
|
|
379
|
-
methods: ['HEAD']
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* 注册 HTTP OPTIONS 处理函数
|
|
384
|
-
* @param path 要注册的路径
|
|
385
|
-
* @param handle 要注册的处理函数
|
|
386
|
-
* @param options 选项
|
|
387
|
-
*/
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
options(path, handle, options) {
|
|
391
|
-
return this.verb(path, handle, { ...options,
|
|
392
|
-
methods: ['OPTIONS']
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* 注册 HTTP 资源
|
|
397
|
-
* @param path 要注册的路径
|
|
398
|
-
* @param exports 要注册的资源
|
|
399
|
-
* @param options 选项
|
|
400
|
-
*/
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
resource(path, exports, options) {
|
|
404
|
-
({
|
|
405
|
-
path,
|
|
406
|
-
options
|
|
407
|
-
} = initOptions(this, path, exports, options));
|
|
408
|
-
const removelist = [];
|
|
409
|
-
|
|
410
|
-
for (const k in exports) {
|
|
411
|
-
if (!/^[a-z0-9][a-z0-9A-Z_-]*$/.test(k)) {
|
|
412
|
-
continue;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
const item = exports[k];
|
|
416
|
-
|
|
417
|
-
if (!item) {
|
|
418
|
-
continue;
|
|
419
|
-
} // 特定处理处理函数
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
if (typeof item === 'function' && k in _vars.resourceHandleMap) {
|
|
423
|
-
const info = _vars.resourceHandleMap[k];
|
|
424
|
-
const config = { ...options.config,
|
|
425
|
-
...item[_index.symbols.config]
|
|
426
|
-
};
|
|
427
|
-
let order = item[_index.symbols.order];
|
|
428
|
-
|
|
429
|
-
if (typeof order !== 'number' || !isFinite(order)) {
|
|
430
|
-
({
|
|
431
|
-
order
|
|
432
|
-
} = options);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
const remove = this.verb(`${path}${info.path}`, item, { ...options,
|
|
436
|
-
config,
|
|
437
|
-
order,
|
|
438
|
-
test: item[_index.symbols.test],
|
|
439
|
-
methods: info.methods,
|
|
440
|
-
name: k
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
if (remove) {
|
|
444
|
-
removelist.push(remove);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
continue;
|
|
448
|
-
} // 成员处理函数
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
removelist.push(...(0, _setHandleItem.default)(this, `${path}/:id/${k}`, item, options, k));
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
return (0, _util.onceExec)(...removelist);
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* 注册 HTTP 处理函数集
|
|
458
|
-
* @param path 要注册的路径
|
|
459
|
-
* @param exports 要注册的处理函数集
|
|
460
|
-
* @param options 选项
|
|
461
|
-
*/
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
collection(path, exports, options) {
|
|
465
|
-
({
|
|
466
|
-
path,
|
|
467
|
-
options
|
|
468
|
-
} = initOptions(this, path, exports, options));
|
|
469
|
-
const removelist = [];
|
|
470
|
-
|
|
471
|
-
for (const k in exports) {
|
|
472
|
-
if (!/^[a-z0-9][a-z0-9A-Z_-]*$/.test(k)) {
|
|
473
|
-
continue;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
removelist.push(...(0, _setHandleItem.default)(this, `${path}/${k}`, exports[k], options, k));
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
return (0, _util.onceExec)(...removelist);
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* 注册 HTTP 资源成员处理函数集
|
|
483
|
-
* @param path 要注册的路径
|
|
484
|
-
* @param exports 要注册的处理函数集
|
|
485
|
-
* @param options 选项
|
|
486
|
-
*/
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
member(path, exports, options) {
|
|
490
|
-
({
|
|
491
|
-
path,
|
|
492
|
-
options
|
|
493
|
-
} = initOptions(this, path, exports, options));
|
|
494
|
-
const removelist = [];
|
|
495
|
-
|
|
496
|
-
for (const k in exports) {
|
|
497
|
-
if (!/^[a-z0-9][a-z0-9A-Z_-]*$/.test(k)) {
|
|
498
|
-
continue;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
removelist.push(...(0, _setHandleItem.default)(this, `${path}/:id/${k}`, exports[k], options));
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
return (0, _util.onceExec)(...removelist);
|
|
505
|
-
}
|
|
506
|
-
/** 获取匹配路径的项目 */
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
*match(path, method) {
|
|
510
|
-
for (const item of Array.from(this._routes)) {
|
|
511
|
-
if (method && item.methods.length && !item.methods.includes(method)) {
|
|
512
|
-
continue;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
if (!item.match(path)) {
|
|
516
|
-
continue;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
yield item;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
*[Symbol.iterator]() {
|
|
524
|
-
yield* Array.from(this._routes);
|
|
525
|
-
}
|
|
526
|
-
/**
|
|
527
|
-
* 扫描指定路径,并将扫描到的文件进行注册
|
|
528
|
-
* @param root 要扫描的路径
|
|
529
|
-
* @param options 选项
|
|
530
|
-
*/
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
async scan(root, {
|
|
534
|
-
group,
|
|
535
|
-
scope,
|
|
536
|
-
order
|
|
537
|
-
} = {}) {
|
|
538
|
-
scope = typeof scope !== 'string' ? '' : scope;
|
|
539
|
-
group = group && typeof group === 'string' ? group.replace(/[/\-_][a-z]/g, a => a.toUpperCase()).replace(/^\.+|[^a-zA-Z0-9.]|\.+$/g, '').replace(/(^|\.)[0-9]+/g, '$1').replace(/(^|\.)[A-Z]/g, a => a.toLowerCase()).replace(/\.+/g, '.') : '';
|
|
540
|
-
|
|
541
|
-
for await (const file of (0, _scan.default)(root)) {
|
|
542
|
-
await (0, _register.register)(file, {
|
|
543
|
-
group,
|
|
544
|
-
order
|
|
545
|
-
}, scope ? this.route(scope) : this);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
/** 为当前路由设置注册器 */
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
setRegister(register) {
|
|
552
|
-
return (0, _register.setRegister)(register, this._registers);
|
|
553
|
-
}
|
|
554
|
-
/** 注册文件 */
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
async register(file, opt = {}) {
|
|
558
|
-
return (0, _register.register)(file, opt, this);
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
controller(id, value) {
|
|
562
|
-
if (value === undefined || typeof value === 'boolean') {
|
|
563
|
-
return RegisterManager.find(_Controller.default, this._controllers, id, value);
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
return RegisterManager.register(_Controller.default, this._controllers, id || '', value);
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
service(id, value) {
|
|
570
|
-
if (value === undefined || typeof value === 'boolean') {
|
|
571
|
-
return RegisterManager.find(_Service.default, this._services, id, value);
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
return RegisterManager.register(_Service.default, this._services, id || '', value);
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
extension(id, value) {
|
|
578
|
-
if (value === undefined || typeof value === 'boolean') {
|
|
579
|
-
return RegisterManager.find(_Extension.default, this._extensions, id, value);
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
return RegisterManager.register(_Extension.default, this._extensions, id || '', value);
|
|
583
|
-
}
|
|
584
|
-
/** 获取安装的 */
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
plugin(plugin) {
|
|
588
|
-
if (!(plugin instanceof _Plugin.default)) {
|
|
589
|
-
return this._plugins[plugin];
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
const {
|
|
593
|
-
order,
|
|
594
|
-
name,
|
|
595
|
-
path
|
|
596
|
-
} = plugin;
|
|
597
|
-
this._plugins[name] = plugin;
|
|
598
|
-
this._plugins[path] = plugin;
|
|
599
|
-
|
|
600
|
-
for (const type in order) {
|
|
601
|
-
(0, _order.setOrder)(this._orders, name || '', order[type], type);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
/** 获取指定类型的顺序列表 */
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
order(type = 'default') {
|
|
608
|
-
return Array.from((0, _order.getOrder)(this._orders, type)[0]);
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
var _default = Router;
|
|
614
|
-
exports.default = _default;
|
|
615
|
-
//# sourceMappingURL=index.js.map
|
package/Router/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/k99/Router/index.ts"],"names":["getBasePath","path","replace","initOptions","router","exports","controller","group","order","root","filePath","absPath","config","Config","Order","isFinite","preprocessor","Preprocessor","options","Controller","getRuntime","Router","runtime","pathFn","resolve","process","cwd","settings","relative","assets","log","setRegister","register","start","opt","constructor","parent","_routes","_registers","Object","create","_preprocessors","_controllers","_services","_extensions","_plugins","_orders","callback","bind","route","arguments","length","list","findPath","paths","split","filter","Boolean","push","shift","preprocessors","join","map","p","prototype","isPrototypeOf","call","k","item","sort","a","b","index","indexOf","splice","verb","handle","methods","Array","isArray","symbols","undefined","test","name","token","pathToRegexp","parse","regex","tokensToRegExp","names","x","t","String","nameLength","scope","concat","match","res","exec","params","i","get","post","put","delete","head","resource","removelist","resourceHandleMap","info","remove","collection","member","method","from","includes","Symbol","iterator","scan","toUpperCase","toLowerCase","file","id","value","RegisterManager","find","service","Service","extension","Extension","plugin","Plugin","type"],"mappings":";;;;;;;AAAA;;AAIA;;AAEA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA;AACA,SAASA,WAAT,CAAqBC,IAArB,EAAmC;AAAE,SAAOA,IAAI,CAACC,OAAL,CAAa,YAAb,EAA2B,EAA3B,CAAP;AAAwC;;AAE7E,SAASC,WAAT,CAAqBC,MAArB,EAAqCH,IAArC,EAAmDI,OAAnD,EAAqE;AAAEC,EAAAA,UAAF;AAAcC,EAAAA,KAAd;AAAqBC,EAAAA,KAArB;AAA4BC,EAAAA,IAA5B;AAAkCC,EAAAA,QAAlC;AAA4CC,EAAAA,OAA5C;AAAqDC,EAAAA;AAArD,IAAgF,EAArJ,EAAyJ;AACxJ;AACAA,EAAAA,MAAM,GAAG,EAAE,GAAGA,MAAL;AAAa,OAAGP,OAAO,CAACQ;AAAxB,GAAT,CAFwJ,CAGxJ;;AACAL,EAAAA,KAAK,GAAG,OAAOH,OAAO,CAACS,KAAf,KAAyB,QAAzB,IAAqCC,QAAQ,CAACV,OAAO,CAACS,KAAT,CAA7C,GAA+DT,OAAO,CAACS,KAAvE,GAA+EN,KAAvF,CAJwJ,CAKxJ;;AACAJ,EAAAA,MAAM,CAACY,YAAP,CAAoBf,I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KrF,WAArC,EAAkD8E,EAAlD,EAAsDC,KAAtD,CAAP;AACA;;AACD,WAAOC,eAAe,CAAC5F,QAAhB,CAAyBiG,kBAAzB,EAAoC,KAAKrF,WAAzC,EAAsD8E,EAAE,IAAI,EAA5D,EAAgEC,KAAhE,CAAP;AACA;AACD;;;AAIAO,EAAAA,MAAM,CAACA,MAAD,EAA8C;AACnD,QAAI,EAAEA,MAAM,YAAYC,eAApB,CAAJ,EAAiC;AAChC,aAAO,KAAKtF,QAAL,CAAcqF,MAAd,CAAP;AACA;;AACD,UAAM;AAAE1H,MAAAA,KAAF;AAAS2E,MAAAA,IAAT;AAAelF,MAAAA;AAAf,QAAwBiI,MAA9B;AACA,SAAKrF,QAAL,CAAcsC,IAAd,IAAsB+C,MAAtB;AACA,SAAKrF,QAAL,CAAc5C,IAAd,IAAsBiI,MAAtB;;AACA,SAAK,MAAME,IAAX,IAAmB5H,KAAnB,EAA0B;AAAE,2BAAS,KAAKsC,OAAd,EAAuBqC,IAAI,IAAI,EAA/B,EAAmC3E,KAAK,CAAC4H,IAAD,CAAxC,EAAgDA,IAAhD;AAAwD;AACpF;AACD;;;AACA5H,EAAAA,KAAK,CAAC4H,IAAI,GAAG,SAAR,EAA6B;AACjC,WAAOtD,KAAK,CAACoC,IAAN,CAAW,qBAAS,KAAKpE,OAAd,EAAuBsF,IAAvB,EAA6B,CAA7B,CAAX,CAAP;AACA;;AAtUW;;eAoWE/G,M","sourcesContent":["import * as pathFn from 'path';\nimport { IncomingMessage, ServerResponse } from 'http';\nimport { Http2ServerRequest, Http2ServerResponse } from 'http2';\n\nimport * as pathToRegexp from 'path-to-regexp';\n\nimport { Exports, Method, Handle, ResourceOption, HandleInfo, HandleOption, FileItem, AddOptions, ROptions, Register, K99Request, K99Response, RouterOptions, RouterRuntime, StartOption, symbols, Handles } from '../index';\nimport Controller, { Class as ControllerClass, Param as ControllerParam, Base as ControllerBase } from '../Controller';\n\nimport Service, { Class as ServiceClass, Param as ServiceParam } from '../Service';\nimport Preprocessor, { Class as PreprocessorClass } from '../Preprocessor';\nimport Extension, { Class as ExtensionClass, Param as ExtensionParam, Base as ExtensionBase} from '../Extension';\nimport Plugin from '../Plugin';\nimport { defineProperty, onceExec } from '../util';\n\nimport * as RegisterManager from './registerManager';\nimport { setRegister, register } from './register';\nimport callback from './callback';\nimport scan from './scan';\nimport { setOrder, getOrder } from './order';\nimport start from './start';\nimport Settings from './settings';\nimport Assets from './assets';\nimport Log from './log';\nimport setHandleItem from './setHandleItem';\nimport { resourceHandleMap } from './vars';\n\n/** 去除路径开头与结尾的斜杠 */\nfunction getBasePath(path: string) { return path.replace(/^\\/+|\\/+$/g, ''); }\n\nfunction initOptions(router: Router, path: string, exports: Exports, { controller, group, order, root, filePath, absPath, config }: ResourceOption = {}) {\n\t// 默认配置\n\tconfig = { ...config, ...exports.Config };\n\t// 默认顺序\n\torder = typeof exports.Order === 'number' && isFinite(exports.Order) ? exports.Order : order;\n\t// 安装预处理器\n\trouter.preprocessor(path, exports.Preprocessor!, { group, order });\n\t// 路径\n\tpath = getBasePath(path);\n\t// 公共选项\n\tconst options: ResourceOption & { exports?: Exports } = {controller: exports.Controller || controller, group, order, root, filePath, absPath, exports, config};\n\t// 将自身添加到路由\n\tsetHandleItem(router, path, exports, options);\n\treturn { path, options };\n}\n\nfunction getRuntime(options: Router | RouterOptions): RouterRuntime {\n\tif (options instanceof Router) { return options.runtime; }\n\tconst path = pathFn.resolve(options.path || process.cwd());\n\tconst settings = pathFn.relative(path, pathFn.resolve(path, options.settings || 'runtime/settings'));\n\tconst assets = pathFn.relative(path, pathFn.resolve(path, options.assets || 'runtime/assets'));\n\tconst log = pathFn.relative(path, pathFn.resolve(path, options.log || 'runtime/log'));\n\treturn { path, settings, assets, log };\n}\nclass Router {\n\t/**\n\t * 设置公共的文件注册器\n\t * @param register 注册配置\n\t */\n\tstatic setRegister(register: Register): boolean {\n\t\treturn setRegister(register);\n\t}\n\tstatic async start(opt: StartOption = {}){\n\t\tconst router = new Router();\n\t\treturn start(router, opt);\n\t}\n\tconstructor(path = '', parent: Router | RouterOptions = {}) {\n\t\tpath = getBasePath(path);\n\t\tpath = path ? `/${ path }` : '';\n\t\tdefineProperty(this, 'runtime', getRuntime(parent));\n\t\tdefineProperty(this, 'path', parent instanceof Router ? `${ parent.path }${ path }` : path);\n\t\tdefineProperty(this, 'settings', parent instanceof Router ? parent.settings : Settings(this));\n\t\tdefineProperty(this, 'assets', parent instanceof Router ? parent.assets : Assets(this));\n\t\tdefineProperty(this, 'log', parent instanceof Router ? parent.log : Log(this));\n\t\tdefineProperty(this, '_routes', parent instanceof Router ? parent._routes : []);\n\t\tdefineProperty(this, '_registers', parent instanceof Router ? parent._registers : Object.create(null));\n\t\tdefineProperty(this, '_preprocessors', parent instanceof Router ? parent._preprocessors : Object.create(null));\n\t\tdefineProperty(this, '_controllers', parent instanceof Router ? parent._controllers : Object.create(null));\n\t\tdefineProperty(this, '_services', parent instanceof Router ? parent._services : Object.create(null));\n\t\tdefineProperty(this, '_extensions', parent instanceof Router ? parent._extensions : Object.create(null));\n\t\tdefineProperty(this, '_plugins', parent instanceof Router ? parent._plugins : Object.create(null));\n\t\tdefineProperty(this, '_orders', parent instanceof Router ? parent._orders : Object.create(null));\n\t\tthis.callback = callback.bind(this, this._routes);\n\t}\n\t/** 子路由 */\n\troute(path: string) { return new Router(path, this); }\n\t/** 获取指定路径的 Preprocessor 列表 */\n\tpreprocessor(path: string): PreprocessorClass<any>[];\n\t/**\n\t * 注册 Preprocessor\n\t * @param path 所要注册到的路径\n\t * @param preprocessor 所要注册的 Preprocessor\n\t * @param options 注册选项\n\t */\n\tpreprocessor(\n\t\tpath: string,\n\t\tpreprocessor: PreprocessorClass<any>,\n\t\toptions?: {order?: number, group?: string},\n\t): (() => void) | null;\n\tpreprocessor(\n\t\tpath: string,\n\t\tpreprocessor?: PreprocessorClass<any>,\n\t\t{ order = 0, group = '' }: {order?: number, group?: string} = {},\n\t): PreprocessorClass<any>[] | (() => void) | null {\n\t\tif (arguments.length <= 1) {\n\t\t\tconst list: PreprocessorClass<any>[] = [];\n\t\t\tfor (const findPath: string[] = [], paths = [...path.split('/').filter(Boolean), '']; paths.length; findPath.push(paths.shift()!)) {\n\t\t\t\tconst preprocessors = this._preprocessors[findPath.join('/')];\n\t\t\t\tif (!preprocessors) { continue; }\n\t\t\t\tlist.push(...preprocessors.map(p => p.preprocessor));\n\t\t\t}\n\t\t\treturn list;\n\t\t}\n\t\tif (!preprocessor) { return null; }\n\t\tif (!Object.prototype.isPrototypeOf.call(Preprocessor, preprocessor)) { return null; }\n\t\tconst k = `${ this.path }/${ getBasePath(path) }`;\n\t\tlet list = this._preprocessors[k];\n\t\tif (!list) { list = this._preprocessors[k] = []; }\n\t\tconst item = {order, group, preprocessor};\n\t\tlist.push(item);\n\t\tlist.sort(({order: a}, {order: b}) => a - b);\n\t\treturn onceExec(() => {\n\t\t\tconst index = list.indexOf(item);\n\t\t\tif (index < 0) { return; }\n\t\t\tlist.splice(index, 1);\n\t\t});\n\t}\n\t/**\n\t * 注册处理函数\n\t * @param path 要注册的路径\n\t * @param handle 要注册的处理函数\n\t * @param options 选项\n\t */\n\tverb(path: string, handle: Handle, options?: HandleOption): (() => void) | null;\n\t/**\n\t * 注册处理函数\n\t * @param path 要注册的路径\n\t * @param handle 要注册的处理函数\n\t * @param methods 有效的 HTTP 请求方法\n\t * @param options 选项\n\t */\n\tverb(path: string, handle: Handle, methods: Method | Method[], options?: HandleOption): (() => void) | null;\n\tverb(path: string, handle: Handle, methods?: Method | Method[] | HandleOption, options?: HandleOption): (() => void) | null {\n\t\tif (typeof handle !== 'function') { return null; }\n\n\t\t// 参数预处理\n\t\tif (!Array.isArray(methods) && typeof methods === 'object') { options = methods; }\n\t\tif (typeof methods === 'string') {\n\t\t\tmethods = [methods];\n\t\t} else if (!Array.isArray(methods)) {\n\t\t\tmethods = options ? options.methods || handle[symbols.methods] : undefined;\n\t\t\tmethods = typeof methods === 'string' ? [methods] : Array.isArray(methods) ? methods : ['GET', 'POST', 'PUT', 'DELETE'];\n\t\t}\n\t\tif (!methods.length) { return null; }\n\n\t\tpath = `${ this.path }/${ getBasePath(path) }`;\n\t\tlet {\n\t\t\tcontroller,\n\t\t\torder = handle[symbols.order] || 0,\n\t\t\ttest = handle[symbols.test],\n\t\t\tconfig = handle[symbols.config] || {},\n\t\t\tgroup = '',\n\t\t\texports = {},\n\t\t\troot = '',\n\t\t\tabsPath = '',\n\t\t\tfilePath = '',\n\t\t\tname = handle.name,\n\t\t}: HandleOption = options || {};\n\t\tif (filePath && !absPath) {\n\t\t\tabsPath = root ? pathFn.resolve(root, pathFn.join('.', filePath)) : filePath;\n\t\t} else if (!filePath && absPath) {\n\t\t\tfilePath = root ? pathFn.relative(root, absPath) : absPath;\n\t\t}\n\n\t\tconst token = pathToRegexp.parse(path);\n\t\tconst regex = pathToRegexp.tokensToRegExp(token);\n\t\tconst names = token.filter(x => x && typeof x === 'object').map(t => typeof t === 'string' ? t : String(t.name));\n\t\tconst nameLength = names.length;\n\t\tconst item: HandleInfo = {\n\t\t\tcontroller, root, absPath, filePath, exports, config, handle, group, order, path, methods, test, name,\n\t\t\tscope: ([] as string[]).concat(...token.map(t => typeof t === 'string' ? t.split('/') : [`:${ t.name }`])).filter(Boolean),\n\t\t\tmatch(path: string) {\n\t\t\t\tconst res = regex.exec(path);\n\t\t\t\tif (!res) { return; }\n\t\t\t\tconst params: {[k: string]: string | undefined} = {};\n\t\t\t\tfor (let i = 0; i < nameLength; i++) {\n\t\t\t\t\tparams[names[i]] = res[i + 1];\n\t\t\t\t}\n\t\t\t\treturn params;\n\t\t\t},\n\t\t};\n\n\t\tconst list = this._routes;\n\t\tlist.push(item);\n\t\tlist.sort(({order: a}, {order: b}) => a - b);\n\t\treturn onceExec(() => {\n\t\t\tconst index = list.indexOf(item);\n\t\t\tif (index < 0) { return; }\n\t\t\tlist.splice(index, 1);\n\t\t});\n\t}\n\t/**\n\t * 注册 HTTP GET 处理函数\n\t * @param path 要注册的路径\n\t * @param handle 要注册的处理函数\n\t * @param options 选项\n\t */\n\tget(path: string, handle: Handle, options?: HandleOption) { return this.verb(path, handle, {...options, methods: ['GET']}); }\n\t/**\n\t * 注册 HTTP POST 处理函数\n\t * @param path 要注册的路径\n\t * @param handle 要注册的处理函数\n\t * @param options 选项\n\t */\n\tpost(path: string, handle: Handle, options?: HandleOption) { return this.verb(path, handle, {...options, methods: ['POST']}); }\n\t/**\n\t * 注册 HTTP PUT 处理函数\n\t * @param path 要注册的路径\n\t * @param handle 要注册的处理函数\n\t * @param options 选项\n\t */\n\tput(path: string, handle: Handle, options?: HandleOption) { return this.verb(path, handle, {...options, methods: ['PUT']}); }\n\t/**\n\t * 注册 HTTP DELETE 处理函数\n\t * @param path 要注册的路径\n\t * @param handle 要注册的处理函数\n\t * @param options 选项\n\t */\n\tdelete(path: string, handle: Handle, options?: HandleOption) { return this.verb(path, handle, {...options, methods: ['DELETE']}); }\n\t/**\n\t * 注册 HTTP HEAD 处理函数\n\t * @param path 要注册的路径\n\t * @param handle 要注册的处理函数\n\t * @param options 选项\n\t */\n\thead(path: string, handle: Handle, options?: HandleOption) { return this.verb(path, handle, {...options, methods: ['HEAD']}); }\n\t/**\n\t * 注册 HTTP OPTIONS 处理函数\n\t * @param path 要注册的路径\n\t * @param handle 要注册的处理函数\n\t * @param options 选项\n\t */\n\toptions(path: string, handle: Handle, options?: HandleOption) { return this.verb(path, handle, {...options, methods: ['OPTIONS']}); }\n\t/**\n\t * 注册 HTTP 资源\n\t * @param path 要注册的路径\n\t * @param exports 要注册的资源\n\t * @param options 选项\n\t */\n\tresource(path: string, exports: Exports, options?: ResourceOption): () => void {\n\t\t({ path, options } = initOptions(this, path, exports, options));\n\t\tconst removelist: (() => void)[] = [];\n\t\tfor (const k in exports) {\n\t\t\tif (!/^[a-z0-9][a-z0-9A-Z_-]*$/.test(k)) { continue; }\n\t\t\tconst item = exports[k] as undefined | Handle | Handles;\n\t\t\tif (!item) { continue; }\n\t\t\t// 特定处理处理函数\n\t\t\tif (typeof item === 'function' && k in resourceHandleMap) {\n\t\t\t\tconst info = resourceHandleMap[k];\n\t\t\t\tconst config = { ...options.config, ...item[symbols.config] };\n\t\t\t\tlet order = item[symbols.order];\n\t\t\t\tif (typeof order !== 'number' || !isFinite(order)) { ({ order } = options); }\n\t\t\t\tconst remove = this.verb(\n\t\t\t\t\t`${ path }${ info.path }`,\n\t\t\t\t\titem,\n\t\t\t\t\t{...options, config, order, test: item[symbols.test], methods: info.methods, name: k},\n\t\t\t\t);\n\t\t\t\tif (remove) { removelist.push(remove); }\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// 成员处理函数\n\t\t\tremovelist.push(...setHandleItem(this, `${ path }/:id/${ k }`, item, options, k));\n\t\t}\n\t\treturn onceExec(...removelist);\n\t}\n\t/**\n\t * 注册 HTTP 处理函数集\n\t * @param path 要注册的路径\n\t * @param exports 要注册的处理函数集\n\t * @param options 选项\n\t */\n\tcollection(path: string, exports: Exports, options?: ResourceOption): () => void {\n\t\t({ path, options } = initOptions(this, path, exports, options));\n\t\tconst removelist: (() => void)[] = [];\n\t\tfor (const k in exports) {\n\t\t\tif (!/^[a-z0-9][a-z0-9A-Z_-]*$/.test(k)) { continue; }\n\t\t\tremovelist.push(...setHandleItem(this, `${ path }/${ k }`, exports[k], options, k));\n\t\t}\n\t\treturn onceExec(...removelist);\n\t}\n\t/**\n\t * 注册 HTTP 资源成员处理函数集\n\t * @param path 要注册的路径\n\t * @param exports 要注册的处理函数集\n\t * @param options 选项\n\t */\n\tmember(path: string, exports: Exports, options?: ResourceOption): () => void {\n\t\t({ path, options } = initOptions(this, path, exports, options));\n\t\tconst removelist: (() => void)[] = [];\n\t\tfor (const k in exports) {\n\t\t\tif (!/^[a-z0-9][a-z0-9A-Z_-]*$/.test(k)) { continue; }\n\t\t\tremovelist.push(...setHandleItem(this, `${ path }/:id/${ k }`, exports[k], options));\n\t\t}\n\t\treturn onceExec(...removelist);\n\t}\n\t/** 获取匹配路径的项目 */\n\t*match(path: string, method?: Method): Iterable<HandleInfo> {\n\t\tfor (const item of Array.from(this._routes)) {\n\t\t\tif (method && item.methods.length && !item.methods.includes(method)) { continue; }\n\t\t\tif (!item.match(path)) { continue; }\n\t\t\tyield item;\n\t\t}\n\t}\n\t*[Symbol.iterator]() { yield *Array.from(this._routes); }\n\t/**\n\t * 扫描指定路径,并将扫描到的文件进行注册\n\t * @param root 要扫描的路径\n\t * @param options 选项\n\t */\n\tasync scan(root: string, {group, scope, order}: AddOptions = {}): Promise<void> {\n\t\tscope = typeof scope !== 'string' ? '' : scope;\n\n\t\tgroup = group && typeof group === 'string' ? group\n\t\t\t.replace(/[/\\-_][a-z]/g, a => a.toUpperCase())\n\t\t\t.replace(/^\\.+|[^a-zA-Z0-9.]|\\.+$/g, '')\n\t\t\t.replace(/(^|\\.)[0-9]+/g, '$1')\n\t\t\t.replace(/(^|\\.)[A-Z]/g, a => a.toLowerCase())\n\t\t\t.replace(/\\.+/g, '.') : '';\n\n\t\tfor await (const file of scan(root)) {\n\t\t\tawait register(file, {group, order}, scope ? this.route(scope) : this);\n\t\t}\n\t}\n\t/** 为当前路由设置注册器 */\n\tsetRegister(register: Register): boolean { return setRegister(register, this._registers); }\n\t/** 注册文件 */\n\tasync register(file: FileItem, opt: ROptions = {}): Promise<boolean> { return register(file, opt, this); }\n\tcontroller<T extends Controller>(id: string, controller: ControllerClass<T> | string): boolean;\n\tcontroller<T extends Controller>(id?: string, nodefault?: false): ControllerClass<T>;\n\tcontroller<T extends Controller>(id?: string, nodefault?: boolean): ControllerClass<T> | undefined;\n\tcontroller<T extends Controller>(id?: string, value?: ControllerClass<T> | string | boolean): boolean | ControllerClass<T> | undefined {\n\t\tif (value === undefined || typeof value === 'boolean') {\n\t\t\treturn RegisterManager.find(Controller, this._controllers, id, value) as ControllerClass<T> | undefined;\n\t\t}\n\t\treturn RegisterManager.register(Controller, this._controllers, id || '', value);\n\t}\n\tservice<T extends Service<any, any>>(id: string, service: ServiceClass<T> | string): boolean;\n\tservice<T extends Service<any, any>>(id?: string, nodefault?: false): ServiceClass<T>;\n\tservice<T extends Service<any, any>>(id?: string, nodefault?: boolean): ServiceClass<T> | undefined;\n\tservice<T extends Service<any, any>>(id?: string, value?: ServiceClass<T> | string | boolean): boolean | ServiceClass<T> | undefined {\n\t\tif (value === undefined || typeof value === 'boolean') {\n\t\t\treturn RegisterManager.find(Service, this._services, id, value) as ServiceClass<T> | undefined;\n\t\t}\n\t\treturn RegisterManager.register(Service, this._services, id || '', value);\n\t}\n\textension<T extends Extension<any, any>>(id: string, service: ExtensionClass<T> | string): boolean;\n\textension<T extends Extension<any, any>>(id?: string, nodefault?: false): ExtensionClass<T>;\n\textension<T extends Extension<any, any>>(id?: string, nodefault?: boolean): ExtensionClass<T> | undefined;\n\textension<T extends Extension<any, any>>(id?: string, value?: ExtensionClass<T> | string | boolean): boolean | ExtensionClass<T> | undefined {\n\t\tif (value === undefined || typeof value === 'boolean') {\n\t\t\treturn RegisterManager.find(Extension, this._extensions, id, value) as ExtensionClass<T> | undefined;\n\t\t}\n\t\treturn RegisterManager.register(Extension, this._extensions, id || '', value);\n\t}\n\t/** 获取安装的 */\n\tplugin(id: string): Plugin | undefined;\n\t/** 安装插件 */\n\tplugin(plugin: Plugin): undefined;\n\tplugin(plugin: string | Plugin): Plugin | undefined {\n\t\tif (!(plugin instanceof Plugin)) {\n\t\t\treturn this._plugins[plugin];\n\t\t}\n\t\tconst { order, name, path } = plugin;\n\t\tthis._plugins[name] = plugin;\n\t\tthis._plugins[path] = plugin;\n\t\tfor (const type in order) { setOrder(this._orders, name || '', order[type], type); }\n\t}\n\t/** 获取指定类型的顺序列表 */\n\torder(type = 'default'): string[] {\n\t\treturn Array.from(getOrder(this._orders, type)[0]);\n\t}\n}\n\ninterface Router {\n\t/** 运行时配置 */\n\treadonly runtime: RouterRuntime;\n\t/** 设置接口 */\n\treadonly settings: Settings;\n\t/** 资产接口 */\n\treadonly assets: Assets;\n\t/** 日志接口 */\n\treadonly log: Log;\n\t/** 工作路径 */\n\treadonly cwd: string;\n\t/** 注册器列表 */\n\treadonly _registers: {[key: string]: Register };\n\t/** 设置的预处理器 */\n\treadonly _preprocessors: {[k: string]: {preprocessor: PreprocessorClass<any>, order: number, group: string}[]};\n\treadonly _controllers: RegisterManager.ClassList<Controller, ControllerParam, ControllerBase<Controller>>;\n\treadonly _services: RegisterManager.ClassList<Service<any, any>, ServiceParam>;\n\treadonly _extensions: RegisterManager.ClassList<Extension<any, any>, ExtensionParam, ExtensionBase>;\n\treadonly _plugins: {[id: string]: Plugin};\n\treadonly _orders: { [key: string]: [string[], {[key: string]: number }]; };\n\t/** 路由列表 */\n\treadonly _routes: HandleInfo[];\n\t/** 当前路由路径 */\n\treadonly path: string;\n\t/** 连接的处理函数 */\n\tcallback(request: K99Request | IncomingMessage | Http2ServerRequest, response: K99Response | ServerResponse | Http2ServerResponse, next?: () => void): Promise<void>;\n}\nexport default Router;\n"],"file":"index.js"}
|