@innet/server 2.0.0-alpha.23 → 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.
Files changed (132) hide show
  1. package/handler/handler.d.ts +5 -5
  2. package/handler/handler.es6.js +3 -3
  3. package/handler/handler.js +3 -3
  4. package/hooks/index.d.ts +1 -0
  5. package/hooks/index.es6.js +1 -0
  6. package/hooks/index.js +1 -0
  7. package/hooks/useClientIp/useClientIp.d.ts +1 -1
  8. package/hooks/useEndpoint/useEndpoint.d.ts +1 -1
  9. package/hooks/useSchemaType/useSchemaType.d.ts +3 -3
  10. package/hooks/useSchemaType/useSchemaType.es6.js +5 -5
  11. package/hooks/useSchemaType/useSchemaType.js +5 -5
  12. package/hooks/useServer/useServer.d.ts +1 -1
  13. package/hooks/useServerPort/index.d.ts +1 -0
  14. package/hooks/useServerPort/index.es6.js +1 -0
  15. package/hooks/useServerPort/index.js +10 -0
  16. package/hooks/useServerPort/useServerPort.d.ts +3 -0
  17. package/hooks/useServerPort/useServerPort.es6.js +14 -0
  18. package/hooks/useServerPort/useServerPort.js +19 -0
  19. package/index.es6.js +1 -0
  20. package/index.js +3 -0
  21. package/package.json +1 -1
  22. package/plugins/main/api/api.d.ts +10 -10
  23. package/plugins/main/api/api.es6.js +7 -7
  24. package/plugins/main/api/api.js +7 -7
  25. package/plugins/main/contact/contact.d.ts +2 -2
  26. package/plugins/main/endpoint/endpoint.d.ts +15 -15
  27. package/plugins/main/endpoint/endpoint.es6.js +3 -3
  28. package/plugins/main/endpoint/endpoint.js +3 -3
  29. package/plugins/main/host/host.d.ts +5 -5
  30. package/plugins/main/license/license.d.ts +5 -5
  31. package/plugins/main/param/param.d.ts +11 -11
  32. package/plugins/main/param/param.es6.js +3 -3
  33. package/plugins/main/param/param.js +3 -3
  34. package/plugins/main/response/response.d.ts +1 -1
  35. package/plugins/main/response/response.es6.js +2 -2
  36. package/plugins/main/response/response.js +2 -2
  37. package/plugins/main/server/server.d.ts +4 -4
  38. package/plugins/main/server/server.es6.js +9 -7
  39. package/plugins/main/server/server.js +9 -7
  40. package/plugins/main/tag/tag.d.ts +2 -2
  41. package/plugins/main/tag/tag.es6.js +1 -1
  42. package/plugins/main/tag/tag.js +1 -1
  43. package/plugins/main/variable/variable.d.ts +5 -5
  44. package/plugins/main/variable/variable.es6.js +3 -1
  45. package/plugins/main/variable/variable.js +3 -1
  46. package/plugins/request/cms/cms.es6.js +2 -2
  47. package/plugins/request/cms/cms.js +2 -2
  48. package/plugins/request/error/error.d.ts +40 -40
  49. package/plugins/request/error/error.es6.js +42 -42
  50. package/plugins/request/error/error.js +42 -42
  51. package/plugins/request/file/file.es6.js +2 -3
  52. package/plugins/request/file/file.js +2 -3
  53. package/plugins/request/header/header.es6.js +1 -1
  54. package/plugins/request/header/header.js +1 -1
  55. package/plugins/request/proxy/proxy.d.ts +2 -2
  56. package/plugins/request/proxy/proxy.es6.js +2 -2
  57. package/plugins/request/proxy/proxy.js +2 -2
  58. package/plugins/request/redirect/redirect.d.ts +7 -7
  59. package/plugins/request/redirect/redirect.es6.js +7 -7
  60. package/plugins/request/redirect/redirect.js +7 -7
  61. package/plugins/request/success/success.d.ts +6 -6
  62. package/plugins/request/success/success.es6.js +8 -8
  63. package/plugins/request/success/success.js +8 -8
  64. package/plugins/schema/binary/binary.d.ts +3 -3
  65. package/plugins/schema/date/date.d.ts +1 -1
  66. package/plugins/schema/date/date.es6.js +3 -3
  67. package/plugins/schema/date/date.js +3 -3
  68. package/plugins/schema/field/field.es6.js +1 -1
  69. package/plugins/schema/field/field.js +1 -1
  70. package/plugins/schema/integer/integer.d.ts +3 -3
  71. package/plugins/schema/integer/integer.es6.js +1 -1
  72. package/plugins/schema/integer/integer.js +1 -1
  73. package/plugins/schema/number/number.d.ts +2 -2
  74. package/plugins/schema/number/number.es6.js +1 -1
  75. package/plugins/schema/number/number.js +1 -1
  76. package/plugins/schema/string/string.d.ts +2 -2
  77. package/plugins/schema/string/string.es6.js +1 -1
  78. package/plugins/schema/string/string.js +1 -1
  79. package/plugins/utils/dts/dts.d.ts +1 -1
  80. package/plugins/utils/dts/dts.es6.js +1 -1
  81. package/plugins/utils/dts/dts.js +1 -1
  82. package/plugins/utils/env/env.d.ts +1 -1
  83. package/plugins/utils/env/env.es6.js +1 -1
  84. package/plugins/utils/env/env.js +1 -1
  85. package/plugins/utils/protection/protection.d.ts +3 -3
  86. package/plugins/utils/protection/protection.es6.js +3 -3
  87. package/plugins/utils/protection/protection.js +3 -3
  88. package/plugins/utils/swagger/swagger.es6.js +1 -1
  89. package/plugins/utils/swagger/swagger.js +1 -1
  90. package/types.d.ts +13 -13
  91. package/utils/FileData/Bin.d.ts +13 -13
  92. package/utils/FileData/Bin.es6.js +2 -2
  93. package/utils/FileData/Bin.js +2 -2
  94. package/utils/action/Action.d.ts +12 -12
  95. package/utils/action/Action.es6.js +80 -80
  96. package/utils/action/Action.js +79 -79
  97. package/utils/dateFormat/dateFormat.d.ts +1 -1
  98. package/utils/dateFormat/dateFormat.es6.js +1 -1
  99. package/utils/dateFormat/dateFormat.js +1 -1
  100. package/utils/generateTypes/generateTypes.es6.js +3 -3
  101. package/utils/generateTypes/generateTypes.js +3 -3
  102. package/utils/getOrAdd/getOrAdd.d.ts +1 -1
  103. package/utils/httpOnStart/httpOnStart.d.ts +1 -1
  104. package/utils/httpOnStart/httpOnStart.es6.js +1 -1
  105. package/utils/httpOnStart/httpOnStart.js +1 -1
  106. package/utils/rules/binaryAccept/binaryAccept.es6.js +2 -2
  107. package/utils/rules/binaryAccept/binaryAccept.js +2 -2
  108. package/utils/rules/dateTo/dateTo.d.ts +1 -1
  109. package/utils/rules/helpers.d.ts +1 -1
  110. package/utils/rules/int/int.es6.js +2 -2
  111. package/utils/rules/int/int.js +2 -2
  112. package/utils/rules/max/max.d.ts +1 -1
  113. package/utils/rules/max/max.es6.js +3 -3
  114. package/utils/rules/max/max.js +3 -3
  115. package/utils/rules/maxBin/maxBin.es6.js +2 -2
  116. package/utils/rules/maxBin/maxBin.js +2 -2
  117. package/utils/rules/maxDate/maxDate.es6.js +1 -1
  118. package/utils/rules/maxDate/maxDate.js +1 -1
  119. package/utils/rules/maxLength/maxLength.es6.js +2 -2
  120. package/utils/rules/maxLength/maxLength.js +2 -2
  121. package/utils/rules/min/min.d.ts +1 -1
  122. package/utils/rules/min/min.es6.js +3 -3
  123. package/utils/rules/min/min.js +3 -3
  124. package/utils/rules/minBin/minBin.es6.js +2 -2
  125. package/utils/rules/minBin/minBin.js +2 -2
  126. package/utils/rules/minDate/minDate.es6.js +1 -1
  127. package/utils/rules/minDate/minDate.js +1 -1
  128. package/utils/rules/minLength/minLength.es6.js +2 -2
  129. package/utils/rules/minLength/minLength.js +2 -2
  130. package/utils/rules/pattern/pattern.d.ts +1 -1
  131. package/utils/rules/pattern/pattern.es6.js +2 -1
  132. package/utils/rules/pattern/pattern.js +2 -1
