@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/lib/validator.d.ts
CHANGED
|
@@ -1,42 +1,57 @@
|
|
|
1
1
|
import { Cookie } from './cookie';
|
|
2
2
|
import { Session } from './session';
|
|
3
|
-
|
|
3
|
+
import { Logger } from '@faasjs/logger';
|
|
4
|
+
export declare type ValidatorRuleOptions = {
|
|
4
5
|
type?: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
5
6
|
required?: boolean;
|
|
6
7
|
in?: any[];
|
|
7
8
|
default?: any;
|
|
8
9
|
config?: Partial<ValidatorOptions>;
|
|
9
|
-
}
|
|
10
|
-
export
|
|
10
|
+
};
|
|
11
|
+
export declare type ValidatorOptions<Content = Record<string, any>> = {
|
|
11
12
|
whitelist?: 'error' | 'ignore';
|
|
12
13
|
rules: {
|
|
13
|
-
[
|
|
14
|
+
[k in keyof Content]?: ValidatorRuleOptions;
|
|
14
15
|
};
|
|
15
16
|
onError?: (type: string, key: string | string[], value?: any) => {
|
|
16
17
|
statusCode?: number;
|
|
17
|
-
headers?: {
|
|
18
|
-
[key: string]: any;
|
|
19
|
-
};
|
|
20
18
|
message: any;
|
|
21
19
|
} | void;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
};
|
|
21
|
+
declare type Request<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any> = {
|
|
22
|
+
headers: {
|
|
23
|
+
[key: string]: string;
|
|
24
|
+
};
|
|
25
|
+
params?: TParams;
|
|
26
|
+
cookie?: Cookie<TCookie, TSession>;
|
|
27
|
+
session?: Session<TSession, TCookie>;
|
|
28
|
+
};
|
|
29
|
+
export declare type BeforeOption<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any> = (request: Request<TParams, TCookie, TSession>) => Promise<void | {
|
|
30
|
+
statusCode?: number;
|
|
31
|
+
message: string;
|
|
32
|
+
}>;
|
|
33
|
+
export declare type ValidatorConfig<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any> = {
|
|
34
|
+
params?: ValidatorOptions<TParams>;
|
|
35
|
+
cookie?: ValidatorOptions<TCookie>;
|
|
36
|
+
session?: ValidatorOptions<TSession>;
|
|
37
|
+
before?: BeforeOption;
|
|
38
|
+
};
|
|
39
|
+
export declare class Validator<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any> {
|
|
40
|
+
before?: BeforeOption<TParams, TCookie, TSession>;
|
|
41
|
+
paramsConfig?: ValidatorOptions<TParams>;
|
|
42
|
+
cookieConfig?: ValidatorOptions<TCookie>;
|
|
43
|
+
sessionConfig?: ValidatorOptions<TSession>;
|
|
44
|
+
private request;
|
|
45
|
+
private readonly logger;
|
|
29
46
|
constructor(config: {
|
|
30
|
-
params?: ValidatorOptions
|
|
31
|
-
cookie?: ValidatorOptions
|
|
32
|
-
session?: ValidatorOptions
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
cookie?: Cookie;
|
|
37
|
-
session?: Session;
|
|
38
|
-
}): void;
|
|
47
|
+
params?: ValidatorOptions<TParams>;
|
|
48
|
+
cookie?: ValidatorOptions<TCookie>;
|
|
49
|
+
session?: ValidatorOptions<TSession>;
|
|
50
|
+
before?: BeforeOption<TParams, TCookie, TSession>;
|
|
51
|
+
}, logger: Logger);
|
|
52
|
+
valid(request: Request<TParams, TCookie, TSession>): Promise<void>;
|
|
39
53
|
validContent(type: string, params: {
|
|
40
54
|
[key: string]: any;
|
|
41
55
|
}, baseKey: string, config: ValidatorOptions): void;
|
|
42
56
|
}
|
|
57
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/http",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.302",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.es.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
8
|
+
"homepage": "https://faasjs.com/docs/http",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/faasjs/faasjs.git",
|
|
12
|
+
"directory": "packages/http"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/faasjs/faasjs/issues"
|
|
16
|
+
},
|
|
17
|
+
"funding": "https://github.com/sponsors/faasjs",
|
|
8
18
|
"scripts": {
|
|
9
19
|
"prepack": "rm -rf ./lib && rollup -c && mv lib/*/src/* lib/"
|
|
10
20
|
},
|
|
@@ -12,7 +22,7 @@
|
|
|
12
22
|
"lib"
|
|
13
23
|
],
|
|
14
24
|
"devDependencies": {
|
|
15
|
-
"@faasjs/func": "^0.0.2-beta.
|
|
25
|
+
"@faasjs/func": "^0.0.2-beta.302",
|
|
16
26
|
"@types/debug": "*",
|
|
17
27
|
"@types/jest": "*",
|
|
18
28
|
"@types/node": "*",
|
|
@@ -20,5 +30,8 @@
|
|
|
20
30
|
"rollup-plugin-typescript2": "*",
|
|
21
31
|
"typescript": "*"
|
|
22
32
|
},
|
|
23
|
-
"
|
|
33
|
+
"engines": {
|
|
34
|
+
"npm": ">=8.0.0"
|
|
35
|
+
},
|
|
36
|
+
"gitHead": "b53fb35a91369afd0185fb555d98e5c9d90b54bd"
|
|
24
37
|
}
|