starlight-server 1.7.2 → 1.7.4
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/helpers.d.ts +2 -0
- package/dist/router/helpers.js +10 -2
- package/package.json +1 -1
- package/src/router/helpers.ts +14 -3
package/dist/router/helpers.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type MaySuccess } from '@anjianshi/utils';
|
|
1
2
|
import { type Definition as ValidatorDefinition } from '@anjianshi/utils/validators/index.js';
|
|
2
3
|
import { type Request } from '../http/request.js';
|
|
3
4
|
import { type ResponseUtils } from '../http/response.js';
|
|
@@ -66,6 +67,7 @@ declare class ResponseUtilsHelpers {
|
|
|
66
67
|
success(data?: unknown): void;
|
|
67
68
|
failed(message: string, code?: string | number): void;
|
|
68
69
|
failed<T>(message: string, code: string | number | undefined, data: T): void;
|
|
70
|
+
maySuccess(result: MaySuccess<unknown, unknown>): void;
|
|
69
71
|
}
|
|
70
72
|
export type ResponseUtilsWithHelpers = ResponseUtils & ResponseUtilsHelpers;
|
|
71
73
|
export declare function getResponseUtilsWithHelpers(response: ResponseUtils): ResponseUtilsWithHelpers;
|
package/dist/router/helpers.js
CHANGED
|
@@ -46,11 +46,19 @@ class ResponseUtilsHelpers {
|
|
|
46
46
|
constructor(response) {
|
|
47
47
|
this.response = response;
|
|
48
48
|
}
|
|
49
|
+
// 原本这里想做成调用方法后直接结束 handler
|
|
50
|
+
// 但因为 TypeScript 的限制,无法正确处理类方法的 never 返回值,所以作罢
|
|
51
|
+
// https://github.com/microsoft/TypeScript/issues/36753
|
|
52
|
+
// 输出成功结果
|
|
49
53
|
success(data) {
|
|
50
|
-
this.
|
|
54
|
+
this.maySuccess(success(data));
|
|
51
55
|
}
|
|
52
56
|
failed(message, code, data) {
|
|
53
|
-
this.
|
|
57
|
+
this.maySuccess(failed(message, code, data));
|
|
58
|
+
}
|
|
59
|
+
// 输出 MaySuccess 对象
|
|
60
|
+
maySuccess(result) {
|
|
61
|
+
this.response.json(result);
|
|
54
62
|
}
|
|
55
63
|
}
|
|
56
64
|
export function getResponseUtilsWithHelpers(response) {
|
package/package.json
CHANGED
package/src/router/helpers.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { success, failed } from '@anjianshi/utils'
|
|
1
|
+
import { type MaySuccess, success, failed } from '@anjianshi/utils'
|
|
2
2
|
import {
|
|
3
3
|
getValidator,
|
|
4
4
|
type Definition as ValidatorDefinition,
|
|
@@ -59,14 +59,25 @@ export function getRequestWithHelpers(request: Request, pathParameters: PathPara
|
|
|
59
59
|
class ResponseUtilsHelpers {
|
|
60
60
|
constructor(readonly response: ResponseUtils) {}
|
|
61
61
|
|
|
62
|
+
// 原本这里想做成调用方法后直接结束 handler
|
|
63
|
+
// 但因为 TypeScript 的限制,无法正确处理类方法的 never 返回值,所以作罢
|
|
64
|
+
// https://github.com/microsoft/TypeScript/issues/36753
|
|
65
|
+
|
|
66
|
+
// 输出成功结果
|
|
62
67
|
success(data?: unknown) {
|
|
63
|
-
this.
|
|
68
|
+
this.maySuccess(success(data))
|
|
64
69
|
}
|
|
65
70
|
|
|
71
|
+
// 输出失败结果
|
|
66
72
|
failed(message: string, code?: string | number): void
|
|
67
73
|
failed<T>(message: string, code: string | number | undefined, data: T): void
|
|
68
74
|
failed<T>(message: string, code?: string | number, data?: T) {
|
|
69
|
-
this.
|
|
75
|
+
this.maySuccess(failed(message, code, data))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 输出 MaySuccess 对象
|
|
79
|
+
maySuccess(result: MaySuccess<unknown, unknown>): void {
|
|
80
|
+
this.response.json(result)
|
|
70
81
|
}
|
|
71
82
|
}
|
|
72
83
|
|