starlight-server 1.0.2 → 1.2.0
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/dist/router/match.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 标准化路径
|
|
3
|
-
*
|
|
3
|
+
* 移除首尾和重复的 '/',完成后有 path 有这几种可能的格式: ''、'abc'、'abc/def'
|
|
4
|
+
* 例如 /abc/def 和 abc/def/ 都会变成 abc/def
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
* - 统一改为小写
|
|
6
|
+
* 注意:此操作不会统一大小写,因此不保证标准化后两个字符串在代码层面 ===
|
|
7
7
|
*/
|
|
8
8
|
export declare function normalizePath(path: string): string;
|
|
9
9
|
/**
|
package/dist/router/match.js
CHANGED
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
import escapeRegExp from 'lodash/escapeRegExp.js';
|
|
13
13
|
/**
|
|
14
14
|
* 标准化路径
|
|
15
|
-
*
|
|
15
|
+
* 移除首尾和重复的 '/',完成后有 path 有这几种可能的格式: ''、'abc'、'abc/def'
|
|
16
|
+
* 例如 /abc/def 和 abc/def/ 都会变成 abc/def
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
-
* - 统一改为小写
|
|
18
|
+
* 注意:此操作不会统一大小写,因此不保证标准化后两个字符串在代码层面 ===
|
|
19
19
|
*/
|
|
20
20
|
export function normalizePath(path) {
|
|
21
21
|
if (path.startsWith('/'))
|
|
@@ -23,7 +23,7 @@ export function normalizePath(path) {
|
|
|
23
23
|
if (path.endsWith('/'))
|
|
24
24
|
path = path.slice(0, -1);
|
|
25
25
|
path = path.replace(/\/+/g, '/');
|
|
26
|
-
return path
|
|
26
|
+
return path;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* 解析路由路径定义
|
|
@@ -32,7 +32,7 @@ function getValidatorOfParameter(parameter) {
|
|
|
32
32
|
const validatorConstructor = getValidatorConstructor(parameter.type);
|
|
33
33
|
const options = {
|
|
34
34
|
null: parameter.nullable,
|
|
35
|
-
void: typeof parameter.required === 'boolean' ? parameter.required : undefined,
|
|
35
|
+
void: typeof parameter.required === 'boolean' ? !parameter.required : undefined,
|
|
36
36
|
defaults: parameter.defaults,
|
|
37
37
|
...(parameter.validate ?? {}),
|
|
38
38
|
};
|
package/dist/router/router.d.ts
CHANGED
|
@@ -105,7 +105,7 @@ export declare abstract class Router<Ctx extends BaseContext = BaseContext> {
|
|
|
105
105
|
/**
|
|
106
106
|
* 为未指定 CORS 配置的 route 提供默认配置
|
|
107
107
|
*/
|
|
108
|
-
getCORSOptions(request: Request, routeMatch: RouteMatch<Route<Ctx>>):
|
|
108
|
+
getCORSOptions(request: Request, routeMatch: RouteMatch<Route<Ctx>>): CORSOptions;
|
|
109
109
|
/**
|
|
110
110
|
* 完善 context 对象并执行 route
|
|
111
111
|
* 注意:handler 在很多时候都是异步的,要用 await 等待执行完成
|
package/package.json
CHANGED
package/src/router/match.ts
CHANGED
|
@@ -13,16 +13,16 @@ import escapeRegExp from 'lodash/escapeRegExp.js'
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* 标准化路径
|
|
16
|
-
*
|
|
16
|
+
* 移除首尾和重复的 '/',完成后有 path 有这几种可能的格式: ''、'abc'、'abc/def'
|
|
17
|
+
* 例如 /abc/def 和 abc/def/ 都会变成 abc/def
|
|
17
18
|
*
|
|
18
|
-
*
|
|
19
|
-
* - 统一改为小写
|
|
19
|
+
* 注意:此操作不会统一大小写,因此不保证标准化后两个字符串在代码层面 ===
|
|
20
20
|
*/
|
|
21
21
|
export function normalizePath(path: string) {
|
|
22
22
|
if (path.startsWith('/')) path = path.slice(1)
|
|
23
23
|
if (path.endsWith('/')) path = path.slice(0, -1)
|
|
24
24
|
path = path.replace(/\/+/g, '/')
|
|
25
|
-
return path
|
|
25
|
+
return path
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
package/src/router/parameters.ts
CHANGED
|
@@ -82,7 +82,7 @@ function getValidatorOfParameter(parameter: BasicParameter) {
|
|
|
82
82
|
const validatorConstructor = getValidatorConstructor(parameter.type) as typeof validators.any
|
|
83
83
|
const options = {
|
|
84
84
|
null: parameter.nullable,
|
|
85
|
-
void: typeof parameter.required === 'boolean' ? parameter.required : undefined,
|
|
85
|
+
void: typeof parameter.required === 'boolean' ? !parameter.required : undefined,
|
|
86
86
|
defaults: parameter.defaults,
|
|
87
87
|
...(parameter.validate ?? {}),
|
|
88
88
|
}
|
package/src/router/router.ts
CHANGED
|
@@ -179,7 +179,7 @@ export abstract class Router<Ctx extends BaseContext = BaseContext> {
|
|
|
179
179
|
* 为未指定 CORS 配置的 route 提供默认配置
|
|
180
180
|
*/
|
|
181
181
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
182
|
-
getCORSOptions(request: Request, routeMatch: RouteMatch<Route<Ctx>>) {
|
|
182
|
+
getCORSOptions(request: Request, routeMatch: RouteMatch<Route<Ctx>>): CORSOptions {
|
|
183
183
|
return false
|
|
184
184
|
}
|
|
185
185
|
|