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/types.d.ts
ADDED
|
@@ -0,0 +1,748 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* k99 v0.3.0-beta.1
|
|
3
|
+
* (c) 2019-2022 Fierflame
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 服务
|
|
8
|
+
*/
|
|
9
|
+
declare abstract class Service<T = unknown, P extends any[] = []> implements Context {
|
|
10
|
+
/**
|
|
11
|
+
* @warning 不要重载构造函数或者主动调用创建实例
|
|
12
|
+
*/
|
|
13
|
+
constructor(context: Context);
|
|
14
|
+
readonly context: Context;
|
|
15
|
+
abstract export(...p: P): T;
|
|
16
|
+
/** 销毁时,会自动调用此方法销毁自动创建的容器 */
|
|
17
|
+
destroy(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
interface Service extends Context {
|
|
20
|
+
}
|
|
21
|
+
declare namespace Service {
|
|
22
|
+
interface Constructor<T, P extends any[] = []> {
|
|
23
|
+
new (context: Context): Service<T, P>;
|
|
24
|
+
prototype: Service<T, P>;
|
|
25
|
+
}
|
|
26
|
+
interface Func<T, P extends any[] = []> {
|
|
27
|
+
(context: Context, ...p: P): T;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 路由卫士
|
|
33
|
+
* @description 用于路由的过滤及处理函数执行前的预处理
|
|
34
|
+
*/
|
|
35
|
+
declare abstract class Guard<T = unknown> extends Service<T> {
|
|
36
|
+
decide(): void | boolean | null | undefined | Promise<void | boolean | null | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* 测试请求是否允许通过此路由访问
|
|
39
|
+
* @description 同一请求、同一路径下,在此函数中调用的 this.set、this.get、this.delete、this.has、this.keys、this.clear 等方法的数据与实例初始化后的共享。目前不同路径下暂不共享,后续可能会被设计为共享,但不同请求下必然不共享
|
|
40
|
+
* @description 同一路径下,若存在任意 test 返回 false 均会使得此路径不会被执行
|
|
41
|
+
* @param param 请求参数
|
|
42
|
+
*/
|
|
43
|
+
static test(param?: {
|
|
44
|
+
[k: string]: string | string[] | undefined;
|
|
45
|
+
}): Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* @description 映射的 Map 实例的 set 方法,与同一请求同一路径下的 test 共享同一 Map 实例,此方法会在其他地方重载,常规方式重载无效
|
|
48
|
+
*/
|
|
49
|
+
set(k: any, v: any): this;
|
|
50
|
+
/**
|
|
51
|
+
* @description 映射的 Map 实例的 get 方法,与同一请求同一路径下的 test 共享同一 Map 实例,此方法会在其他地方重载,常规方式重载无效
|
|
52
|
+
*/
|
|
53
|
+
get(k: any): any;
|
|
54
|
+
/**
|
|
55
|
+
* @description 映射的 Map 实例的 delete 方法,与同一请求同一路径下的 test 共享同一 Map 实例,此方法会在其他地方重载,常规方式重载无效
|
|
56
|
+
*/
|
|
57
|
+
delete(k: any): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* @description 映射的 Map 实例的 has 方法,与同一请求同一路径下的 test 共享同一 Map 实例,此方法会在其他地方重载,常规方式重载无效
|
|
60
|
+
*/
|
|
61
|
+
has(k: any): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* @description 映射的 Map 实例的 keys 方法,与同一请求同一路径下的 test 共享同一 Map 实例,此方法会在其他地方重载,常规方式重载无效
|
|
64
|
+
*/
|
|
65
|
+
keys(): IterableIterator<any>;
|
|
66
|
+
/**
|
|
67
|
+
* @description 映射的 Map 实例的 clear 方法,与同一请求同一路径下的 test 共享同一 Map 实例,此方法会在其他地方重载,常规方式重载无效
|
|
68
|
+
*/
|
|
69
|
+
clear(): void;
|
|
70
|
+
/**
|
|
71
|
+
* @description 映射的 Map 实例的 size 属性,与同一请求同一路径下的 test 共享同一 Map 实例,此方法会在其他地方重载,常规方式重载无效
|
|
72
|
+
*/
|
|
73
|
+
get size(): number;
|
|
74
|
+
/**
|
|
75
|
+
* @description 映射的 Map 实例的 set 方法,与同一请求同一路径下的 Guard 实例共享同一 Map 实例,此方法会在其他地方重载,常规方式重载无效
|
|
76
|
+
*/
|
|
77
|
+
static set(k: any, v: any): typeof Guard;
|
|
78
|
+
/**
|
|
79
|
+
* @description 映射的 Map 实例的 get 方法,与同一请求同一路径下的 Guard 实例共享同一 Map 实例,此方法会在其他地方重载,常规方式重载无效
|
|
80
|
+
*/
|
|
81
|
+
static get(k: any): any;
|
|
82
|
+
/**
|
|
83
|
+
* @description 映射的 Map 实例的 delete 方法,与同一请求同一路径下的 Guard 实例共享同一 Map 实例,此方法会在其他地方重载,常规方式重载无效
|
|
84
|
+
*/
|
|
85
|
+
static delete(k: any): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* @description 映射的 Map 实例的 has 方法,与同一请求同一路径下的 Guard 实例共享同一 Map 实例,此方法会在其他地方重载,常规方式重载无效
|
|
88
|
+
*/
|
|
89
|
+
static has(k: any): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* @description 映射的 Map 实例的 keys 方法,与同一请求同一路径下的 Guard 实例共享同一 Map 实例,此方法会在其他地方重载,常规方式重载无效
|
|
92
|
+
*/
|
|
93
|
+
static keys(): IterableIterator<any>;
|
|
94
|
+
/**
|
|
95
|
+
* @description 映射的 Map 实例的 clear 方法,与同一请求同一路径下的 Guard 实例共享同一 Map 实例,此方法会在其他地方重载,常规方式重载无效
|
|
96
|
+
*/
|
|
97
|
+
static clear(): void;
|
|
98
|
+
/**
|
|
99
|
+
* @description 映射的 Map 实例的 size 属性,与同一请求同一路径下的 Guard 实例共享同一 Map 实例,此方法会在其他地方重载,常规方式重载无效
|
|
100
|
+
*/
|
|
101
|
+
static get size(): number;
|
|
102
|
+
}
|
|
103
|
+
declare namespace Guard {
|
|
104
|
+
interface Constructor<T> extends Service.Constructor<T> {
|
|
105
|
+
new (context: Context): Guard<T>;
|
|
106
|
+
prototype: Guard<T>;
|
|
107
|
+
test(param: {
|
|
108
|
+
[k: string]: string | string[] | undefined;
|
|
109
|
+
}): void | boolean | null | undefined | Promise<void | boolean | null | undefined>;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
declare const returnSymbol: unique symbol;
|
|
114
|
+
declare const catchSymbol: unique symbol;
|
|
115
|
+
declare const finallySymbol: unique symbol;
|
|
116
|
+
declare const dataSymbol: unique symbol;
|
|
117
|
+
declare const initSymbol: unique symbol;
|
|
118
|
+
declare const methodsSymbol: unique symbol;
|
|
119
|
+
declare const testSymbol: unique symbol;
|
|
120
|
+
declare const optionsSymbol: unique symbol;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 处理器
|
|
124
|
+
*/
|
|
125
|
+
declare class Controller implements Context {
|
|
126
|
+
static isControllerConstructor(v: any): v is Controller.Constructor<any>;
|
|
127
|
+
readonly context: Context;
|
|
128
|
+
/**
|
|
129
|
+
* @warning 不要重载构造函数或者主动调用创建实例
|
|
130
|
+
*/
|
|
131
|
+
constructor(context: Context);
|
|
132
|
+
/**
|
|
133
|
+
* 初始化
|
|
134
|
+
* @description 如果有初始化操作,应当在 init 中实现
|
|
135
|
+
* @description 此方法由路由调用
|
|
136
|
+
*/
|
|
137
|
+
[initSymbol](): void | Promise<void>;
|
|
138
|
+
/** 处理函数的第一个参数 */
|
|
139
|
+
[dataSymbol](): Record<string, any> | Promise<Record<string, any>>;
|
|
140
|
+
/**
|
|
141
|
+
* OPTIONS 的默认处理函数
|
|
142
|
+
* @description 如果需要,则需要在此函数中实现
|
|
143
|
+
* @description 当已 OPTIONS 方法请求资源,且资源对应的路径中没有定义 OPTIONS 方法处理是的处理函数
|
|
144
|
+
*/
|
|
145
|
+
[optionsSymbol](): void | undefined | WriteType | Promise<void | undefined | WriteType>;
|
|
146
|
+
/**
|
|
147
|
+
* 对处理函数的结果进行处理
|
|
148
|
+
* @description 如果需要自定义处理,需要重载此方法
|
|
149
|
+
* @description 此方法由路由调用
|
|
150
|
+
* @param result 处理函数的结果
|
|
151
|
+
*/
|
|
152
|
+
[returnSymbol](result: any): void | PromiseLike<void>;
|
|
153
|
+
/**
|
|
154
|
+
* 处理完成后,实例销毁前,如果有错误未被处理,将回交由此参数处理
|
|
155
|
+
* @description 如果需要自定义处理,需要重载此方法
|
|
156
|
+
* @description 此方法由路由调用
|
|
157
|
+
*/
|
|
158
|
+
[catchSymbol](e: any): void | PromiseLike<void>;
|
|
159
|
+
/**
|
|
160
|
+
* 处理完成后,实例即将销毁时的处理函数
|
|
161
|
+
* @description 如果有销毁操作,应当在 finally 中通过实现
|
|
162
|
+
* @description 此方法由 destroy 调用
|
|
163
|
+
*/
|
|
164
|
+
[finallySymbol](): void | PromiseLike<void>;
|
|
165
|
+
}
|
|
166
|
+
interface Controller extends Context {
|
|
167
|
+
}
|
|
168
|
+
declare namespace Controller {
|
|
169
|
+
interface Constructor<T extends Controller> {
|
|
170
|
+
new (context: Context): T;
|
|
171
|
+
prototype: T;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
declare class Router {
|
|
176
|
+
disabled: boolean;
|
|
177
|
+
/** 当前路由路径 */
|
|
178
|
+
readonly path: string;
|
|
179
|
+
/** 路由列表 */
|
|
180
|
+
private readonly __routes;
|
|
181
|
+
readonly match: Match;
|
|
182
|
+
constructor(path?: string);
|
|
183
|
+
/** 子路由 */
|
|
184
|
+
route(path: string | Router): Router;
|
|
185
|
+
controller?: Controller.Constructor<any>;
|
|
186
|
+
readonly guards: Set<Guard.Constructor<any>>;
|
|
187
|
+
/**
|
|
188
|
+
* 注册处理函数
|
|
189
|
+
* @param path 要注册的路径
|
|
190
|
+
* @param handle 要注册的处理函数
|
|
191
|
+
* @param options 选项
|
|
192
|
+
*/
|
|
193
|
+
verb(path: string, handle: Handle<any>, options?: Handle.Options): this;
|
|
194
|
+
/**
|
|
195
|
+
* 注册处理函数
|
|
196
|
+
* @param path 要注册的路径
|
|
197
|
+
* @param handle 要注册的处理函数
|
|
198
|
+
* @param methods 有效的 HTTP 请求方法
|
|
199
|
+
* @param options 选项
|
|
200
|
+
*/
|
|
201
|
+
verb(path: string, handle: Handle<any>, methods: Method | Method[], options?: Handle.Options): this;
|
|
202
|
+
verb(path: string, handle: Handle<any>, methods?: Method | Method[] | Handle.Options, options?: Handle.Options): this;
|
|
203
|
+
/**
|
|
204
|
+
* 注册 HTTP GET 处理函数
|
|
205
|
+
* @param path 要注册的路径
|
|
206
|
+
* @param handle 要注册的处理函数
|
|
207
|
+
* @param options 选项
|
|
208
|
+
*/
|
|
209
|
+
get(path: string, handle: Handle<any>, options?: Handle.Options): this;
|
|
210
|
+
/**
|
|
211
|
+
* 注册 HTTP POST 处理函数
|
|
212
|
+
* @param path 要注册的路径
|
|
213
|
+
* @param handle 要注册的处理函数
|
|
214
|
+
* @param options 选项
|
|
215
|
+
*/
|
|
216
|
+
post(path: string, handle: Handle<any>, options?: Handle.Options): this;
|
|
217
|
+
/**
|
|
218
|
+
* 注册 HTTP PUT 处理函数
|
|
219
|
+
* @param path 要注册的路径
|
|
220
|
+
* @param handle 要注册的处理函数
|
|
221
|
+
* @param options 选项
|
|
222
|
+
*/
|
|
223
|
+
put(path: string, handle: Handle<any>, options?: Handle.Options): this;
|
|
224
|
+
/**
|
|
225
|
+
* 注册 HTTP DELETE 处理函数
|
|
226
|
+
* @param path 要注册的路径
|
|
227
|
+
* @param handle 要注册的处理函数
|
|
228
|
+
* @param options 选项
|
|
229
|
+
*/
|
|
230
|
+
delete(path: string, handle: Handle<any>, options?: Handle.Options): this;
|
|
231
|
+
/**
|
|
232
|
+
* 注册 HTTP HEAD 处理函数
|
|
233
|
+
* @param path 要注册的路径
|
|
234
|
+
* @param handle 要注册的处理函数
|
|
235
|
+
* @param options 选项
|
|
236
|
+
*/
|
|
237
|
+
head(path: string, handle: Handle<any>, options?: Handle.Options): this;
|
|
238
|
+
/**
|
|
239
|
+
* 注册 HTTP OPTIONS 处理函数
|
|
240
|
+
* @param path 要注册的路径
|
|
241
|
+
* @param handle 要注册的处理函数
|
|
242
|
+
* @param options 选项
|
|
243
|
+
*/
|
|
244
|
+
options(path: string, handle: Handle<any>, options?: Handle.Options): this;
|
|
245
|
+
/**
|
|
246
|
+
* 注册 HTTP 资源
|
|
247
|
+
* @param exports 要注册的资源
|
|
248
|
+
* @param options 选项
|
|
249
|
+
*/
|
|
250
|
+
resource(exports: Exports, options?: ResourceOption): this;
|
|
251
|
+
register(exports: Exports | Controller.Constructor<any>, options?: ResourceOption): this;
|
|
252
|
+
/**
|
|
253
|
+
* 注册 HTTP 处理函数集
|
|
254
|
+
* @param exports 要注册的处理函数集
|
|
255
|
+
* @param options 选项
|
|
256
|
+
*/
|
|
257
|
+
collection(exports: Exports, options?: ResourceOption): this;
|
|
258
|
+
/**
|
|
259
|
+
* 注册 HTTP 资源成员处理函数集
|
|
260
|
+
* @param exports 要注册的处理函数集
|
|
261
|
+
* @param options 选项
|
|
262
|
+
*/
|
|
263
|
+
member(exports: Exports, options?: ResourceOption): this;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
declare abstract class Plugin {
|
|
267
|
+
/** 包名 */
|
|
268
|
+
readonly name: string;
|
|
269
|
+
/** 版本 */
|
|
270
|
+
readonly version: string;
|
|
271
|
+
/** 作者 */
|
|
272
|
+
readonly author: string;
|
|
273
|
+
/** 开源协议 */
|
|
274
|
+
readonly license: string;
|
|
275
|
+
constructor(name: string,
|
|
276
|
+
/** 版本 */
|
|
277
|
+
version: string, { author, license }?: {
|
|
278
|
+
/** 作者 */
|
|
279
|
+
author?: string;
|
|
280
|
+
/** 开源协议 */
|
|
281
|
+
license?: string;
|
|
282
|
+
});
|
|
283
|
+
abstract readSettings(path: string): any | Promise<any>;
|
|
284
|
+
abstract readAsset(path: string, encoding?: false): Promise<ArrayBuffer | null>;
|
|
285
|
+
abstract readAsset(path: string, options: true): Promise<string | null>;
|
|
286
|
+
abstract readAsset(path: string, options?: boolean): Promise<string | ArrayBuffer | null>;
|
|
287
|
+
private __initRouterPromise;
|
|
288
|
+
protected _initRouter(router: Router): Promise<void> | void;
|
|
289
|
+
initRouter(): Promise<Router>;
|
|
290
|
+
get router(): Router;
|
|
291
|
+
get disabled(): boolean;
|
|
292
|
+
set disabled(t: boolean);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
declare class App extends Router {
|
|
296
|
+
/** 连接的处理函数 */
|
|
297
|
+
readonly request: (request: K99Request) => Promise<null | K99Response>;
|
|
298
|
+
/** 设置接口 */
|
|
299
|
+
readonly settings: Settings;
|
|
300
|
+
/** 资产接口 */
|
|
301
|
+
readonly assets: Assets;
|
|
302
|
+
/** 日志接口 */
|
|
303
|
+
readonly logs: Log;
|
|
304
|
+
readonly plugins: Record<string, Plugin>;
|
|
305
|
+
constructor({ router, settingApi, assetApi, logApi, path, }?: App.Options, plugins?: Record<string, Plugin>);
|
|
306
|
+
}
|
|
307
|
+
declare namespace App {
|
|
308
|
+
interface Options {
|
|
309
|
+
path?: string;
|
|
310
|
+
router?: Router;
|
|
311
|
+
assetApi?: Assets.Api;
|
|
312
|
+
settingApi?: Settings.Api;
|
|
313
|
+
logApi?: Log.Api;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
declare type MaybePromise<T> = T | Promise<T>;
|
|
318
|
+
declare type PromiseValue<T> = T extends PromiseLike<infer V> ? V : T;
|
|
319
|
+
|
|
320
|
+
declare type BaseWriteType = string | ArrayBuffer | SharedArrayBuffer | ArrayBufferView;
|
|
321
|
+
declare type WriteType = BaseWriteType | AsyncIterable<WriteType> | Iterable<WriteType>;
|
|
322
|
+
|
|
323
|
+
/** 处理函数定义 */
|
|
324
|
+
interface Handle<T extends Record<string, any>> extends Handle.Attrs<T> {
|
|
325
|
+
(this: Context, data: T): MaybePromise<void | undefined | WriteType | object>;
|
|
326
|
+
}
|
|
327
|
+
declare function Handle<T extends Record<string, any>>(handle: Handle<T> | Handles<T>): Handle<T> | Handles<T>;
|
|
328
|
+
declare namespace Handle {
|
|
329
|
+
/** 处理函数选项选项 */
|
|
330
|
+
interface Attrs<T extends Record<string, any>> {
|
|
331
|
+
/** 方法列表 */
|
|
332
|
+
[methodsSymbol]?: Method | Method[];
|
|
333
|
+
[testSymbol]?(param: {
|
|
334
|
+
[k: string]: string | string[] | undefined;
|
|
335
|
+
}): boolean | Promise<boolean>;
|
|
336
|
+
[optionsSymbol]?: Handle<T> | Option;
|
|
337
|
+
}
|
|
338
|
+
interface Option {
|
|
339
|
+
[key: string]: any;
|
|
340
|
+
}
|
|
341
|
+
interface Options extends ResourceOption {
|
|
342
|
+
/** 处理函数的名称 */
|
|
343
|
+
name?: string;
|
|
344
|
+
/** 方法列表 */
|
|
345
|
+
methods?: Method | Method[];
|
|
346
|
+
/** 文件导出的内容 */
|
|
347
|
+
exports?: Exports;
|
|
348
|
+
/** 测试函数 */
|
|
349
|
+
test?(param: {
|
|
350
|
+
[k: string]: string | string[] | undefined;
|
|
351
|
+
}): boolean | Promise<boolean>;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/** 处理函数定义 */
|
|
355
|
+
interface Handles<T extends Record<string, any>> extends Handle.Attrs<T> {
|
|
356
|
+
OPTIONS?: Handle<T>;
|
|
357
|
+
GET?: Handle<T>;
|
|
358
|
+
POST?: Handle<T>;
|
|
359
|
+
PUT?: Handle<T>;
|
|
360
|
+
DELETE?: Handle<T>;
|
|
361
|
+
HEAD?: Handle<T>;
|
|
362
|
+
}
|
|
363
|
+
interface ResourceOption {
|
|
364
|
+
/** 控制器 */
|
|
365
|
+
controller?: Controller.Constructor<any>;
|
|
366
|
+
/** 所属组 */
|
|
367
|
+
plugin?: string;
|
|
368
|
+
/** 包根目录 */
|
|
369
|
+
root?: string;
|
|
370
|
+
/** 当前文件相对于包根目录的路径 */
|
|
371
|
+
filePath?: string;
|
|
372
|
+
/** 当前文件的绝对路径 */
|
|
373
|
+
absPath?: string;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
declare type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
377
|
+
interface Match {
|
|
378
|
+
(pathname: string, parent: string, key: number): null | Match.Result;
|
|
379
|
+
keyLen: number;
|
|
380
|
+
isRoot?: boolean;
|
|
381
|
+
}
|
|
382
|
+
declare namespace Match {
|
|
383
|
+
interface Result {
|
|
384
|
+
$path: string;
|
|
385
|
+
[key: string]: any;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
interface Route {
|
|
389
|
+
/** 请求路径 */
|
|
390
|
+
path: string;
|
|
391
|
+
/** 路径匹配 */
|
|
392
|
+
match: Match;
|
|
393
|
+
/** 所属插件 */
|
|
394
|
+
plugin?: string;
|
|
395
|
+
/** 处理函数 */
|
|
396
|
+
handle: Handle<any> | typeof optionsSymbol | string;
|
|
397
|
+
/** 方法列表 */
|
|
398
|
+
methods: Method[];
|
|
399
|
+
/** 控制器 */
|
|
400
|
+
controller?: Controller.Constructor<any>;
|
|
401
|
+
/** 包根目录 */
|
|
402
|
+
root?: string;
|
|
403
|
+
/** 当前文件相对于包根目录的路径 */
|
|
404
|
+
filePath?: string;
|
|
405
|
+
/** 当前文件的绝对路径 */
|
|
406
|
+
absPath?: string;
|
|
407
|
+
/** 处理函数的名称 */
|
|
408
|
+
name?: string;
|
|
409
|
+
/** 测试函数 */
|
|
410
|
+
test?(param: {
|
|
411
|
+
[k: string]: string | string[] | undefined;
|
|
412
|
+
}): boolean | Promise<boolean>;
|
|
413
|
+
}
|
|
414
|
+
/** 处理项目文件导出 */
|
|
415
|
+
interface Exports<C extends Controller = any> extends Handles<C> {
|
|
416
|
+
Controller?: Controller.Constructor<C>;
|
|
417
|
+
Guard?: Guard.Constructor<Guard<C>>;
|
|
418
|
+
index?: Handle<C> | Handles<C>;
|
|
419
|
+
new?: Handle<C> | Handles<C>;
|
|
420
|
+
create?: Handle<C> | Handles<C>;
|
|
421
|
+
show?: Handle<C> | Handles<C>;
|
|
422
|
+
update?: Handle<C> | Handles<C>;
|
|
423
|
+
destroy?: Handle<C> | Handles<C>;
|
|
424
|
+
[key: string]: any;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
interface CookieClearOption {
|
|
428
|
+
domain?: string;
|
|
429
|
+
path?: string;
|
|
430
|
+
secure?: boolean;
|
|
431
|
+
httpOnly?: boolean;
|
|
432
|
+
}
|
|
433
|
+
interface CookieOption extends CookieClearOption {
|
|
434
|
+
expire?: string;
|
|
435
|
+
}
|
|
436
|
+
interface CookieOptionInfo extends CookieOption {
|
|
437
|
+
value: string;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
interface K99Response extends AsyncIterable<BaseWriteType> {
|
|
441
|
+
statusCode: number;
|
|
442
|
+
finished: boolean;
|
|
443
|
+
headers: K99Response.Headers;
|
|
444
|
+
}
|
|
445
|
+
declare namespace K99Response {
|
|
446
|
+
interface Headers {
|
|
447
|
+
[header: string]: number | string | string[];
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
interface Settings {
|
|
452
|
+
(): string;
|
|
453
|
+
(path: string): this;
|
|
454
|
+
(path: string, mark: true): this;
|
|
455
|
+
/** 读取配置 */
|
|
456
|
+
read(path: string): Promise<object | null | undefined>;
|
|
457
|
+
/** 写入配置 */
|
|
458
|
+
write(path: string, cfg?: object | null | undefined): Promise<boolean>;
|
|
459
|
+
}
|
|
460
|
+
declare namespace Settings {
|
|
461
|
+
interface Api {
|
|
462
|
+
/** 读取配置 */
|
|
463
|
+
read?(path: string): Promise<object | null | undefined>;
|
|
464
|
+
/** 写入配置 */
|
|
465
|
+
write?(path: string, cfg: object | null | undefined): Promise<boolean>;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
interface Assets {
|
|
470
|
+
(): string;
|
|
471
|
+
(path: string): this;
|
|
472
|
+
(path: string, mark: true): this;
|
|
473
|
+
/** 读取文件 */
|
|
474
|
+
read(path: string, encoding?: false): Promise<ArrayBuffer | null>;
|
|
475
|
+
read(path: string, encoding: true): Promise<string | null>;
|
|
476
|
+
read(path: string, encoding?: boolean): Promise<string | ArrayBuffer | null>;
|
|
477
|
+
/** 删除文件 */
|
|
478
|
+
delete(path: string): Promise<boolean>;
|
|
479
|
+
/** 写入文件 */
|
|
480
|
+
write(path: string, data: any): Promise<boolean>;
|
|
481
|
+
/** 获取文件信息 */
|
|
482
|
+
stat(path: string): Promise<Assets.Stats | null>;
|
|
483
|
+
}
|
|
484
|
+
declare namespace Assets {
|
|
485
|
+
interface Reader {
|
|
486
|
+
(path: string, encoding?: false): Promise<ArrayBuffer | null>;
|
|
487
|
+
(path: string, encoding: true): Promise<string | null>;
|
|
488
|
+
(path: string, encoding?: boolean): Promise<string | ArrayBuffer | null>;
|
|
489
|
+
}
|
|
490
|
+
interface Stats {
|
|
491
|
+
isDirectory: boolean;
|
|
492
|
+
size: number;
|
|
493
|
+
updateTime: Date;
|
|
494
|
+
createTime: Date;
|
|
495
|
+
}
|
|
496
|
+
interface Api {
|
|
497
|
+
/** 读取文件 */
|
|
498
|
+
read?: Reader;
|
|
499
|
+
/** 删除文件 */
|
|
500
|
+
delete?(path: string): Promise<boolean>;
|
|
501
|
+
/** 写入文件 */
|
|
502
|
+
write?(path: string, data: any): Promise<boolean>;
|
|
503
|
+
/** 获取文件信息 */
|
|
504
|
+
stat?(path: string): Promise<Stats | null>;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
interface Log {
|
|
509
|
+
(): string;
|
|
510
|
+
(path: string): this;
|
|
511
|
+
(path: string, mark: true): this;
|
|
512
|
+
/** 读取日志 */
|
|
513
|
+
read(path: string): Promise<string>;
|
|
514
|
+
/** 写入日志 */
|
|
515
|
+
write(path: string, log: string, opt?: Log.Options): Promise<boolean>;
|
|
516
|
+
/** 清除日志 */
|
|
517
|
+
clear(path: string): Promise<void>;
|
|
518
|
+
/** 输出信息日志 */
|
|
519
|
+
debug(log: string, opt?: Log.Options): Promise<boolean>;
|
|
520
|
+
/** 输出信息日志 */
|
|
521
|
+
info(log: string, opt?: Log.Options): Promise<boolean>;
|
|
522
|
+
/** 输出警告日志 */
|
|
523
|
+
warn(log: any, opt?: Log.Options): Promise<boolean>;
|
|
524
|
+
/** 输出错误日志 */
|
|
525
|
+
error(log: any, opt?: Log.Options): Promise<boolean>;
|
|
526
|
+
}
|
|
527
|
+
declare namespace Log {
|
|
528
|
+
interface Options {
|
|
529
|
+
/** 在日志前添加的标签 */
|
|
530
|
+
tags?: string | string[];
|
|
531
|
+
/** 多行日志的缩进字符串,或者是缩进空格的数量 */
|
|
532
|
+
indent?: string | number;
|
|
533
|
+
}
|
|
534
|
+
interface Api {
|
|
535
|
+
/** 读取日志 */
|
|
536
|
+
read?(path: string): Promise<string>;
|
|
537
|
+
/** 写入日志 */
|
|
538
|
+
write?(path: string, log: string): Promise<boolean>;
|
|
539
|
+
/** 清除日志 */
|
|
540
|
+
clear?(path: string): Promise<void>;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
interface K99Request {
|
|
545
|
+
readonly method: Method;
|
|
546
|
+
readonly url: string;
|
|
547
|
+
/** 请求路径 */
|
|
548
|
+
readonly pathname: string;
|
|
549
|
+
/** 查询字符串 */
|
|
550
|
+
readonly search: string;
|
|
551
|
+
/** 查询参数 */
|
|
552
|
+
readonly query: Record<string, string | string[]>;
|
|
553
|
+
readonly headers: K99Request.Headers;
|
|
554
|
+
readonly read: K99Request.Reader;
|
|
555
|
+
}
|
|
556
|
+
declare namespace K99Request {
|
|
557
|
+
interface Headers {
|
|
558
|
+
'accept'?: string;
|
|
559
|
+
'accept-language'?: string;
|
|
560
|
+
'accept-patch'?: string;
|
|
561
|
+
'accept-ranges'?: string;
|
|
562
|
+
'access-control-allow-credentials'?: string;
|
|
563
|
+
'access-control-allow-headers'?: string;
|
|
564
|
+
'access-control-allow-methods'?: string;
|
|
565
|
+
'access-control-allow-origin'?: string;
|
|
566
|
+
'access-control-expose-headers'?: string;
|
|
567
|
+
'access-control-max-age'?: string;
|
|
568
|
+
'age'?: string;
|
|
569
|
+
'allow'?: string;
|
|
570
|
+
'alt-svc'?: string;
|
|
571
|
+
'authorization'?: string;
|
|
572
|
+
'cache-control'?: string;
|
|
573
|
+
'connection'?: string;
|
|
574
|
+
'content-disposition'?: string;
|
|
575
|
+
'content-encoding'?: string;
|
|
576
|
+
'content-language'?: string;
|
|
577
|
+
'content-length'?: string;
|
|
578
|
+
'content-location'?: string;
|
|
579
|
+
'content-range'?: string;
|
|
580
|
+
'content-type'?: string;
|
|
581
|
+
'cookie'?: string;
|
|
582
|
+
'date'?: string;
|
|
583
|
+
'expect'?: string;
|
|
584
|
+
'expires'?: string;
|
|
585
|
+
'forwarded'?: string;
|
|
586
|
+
'from'?: string;
|
|
587
|
+
'host'?: string;
|
|
588
|
+
'if-match'?: string;
|
|
589
|
+
'if-modified-since'?: string;
|
|
590
|
+
'if-none-match'?: string;
|
|
591
|
+
'if-unmodified-since'?: string;
|
|
592
|
+
'last-modified'?: string;
|
|
593
|
+
'location'?: string;
|
|
594
|
+
'pragma'?: string;
|
|
595
|
+
'proxy-authenticate'?: string;
|
|
596
|
+
'proxy-authorization'?: string;
|
|
597
|
+
'public-key-pins'?: string;
|
|
598
|
+
'range'?: string;
|
|
599
|
+
'referer'?: string;
|
|
600
|
+
'retry-after'?: string;
|
|
601
|
+
'set-cookie'?: string[];
|
|
602
|
+
'strict-transport-security'?: string;
|
|
603
|
+
'tk'?: string;
|
|
604
|
+
'trailer'?: string;
|
|
605
|
+
'transfer-encoding'?: string;
|
|
606
|
+
'upgrade'?: string;
|
|
607
|
+
'user-agent'?: string;
|
|
608
|
+
'vary'?: string;
|
|
609
|
+
'via'?: string;
|
|
610
|
+
'warning'?: string;
|
|
611
|
+
'www-authenticate'?: string;
|
|
612
|
+
[header: string]: string | string[] | undefined;
|
|
613
|
+
}
|
|
614
|
+
interface Reader {
|
|
615
|
+
(size?: number, encoding?: false): Promise<ArrayBuffer | null>;
|
|
616
|
+
(size: number, encoding: true): Promise<string | null>;
|
|
617
|
+
(size?: number, encoding?: boolean): Promise<string | ArrayBuffer | null>;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
interface Context {
|
|
622
|
+
/** 当前的路由 */
|
|
623
|
+
readonly app: App;
|
|
624
|
+
/** 路径参数 */
|
|
625
|
+
readonly params: Readonly<{
|
|
626
|
+
[p: string]: string;
|
|
627
|
+
}>;
|
|
628
|
+
/** 请求 accept */
|
|
629
|
+
readonly accept: string[];
|
|
630
|
+
/** 请求 accept language */
|
|
631
|
+
readonly acceptLanguage: string[];
|
|
632
|
+
/** 请求头 */
|
|
633
|
+
readonly headers: Readonly<K99Request.Headers>;
|
|
634
|
+
/** 请求方法 */
|
|
635
|
+
readonly method: Method;
|
|
636
|
+
/** 请求 url (不含协议及主机名等) */
|
|
637
|
+
readonly url: string;
|
|
638
|
+
/** 请求路径 */
|
|
639
|
+
readonly pathname: string;
|
|
640
|
+
/** 查询字符串 */
|
|
641
|
+
readonly search: string;
|
|
642
|
+
/** 查询参数 */
|
|
643
|
+
readonly query: Record<string, string | string[]>;
|
|
644
|
+
/** 来源路径 */
|
|
645
|
+
readonly referer: string;
|
|
646
|
+
/** 请求主机 */
|
|
647
|
+
readonly host: string;
|
|
648
|
+
/** 请求主机名 */
|
|
649
|
+
readonly hostname: string;
|
|
650
|
+
/** 请求端口 */
|
|
651
|
+
readonly port: string;
|
|
652
|
+
/** 客户端 UA */
|
|
653
|
+
readonly userAgent: string;
|
|
654
|
+
/** 处理程序所属插件 */
|
|
655
|
+
readonly plugin?: string;
|
|
656
|
+
readonly settings: Settings;
|
|
657
|
+
readonly assets: Assets;
|
|
658
|
+
readonly logs: Log;
|
|
659
|
+
/** 请求 cookie */
|
|
660
|
+
readonly cookies: Readonly<{
|
|
661
|
+
[key: string]: string;
|
|
662
|
+
}>;
|
|
663
|
+
readonly destroyed: boolean;
|
|
664
|
+
readonly finished: boolean;
|
|
665
|
+
/** 响应头是否已经被发送 */
|
|
666
|
+
readonly headersSent: boolean;
|
|
667
|
+
readonly requestType: string;
|
|
668
|
+
responseType: string | number | string[];
|
|
669
|
+
/** 状态码 */
|
|
670
|
+
status: number;
|
|
671
|
+
readonly data: any;
|
|
672
|
+
body: any;
|
|
673
|
+
/**
|
|
674
|
+
* 获取已设置的 cookie 信息
|
|
675
|
+
*/
|
|
676
|
+
getCookie(name?: string): Iterable<CookieOptionInfo>;
|
|
677
|
+
/**
|
|
678
|
+
* 设置 cookie
|
|
679
|
+
* @param name cookie 名称
|
|
680
|
+
* @param value cookie 内容
|
|
681
|
+
* @param option 选项
|
|
682
|
+
*/
|
|
683
|
+
setCookie(name: string, value: string, opt?: CookieOption): void;
|
|
684
|
+
readonly clearCookie: {
|
|
685
|
+
/**
|
|
686
|
+
* 清除 cookie
|
|
687
|
+
* @param name cookie 名称
|
|
688
|
+
* @param option 选项
|
|
689
|
+
*/
|
|
690
|
+
(name: string, option?: CookieClearOption): void;
|
|
691
|
+
/**
|
|
692
|
+
* 清除所有的 cookie
|
|
693
|
+
* @param option 选项
|
|
694
|
+
* @param all 是否包括请求 cookie 在内的 cookie 都要清除
|
|
695
|
+
*/
|
|
696
|
+
(option?: CookieClearOption, all?: boolean): void;
|
|
697
|
+
};
|
|
698
|
+
service<T, P extends any[] = []>(Service: Service.Constructor<T, P> | Service.Func<T, P>, ...p: P): T;
|
|
699
|
+
hasHeader(name: string): boolean;
|
|
700
|
+
getHeader(name: string): string | number | string[] | undefined;
|
|
701
|
+
setHeader(name: string, value?: string | number | string[]): void;
|
|
702
|
+
removeHeader(name: string): void;
|
|
703
|
+
getHeaderNames(): string[];
|
|
704
|
+
getHeaders(): K99Response.Headers;
|
|
705
|
+
readonly read: K99Request.Reader;
|
|
706
|
+
/** 将数据写入相应 */
|
|
707
|
+
write(chunk: WriteType): Promise<boolean>;
|
|
708
|
+
/**
|
|
709
|
+
* 退出执行
|
|
710
|
+
* @param status 状态码
|
|
711
|
+
*/
|
|
712
|
+
exit(status?: number): never;
|
|
713
|
+
/**
|
|
714
|
+
* 302 或 301 跳转
|
|
715
|
+
* @param url 要跳转的 url
|
|
716
|
+
* @param is301 是否采用 301 跳转
|
|
717
|
+
*/
|
|
718
|
+
transfer(url: string, is301?: boolean): never;
|
|
719
|
+
/** 虚拟请求 */
|
|
720
|
+
request(method: Method, path: string, opt?: {
|
|
721
|
+
headers?: K99Request.Headers;
|
|
722
|
+
body?: K99Request.Reader | WriteType;
|
|
723
|
+
}): Promise<null | K99Response>;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
declare class ExitSignal extends Error {
|
|
727
|
+
/**
|
|
728
|
+
* 忽略对退出信号的捕获
|
|
729
|
+
* @description 用于 try { } catch(e) {} 的 catch 中忽略退出信号
|
|
730
|
+
* @example
|
|
731
|
+
* try {
|
|
732
|
+
* doSomething();
|
|
733
|
+
* } catch (e) {
|
|
734
|
+
* ExitSignal.assert(e);
|
|
735
|
+
* customProcess(e);
|
|
736
|
+
* }
|
|
737
|
+
*/
|
|
738
|
+
static assert(v: any): void;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/** 设置配置 */
|
|
742
|
+
declare function setTest(test?: Handle<any>[typeof testSymbol]): <H extends Handle<any> | Handles<any>>(h: H) => H;
|
|
743
|
+
/** 设置方法 */
|
|
744
|
+
declare function setMethods(...methods: Method[]): <H extends Handle<any> | Handles<any>>(h: H) => H;
|
|
745
|
+
/** 设置选项 */
|
|
746
|
+
declare function setOptions(options?: Handle<any>[typeof optionsSymbol]): <H extends Handle<any> | Handles<any>>(h: H) => H;
|
|
747
|
+
|
|
748
|
+
export { App, Assets, BaseWriteType, Context, Controller, CookieClearOption, CookieOption, CookieOptionInfo, ExitSignal, Exports, Guard, Handle, Handles, K99Request, K99Response, Log, Match, MaybePromise, Method, Plugin, PromiseValue, ResourceOption, Route, Router, Service, Settings, WriteType, catchSymbol, dataSymbol, finallySymbol, initSymbol, methodsSymbol, optionsSymbol, returnSymbol, setMethods, setOptions, setTest, testSymbol };
|