package/types.d.ts CHANGED
@@ -15,52 +15,52 @@ export type ReferenceObject = API.ReferenceObject;
15
15
  export type ParameterObject = API.ParameterObject;
16
16
  export type RequestBodyObject = API.RequestBodyObject;
17
17
  export type ObjectType = ArraySchemaObjectType | NonArraySchemaObjectType;
18
- export type RefSchemaObject = SchemaObject | ReferenceObject;
18
+ export type RefSchemaObject = ReferenceObject | SchemaObject;
19
19
  export interface IValidationErrorData extends Record<string, any> {
20
20
  error: RulesErrors;
21
21
  }
22
22
  export type ValidationErrorData = IValidationErrorData | undefined;
23
23
  export interface EndpointRules {
24
- path?: Rule;
25
- search?: Rule;
24
+ body?: Rule;
26
25
  cookie?: Rule;
27
26
  header?: Rule;
28
- body?: Rule;
27
+ path?: Rule;
29
28
  response?: Rule;
29
+ search?: Rule;
30
30
  }
31
31
  export interface EndpointRulesMaps {
32
- path?: Record<string, Rule>;
33
- search?: Record<string, Rule>;
34
32
  cookie?: Record<string, Rule>;
35
33
  header?: Record<string, Rule>;
34
+ path?: Record<string, Rule>;
35
+ search?: Record<string, Rule>;
36
36
  }
