@innet/server 2.0.0-alpha.24 → 2.0.0-alpha.25
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/handler/handler.d.ts +5 -5
- package/handler/handler.es6.js +3 -3
- package/handler/handler.js +3 -3
- package/hooks/index.d.ts +1 -0
- package/hooks/index.es6.js +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useClientIp/useClientIp.d.ts +1 -1
- package/hooks/useEndpoint/useEndpoint.d.ts +1 -1
- package/hooks/useSchemaType/useSchemaType.d.ts +3 -3
- package/hooks/useSchemaType/useSchemaType.es6.js +5 -5
- package/hooks/useSchemaType/useSchemaType.js +5 -5
- package/hooks/useServer/useServer.d.ts +1 -1
- package/hooks/useServerPort/index.d.ts +1 -0
- package/hooks/useServerPort/index.es6.js +1 -0
- package/hooks/useServerPort/index.js +10 -0
- package/hooks/useServerPort/useServerPort.d.ts +3 -0
- package/hooks/useServerPort/useServerPort.es6.js +14 -0
- package/hooks/useServerPort/useServerPort.js +19 -0
- package/index.es6.js +1 -0
- package/index.js +3 -0
- package/package.json +1 -1
- package/plugins/main/api/api.d.ts +10 -10
- package/plugins/main/api/api.es6.js +7 -7
- package/plugins/main/api/api.js +7 -7
- package/plugins/main/contact/contact.d.ts +2 -2
- package/plugins/main/endpoint/endpoint.d.ts +15 -15
- package/plugins/main/endpoint/endpoint.es6.js +3 -3
- package/plugins/main/endpoint/endpoint.js +3 -3
- package/plugins/main/host/host.d.ts +5 -5
- package/plugins/main/license/license.d.ts +5 -5
- package/plugins/main/param/param.d.ts +11 -11
- package/plugins/main/param/param.es6.js +3 -3
- package/plugins/main/param/param.js +3 -3
- package/plugins/main/response/response.d.ts +1 -1
- package/plugins/main/response/response.es6.js +2 -2
- package/plugins/main/response/response.js +2 -2
- package/plugins/main/server/server.d.ts +4 -4
- package/plugins/main/server/server.es6.js +9 -7
- package/plugins/main/server/server.js +9 -7
- package/plugins/main/tag/tag.d.ts +2 -2
- package/plugins/main/tag/tag.es6.js +1 -1
- package/plugins/main/tag/tag.js +1 -1
- package/plugins/main/variable/variable.d.ts +5 -5
- package/plugins/main/variable/variable.es6.js +3 -1
- package/plugins/main/variable/variable.js +3 -1
- package/plugins/request/cms/cms.es6.js +2 -2
- package/plugins/request/cms/cms.js +2 -2
- package/plugins/request/error/error.d.ts +40 -40
- package/plugins/request/error/error.es6.js +42 -42
- package/plugins/request/error/error.js +42 -42
- package/plugins/request/header/header.es6.js +1 -1
- package/plugins/request/header/header.js +1 -1
- package/plugins/request/proxy/proxy.d.ts +2 -2
- package/plugins/request/proxy/proxy.es6.js +2 -2
- package/plugins/request/proxy/proxy.js +2 -2
- package/plugins/request/redirect/redirect.d.ts +7 -7
- package/plugins/request/redirect/redirect.es6.js +7 -7
- package/plugins/request/redirect/redirect.js +7 -7
- package/plugins/request/success/success.d.ts +6 -6
- package/plugins/request/success/success.es6.js +8 -8
- package/plugins/request/success/success.js +8 -8
- package/plugins/schema/binary/binary.d.ts +3 -3
- package/plugins/schema/date/date.d.ts +1 -1
- package/plugins/schema/date/date.es6.js +3 -3
- package/plugins/schema/date/date.js +3 -3
- package/plugins/schema/field/field.es6.js +1 -1
- package/plugins/schema/field/field.js +1 -1
- package/plugins/schema/integer/integer.d.ts +3 -3
- package/plugins/schema/integer/integer.es6.js +1 -1
- package/plugins/schema/integer/integer.js +1 -1
- package/plugins/schema/number/number.d.ts +2 -2
- package/plugins/schema/number/number.es6.js +1 -1
- package/plugins/schema/number/number.js +1 -1
- package/plugins/schema/string/string.d.ts +2 -2
- package/plugins/schema/string/string.es6.js +1 -1
- package/plugins/schema/string/string.js +1 -1
- package/plugins/utils/dts/dts.d.ts +1 -1
- package/plugins/utils/dts/dts.es6.js +1 -1
- package/plugins/utils/dts/dts.js +1 -1
- package/plugins/utils/env/env.d.ts +1 -1
- package/plugins/utils/env/env.es6.js +1 -1
- package/plugins/utils/env/env.js +1 -1
- package/plugins/utils/protection/protection.d.ts +3 -3
- package/plugins/utils/protection/protection.es6.js +3 -3
- package/plugins/utils/protection/protection.js +3 -3
- package/plugins/utils/swagger/swagger.es6.js +1 -1
- package/plugins/utils/swagger/swagger.js +1 -1
- package/types.d.ts +13 -13
- package/utils/FileData/Bin.d.ts +13 -13
- package/utils/FileData/Bin.es6.js +2 -2
- package/utils/FileData/Bin.js +2 -2
- package/utils/action/Action.d.ts +12 -12
- package/utils/action/Action.es6.js +80 -80
- package/utils/action/Action.js +79 -79
- package/utils/dateFormat/dateFormat.d.ts +1 -1
- package/utils/dateFormat/dateFormat.es6.js +1 -1
- package/utils/dateFormat/dateFormat.js +1 -1
- package/utils/generateTypes/generateTypes.es6.js +3 -3
- package/utils/generateTypes/generateTypes.js +3 -3
- package/utils/getOrAdd/getOrAdd.d.ts +1 -1
- package/utils/httpOnStart/httpOnStart.d.ts +1 -1
- package/utils/httpOnStart/httpOnStart.es6.js +1 -1
- package/utils/httpOnStart/httpOnStart.js +1 -1
- package/utils/rules/binaryAccept/binaryAccept.es6.js +2 -2
- package/utils/rules/binaryAccept/binaryAccept.js +2 -2
- package/utils/rules/dateTo/dateTo.d.ts +1 -1
- package/utils/rules/helpers.d.ts +1 -1
- package/utils/rules/int/int.es6.js +2 -2
- package/utils/rules/int/int.js +2 -2
- package/utils/rules/max/max.d.ts +1 -1
- package/utils/rules/max/max.es6.js +3 -3
- package/utils/rules/max/max.js +3 -3
- package/utils/rules/maxBin/maxBin.es6.js +2 -2
- package/utils/rules/maxBin/maxBin.js +2 -2
- package/utils/rules/maxDate/maxDate.es6.js +1 -1
- package/utils/rules/maxDate/maxDate.js +1 -1
- package/utils/rules/maxLength/maxLength.es6.js +2 -2
- package/utils/rules/maxLength/maxLength.js +2 -2
- package/utils/rules/min/min.d.ts +1 -1
- package/utils/rules/min/min.es6.js +3 -3
- package/utils/rules/min/min.js +3 -3
- package/utils/rules/minBin/minBin.es6.js +2 -2
- package/utils/rules/minBin/minBin.js +2 -2
- package/utils/rules/minDate/minDate.es6.js +1 -1
- package/utils/rules/minDate/minDate.js +1 -1
- package/utils/rules/minLength/minLength.es6.js +2 -2
- package/utils/rules/minLength/minLength.js +2 -2
- package/utils/rules/pattern/pattern.d.ts +1 -1
- package/utils/rules/pattern/pattern.es6.js +2 -1
- package/utils/rules/pattern/pattern.js +2 -1
package/utils/FileData/Bin.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export interface BinOptions {
|
|
2
|
+
disposition: string;
|
|
2
3
|
/**
|
|
3
4
|
* A field name of FormData request
|
|
4
5
|
*/
|
|
@@ -11,37 +12,36 @@ export interface BinOptions {
|
|
|
11
12
|
* Full path to the file on server, you MUST use it only on server side for the safe
|
|
12
13
|
*/
|
|
13
14
|
path: string;
|
|
14
|
-
/**
|
|
15
|
-
* MIME-type of the file
|
|
16
|
-
*/
|
|
17
|
-
type: string;
|
|
18
|
-
disposition: string;
|
|
19
15
|
/**
|
|
20
16
|
* The file size
|
|
21
17
|
*/
|
|
22
18
|
size: number;
|
|
23
|
-
}
|
|
24
|
-
export declare class Bin implements BinOptions {
|
|
25
19
|
/**
|
|
26
|
-
*
|
|
20
|
+
* MIME-type of the file
|
|
27
21
|
*/
|
|
28
|
-
|
|
22
|
+
type: string;
|
|
23
|
+
}
|
|
24
|
+
export declare class Bin implements BinOptions {
|
|
25
|
+
disposition: string;
|
|
29
26
|
/**
|
|
30
27
|
* The extension of the origin file from originalFilename
|
|
31
28
|
*/
|
|
32
29
|
extension?: string;
|
|
33
|
-
type: string;
|
|
34
|
-
disposition: string;
|
|
35
30
|
fieldName: string;
|
|
31
|
+
/**
|
|
32
|
+
* A file name, without extension
|
|
33
|
+
*/
|
|
34
|
+
filename: string;
|
|
36
35
|
originalFilename: string;
|
|
37
36
|
path: string;
|
|
38
37
|
size: number;
|
|
38
|
+
type: string;
|
|
39
39
|
constructor(options: BinOptions);
|
|
40
40
|
toJSON(): {
|
|
41
41
|
$: string;
|
|
42
|
-
originalFilename: string;
|
|
43
|
-
type: string;
|
|
44
42
|
disposition: string;
|
|
43
|
+
originalFilename: string;
|
|
45
44
|
size: number;
|
|
45
|
+
type: string;
|
|
46
46
|
};
|
|
47
47
|
}
|
package/utils/FileData/Bin.js
CHANGED
|
@@ -12,10 +12,10 @@ class Bin {
|
|
|
12
12
|
toJSON() {
|
|
13
13
|
return {
|
|
14
14
|
$: 'binary',
|
|
15
|
-
originalFilename: this.originalFilename,
|
|
16
|
-
type: this.type,
|
|
17
15
|
disposition: this.disposition,
|
|
16
|
+
originalFilename: this.originalFilename,
|
|
18
17
|
size: this.size,
|
|
18
|
+
type: this.type,
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
}
|
package/utils/action/Action.d.ts
CHANGED
|
@@ -12,21 +12,21 @@ export declare class Action {
|
|
|
12
12
|
#private;
|
|
13
13
|
readonly req: IncomingMessage;
|
|
14
14
|
readonly res: ServerResponse;
|
|
15
|
+
body?: object;
|
|
15
16
|
constructor(req: IncomingMessage, res: ServerResponse);
|
|
17
|
+
parseBody(): Promise<void>;
|
|
18
|
+
setCookie(name: string, value?: string, options?: CookieSerializeOptions): void;
|
|
19
|
+
get bodyType(): BodyType | undefined;
|
|
20
|
+
get clientIp(): string | null;
|
|
21
|
+
get cookies(): Record<string, string>;
|
|
22
|
+
set cookies(value: Record<string, string>);
|
|
23
|
+
get headers(): IncomingHttpHeaders;
|
|
24
|
+
set headers(value: IncomingHttpHeaders);
|
|
25
|
+
get originCookies(): Record<string, string>;
|
|
26
|
+
get originHeaders(): IncomingHttpHeaders;
|
|
27
|
+
get originSearch(): ParsedQs;
|
|
16
28
|
get parsedUrl(): ParsedUrl;
|
|
17
29
|
get path(): string;
|
|
18
|
-
get originSearch(): ParsedQs;
|
|
19
30
|
get search(): ParsedQs;
|
|
20
31
|
set search(value: ParsedQs);
|
|
21
|
-
get originHeaders(): IncomingHttpHeaders;
|
|
22
|
-
get headers(): IncomingHttpHeaders;
|
|
23
|
-
set headers(value: IncomingHttpHeaders);
|
|
24
|
-
get originCookies(): Record<string, string>;
|
|
25
|
-
get cookies(): Record<string, string>;
|
|
26
|
-
set cookies(value: Record<string, string>);
|
|
27
|
-
get bodyType(): BodyType | undefined;
|
|
28
|
-
body?: object;
|
|
29
|
-
parseBody(): Promise<void>;
|
|
30
|
-
setCookie(name: string, value?: string, options?: CookieSerializeOptions): void;
|
|
31
|
-
get clientIp(): string | null;
|
|
32
32
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __runInitializers, __classPrivateFieldGet, __classPrivateFieldSet,
|
|
1
|
+
import { __runInitializers, __awaiter, __classPrivateFieldGet, __classPrivateFieldSet, __esDecorate } from 'tslib';
|
|
2
2
|
import cookieLib from 'cookie';
|
|
3
3
|
import { getClientIp } from 'request-ip';
|
|
4
4
|
import '../decorators/index.es6.js';
|
|
@@ -6,89 +6,28 @@ import '../parseBody/index.es6.js';
|
|
|
6
6
|
import '../parseFormBody/index.es6.js';
|
|
7
7
|
import '../parseSearch/index.es6.js';
|
|
8
8
|
import { allBodyTypes } from '../../constants.es6.js';
|
|
9
|
-
import { parseSearch } from '../parseSearch/parseSearch.es6.js';
|
|
10
9
|
import { parseFormBody } from '../parseFormBody/parseFormBody.es6.js';
|
|
10
|
+
import { parseSearch } from '../parseSearch/parseSearch.es6.js';
|
|
11
11
|
import { parseBody } from '../parseBody/parseBody.es6.js';
|
|
12
12
|
import { once } from '../decorators/once/once.es6.js';
|
|
13
13
|
|
|
14
14
|
const URL_PARSER = /^(?<path>[^?]+)(\?(?<search>.*))?/;
|
|
15
15
|
let Action = (() => {
|
|
16
|
-
var _a,
|
|
16
|
+
var _a, _Action_cookie, _Action_headers, _Action_search;
|
|
17
17
|
let _instanceExtraInitializers = [];
|
|
18
|
-
let _get_parsedUrl_decorators;
|
|
19
|
-
let _get_originSearch_decorators;
|
|
20
|
-
let _get_originCookies_decorators;
|
|
21
|
-
let _get_bodyType_decorators;
|
|
22
18
|
let _parseBody_decorators;
|
|
19
|
+
let _get_bodyType_decorators;
|
|
23
20
|
let _get_clientIp_decorators;
|
|
21
|
+
let _get_originCookies_decorators;
|
|
22
|
+
let _get_originSearch_decorators;
|
|
23
|
+
let _get_parsedUrl_decorators;
|
|
24
24
|
return _a = class Action {
|
|
25
25
|
constructor(req, res) {
|
|
26
26
|
this.req = (__runInitializers(this, _instanceExtraInitializers), req);
|
|
27
27
|
this.res = res;
|
|
28
|
-
_Action_search.set(this, void 0);
|
|
29
|
-
_Action_headers.set(this, {});
|
|
30
28
|
_Action_cookie.set(this, {});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var _b;
|
|
34
|
-
const match = (_b = this.req.url) === null || _b === void 0 ? void 0 : _b.match(URL_PARSER);
|
|
35
|
-
if (!match)
|
|
36
|
-
throw Error('cannot parse url');
|
|
37
|
-
const result = match.groups;
|
|
38
|
-
result.path = result.path
|
|
39
|
-
.replaceAll(/\/\.\.\//g, '/')
|
|
40
|
-
.replaceAll(/\/+/g, '/');
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
get path() {
|
|
44
|
-
return this.parsedUrl.path;
|
|
45
|
-
}
|
|
46
|
-
get originSearch() {
|
|
47
|
-
return parseSearch(this.parsedUrl.search);
|
|
48
|
-
}
|
|
49
|
-
get search() {
|
|
50
|
-
if (__classPrivateFieldGet(this, _Action_search, "f"))
|
|
51
|
-
return __classPrivateFieldGet(this, _Action_search, "f");
|
|
52
|
-
__classPrivateFieldSet(this, _Action_search, this.originSearch, "f");
|
|
53
|
-
return __classPrivateFieldGet(this, _Action_search, "f");
|
|
54
|
-
}
|
|
55
|
-
set search(value) {
|
|
56
|
-
__classPrivateFieldSet(this, _Action_search, value, "f");
|
|
57
|
-
}
|
|
58
|
-
get originHeaders() {
|
|
59
|
-
return this.req.headers;
|
|
60
|
-
}
|
|
61
|
-
get headers() {
|
|
62
|
-
if (__classPrivateFieldGet(this, _Action_headers, "f"))
|
|
63
|
-
return __classPrivateFieldGet(this, _Action_headers, "f");
|
|
64
|
-
__classPrivateFieldSet(this, _Action_headers, this.originHeaders, "f");
|
|
65
|
-
return __classPrivateFieldGet(this, _Action_headers, "f");
|
|
66
|
-
}
|
|
67
|
-
set headers(value) {
|
|
68
|
-
__classPrivateFieldSet(this, _Action_headers, value, "f");
|
|
69
|
-
}
|
|
70
|
-
get originCookies() {
|
|
71
|
-
var _b;
|
|
72
|
-
return cookieLib.parse((_b = this.req.headers.cookie) !== null && _b !== void 0 ? _b : '');
|
|
73
|
-
}
|
|
74
|
-
get cookies() {
|
|
75
|
-
if (__classPrivateFieldGet(this, _Action_cookie, "f"))
|
|
76
|
-
return __classPrivateFieldGet(this, _Action_cookie, "f");
|
|
77
|
-
__classPrivateFieldSet(this, _Action_cookie, this.originCookies, "f");
|
|
78
|
-
return __classPrivateFieldGet(this, _Action_cookie, "f");
|
|
79
|
-
}
|
|
80
|
-
set cookies(value) {
|
|
81
|
-
__classPrivateFieldSet(this, _Action_cookie, value, "f");
|
|
82
|
-
}
|
|
83
|
-
get bodyType() {
|
|
84
|
-
const headerType = this.req.headers['content-type'];
|
|
85
|
-
if (!headerType)
|
|
86
|
-
return;
|
|
87
|
-
for (const bodyType of allBodyTypes) {
|
|
88
|
-
if (headerType.startsWith(bodyType)) {
|
|
89
|
-
return bodyType;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
29
|
+
_Action_headers.set(this, {});
|
|
30
|
+
_Action_search.set(this, void 0);
|
|
92
31
|
}
|
|
93
32
|
parseBody() {
|
|
94
33
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -120,27 +59,88 @@ let Action = (() => {
|
|
|
120
59
|
}
|
|
121
60
|
this.res.setHeader('Set-Cookie', cookies);
|
|
122
61
|
}
|
|
62
|
+
get bodyType() {
|
|
63
|
+
const headerType = this.req.headers['content-type'];
|
|
64
|
+
if (!headerType)
|
|
65
|
+
return;
|
|
66
|
+
for (const bodyType of allBodyTypes) {
|
|
67
|
+
if (headerType.startsWith(bodyType)) {
|
|
68
|
+
return bodyType;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
123
72
|
get clientIp() {
|
|
124
73
|
return getClientIp(this.req);
|
|
125
74
|
}
|
|
75
|
+
get cookies() {
|
|
76
|
+
if (__classPrivateFieldGet(this, _Action_cookie, "f"))
|
|
77
|
+
return __classPrivateFieldGet(this, _Action_cookie, "f");
|
|
78
|
+
__classPrivateFieldSet(this, _Action_cookie, this.originCookies, "f");
|
|
79
|
+
return __classPrivateFieldGet(this, _Action_cookie, "f");
|
|
80
|
+
}
|
|
81
|
+
set cookies(value) {
|
|
82
|
+
__classPrivateFieldSet(this, _Action_cookie, value, "f");
|
|
83
|
+
}
|
|
84
|
+
get headers() {
|
|
85
|
+
if (__classPrivateFieldGet(this, _Action_headers, "f"))
|
|
86
|
+
return __classPrivateFieldGet(this, _Action_headers, "f");
|
|
87
|
+
__classPrivateFieldSet(this, _Action_headers, this.originHeaders, "f");
|
|
88
|
+
return __classPrivateFieldGet(this, _Action_headers, "f");
|
|
89
|
+
}
|
|
90
|
+
set headers(value) {
|
|
91
|
+
__classPrivateFieldSet(this, _Action_headers, value, "f");
|
|
92
|
+
}
|
|
93
|
+
get originCookies() {
|
|
94
|
+
var _b;
|
|
95
|
+
return cookieLib.parse((_b = this.req.headers.cookie) !== null && _b !== void 0 ? _b : '');
|
|
96
|
+
}
|
|
97
|
+
get originHeaders() {
|
|
98
|
+
return this.req.headers;
|
|
99
|
+
}
|
|
100
|
+
get originSearch() {
|
|
101
|
+
return parseSearch(this.parsedUrl.search);
|
|
102
|
+
}
|
|
103
|
+
get parsedUrl() {
|
|
104
|
+
var _b;
|
|
105
|
+
const match = (_b = this.req.url) === null || _b === void 0 ? void 0 : _b.match(URL_PARSER);
|
|
106
|
+
if (!match)
|
|
107
|
+
throw Error('cannot parse url');
|
|
108
|
+
const result = match.groups;
|
|
109
|
+
result.path = result.path
|
|
110
|
+
.replaceAll(/\/\.\.\//g, '/')
|
|
111
|
+
.replaceAll(/\/+/g, '/');
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
get path() {
|
|
115
|
+
return this.parsedUrl.path;
|
|
116
|
+
}
|
|
117
|
+
get search() {
|
|
118
|
+
if (__classPrivateFieldGet(this, _Action_search, "f"))
|
|
119
|
+
return __classPrivateFieldGet(this, _Action_search, "f");
|
|
120
|
+
__classPrivateFieldSet(this, _Action_search, this.originSearch, "f");
|
|
121
|
+
return __classPrivateFieldGet(this, _Action_search, "f");
|
|
122
|
+
}
|
|
123
|
+
set search(value) {
|
|
124
|
+
__classPrivateFieldSet(this, _Action_search, value, "f");
|
|
125
|
+
}
|
|
126
126
|
},
|
|
127
|
-
_Action_search = new WeakMap(),
|
|
128
|
-
_Action_headers = new WeakMap(),
|
|
129
127
|
_Action_cookie = new WeakMap(),
|
|
128
|
+
_Action_headers = new WeakMap(),
|
|
129
|
+
_Action_search = new WeakMap(),
|
|
130
130
|
(() => {
|
|
131
131
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
132
|
-
_get_parsedUrl_decorators = [once];
|
|
133
|
-
_get_originSearch_decorators = [once];
|
|
134
|
-
_get_originCookies_decorators = [once];
|
|
135
|
-
_get_bodyType_decorators = [once];
|
|
136
132
|
_parseBody_decorators = [once];
|
|
133
|
+
_get_bodyType_decorators = [once];
|
|
137
134
|
_get_clientIp_decorators = [once];
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
__esDecorate(_a, null, _get_bodyType_decorators, { kind: "getter", name: "bodyType", static: false, private: false, access: { has: obj => "bodyType" in obj, get: obj => obj.bodyType }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
135
|
+
_get_originCookies_decorators = [once];
|
|
136
|
+
_get_originSearch_decorators = [once];
|
|
137
|
+
_get_parsedUrl_decorators = [once];
|
|
142
138
|
__esDecorate(_a, null, _parseBody_decorators, { kind: "method", name: "parseBody", static: false, private: false, access: { has: obj => "parseBody" in obj, get: obj => obj.parseBody }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
139
|
+
__esDecorate(_a, null, _get_bodyType_decorators, { kind: "getter", name: "bodyType", static: false, private: false, access: { has: obj => "bodyType" in obj, get: obj => obj.bodyType }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
143
140
|
__esDecorate(_a, null, _get_clientIp_decorators, { kind: "getter", name: "clientIp", static: false, private: false, access: { has: obj => "clientIp" in obj, get: obj => obj.clientIp }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
141
|
+
__esDecorate(_a, null, _get_originCookies_decorators, { kind: "getter", name: "originCookies", static: false, private: false, access: { has: obj => "originCookies" in obj, get: obj => obj.originCookies }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
142
|
+
__esDecorate(_a, null, _get_originSearch_decorators, { kind: "getter", name: "originSearch", static: false, private: false, access: { has: obj => "originSearch" in obj, get: obj => obj.originSearch }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
143
|
+
__esDecorate(_a, null, _get_parsedUrl_decorators, { kind: "getter", name: "parsedUrl", static: false, private: false, access: { has: obj => "parsedUrl" in obj, get: obj => obj.parsedUrl }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
144
144
|
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
145
145
|
})(),
|
|
146
146
|
_a;
|
package/utils/action/Action.js
CHANGED
|
@@ -10,8 +10,8 @@ require('../parseBody/index.js');
|
|
|
10
10
|
require('../parseFormBody/index.js');
|
|
11
11
|
require('../parseSearch/index.js');
|
|
12
12
|
var constants = require('../../constants.js');
|
|
13
|
-
var parseSearch = require('../parseSearch/parseSearch.js');
|
|
14
13
|
var parseFormBody = require('../parseFormBody/parseFormBody.js');
|
|
14
|
+
var parseSearch = require('../parseSearch/parseSearch.js');
|
|
15
15
|
var parseBody = require('../parseBody/parseBody.js');
|
|
16
16
|
var once = require('../decorators/once/once.js');
|
|
17
17
|
|
|
@@ -21,82 +21,21 @@ var cookieLib__default = /*#__PURE__*/_interopDefaultLegacy(cookieLib);
|
|
|
21
21
|
|
|
22
22
|
const URL_PARSER = /^(?<path>[^?]+)(\?(?<search>.*))?/;
|
|
23
23
|
let Action = (() => {
|
|
24
|
-
var _a,
|
|
24
|
+
var _a, _Action_cookie, _Action_headers, _Action_search;
|
|
25
25
|
let _instanceExtraInitializers = [];
|
|
26
|
-
let _get_parsedUrl_decorators;
|
|
27
|
-
let _get_originSearch_decorators;
|
|
28
|
-
let _get_originCookies_decorators;
|
|
29
|
-
let _get_bodyType_decorators;
|
|
30
26
|
let _parseBody_decorators;
|
|
27
|
+
let _get_bodyType_decorators;
|
|
31
28
|
let _get_clientIp_decorators;
|
|
29
|
+
let _get_originCookies_decorators;
|
|
30
|
+
let _get_originSearch_decorators;
|
|
31
|
+
let _get_parsedUrl_decorators;
|
|
32
32
|
return _a = class Action {
|
|
33
33
|
constructor(req, res) {
|
|
34
34
|
this.req = (tslib.__runInitializers(this, _instanceExtraInitializers), req);
|
|
35
35
|
this.res = res;
|
|
36
|
-
_Action_search.set(this, void 0);
|
|
37
|
-
_Action_headers.set(this, {});
|
|
38
36
|
_Action_cookie.set(this, {});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var _b;
|
|
42
|
-
const match = (_b = this.req.url) === null || _b === void 0 ? void 0 : _b.match(URL_PARSER);
|
|
43
|
-
if (!match)
|
|
44
|
-
throw Error('cannot parse url');
|
|
45
|
-
const result = match.groups;
|
|
46
|
-
result.path = result.path
|
|
47
|
-
.replaceAll(/\/\.\.\//g, '/')
|
|
48
|
-
.replaceAll(/\/+/g, '/');
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
get path() {
|
|
52
|
-
return this.parsedUrl.path;
|
|
53
|
-
}
|
|
54
|
-
get originSearch() {
|
|
55
|
-
return parseSearch.parseSearch(this.parsedUrl.search);
|
|
56
|
-
}
|
|
57
|
-
get search() {
|
|
58
|
-
if (tslib.__classPrivateFieldGet(this, _Action_search, "f"))
|
|
59
|
-
return tslib.__classPrivateFieldGet(this, _Action_search, "f");
|
|
60
|
-
tslib.__classPrivateFieldSet(this, _Action_search, this.originSearch, "f");
|
|
61
|
-
return tslib.__classPrivateFieldGet(this, _Action_search, "f");
|
|
62
|
-
}
|
|
63
|
-
set search(value) {
|
|
64
|
-
tslib.__classPrivateFieldSet(this, _Action_search, value, "f");
|
|
65
|
-
}
|
|
66
|
-
get originHeaders() {
|
|
67
|
-
return this.req.headers;
|
|
68
|
-
}
|
|
69
|
-
get headers() {
|
|
70
|
-
if (tslib.__classPrivateFieldGet(this, _Action_headers, "f"))
|
|
71
|
-
return tslib.__classPrivateFieldGet(this, _Action_headers, "f");
|
|
72
|
-
tslib.__classPrivateFieldSet(this, _Action_headers, this.originHeaders, "f");
|
|
73
|
-
return tslib.__classPrivateFieldGet(this, _Action_headers, "f");
|
|
74
|
-
}
|
|
75
|
-
set headers(value) {
|
|
76
|
-
tslib.__classPrivateFieldSet(this, _Action_headers, value, "f");
|
|
77
|
-
}
|
|
78
|
-
get originCookies() {
|
|
79
|
-
var _b;
|
|
80
|
-
return cookieLib__default["default"].parse((_b = this.req.headers.cookie) !== null && _b !== void 0 ? _b : '');
|
|
81
|
-
}
|
|
82
|
-
get cookies() {
|
|
83
|
-
if (tslib.__classPrivateFieldGet(this, _Action_cookie, "f"))
|
|
84
|
-
return tslib.__classPrivateFieldGet(this, _Action_cookie, "f");
|
|
85
|
-
tslib.__classPrivateFieldSet(this, _Action_cookie, this.originCookies, "f");
|
|
86
|
-
return tslib.__classPrivateFieldGet(this, _Action_cookie, "f");
|
|
87
|
-
}
|
|
88
|
-
set cookies(value) {
|
|
89
|
-
tslib.__classPrivateFieldSet(this, _Action_cookie, value, "f");
|
|
90
|
-
}
|
|
91
|
-
get bodyType() {
|
|
92
|
-
const headerType = this.req.headers['content-type'];
|
|
93
|
-
if (!headerType)
|
|
94
|
-
return;
|
|
95
|
-
for (const bodyType of constants.allBodyTypes) {
|
|
96
|
-
if (headerType.startsWith(bodyType)) {
|
|
97
|
-
return bodyType;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
37
|
+
_Action_headers.set(this, {});
|
|
38
|
+
_Action_search.set(this, void 0);
|
|
100
39
|
}
|
|
101
40
|
parseBody() {
|
|
102
41
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -128,27 +67,88 @@ let Action = (() => {
|
|
|
128
67
|
}
|
|
129
68
|
this.res.setHeader('Set-Cookie', cookies);
|
|
130
69
|
}
|
|
70
|
+
get bodyType() {
|
|
71
|
+
const headerType = this.req.headers['content-type'];
|
|
72
|
+
if (!headerType)
|
|
73
|
+
return;
|
|
74
|
+
for (const bodyType of constants.allBodyTypes) {
|
|
75
|
+
if (headerType.startsWith(bodyType)) {
|
|
76
|
+
return bodyType;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
131
80
|
get clientIp() {
|
|
132
81
|
return requestIp.getClientIp(this.req);
|
|
133
82
|
}
|
|
83
|
+
get cookies() {
|
|
84
|
+
if (tslib.__classPrivateFieldGet(this, _Action_cookie, "f"))
|
|
85
|
+
return tslib.__classPrivateFieldGet(this, _Action_cookie, "f");
|
|
86
|
+
tslib.__classPrivateFieldSet(this, _Action_cookie, this.originCookies, "f");
|
|
87
|
+
return tslib.__classPrivateFieldGet(this, _Action_cookie, "f");
|
|
88
|
+
}
|
|
89
|
+
set cookies(value) {
|
|
90
|
+
tslib.__classPrivateFieldSet(this, _Action_cookie, value, "f");
|
|
91
|
+
}
|
|
92
|
+
get headers() {
|
|
93
|
+
if (tslib.__classPrivateFieldGet(this, _Action_headers, "f"))
|
|
94
|
+
return tslib.__classPrivateFieldGet(this, _Action_headers, "f");
|
|
95
|
+
tslib.__classPrivateFieldSet(this, _Action_headers, this.originHeaders, "f");
|
|
96
|
+
return tslib.__classPrivateFieldGet(this, _Action_headers, "f");
|
|
97
|
+
}
|
|
98
|
+
set headers(value) {
|
|
99
|
+
tslib.__classPrivateFieldSet(this, _Action_headers, value, "f");
|
|
100
|
+
}
|
|
101
|
+
get originCookies() {
|
|
102
|
+
var _b;
|
|
103
|
+
return cookieLib__default["default"].parse((_b = this.req.headers.cookie) !== null && _b !== void 0 ? _b : '');
|
|
104
|
+
}
|
|
105
|
+
get originHeaders() {
|
|
106
|
+
return this.req.headers;
|
|
107
|
+
}
|
|
108
|
+
get originSearch() {
|
|
109
|
+
return parseSearch.parseSearch(this.parsedUrl.search);
|
|
110
|
+
}
|
|
111
|
+
get parsedUrl() {
|
|
112
|
+
var _b;
|
|
113
|
+
const match = (_b = this.req.url) === null || _b === void 0 ? void 0 : _b.match(URL_PARSER);
|
|
114
|
+
if (!match)
|
|
115
|
+
throw Error('cannot parse url');
|
|
116
|
+
const result = match.groups;
|
|
117
|
+
result.path = result.path
|
|
118
|
+
.replaceAll(/\/\.\.\//g, '/')
|
|
119
|
+
.replaceAll(/\/+/g, '/');
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
get path() {
|
|
123
|
+
return this.parsedUrl.path;
|
|
124
|
+
}
|
|
125
|
+
get search() {
|
|
126
|
+
if (tslib.__classPrivateFieldGet(this, _Action_search, "f"))
|
|
127
|
+
return tslib.__classPrivateFieldGet(this, _Action_search, "f");
|
|
128
|
+
tslib.__classPrivateFieldSet(this, _Action_search, this.originSearch, "f");
|
|
129
|
+
return tslib.__classPrivateFieldGet(this, _Action_search, "f");
|
|
130
|
+
}
|
|
131
|
+
set search(value) {
|
|
132
|
+
tslib.__classPrivateFieldSet(this, _Action_search, value, "f");
|
|
133
|
+
}
|
|
134
134
|
},
|
|
135
|
-
_Action_search = new WeakMap(),
|
|
136
|
-
_Action_headers = new WeakMap(),
|
|
137
135
|
_Action_cookie = new WeakMap(),
|
|
136
|
+
_Action_headers = new WeakMap(),
|
|
137
|
+
_Action_search = new WeakMap(),
|
|
138
138
|
(() => {
|
|
139
139
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
140
|
-
_get_parsedUrl_decorators = [once.once];
|
|
141
|
-
_get_originSearch_decorators = [once.once];
|
|
142
|
-
_get_originCookies_decorators = [once.once];
|
|
143
|
-
_get_bodyType_decorators = [once.once];
|
|
144
140
|
_parseBody_decorators = [once.once];
|
|
141
|
+
_get_bodyType_decorators = [once.once];
|
|
145
142
|
_get_clientIp_decorators = [once.once];
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
tslib.__esDecorate(_a, null, _get_bodyType_decorators, { kind: "getter", name: "bodyType", static: false, private: false, access: { has: obj => "bodyType" in obj, get: obj => obj.bodyType }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
143
|
+
_get_originCookies_decorators = [once.once];
|
|
144
|
+
_get_originSearch_decorators = [once.once];
|
|
145
|
+
_get_parsedUrl_decorators = [once.once];
|
|
150
146
|
tslib.__esDecorate(_a, null, _parseBody_decorators, { kind: "method", name: "parseBody", static: false, private: false, access: { has: obj => "parseBody" in obj, get: obj => obj.parseBody }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
147
|
+
tslib.__esDecorate(_a, null, _get_bodyType_decorators, { kind: "getter", name: "bodyType", static: false, private: false, access: { has: obj => "bodyType" in obj, get: obj => obj.bodyType }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
151
148
|
tslib.__esDecorate(_a, null, _get_clientIp_decorators, { kind: "getter", name: "clientIp", static: false, private: false, access: { has: obj => "clientIp" in obj, get: obj => obj.clientIp }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
149
|
+
tslib.__esDecorate(_a, null, _get_originCookies_decorators, { kind: "getter", name: "originCookies", static: false, private: false, access: { has: obj => "originCookies" in obj, get: obj => obj.originCookies }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
150
|
+
tslib.__esDecorate(_a, null, _get_originSearch_decorators, { kind: "getter", name: "originSearch", static: false, private: false, access: { has: obj => "originSearch" in obj, get: obj => obj.originSearch }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
151
|
+
tslib.__esDecorate(_a, null, _get_parsedUrl_decorators, { kind: "getter", name: "parsedUrl", static: false, private: false, access: { has: obj => "parsedUrl" in obj, get: obj => obj.parsedUrl }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
152
152
|
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
153
153
|
})(),
|
|
154
154
|
_a;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type DateFormat = 'now' |
|
|
1
|
+
export type DateFormat = 'now' | Date | number | string;
|
|
2
2
|
export declare function dateFormat(date?: DateFormat): Date | undefined;
|
|
@@ -18,7 +18,7 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
|
|
|
18
18
|
}
|
|
19
19
|
return `string${lastChar}`;
|
|
20
20
|
}
|
|
21
|
-
if (['boolean', '
|
|
21
|
+
if (['boolean', 'null', 'number'].includes(schema.type)) {
|
|
22
22
|
return `${schema.type}${lastChar}`;
|
|
23
23
|
}
|
|
24
24
|
if (schema.oneOf) {
|
|
@@ -100,10 +100,10 @@ function generateTypes(docs, namespace = 'Api') {
|
|
|
100
100
|
result += ` ['${method.toUpperCase()}:${path}']: {\n`;
|
|
101
101
|
if (parameters) {
|
|
102
102
|
const params = {
|
|
103
|
-
|
|
103
|
+
cookie: '',
|
|
104
104
|
header: '',
|
|
105
105
|
path: '',
|
|
106
|
-
|
|
106
|
+
query: '',
|
|
107
107
|
};
|
|
108
108
|
for (const param of parameters) {
|
|
109
109
|
const splitter = param.in === 'path' || hasDefault(param.schema) ? ':' : '?:';
|
|
@@ -22,7 +22,7 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
|
|
|
22
22
|
}
|
|
23
23
|
return `string${lastChar}`;
|
|
24
24
|
}
|
|
25
|
-
if (['boolean', '
|
|
25
|
+
if (['boolean', 'null', 'number'].includes(schema.type)) {
|
|
26
26
|
return `${schema.type}${lastChar}`;
|
|
27
27
|
}
|
|
28
28
|
if (schema.oneOf) {
|
|
@@ -104,10 +104,10 @@ function generateTypes(docs, namespace = 'Api') {
|
|
|
104
104
|
result += ` ['${method.toUpperCase()}:${path}']: {\n`;
|
|
105
105
|
if (parameters) {
|
|
106
106
|
const params = {
|
|
107
|
-
|
|
107
|
+
cookie: '',
|
|
108
108
|
header: '',
|
|
109
109
|
path: '',
|
|
110
|
-
|
|
110
|
+
query: '',
|
|
111
111
|
};
|
|
112
112
|
for (const param of parameters) {
|
|
113
113
|
const splitter = param.in === 'path' || hasDefault(param.schema) ? ':' : '?:';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getOrAdd<R = any>(target: object, path:
|
|
1
|
+
export declare function getOrAdd<R = any>(target: object, path: number | string, defaultValues: any[]): R;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type ServerStartParams } from '../../types';
|
|
2
|
-
export declare function httpOnStart({ port,
|
|
2
|
+
export declare function httpOnStart({ https, port, }: ServerStartParams): void;
|
|
@@ -28,8 +28,8 @@ function binaryAccept(accept) {
|
|
|
28
28
|
continue;
|
|
29
29
|
return value;
|
|
30
30
|
}
|
|
31
|
-
throw new helpers.RulesError('binaryAccept', Object.assign({
|
|
32
|
-
|
|
31
|
+
throw new helpers.RulesError('binaryAccept', Object.assign({ accept,
|
|
32
|
+
value }, data));
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type DateFormat = 'now' |
|
|
1
|
+
export type DateFormat = 'now' | Date | number | string;
|
|
2
2
|
export declare function dateTo(value: any, data?: object): Date;
|
package/utils/rules/helpers.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export declare class RulesError extends Error {
|
|
|
5
5
|
} & object;
|
|
6
6
|
constructor(error: RulesErrors, data?: object);
|
|
7
7
|
}
|
|
8
|
-
export declare function addKey(key:
|
|
8
|
+
export declare function addKey(key: number | string, data?: any): string | number;
|