@innet/server 2.0.0-beta.1 → 2.0.0-beta.10

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 (190) hide show
  1. package/README.md +385 -9
  2. package/handler/handler.d.ts +6 -9
  3. package/handler/handler.es6.js +3 -4
  4. package/handler/handler.js +2 -3
  5. package/hooks/index.d.ts +24 -23
  6. package/hooks/index.es6.js +24 -23
  7. package/hooks/index.js +24 -23
  8. package/hooks/useEffect/index.d.ts +1 -0
  9. package/hooks/useEffect/index.es6.js +1 -0
  10. package/hooks/useEffect/index.js +9 -0
  11. package/hooks/useEffect/useEffect.d.ts +2 -0
  12. package/hooks/useEffect/useEffect.es6.js +8 -0
  13. package/hooks/useEffect/useEffect.js +12 -0
  14. package/hooks/useHeaders/useHeaders.d.ts +0 -1
  15. package/hooks/useNewSchema/useNewSchema.es6.js +1 -1
  16. package/hooks/useNewSchema/useNewSchema.js +1 -1
  17. package/hooks/useRequest/useRequest.d.ts +0 -1
  18. package/hooks/useResponse/useResponse.d.ts +0 -1
  19. package/hooks/useSchemaType/useSchemaType.es6.js +17 -9
  20. package/hooks/useSchemaType/useSchemaType.js +17 -9
  21. package/hooks/useServer/useServer.d.ts +0 -2
  22. package/index.d.ts +2 -2
  23. package/index.es6.js +88 -86
  24. package/index.js +201 -194
  25. package/package.json +16 -15
  26. package/plugins/handler/serverFn/serverFn.es6.js +2 -2
  27. package/plugins/handler/serverFn/serverFn.js +2 -6
  28. package/plugins/index.d.ts +2 -2
  29. package/plugins/index.es6.js +2 -2
  30. package/plugins/index.js +2 -2
  31. package/plugins/main/api/api.es6.js +74 -74
  32. package/plugins/main/api/api.js +75 -79
  33. package/plugins/main/body/body.es6.js +4 -4
  34. package/plugins/main/body/body.js +4 -8
  35. package/plugins/main/endpoint/endpoint.d.ts +5 -0
  36. package/plugins/main/endpoint/endpoint.es6.js +5 -5
  37. package/plugins/main/endpoint/endpoint.js +5 -9
  38. package/plugins/main/host/host.es6.js +4 -2
  39. package/plugins/main/host/host.js +4 -6
  40. package/plugins/main/index.d.ts +8 -8
  41. package/plugins/main/index.es6.js +8 -8
  42. package/plugins/main/index.js +8 -8
  43. package/plugins/main/param/param.es6.js +3 -4
  44. package/plugins/main/param/param.js +3 -8
  45. package/plugins/main/preset/preset.es6.js +1 -1
  46. package/plugins/main/preset/preset.js +1 -5
  47. package/plugins/main/response/response.es6.js +11 -4
  48. package/plugins/main/response/response.js +11 -8
  49. package/plugins/main/server/server.d.ts +0 -1
  50. package/plugins/main/server/server.es6.js +7 -10
  51. package/plugins/main/server/server.js +8 -12
  52. package/plugins/main/tag/index.es6.js +1 -1
  53. package/plugins/main/tag/index.js +1 -0
  54. package/plugins/main/tag/tag.d.ts +8 -1
  55. package/plugins/main/tag/tag.es6.js +20 -3
  56. package/plugins/main/tag/tag.js +20 -6
  57. package/plugins/main/variable/variable.es6.js +3 -4
  58. package/plugins/main/variable/variable.js +3 -4
  59. package/plugins/request/cms/cms.es6.js +1 -1
  60. package/plugins/request/cms/cms.js +2 -3
  61. package/plugins/request/cookie/cookie.d.ts +2 -2
  62. package/plugins/request/cookie/cookie.es6.js +1 -2
  63. package/plugins/request/cookie/cookie.js +1 -2
  64. package/plugins/request/error/error.es6.js +1 -2
  65. package/plugins/request/error/error.js +1 -2
  66. package/plugins/request/file/file.es6.js +2 -3
  67. package/plugins/request/file/file.js +2 -4
  68. package/plugins/request/index.d.ts +5 -5
  69. package/plugins/request/index.es6.js +5 -5
  70. package/plugins/request/index.js +5 -5
  71. package/plugins/request/proxy/proxy.d.ts +0 -1
  72. package/plugins/schema/array/array.d.ts +3 -0
  73. package/plugins/schema/array/array.es6.js +14 -6
  74. package/plugins/schema/array/array.js +15 -11
  75. package/plugins/schema/binary/binary.d.ts +4 -0
  76. package/plugins/schema/boolean/boolean.d.ts +1 -0
  77. package/plugins/schema/date/date.d.ts +2 -1
  78. package/plugins/schema/date/date.es6.js +8 -4
  79. package/plugins/schema/date/date.js +8 -4
  80. package/plugins/schema/field/field.d.ts +4 -0
  81. package/plugins/schema/field/field.es6.js +16 -3
  82. package/plugins/schema/field/field.js +16 -7
  83. package/plugins/schema/index.d.ts +8 -8
  84. package/plugins/schema/index.es6.js +8 -8
  85. package/plugins/schema/index.js +8 -8
  86. package/plugins/schema/integer/integer.d.ts +37 -0
  87. package/plugins/schema/integer/integer.es6.js +29 -9
  88. package/plugins/schema/integer/integer.js +29 -9
  89. package/plugins/schema/number/number.d.ts +32 -0
  90. package/plugins/schema/number/number.es6.js +21 -6
  91. package/plugins/schema/number/number.js +21 -6
  92. package/plugins/schema/object/object.es6.js +9 -8
  93. package/plugins/schema/object/object.js +9 -12
  94. package/plugins/schema/string/string.d.ts +27 -0
  95. package/plugins/schema/string/string.es6.js +9 -4
  96. package/plugins/schema/string/string.js +9 -4
  97. package/plugins/schema/tuple/tuple.es6.js +5 -6
  98. package/plugins/schema/tuple/tuple.js +5 -10
  99. package/plugins/schema/uuid/uuid.es6.js +5 -3
  100. package/plugins/schema/uuid/uuid.js +5 -3
  101. package/plugins/utils/dts/dts.es6.js +5 -2
  102. package/plugins/utils/dts/dts.js +5 -2
  103. package/plugins/utils/env/env.es6.js +1 -1
  104. package/plugins/utils/env/env.js +1 -5
  105. package/plugins/utils/index.d.ts +3 -2
  106. package/plugins/utils/index.es6.js +3 -2
  107. package/plugins/utils/index.js +3 -2
  108. package/plugins/utils/swagger/swagger.d.ts +1 -0
  109. package/plugins/utils/swagger/swagger.es6.js +1 -0
  110. package/plugins/utils/swagger/swagger.js +1 -0
  111. package/plugins/utils/ui/index.d.ts +1 -0
  112. package/plugins/utils/ui/index.es6.js +1 -0
  113. package/plugins/utils/ui/index.js +10 -0
  114. package/plugins/utils/ui/rapidoc.html.es6.js +3 -0
  115. package/plugins/utils/ui/rapidoc.html.js +7 -0
  116. package/plugins/utils/ui/redoc.html.es6.js +3 -0
  117. package/plugins/utils/ui/redoc.html.js +7 -0
  118. package/plugins/utils/ui/scalar.html.es6.js +3 -0
  119. package/plugins/utils/ui/scalar.html.js +7 -0
  120. package/plugins/utils/ui/swagger.html.es6.js +3 -0
  121. package/plugins/utils/ui/swagger.html.js +7 -0
  122. package/plugins/utils/ui/ui.d.ts +13 -0
  123. package/plugins/utils/ui/ui.es6.js +45 -0
  124. package/plugins/utils/ui/ui.js +50 -0
  125. package/types.d.ts +6 -0
  126. package/utils/action/Action.d.ts +4 -5
  127. package/utils/action/Action.es6.js +14 -16
  128. package/utils/action/Action.js +13 -15
  129. package/utils/getSafeSchema/getSafeSchema.d.ts +2 -0
  130. package/utils/getSafeSchema/getSafeSchema.es6.js +5 -0
  131. package/utils/getSafeSchema/getSafeSchema.js +9 -0
  132. package/utils/getSafeSchema/index.d.ts +1 -0
  133. package/utils/getSafeSchema/index.es6.js +1 -0
  134. package/utils/getSafeSchema/index.js +9 -0
  135. package/utils/index.d.ts +9 -8
  136. package/utils/index.es6.js +9 -8
  137. package/utils/index.js +9 -8
  138. package/utils/parseBody/parseBody.d.ts +0 -1
  139. package/utils/parseBody/parseBody.es6.js +13 -16
  140. package/utils/parseBody/parseBody.js +13 -16
  141. package/utils/parseFormBody/parseFormBody.d.ts +0 -1
  142. package/utils/parseFormBody/parseFormBody.es6.js +41 -41
  143. package/utils/parseFormBody/parseFormBody.js +41 -41
  144. package/utils/parseSearch/parseSearch.es6.js +4 -1
  145. package/utils/parseSearch/parseSearch.js +4 -1
  146. package/utils/rules/arrayOf/arrayOf.es6.js +1 -1
  147. package/utils/rules/arrayOf/arrayOf.js +1 -1
  148. package/utils/rules/bin/bin.es6.js +4 -1
  149. package/utils/rules/bin/bin.js +4 -1
  150. package/utils/rules/binaryAccept/binaryAccept.es6.js +5 -2
  151. package/utils/rules/binaryAccept/binaryAccept.js +5 -2
  152. package/utils/rules/dateTo/dateTo.es6.js +4 -1
  153. package/utils/rules/dateTo/dateTo.js +4 -1
  154. package/utils/rules/helpers.es6.js +4 -1
  155. package/utils/rules/helpers.js +4 -1
  156. package/utils/rules/index.d.ts +17 -17
  157. package/utils/rules/index.es6.js +17 -17
  158. package/utils/rules/index.js +18 -18
  159. package/utils/rules/int/int.es6.js +17 -4
  160. package/utils/rules/int/int.js +17 -4
  161. package/utils/rules/max/max.es6.js +9 -3
  162. package/utils/rules/max/max.js +9 -3
  163. package/utils/rules/maxBin/maxBin.es6.js +5 -2
  164. package/utils/rules/maxBin/maxBin.js +5 -2
  165. package/utils/rules/maxDate/maxDate.es6.js +5 -1
  166. package/utils/rules/maxDate/maxDate.js +5 -1
  167. package/utils/rules/maxLength/maxLength.es6.js +5 -2
  168. package/utils/rules/maxLength/maxLength.js +5 -2
  169. package/utils/rules/min/min.es6.js +9 -3
  170. package/utils/rules/min/min.js +9 -3
  171. package/utils/rules/minBin/minBin.es6.js +5 -2
  172. package/utils/rules/minBin/minBin.js +5 -2
  173. package/utils/rules/minDate/minDate.es6.js +5 -1
  174. package/utils/rules/minDate/minDate.js +5 -1
  175. package/utils/rules/minLength/minLength.es6.js +5 -2
  176. package/utils/rules/minLength/minLength.js +5 -2
  177. package/utils/rules/num/num.es6.js +4 -1
  178. package/utils/rules/num/num.js +4 -1
  179. package/utils/rules/objectOf/objectOf.es6.js +6 -3
  180. package/utils/rules/objectOf/objectOf.js +6 -3
  181. package/utils/rules/pattern/pattern.es6.js +6 -2
  182. package/utils/rules/pattern/pattern.js +6 -2
  183. package/utils/rules/tupleOf/tupleOf.es6.js +1 -1
  184. package/utils/rules/tupleOf/tupleOf.js +1 -1
  185. package/utils/rules/values/values.es6.js +5 -2
  186. package/utils/rules/values/values.js +5 -2
  187. package/utils/stringifySearch/stringifySearch.es6.js +4 -1
  188. package/utils/stringifySearch/stringifySearch.js +4 -1
  189. package/_virtual/_rollup-plugin-process-env.es6.js +0 -10
  190. package/_virtual/_rollup-plugin-process-env.js +0 -12
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var scalar = "<!doctype html>\n<html>\n<head>\n <title>API Reference</title>\n <meta charset=\"utf-8\" />\n <meta\n name=\"viewport\"\n content=\"width=device-width, initial-scale=1\" />\n</head>\n<body>\n<div id=\"app\"></div>\n<script src=\"https://cdn.jsdelivr.net/npm/@scalar/api-reference\"></script>\n<script>\n Scalar.createApiReference('#app', {\n url: '{apiUrl}',\n ...{params}\n })\n</script>\n</body>\n</html>\n";
6
+
7
+ exports["default"] = scalar;
@@ -0,0 +1,3 @@
1
+ var swagger = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <meta\n name=\"description\"\n content=\"SwaggerUI\"\n />\n <title>SwaggerUI</title>\n <link rel=\"stylesheet\" href=\"https://unpkg.com/swagger-ui-dist/swagger-ui.css\" />\n</head>\n<body>\n<div id=\"swagger-ui\"></div>\n<script src=\"https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js\" crossorigin></script>\n<script>\n window.onload = () => {\n window.ui = SwaggerUIBundle({\n url: \"{apiUrl}\",\n dom_id: '#swagger-ui',\n ...{params}\n });\n };\n</script>\n</body>\n</html>\n";
2
+
3
+ export { swagger as default };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var swagger = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <meta\n name=\"description\"\n content=\"SwaggerUI\"\n />\n <title>SwaggerUI</title>\n <link rel=\"stylesheet\" href=\"https://unpkg.com/swagger-ui-dist/swagger-ui.css\" />\n</head>\n<body>\n<div id=\"swagger-ui\"></div>\n<script src=\"https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js\" crossorigin></script>\n<script>\n window.onload = () => {\n window.ui = SwaggerUIBundle({\n url: \"{apiUrl}\",\n dom_id: '#swagger-ui',\n ...{params}\n });\n };\n</script>\n</body>\n</html>\n";
6
+
7
+ exports["default"] = swagger;
@@ -0,0 +1,13 @@
1
+ import { type HandlerPlugin } from 'innet';
2
+ export declare const uiPresets: {
3
+ rapidoc: string;
4
+ redoc: string;
5
+ scalar: string;
6
+ swagger: string;
7
+ };
8
+ export interface UiProps {
9
+ html?: string;
10
+ params?: Record<string, any>;
11
+ path?: string;
12
+ }
13
+ export declare const ui: HandlerPlugin;
@@ -0,0 +1,45 @@
1
+ import { placeholder } from '@cantinc/utils';
2
+ import { useProps } from '@innet/jsx';
3
+ import '../../../hooks/index.es6.js';
4
+ import rapidoc from './rapidoc.html.es6.js';
5
+ import redoc from './redoc.html.es6.js';
6
+ import scalar from './scalar.html.es6.js';
7
+ import swagger from './swagger.html.es6.js';
8
+ import { useApi } from '../../../hooks/useApi/useApi.es6.js';
9
+ import { useServerPlugin } from '../../../hooks/useServerPlugin/useServerPlugin.es6.js';
10
+ import { useAction } from '../../../hooks/useAction/useAction.es6.js';
11
+
12
+ function camelToDash(str) {
13
+ return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
14
+ }
15
+ const uiPresets = { rapidoc, redoc, scalar, swagger };
16
+ const ui = () => {
17
+ const { html = uiPresets.swagger, params = {}, path = process.env.INNET_UI_PATH || '/ui', } = useProps() || {};
18
+ const { docs, prefix, } = useApi();
19
+ let cache = '';
20
+ useServerPlugin(() => {
21
+ const action = useAction();
22
+ if (action.path === prefix + path) {
23
+ if (!cache) {
24
+ const attributes = Object
25
+ .keys(params)
26
+ .reduce((res, key) => {
27
+ return `${res} ${camelToDash(key)}='${String(params[key])}'`;
28
+ }, '');
29
+ cache = placeholder(html, {
30
+ apiUrl: prefix,
31
+ attributes,
32
+ docs: JSON.stringify(docs),
33
+ params: JSON.stringify(params),
34
+ ...params,
35
+ });
36
+ }
37
+ action.res.statusCode = 200;
38
+ action.res.write(cache);
39
+ action.res.end();
40
+ return true;
41
+ }
42
+ });
43
+ };
44
+
45
+ export { ui, uiPresets };
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var utils = require('@cantinc/utils');
6
+ var jsx = require('@innet/jsx');
7
+ require('../../../hooks/index.js');
8
+ var rapidoc = require('./rapidoc.html.js');
9
+ var redoc = require('./redoc.html.js');
10
+ var scalar = require('./scalar.html.js');
11
+ var swagger = require('./swagger.html.js');
12
+ var useApi = require('../../../hooks/useApi/useApi.js');
13
+ var useServerPlugin = require('../../../hooks/useServerPlugin/useServerPlugin.js');
14
+ var useAction = require('../../../hooks/useAction/useAction.js');
15
+
16
+ function camelToDash(str) {
17
+ return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
18
+ }
19
+ const uiPresets = { rapidoc: rapidoc["default"], redoc: redoc["default"], scalar: scalar["default"], swagger: swagger["default"] };
20
+ const ui = () => {
21
+ const { html = uiPresets.swagger, params = {}, path = process.env.INNET_UI_PATH || '/ui', } = jsx.useProps() || {};
22
+ const { docs, prefix, } = useApi.useApi();
23
+ let cache = '';
24
+ useServerPlugin.useServerPlugin(() => {
25
+ const action = useAction.useAction();
26
+ if (action.path === prefix + path) {
27
+ if (!cache) {
28
+ const attributes = Object
29
+ .keys(params)
30
+ .reduce((res, key) => {
31
+ return `${res} ${camelToDash(key)}='${String(params[key])}'`;
32
+ }, '');
33
+ cache = utils.placeholder(html, {
34
+ apiUrl: prefix,
35
+ attributes,
36
+ docs: JSON.stringify(docs),
37
+ params: JSON.stringify(params),
38
+ ...params,
39
+ });
40
+ }
41
+ action.res.statusCode = 200;
42
+ action.res.write(cache);
43
+ action.res.end();
44
+ return true;
45
+ }
46
+ });
47
+ };
48
+
49
+ exports.ui = ui;
50
+ exports.uiPresets = uiPresets;
package/types.d.ts CHANGED
@@ -16,6 +16,7 @@ export type ParameterObject = API.ParameterObject;
16
16
  export type RequestBodyObject = API.RequestBodyObject;