37
37
  export interface Endpoint<I = unknown, O = unknown, E extends ApiErrorValue = ApiErrorValue, P extends InValidationErrorParam = InValidationErrorParam, D extends ValidationErrorData = ValidationErrorData> {
38
+ dynamic?: Endpoint<I, O, E, P, D>[];
38
39
  key: string;
39
40
  plugins: Set<ServerPlugin>;
40
41
  rules?: EndpointRules;
41
42
  rulesMaps?: EndpointRulesMaps;
42
43
  static?: Record<string, Endpoint<I, O, E, P, D>>;
43
- dynamic?: Endpoint<I, O, E, P, D>[];
44
44
  }
45
45
  export type IntegerFormats = 'int32' | 'int64';
46
- export type EndpointsMethods = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'head' | 'trace';
47
- export type InParam = 'query' | 'header' | 'path' | 'cookie';
48
- export type InValidationErrorParam = InParam | 'body';
49
- export type BodyType = 'application/x-www-form-urlencoded' | 'application/json' | 'multipart/form-data';
46
+ export type EndpointsMethods = 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
47
+ export type InParam = 'cookie' | 'header' | 'path' | 'query';
48
+ export type InValidationErrorParam = 'body' | InParam;
49
+ export type BodyType = 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data';
50
50
  export type Endpoints<I = unknown, O = unknown, E extends ApiErrorValue = ApiErrorValue, P extends InValidationErrorParam = InValidationErrorParam, D extends ValidationErrorData = ValidationErrorData> = Partial<Record<EndpointsMethods, Endpoint<I, O, E, P, D>>>;
51
51
  export interface SSL {
52
52
  cert: string;
53
53
  key: string;
54
54
  }
55
55
  export interface ServerStartParams {
56
- port: number;
57
56
  https: boolean;
57
+ port: number;
58
58
  }
59
59
  export interface BaseSchemaProps<T> {
60
60
  default?: T;
61
+ description?: string;
61
62
  example?: T;
62
63
  examples?: T[];
63
- description?: string;
64
64
  ref?: string;
65
65
  }
66
66
  export interface ValuesSchemaProps<T> extends BaseSchemaProps<T> {
@@ -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
- * A file name, without extension
20
+ * MIME-type of the file
27
21
  */
28
- filename: string;
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
  }
@@ -8,10 +8,10 @@ class Bin {
8
8
  toJSON() {
9
9
  return {
10
10
  $: 'binary',
11
- originalFilename: this.originalFilename,
12
- type: this.type,
13
11
  disposition: this.disposition,
12
+ originalFilename: this.originalFilename,
14
13
  size: this.size,
14
+ type: this.type,
15
15
  };
16
16
  }
17
17
  }
@@ -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
  }
@@ -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, __awaiter, __esDecorate } from 'tslib';
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, _Action_search, _Action_headers, _Action_cookie;
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
- get parsedUrl() {
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
- __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);
139
- __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);
140
- __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);
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;
@@ -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, _Action_search, _Action_headers, _Action_cookie;
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
- get parsedUrl() {
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
- 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);
147
- 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);
148
- 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);
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' | string | number | Date;
1
+ export type DateFormat = 'now' | Date | number | string;
2
2
  export declare function dateFormat(date?: DateFormat): Date | undefined;
@@ -3,7 +3,7 @@ function dateFormat(date) {
3
3
  return;
4
4
  if (date === 'now')
5
5
  return new Date();
6
- if (['string', 'number'].includes(typeof date))
6
+ if (['number', 'string'].includes(typeof date))
7
7
  return new Date(date);
8
8
  return date;
9
9
  }
@@ -7,7 +7,7 @@ function dateFormat(date) {
7
7
  return;
8
8
  if (date === 'now')
9
9
  return new Date();
10
- if (['string', 'number'].includes(typeof date))
10
+ if (['number', 'string'].includes(typeof date))
11
11
  return new Date(date);
12
12
  return date;
13
13
  }
@@ -18,7 +18,7 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
18
18
  }
19
19
  return `string${lastChar}`;
20
20
  }
21
- if (['boolean', 'number', 'null'].includes(schema.type)) {
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
- query: '',
103
+ cookie: '',
104
104
  header: '',
105
105
  path: '',
106
- cookie: '',
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', 'number', 'null'].includes(schema.type)) {
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
- query: '',
107
+ cookie: '',
108
108
  header: '',
109
109
  path: '',
110
- cookie: '',
110
+ query: '',
111
111
  };
112
112
  for (const param of parameters) {
113
113
  const splitter = param.in === 'path' || hasDefault(param.schema) ? ':' : '?:';