@faasjs/http 0.0.2-beta.3 → 0.0.2-beta.302
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/README.md +1 -1
- package/lib/cookie.d.ts +9 -13
- package/lib/index.d.ts +43 -35
- package/lib/index.es.js +194 -173
- package/lib/index.js +197 -176
- package/lib/session.d.ts +16 -15
- package/lib/validator.d.ts +38 -23
- package/package.json +16 -3
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
http 插件
|
|
4
4
|
|
|
5
|
-
[](https://github.com/faasjs/faasjs/blob/
|
|
5
|
+
[](https://github.com/faasjs/faasjs/blob/main/packages/faasjs/http/LICENSE)
|
|
6
6
|
[](https://www.npmjs.com/package/@faasjs/http)
|
|
7
7
|
[](https://www.npmjs.com/package/@faasjs/http)
|
|
8
8
|
|
package/lib/cookie.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Session, SessionOptions } from './session';
|
|
2
|
-
export
|
|
2
|
+
export declare type CookieOptions = {
|
|
3
3
|
domain?: string;
|
|
4
4
|
path?: string;
|
|
5
5
|
expires?: number;
|
|
@@ -8,12 +8,10 @@ export interface CookieOptions {
|
|
|
8
8
|
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
9
9
|
session?: SessionOptions;
|
|
10
10
|
[key: string]: any;
|
|
11
|
-
}
|
|
12
|
-
export declare class Cookie {
|
|
13
|
-
session: Session
|
|
14
|
-
content:
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
};
|
|
11
|
+
};
|
|
12
|
+
export declare class Cookie<C extends Record<string, string> = any, S extends Record<string, string> = any> {
|
|
13
|
+
session: Session<S, C>;
|
|
14
|
+
content: Record<string, string>;
|
|
17
15
|
readonly config: {
|
|
18
16
|
domain?: string;
|
|
19
17
|
path: string;
|
|
@@ -25,19 +23,17 @@ export declare class Cookie {
|
|
|
25
23
|
};
|
|
26
24
|
private setCookie;
|
|
27
25
|
constructor(config: CookieOptions);
|
|
28
|
-
invoke(cookie: string | undefined):
|
|
26
|
+
invoke(cookie: string | undefined): Cookie<C, S>;
|
|
29
27
|
read(key: string): any;
|
|
30
|
-
write(key: string, value:
|
|
28
|
+
write(key: string, value: string, opts?: {
|
|
31
29
|
domain?: string;
|
|
32
30
|
path?: string;
|
|
33
31
|
expires?: number | string;
|
|
34
32
|
secure?: boolean;
|
|
35
33
|
httpOnly?: boolean;
|
|
36
34
|
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
37
|
-
}):
|
|
35
|
+
}): Cookie<C, S>;
|
|
38
36
|
headers(): {
|
|
39
|
-
'Set-Cookie'?:
|
|
40
|
-
} | {
|
|
41
|
-
'Set-Cookie': string[];
|
|
37
|
+
'Set-Cookie'?: string[];
|
|
42
38
|
};
|
|
43
39
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,59 +1,65 @@
|
|
|
1
|
-
import { Plugin, InvokeData, MountData, DeployData, Next } from '@faasjs/func';
|
|
1
|
+
import { Plugin, InvokeData, MountData, DeployData, Next, UseifyPlugin } from '@faasjs/func';
|
|
2
2
|
import { Cookie, CookieOptions } from './cookie';
|
|
3
3
|
import { Session, SessionOptions } from './session';
|
|
4
|
-
import { Validator, ValidatorOptions, ValidatorRuleOptions } from './validator';
|
|
5
|
-
export { Cookie, CookieOptions, Session, SessionOptions, Validator, ValidatorOptions, ValidatorRuleOptions };
|
|
4
|
+
import { Validator, ValidatorOptions, ValidatorRuleOptions, ValidatorConfig } from './validator';
|
|
5
|
+
export { Cookie, CookieOptions, Session, SessionOptions, Validator, ValidatorConfig, ValidatorOptions, ValidatorRuleOptions };
|
|
6
6
|
export declare const ContentType: {
|
|
7
7
|
[key: string]: string;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export declare type HttpConfig<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any> = {
|
|
10
|
+
[key: string]: any;
|
|
10
11
|
name?: string;
|
|
11
12
|
config?: {
|
|
12
|
-
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
method?: 'BEGIN' | 'GET' | 'POST' | 'DELETE' | 'HEAD' | 'PUT' | 'OPTIONS' | 'TRACE' | 'PATCH' | 'ANY';
|
|
13
15
|
timeout?: number;
|
|
16
|
+
path?: string;
|
|
17
|
+
ignorePathPrefix?: string;
|
|
14
18
|
functionName?: string;
|
|
15
19
|
cookie?: CookieOptions;
|
|
16
|
-
[key: string]: any;
|
|
17
20
|
};
|
|
18
|
-
validator?:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
session?: ValidatorOptions;
|
|
22
|
-
};
|
|
23
|
-
[key: string]: any;
|
|
24
|
-
}
|
|
25
|
-
export interface Response {
|
|
21
|
+
validator?: ValidatorConfig<TParams, TCookie, TSession>;
|
|
22
|
+
};
|
|
23
|
+
export declare type Response = {
|
|
26
24
|
statusCode?: number;
|
|
27
|
-
headers
|
|
28
|
-
[key: string]:
|
|
25
|
+
headers?: {
|
|
26
|
+
[key: string]: string;
|
|
29
27
|
};
|
|
30
28
|
body?: string;
|
|
29
|
+
message?: string;
|
|
30
|
+
};
|
|
31
|
+
export declare class HttpError extends Error {
|
|
32
|
+
readonly statusCode: number;
|
|
33
|
+
readonly message: string;
|
|
34
|
+
constructor({ statusCode, message }: {
|
|
35
|
+
statusCode?: number;
|
|
36
|
+
message: string;
|
|
37
|
+
});
|
|
31
38
|
}
|
|
32
|
-
export declare class Http implements Plugin {
|
|
39
|
+
export declare class Http<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any> implements Plugin {
|
|
33
40
|
readonly type: string;
|
|
34
|
-
name
|
|
41
|
+
readonly name: string;
|
|
35
42
|
headers: {
|
|
36
43
|
[key: string]: string;
|
|
37
44
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
functionName?: string;
|
|
45
|
-
cookie?: CookieOptions;
|
|
46
|
-
[key: string]: any;
|
|
47
|
-
};
|
|
48
|
-
private validatorOptions?;
|
|
45
|
+
body: any;
|
|
46
|
+
params: TParams;
|
|
47
|
+
cookie: Cookie<TCookie, TSession>;
|
|
48
|
+
session: Session<TSession, TCookie>;
|
|
49
|
+
config: HttpConfig<TParams, TCookie, TSession>;
|
|
50
|
+
private readonly validatorOptions?;
|
|
49
51
|
private response?;
|
|
50
52
|
private validator?;
|
|
51
|
-
private logger;
|
|
53
|
+
private readonly logger;
|
|
52
54
|
/**
|
|
53
55
|
* 创建 Http 插件实例
|
|
54
56
|
* @param config {object} 配置项
|
|
55
57
|
* @param config.name {string} 配置名
|
|
56
58
|
* @param config.config {object} 网关配置
|
|
59
|
+
* @param config.config.method {string} 请求方法,默认为 POST
|
|
60
|
+
* @param config.config.path {string} 请求路径,默认为云函数文件路径
|
|
61
|
+
* @param config.config.ignorePathPrefix {string} 排除的路径前缀,当设置 path 时无效
|
|
62
|
+
* @param config.config.cookie {object} Cookie 配置
|
|
57
63
|
* @param config.validator {object} 入参校验配置
|
|
58
64
|
* @param config.validator.params {object} params 校验配置
|
|
59
65
|
* @param config.validator.params.whitelist {string} 白名单配置
|
|
@@ -67,8 +73,9 @@ export declare class Http implements Plugin {
|
|
|
67
73
|
* @param config.validator.session.whitelist {string} 白名单配置
|
|
68
74
|
* @param config.validator.session.onError {function} 自定义报错
|
|
69
75
|
* @param config.validator.session.rules {object} 参数校验规则
|
|
76
|
+
* @param config.validator.before {function} 参数校验前自定义函数
|
|
70
77
|
*/
|
|
71
|
-
constructor(config?: HttpConfig);
|
|
78
|
+
constructor(config?: HttpConfig<TParams, TCookie, TSession>);
|
|
72
79
|
onDeploy(data: DeployData, next: Next): Promise<void>;
|
|
73
80
|
onMount(data: MountData, next: Next): Promise<void>;
|
|
74
81
|
onInvoke(data: InvokeData, next: Next): Promise<void>;
|
|
@@ -77,21 +84,22 @@ export declare class Http implements Plugin {
|
|
|
77
84
|
* @param key {string} key
|
|
78
85
|
* @param value {*} value
|
|
79
86
|
*/
|
|
80
|
-
setHeader(key: string, value:
|
|
87
|
+
setHeader(key: string, value: string): Http<TParams, TCookie, TSession>;
|
|
81
88
|
/**
|
|
82
89
|
* 设置 Content-Type
|
|
83
90
|
* @param type {string} 类型
|
|
84
91
|
* @param charset {string} 编码
|
|
85
92
|
*/
|
|
86
|
-
setContentType(type: string, charset?: string):
|
|
93
|
+
setContentType(type: string, charset?: string): Http<TParams, TCookie, TSession>;
|
|
87
94
|
/**
|
|
88
95
|
* 设置状态码
|
|
89
96
|
* @param code {number} 状态码
|
|
90
97
|
*/
|
|
91
|
-
setStatusCode(code: number):
|
|
98
|
+
setStatusCode(code: number): Http<TParams, TCookie, TSession>;
|
|
92
99
|
/**
|
|
93
100
|
* 设置 body
|
|
94
101
|
* @param body {*} 内容
|
|
95
102
|
*/
|
|
96
|
-
setBody(body: string):
|
|
103
|
+
setBody(body: string): Http<TParams, TCookie, TSession>;
|
|
97
104
|
}
|
|
105
|
+
export declare function useHttp<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any>(config?: HttpConfig<TParams, TCookie, TSession>): Http<TParams, TCookie, TSession> & UseifyPlugin;
|