17
17
  export type ObjectType = ArraySchemaObjectType | NonArraySchemaObjectType;
18
18
  export type RefSchemaObject = ReferenceObject | SchemaObject;
19
+ export type Effect = () => void;
19
20
  export interface IValidationErrorData extends Record<string, any> {
20
21
  error: RulesErrors;
21
22
  }
@@ -58,11 +59,16 @@ export interface ServerStartParams {
58
59
  }
59
60
  export interface BaseSchemaProps<T> {
60
61
  default?: T;
62
+ deprecated?: boolean;
61
63
  description?: string;
62
64
  example?: T;
63
65
  examples?: T[];
66
+ readOnly?: boolean;
64
67
  ref?: string;
68
+ title?: string;
69
+ writeOnly?: boolean;
65
70
  }
66
71
  export interface ValuesSchemaProps<T> extends BaseSchemaProps<T> {
72
+ const?: T;
67
73
  values?: T[];
68
74
  }
@@ -1,5 +1,4 @@
1
- /// <reference types="node" />
2
- import { type CookieSerializeOptions } from 'cookie';
1
+ import { type Cookies, type SerializeOptions } from 'cookie';
3
2
  import { type IncomingHttpHeaders, type IncomingMessage, type ServerResponse } from 'http';
4
3
  import { type ParsedQs } from 'qs';
5
4
  import { type BodyType } from '../../types';
@@ -15,14 +14,14 @@ export declare class Action {
15
14
  body?: object;
16
15
  constructor(req: IncomingMessage, res: ServerResponse);
17
16
  parseBody(): Promise<void>;
18
- setCookie(name: string, value?: string, options?: CookieSerializeOptions): void;
17
+ setCookie(name: string, value?: string, options?: SerializeOptions): void;
19
18
  get bodyType(): BodyType | undefined;
20
19
  get clientIp(): string | null;
21
- get cookies(): Record<string, string>;
20
+ get cookies(): Cookies;
22
21
  set cookies(value: Record<string, string>);
23
22
  get headers(): IncomingHttpHeaders;
24
23
  set headers(value: IncomingHttpHeaders);
25
- get originCookies(): Record<string, string>;
24
+ get originCookies(): Cookies;
26
25
  get originHeaders(): IncomingHttpHeaders;
27
26
  get originSearch(): ParsedQs;
28
27
  get parsedUrl(): ParsedUrl;
@@ -1,4 +1,4 @@
1
- import { __runInitializers, __awaiter, __classPrivateFieldGet, __classPrivateFieldSet, __esDecorate } from 'tslib';
1
+ import { __runInitializers, __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';
@@ -29,21 +29,19 @@ let Action = (() => {
29
29
  _Action_headers.set(this, {});
30
30
  _Action_search.set(this, void 0);
31
31
  }
32
- parseBody() {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- if (!this.bodyType) {
35
- return;
36
- }
37
- if (this.bodyType === 'multipart/form-data') {
38
- this.body = yield parseFormBody(this.req);
39
- }
40
- if (this.bodyType === 'application/x-www-form-urlencoded') {
41
- this.body = parseSearch(yield parseBody(this.req));
42
- }
43
- if (this.bodyType === 'application/json') {
44
- this.body = JSON.parse(yield parseBody(this.req));
45
- }
46
- });
32
+ async parseBody() {
33
+ if (!this.bodyType) {
34
+ return;
35
+ }
36
+ if (this.bodyType === 'multipart/form-data') {
37
+ this.body = await parseFormBody(this.req);
38
+ }
39
+ if (this.bodyType === 'application/x-www-form-urlencoded') {
40
+ this.body = parseSearch(await parseBody(this.req));
41
+ }
42
+ if (this.bodyType === 'application/json') {
43
+ this.body = JSON.parse(await parseBody(this.req));
44
+ }
47
45
  }
48
46
  setCookie(name, value, options) {
49
47
  let cookies = this.res.getHeader('Set-Cookie');
@@ -37,21 +37,19 @@ let Action = (() => {
37
37
  _Action_headers.set(this, {});
38
38
  _Action_search.set(this, void 0);
39
39
  }
40
- parseBody() {
41
- return tslib.__awaiter(this, void 0, void 0, function* () {
42
- if (!this.bodyType) {
43
- return;
44
- }
45
- if (this.bodyType === 'multipart/form-data') {
46
- this.body = yield parseFormBody.parseFormBody(this.req);
47
- }
48
- if (this.bodyType === 'application/x-www-form-urlencoded') {
49
- this.body = parseSearch.parseSearch(yield parseBody.parseBody(this.req));
50
- }
51
- if (this.bodyType === 'application/json') {
52
- this.body = JSON.parse(yield parseBody.parseBody(this.req));
53
- }
54
- });
40
+ async parseBody() {
41
+ if (!this.bodyType) {
42
+ return;
43
+ }
44
+ if (this.bodyType === 'multipart/form-data') {
45
+ this.body = await parseFormBody.parseFormBody(this.req);
46
+ }
47
+ if (this.bodyType === 'application/x-www-form-urlencoded') {
48
+ this.body = parseSearch.parseSearch(await parseBody.parseBody(this.req));
49
+ }
50
+ if (this.bodyType === 'application/json') {
51
+ this.body = JSON.parse(await parseBody.parseBody(this.req));
52
+ }
55
53
  }
56
54
  setCookie(name, value, options) {
57
55
  let cookies = this.res.getHeader('Set-Cookie');
@@ -0,0 +1,2 @@
1
+ import { type SchemaObject } from '../../types';
2
+ export declare function getSafeSchema(schema: SchemaObject): SchemaObject;
@@ -0,0 +1,5 @@
1
+ function getSafeSchema(schema) {
2
+ return 'oneOf' in schema ? schema.oneOf[0] : schema;
3
+ }
4
+
5
+ export { getSafeSchema };
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function getSafeSchema(schema) {
6
+ return 'oneOf' in schema ? schema.oneOf[0] : schema;
7
+ }
8
+
9
+ exports.getSafeSchema = getSafeSchema;
@@ -0,0 +1 @@
1
+ export * from './getSafeSchema';
@@ -0,0 +1 @@
1
+ export { getSafeSchema } from './getSafeSchema.es6.js';
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var getSafeSchema = require('./getSafeSchema.js');
6
+
7
+
8
+
9
+ exports.getSafeSchema = getSafeSchema.getSafeSchema;
package/utils/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
- export * from './parseSearch';
2
- export * from './stringifySearch';
3
- export * from './httpOnStart';
1
+ export * from './FileData';
2
+ export * from './JSONString';
3
+ export * from './action';
4
+ export * from './decorators';
5
+ export * from './generateTypes';
4
6
  export * from './getEndpoint';
5
7
  export * from './getOrAdd';
6
- export * from './decorators';
7
- export * from './action';
8
+ export * from './getSafeSchema';
9
+ export * from './httpOnStart';
8
10
  export * from './parseBody';
9
11
  export * from './parseFormBody';
12
+ export * from './parseSearch';
10
13
  export * from './rules';
11
- export * from './JSONString';
12
- export * from './FileData';
13
- export * from './generateTypes';
14
+ export * from './stringifySearch';
@@ -1,13 +1,14 @@
1
- import './parseSearch/index.es6.js';
2
- import './stringifySearch/index.es6.js';
3
- import './httpOnStart/index.es6.js';
1
+ import './FileData/index.es6.js';
2
+ import './JSONString/index.es6.js';
3
+ import './action/index.es6.js';
4
+ import './decorators/index.es6.js';
5
+ import './generateTypes/index.es6.js';
4
6
  import './getEndpoint/index.es6.js';
5
7
  import './getOrAdd/index.es6.js';
6
- import './decorators/index.es6.js';
7
- import './action/index.es6.js';
8
+ import './getSafeSchema/index.es6.js';
9
+ import './httpOnStart/index.es6.js';
8
10
  import './parseBody/index.es6.js';
9
11
  import './parseFormBody/index.es6.js';
12
+ import './parseSearch/index.es6.js';
10
13
  import './rules/index.es6.js';
11
- import './JSONString/index.es6.js';
12
- import './FileData/index.es6.js';
13
- import './generateTypes/index.es6.js';
14
+ import './stringifySearch/index.es6.js';
package/utils/index.js CHANGED
@@ -1,16 +1,17 @@
1
1
  'use strict';
2
2
 
3
- require('./parseSearch/index.js');
4
- require('./stringifySearch/index.js');
5
- require('./httpOnStart/index.js');
3
+ require('./FileData/index.js');
4
+ require('./JSONString/index.js');
5
+ require('./action/index.js');
6
+ require('./decorators/index.js');
7
+ require('./generateTypes/index.js');
6
8
  require('./getEndpoint/index.js');
7
9
  require('./getOrAdd/index.js');
8
- require('./decorators/index.js');
9
- require('./action/index.js');
10
+ require('./getSafeSchema/index.js');
11
+ require('./httpOnStart/index.js');
10
12
  require('./parseBody/index.js');
11
13
  require('./parseFormBody/index.js');
14
+ require('./parseSearch/index.js');
12
15
  require('./rules/index.js');
13
- require('./JSONString/index.js');
14
- require('./FileData/index.js');
15
- require('./generateTypes/index.js');
16
+ require('./stringifySearch/index.js');
16
17
 
@@ -1,3 +1,2 @@
1
- /// <reference types="node" />
2
1
  import type http from 'http';
3
2
  export declare function parseBody(req: http.IncomingMessage): Promise<string>;
@@ -1,21 +1,18 @@
1
- import { __awaiter } from 'tslib';
2
1
  import { StringDecoder } from 'node:string_decoder';
3
2
 
4
- function parseBody(req) {
5
- return __awaiter(this, void 0, void 0, function* () {
6
- return yield new Promise((resolve, reject) => {
7
- const decoder = new StringDecoder('utf-8');
8
- let buffer = '';
9
- req.on('data', chunk => {
10
- buffer += decoder.write(chunk);
11
- });
12
- req.on('end', () => {
13
- buffer += decoder.end();
14
- resolve(buffer);
15
- });
16
- req.on('error', err => {
17
- reject(err);
18
- });
3
+ async function parseBody(req) {
4
+ return await new Promise((resolve, reject) => {
5
+ const decoder = new StringDecoder('utf-8');
6
+ let buffer = '';
7
+ req.on('data', chunk => {
8
+ buffer += decoder.write(chunk);
9
+ });
10
+ req.on('end', () => {
11
+ buffer += decoder.end();
12
+ resolve(buffer);
13
+ });
14
+ req.on('error', err => {
15
+ reject(err);
19
16
  });
20
17
  });
21
18
  }
@@ -2,24 +2,21 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib = require('tslib');
6
5
  var node_string_decoder = require('node:string_decoder');
7
6
 
8
- function parseBody(req) {
9
- return tslib.__awaiter(this, void 0, void 0, function* () {
10
- return yield new Promise((resolve, reject) => {
11
- const decoder = new node_string_decoder.StringDecoder('utf-8');
12
- let buffer = '';
13
- req.on('data', chunk => {
14
- buffer += decoder.write(chunk);
15
- });
16
- req.on('end', () => {
17
- buffer += decoder.end();
18
- resolve(buffer);
19
- });
20
- req.on('error', err => {
21
- reject(err);
22
- });
7
+ async function parseBody(req) {
8
+ return await new Promise((resolve, reject) => {
9
+ const decoder = new node_string_decoder.StringDecoder('utf-8');
10
+ let buffer = '';
11
+ req.on('data', chunk => {
12
+ buffer += decoder.write(chunk);
13
+ });
14
+ req.on('end', () => {
15
+ buffer += decoder.end();
16
+ resolve(buffer);
17
+ });
18
+ req.on('error', err => {
19
+ reject(err);
23
20
  });
24
21
  });
25
22
  }
@@ -1,3 +1,2 @@
1
- /// <reference types="node" />
2
1
  import type http from 'http';
3
2
  export declare function parseFormBody(req: http.IncomingMessage): Promise<object>;
@@ -1,54 +1,54 @@
1
- import { __awaiter, __rest } from 'tslib';
2
1
  import { Form } from 'multiparty';
3
2
  import '../FileData/index.es6.js';
4
3
  import '../parseSearch/index.es6.js';
5
4
  import { Bin } from '../FileData/Bin.es6.js';
6
5
  import { parseSearch } from '../parseSearch/parseSearch.es6.js';
7
6
 
8
- function parseFormBody(req) {
9
- return __awaiter(this, void 0, void 0, function* () {
10
- return yield new Promise((resolve, reject) => {
11
- const form = new Form();
12
- form.parse(req, (error, fields, files) => {
13
- if (error) {
14
- reject(error);
15
- return;
16
- }
17
- let query = '';
18
- const queryFiles = [];
19
- for (const key in fields) {
20
- for (const value of fields[key]) {
21
- if (query) {
22
- query += '&';
23
- }
24
- query += `${key}=${value.replaceAll('=', '%26')}`;
7
+ async function parseFormBody(req) {
8
+ return await new Promise((resolve, reject) => {
9
+ const form = new Form();
10
+ form.parse(req, (error, fields, files) => {
11
+ if (error) {
12
+ reject(error);
13
+ return;
14
+ }
15
+ let query = '';
16
+ const queryFiles = [];
17
+ for (const key in fields) {
18
+ for (const value of fields[key]) {
19
+ if (query) {
20
+ query += '&';
25
21
  }
22
+ query += `${key}=${value.replaceAll('=', '%26')}`;
26
23
  }
27
- for (const key in files) {
28
- const values = files[key];
29
- for (const value of values) {
30
- if (query) {
31
- query += '&';
32
- }
33
- query += `${key}==${queryFiles.length}`;
34
- const { headers } = value, options = __rest(value, ["headers"]);
35
- options.type = headers['content-type'];
36
- options.disposition = headers['content-disposition'];
37
- queryFiles.push(new Bin(options));
24
+ }
25
+ for (const key in files) {
26
+ const values = files[key];
27
+ for (const value of values) {
28
+ if (query) {
29
+ query += '&';
38
30
  }
31
+ query += `${key}==${queryFiles.length}`;
32
+ const { headers, ...options } = value;
33
+ const binOptions = {
34
+ ...options,
35
+ disposition: headers['content-disposition'],
36
+ type: headers['content-type'],
37
+ };
38
+ queryFiles.push(new Bin(binOptions));
39
39
  }
40
- resolve(parseSearch(query, {
41
- decoder(value, decoder, charset, type) {
42
- if (type === 'key') {
43
- return decoder(value, decoder, charset);
44
- }
45
- if (value.startsWith('=')) {
46
- return queryFiles[Number(value.slice(1))];
47
- }
48
- return value.replaceAll('%26', '=');
49
- },
50
- }));
51
- });
40
+ }
41
+ resolve(parseSearch(query, {
42
+ decoder(value, decoder, charset, type) {
43
+ if (type === 'key') {
44
+ return decoder(value, decoder, charset);
45
+ }
46
+ if (value.startsWith('=')) {
47
+ return queryFiles[Number(value.slice(1))];
48
+ }
49
+ return value.replaceAll('%26', '=');
50
+ },
51
+ }));
52
52
  });
53
53
  });
54
54
  }