@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
@@ -1,5 +1,4 @@
1
- import { __rest, __awaiter } from 'tslib';
2
- import innet, { useNewHandler } from 'innet';
1
+ import { useNewHandler, innet } from 'innet';
3
2
  import { useProps } from '@innet/jsx';
4
3
  import '../../../hooks/index.es6.js';
5
4
  import '../../../utils/index.es6.js';
@@ -15,8 +14,8 @@ import { paramsContext } from '../../../hooks/useParams/useParams.es6.js';
15
14
  const api = () => {
16
15
  const handler = useNewHandler();
17
16
  const props = useProps();
18
- const { children, exclude, include, prefix = process.env.INNET_API_PREFIX || '', title = '', version = process.env.INNET_API_VERSION || '0.0.0' } = props, rest = __rest(props, ["children", "exclude", "include", "prefix", "title", "version"]);
19
- const info = Object.assign(Object.assign({}, rest), { title, version });
17
+ const { children, exclude, include, prefix = process.env.INNET_API_PREFIX || '', title = '', version = process.env.INNET_API_VERSION || '0.0.0', ...rest } = props;
18
+ const info = { ...rest, title, version };
20
19
  const endpoints = {};
21
20
  const docs = {
22
21
  info,
@@ -38,7 +37,7 @@ const api = () => {
38
37
  };
39
38
  serverPlugins.set(handler, plugins);
40
39
  apiContext.set(handler, context);
41
- useServerPlugin(() => __awaiter(void 0, void 0, void 0, function* () {
40
+ useServerPlugin(async () => {
42
41
  var _a, _b, _c, _d, _e, _f;
43
42
  const action = useAction();
44
43
  if (!condition(action))
@@ -62,91 +61,92 @@ const api = () => {
62
61
  const [deep, currentEndpoint, params] = endpointQueue.shift();
63
62
  const key = splitPath[deep];
64
63
  if (deep + 1 === splitPath.length) {
65
- function run(runEndpoint, params) {
64
+ async function run(runEndpoint, params) {
66
65
  var _a, _b, _c, _d, _e;
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const pathRules = (_a = runEndpoint.rules) === null || _a === void 0 ? void 0 : _a.path;
69
- const headerRules = (_b = runEndpoint.rules) === null || _b === void 0 ? void 0 : _b.header;
70
- const cookieRules = (_c = runEndpoint.rules) === null || _c === void 0 ? void 0 : _c.cookie;
71
- const searchRules = (_d = runEndpoint.rules) === null || _d === void 0 ? void 0 : _d.search;
72
- const bodyRules = (_e = runEndpoint.rules) === null || _e === void 0 ? void 0 : _e.body;
73
- if (pathRules) {
74
- try {
75
- Object.assign(params, pathRules(params, { in: 'path' }));
76
- }
77
- catch (_f) {
78
- return false;
79
- }
66
+ const pathRules = (_a = runEndpoint.rules) === null || _a === void 0 ? void 0 : _a.path;
67
+ const headerRules = (_b = runEndpoint.rules) === null || _b === void 0 ? void 0 : _b.header;
68
+ const cookieRules = (_c = runEndpoint.rules) === null || _c === void 0 ? void 0 : _c.cookie;
69
+ const searchRules = (_d = runEndpoint.rules) === null || _d === void 0 ? void 0 : _d.search;
70
+ const bodyRules = (_e = runEndpoint.rules) === null || _e === void 0 ? void 0 : _e.body;
71
+ if (pathRules) {
72
+ try {
73
+ Object.assign(params, pathRules(params, { in: 'path' }));
80
74
  }
81
- function checkActionRules(rules, key = 'search') {
82
- if (rules) {
83
- try {
84
- action[key] = rules(action[key]);
85
- }
86
- catch (e) {
87
- res.setHeader('Content-Type', 'application/json');
88
- if (e instanceof RulesError) {
89
- res.statusCode = 400;
90
- res.write(JSONString({
91
- data: Object.assign(Object.assign({}, e.data), { in: key }),
92
- error: 'requestValidation',
93
- }));
94
- res.end();
95
- }
96
- else {
97
- console.error(e);
98
- res.statusCode = 500;
99
- res.write(JSONString({
100
- data: { in: key },
101
- error: 'unknown',
102
- }));
103
- res.end();
104
- }
105
- return true;
106
- }
107
- }
75
+ catch (_f) {
108
76
  return false;
109
77
  }
110
- if (checkActionRules(headerRules, 'headers'))
111
- return true;
112
- if (checkActionRules(cookieRules, 'cookies'))
113
- return true;
114
- if (checkActionRules(searchRules, 'search'))
115
- return true;
116
- if (bodyRules) {
117
- yield action.parseBody();
118
- if (!action.body) {
119
- res.statusCode = 400;
78
+ }
79
+ function checkActionRules(rules, key = 'search') {
80
+ if (rules) {
81
+ try {
82
+ action[key] = rules(action[key]);
83
+ }
84
+ catch (e) {
120
85
  res.setHeader('Content-Type', 'application/json');
121
- res.write(JSONString({
122
- error: 'requestBodyContentType',
123
- }));
124
- res.end();
86
+ if (e instanceof RulesError) {
87
+ res.statusCode = 400;
88
+ res.write(JSONString({
89
+ data: {
90
+ ...e.data,
91
+ in: key,
92
+ },
93
+ error: 'requestValidation',
94
+ }));
95
+ res.end();
96
+ }
97
+ else {
98
+ console.error(e);
99
+ res.statusCode = 500;
100
+ res.write(JSONString({
101
+ data: { in: key },
102
+ error: 'unknown',
103
+ }));
104
+ res.end();
105
+ }
125
106
  return true;
126
107
  }
127
- if (checkActionRules(bodyRules, 'body'))
128
- return true;
129
108
  }
130
- paramsContext.set(actionHandler, params);
131
- for (const plugin of runEndpoint.plugins) {
132
- const result = yield plugin();
133
- if (result === undefined)
134
- continue;
135
- innet(result, actionHandler);
109
+ return false;
110
+ }
111
+ if (checkActionRules(headerRules, 'headers'))
112
+ return true;
113
+ if (checkActionRules(cookieRules, 'cookies'))
114
+ return true;
115
+ if (checkActionRules(searchRules, 'search'))
116
+ return true;
117
+ if (bodyRules) {
118
+ await action.parseBody();
119
+ if (!action.body) {
120
+ res.statusCode = 400;
121
+ res.setHeader('Content-Type', 'application/json');
122
+ res.write(JSONString({
123
+ error: 'requestBodyContentType',
124
+ }));
125
+ res.end();
136
126
  return true;
137
127
  }
128
+ if (checkActionRules(bodyRules, 'body'))
129
+ return true;
130
+ }
131
+ paramsContext.set(actionHandler, params);
132
+ for (const plugin of runEndpoint.plugins) {
133
+ const result = await plugin();
134
+ if (result === undefined)
135
+ continue;
136
+ innet(result, actionHandler);
138
137
  return true;
139
- });
138
+ }
139
+ return true;
140
140
  }
141
141
  if ((_d = (_c = currentEndpoint.static) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.plugins) {
142
- if (!(yield run((_e = currentEndpoint.static) === null || _e === void 0 ? void 0 : _e[key], params)))
142
+ if (!await run((_e = currentEndpoint.static) === null || _e === void 0 ? void 0 : _e[key], params))
143
143
  continue;
144
144
  return null;
145
145
  }
146
146
  if (currentEndpoint.dynamic) {
147
147
  for (const dynamicEndpoint of currentEndpoint.dynamic) {
148
148
  if (dynamicEndpoint.plugins) {
149
- if (!(yield run(dynamicEndpoint, Object.assign(Object.assign({}, params), { [dynamicEndpoint.key.slice(1, -1)]: key }))))
149
+ if (!await run(dynamicEndpoint, { ...params, [dynamicEndpoint.key.slice(1, -1)]: key }))
150
150
  continue;
151
151
  return null;
152
152
  }
@@ -159,12 +159,12 @@ const api = () => {
159
159
  }
160
160
  if (currentEndpoint.dynamic) {
161
161
  for (const dynamicEndpoint of currentEndpoint.dynamic) {
162
- endpointQueue.push([deep + 1, dynamicEndpoint, Object.assign(Object.assign({}, params), { [dynamicEndpoint.key.slice(1, -1)]: key })]);
162
+ endpointQueue.push([deep + 1, dynamicEndpoint, { ...params, [dynamicEndpoint.key.slice(1, -1)]: key }]);
163
163
  }
164
164
  }
165
165
  }
166
166
  for (const plugin of plugins) {
167
- const result = yield plugin();
167
+ const result = await plugin();
168
168
  if (result === undefined)
169
169
  continue;
170
170
  const newHandler = Object.create(handler);
@@ -172,7 +172,7 @@ const api = () => {
172
172
  innet(result, newHandler);
173
173
  return null;
174
174
  }
175
- }));
175
+ });
176
176
  innet(children, handler);
177
177
  };
178
178
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib = require('tslib');
6
5
  var innet = require('innet');
7
6
  var jsx = require('@innet/jsx');
8
7
  require('../../../hooks/index.js');
@@ -16,15 +15,11 @@ var JSONString = require('../../../utils/JSONString/JSONString.js');
16
15
  var helpers = require('../../../utils/rules/helpers.js');
17
16
  var useParams = require('../../../hooks/useParams/useParams.js');
18
17
 
19
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
-
21
- var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
22
-
23
18
  const api = () => {
24
19
  const handler = innet.useNewHandler();
25
20
  const props = jsx.useProps();
26
- const { children, exclude, include, prefix = process.env.INNET_API_PREFIX || '', title = '', version = process.env.INNET_API_VERSION || '0.0.0' } = props, rest = tslib.__rest(props, ["children", "exclude", "include", "prefix", "title", "version"]);
27
- const info = Object.assign(Object.assign({}, rest), { title, version });
21
+ const { children, exclude, include, prefix = process.env.INNET_API_PREFIX || '', title = '', version = process.env.INNET_API_VERSION || '0.0.0', ...rest } = props;
22
+ const info = { ...rest, title, version };
28
23
  const endpoints = {};
29
24
  const docs = {
30
25
  info,
@@ -46,7 +41,7 @@ const api = () => {
46
41
  };
47
42
  useServerPlugins.serverPlugins.set(handler, plugins);
48
43
  useApi.apiContext.set(handler, context);
49
- useServerPlugin.useServerPlugin(() => tslib.__awaiter(void 0, void 0, void 0, function* () {
44
+ useServerPlugin.useServerPlugin(async () => {
50
45
  var _a, _b, _c, _d, _e, _f;
51
46
  const action = useAction.useAction();
52
47
  if (!condition(action))
@@ -70,91 +65,92 @@ const api = () => {
70
65
  const [deep, currentEndpoint, params] = endpointQueue.shift();
71
66
  const key = splitPath[deep];
72
67
  if (deep + 1 === splitPath.length) {
73
- function run(runEndpoint, params) {
68
+ async function run(runEndpoint, params) {
74
69
  var _a, _b, _c, _d, _e;
75
- return tslib.__awaiter(this, void 0, void 0, function* () {
76
- const pathRules = (_a = runEndpoint.rules) === null || _a === void 0 ? void 0 : _a.path;
77
- const headerRules = (_b = runEndpoint.rules) === null || _b === void 0 ? void 0 : _b.header;
78
- const cookieRules = (_c = runEndpoint.rules) === null || _c === void 0 ? void 0 : _c.cookie;
79
- const searchRules = (_d = runEndpoint.rules) === null || _d === void 0 ? void 0 : _d.search;
80
- const bodyRules = (_e = runEndpoint.rules) === null || _e === void 0 ? void 0 : _e.body;
81
- if (pathRules) {
82
- try {
83
- Object.assign(params, pathRules(params, { in: 'path' }));
84
- }
85
- catch (_f) {
86
- return false;
87
- }
70
+ const pathRules = (_a = runEndpoint.rules) === null || _a === void 0 ? void 0 : _a.path;
71
+ const headerRules = (_b = runEndpoint.rules) === null || _b === void 0 ? void 0 : _b.header;
72
+ const cookieRules = (_c = runEndpoint.rules) === null || _c === void 0 ? void 0 : _c.cookie;
73
+ const searchRules = (_d = runEndpoint.rules) === null || _d === void 0 ? void 0 : _d.search;
74
+ const bodyRules = (_e = runEndpoint.rules) === null || _e === void 0 ? void 0 : _e.body;
75
+ if (pathRules) {
76
+ try {
77
+ Object.assign(params, pathRules(params, { in: 'path' }));
88
78
  }
89
- function checkActionRules(rules, key = 'search') {
90
- if (rules) {
91
- try {
92
- action[key] = rules(action[key]);
93
- }
94
- catch (e) {
95
- res.setHeader('Content-Type', 'application/json');
96
- if (e instanceof helpers.RulesError) {
97
- res.statusCode = 400;
98
- res.write(JSONString.JSONString({
99
- data: Object.assign(Object.assign({}, e.data), { in: key }),
100
- error: 'requestValidation',
101
- }));
102
- res.end();
103
- }
104
- else {
105
- console.error(e);
106
- res.statusCode = 500;
107
- res.write(JSONString.JSONString({
108
- data: { in: key },
109
- error: 'unknown',
110
- }));
111
- res.end();
112
- }
113
- return true;
114
- }
115
- }
79
+ catch (_f) {
116
80
  return false;
117
81
  }
118
- if (checkActionRules(headerRules, 'headers'))
119
- return true;
120
- if (checkActionRules(cookieRules, 'cookies'))
121
- return true;
122
- if (checkActionRules(searchRules, 'search'))
123
- return true;
124
- if (bodyRules) {
125
- yield action.parseBody();
126
- if (!action.body) {
127
- res.statusCode = 400;
82
+ }
83
+ function checkActionRules(rules, key = 'search') {
84
+ if (rules) {
85
+ try {
86
+ action[key] = rules(action[key]);
87
+ }
88
+ catch (e) {
128
89
  res.setHeader('Content-Type', 'application/json');
129
- res.write(JSONString.JSONString({
130
- error: 'requestBodyContentType',
131
- }));
132
- res.end();
90
+ if (e instanceof helpers.RulesError) {
91
+ res.statusCode = 400;
92
+ res.write(JSONString.JSONString({
93
+ data: {
94
+ ...e.data,
95
+ in: key,
96
+ },
97
+ error: 'requestValidation',
98
+ }));
99
+ res.end();
100
+ }
101
+ else {
102
+ console.error(e);
103
+ res.statusCode = 500;
104
+ res.write(JSONString.JSONString({
105
+ data: { in: key },
106
+ error: 'unknown',
107
+ }));
108
+ res.end();
109
+ }
133
110
  return true;
134
111
  }
135
- if (checkActionRules(bodyRules, 'body'))
136
- return true;
137
112
  }
138
- useParams.paramsContext.set(actionHandler, params);
139
- for (const plugin of runEndpoint.plugins) {
140
- const result = yield plugin();
141
- if (result === undefined)
142
- continue;
143
- innet__default["default"](result, actionHandler);
113
+ return false;
114
+ }
115
+ if (checkActionRules(headerRules, 'headers'))
116
+ return true;
117
+ if (checkActionRules(cookieRules, 'cookies'))
118
+ return true;
119
+ if (checkActionRules(searchRules, 'search'))
120
+ return true;
121
+ if (bodyRules) {
122
+ await action.parseBody();
123
+ if (!action.body) {
124
+ res.statusCode = 400;
125
+ res.setHeader('Content-Type', 'application/json');
126
+ res.write(JSONString.JSONString({
127
+ error: 'requestBodyContentType',
128
+ }));
129
+ res.end();
144
130
  return true;
145
131
  }
132
+ if (checkActionRules(bodyRules, 'body'))
133
+ return true;
134
+ }
135
+ useParams.paramsContext.set(actionHandler, params);
136
+ for (const plugin of runEndpoint.plugins) {
137
+ const result = await plugin();
138
+ if (result === undefined)
139
+ continue;
140
+ innet.innet(result, actionHandler);
146
141
  return true;
147
- });
142
+ }
143
+ return true;
148
144
  }
149
145
  if ((_d = (_c = currentEndpoint.static) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.plugins) {
150
- if (!(yield run((_e = currentEndpoint.static) === null || _e === void 0 ? void 0 : _e[key], params)))
146
+ if (!await run((_e = currentEndpoint.static) === null || _e === void 0 ? void 0 : _e[key], params))
151
147
  continue;
152
148
  return null;
153
149
  }
154
150
  if (currentEndpoint.dynamic) {
155
151
  for (const dynamicEndpoint of currentEndpoint.dynamic) {
156
152
  if (dynamicEndpoint.plugins) {
157
- if (!(yield run(dynamicEndpoint, Object.assign(Object.assign({}, params), { [dynamicEndpoint.key.slice(1, -1)]: key }))))
153
+ if (!await run(dynamicEndpoint, { ...params, [dynamicEndpoint.key.slice(1, -1)]: key }))
158
154
  continue;
159
155
  return null;
160
156
  }
@@ -167,21 +163,21 @@ const api = () => {
167
163
  }
168
164
  if (currentEndpoint.dynamic) {
169
165
  for (const dynamicEndpoint of currentEndpoint.dynamic) {
170
- endpointQueue.push([deep + 1, dynamicEndpoint, Object.assign(Object.assign({}, params), { [dynamicEndpoint.key.slice(1, -1)]: key })]);
166
+ endpointQueue.push([deep + 1, dynamicEndpoint, { ...params, [dynamicEndpoint.key.slice(1, -1)]: key }]);
171
167
  }
172
168
  }
173
169
  }
174
170
  for (const plugin of plugins) {
175
- const result = yield plugin();
171
+ const result = await plugin();
176
172
  if (result === undefined)
177
173
  continue;
178
174
  const newHandler = Object.create(handler);
179
175
  useAction.actionContext.set(newHandler, action);
180
- innet__default["default"](result, newHandler);
176
+ innet.innet(result, newHandler);
181
177
  return null;
182
178
  }
183
- }));
184
- innet__default["default"](children, handler);
179
+ });
180
+ innet.innet(children, handler);
185
181
  };
186
182
 
187
183
  exports.api = api;
@@ -1,6 +1,5 @@
1
- import innet, { useNewHandler } from 'innet';
1
+ import { useNewHandler, innet } from 'innet';
2
2
  import { useContext, useChildren } from '@innet/jsx';
3
- import { callHandler } from '@innet/utils';
4
3
  import { allBodyTypes } from '../../../constants.es6.js';
5
4
  import '../../../hooks/index.es6.js';
6
5
  import '../../../utils/index.es6.js';
@@ -9,6 +8,7 @@ import { schemaContext } from '../../../hooks/useSchemaContext/useSchemaContext.
9
8
  import { getOrAdd } from '../../../utils/getOrAdd/getOrAdd.es6.js';
10
9
  import { bodyFileContext } from '../../../hooks/useBodyFile/useBodyFile.es6.js';
11
10
  import { ruleContext } from '../../../hooks/useRule/useRule.es6.js';
11
+ import { useEffect } from '../../../hooks/useEffect/useEffect.es6.js';
12
12
 
13
13
  const body = () => {
14
14
  const endpoint = useContext(endpointContext);
@@ -40,7 +40,7 @@ const body = () => {
40
40
  rules.body = rule;
41
41
  });
42
42
  innet(children, handler);
43
- innet(() => {
43
+ useEffect(() => {
44
44
  if (fileUsed) {
45
45
  requestBody.content['multipart/form-data'] = { schema };
46
46
  }
@@ -49,7 +49,7 @@ const body = () => {
49
49
  requestBody.content[type] = { schema };
50
50
  }
51
51
  }
52
- }, callHandler);
52
+ });
53
53
  };
54
54
 
55
55
  export { body };
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var innet = require('innet');
6
6
  var jsx = require('@innet/jsx');
7
- var utils = require('@innet/utils');
8
7
  var constants = require('../../../constants.js');
9
8
  require('../../../hooks/index.js');
10
9
  require('../../../utils/index.js');
@@ -13,10 +12,7 @@ var useSchemaContext = require('../../../hooks/useSchemaContext/useSchemaContext
13
12
  var getOrAdd = require('../../../utils/getOrAdd/getOrAdd.js');
14
13
  var useBodyFile = require('../../../hooks/useBodyFile/useBodyFile.js');
15
14
  var useRule = require('../../../hooks/useRule/useRule.js');
16
-
17
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
-
19
- var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
15
+ var useEffect = require('../../../hooks/useEffect/useEffect.js');
20
16
 
21
17
  const body = () => {
22
18
  const endpoint = jsx.useContext(useEndpoint.endpointContext);
@@ -47,8 +43,8 @@ const body = () => {
47
43
  useRule.ruleContext.set(handler, rule => {
48
44
  rules.body = rule;
49
45
  });
50
- innet__default["default"](children, handler);
51
- innet__default["default"](() => {
46
+ innet.innet(children, handler);
47
+ useEffect.useEffect(() => {
52
48
  if (fileUsed) {
53
49
  requestBody.content['multipart/form-data'] = { schema };
54
50
  }
@@ -57,7 +53,7 @@ const body = () => {
57
53
  requestBody.content[type] = { schema };
58
54
  }
59
55
  }
60
- }, utils.callHandler);
56
+ });
61
57
  };
62
58
 
63
59
  exports.body = body;
@@ -17,6 +17,11 @@ export interface EndpointProps {
17
17
  * A method of the endpoint.
18
18
  * */
19
19
  method: EndpointsMethods;
20
+ /**
21
+ * `operationId` is an optional unique string used to identify an operation.
22
+ * If provided, these IDs must be unique among all operations described in your API.
23
+ * */
24
+ operationId?: string;
20
25
  /**
21
26
  * A relative path to an individual endpoint.
22
27
  * The property MUST begin with a forward slash (/).
@@ -1,4 +1,4 @@
1
- import innet, { useNewHandler } from 'innet';
1
+ import { useNewHandler, innet } from 'innet';
2
2
  import { useProps } from '@innet/jsx';
3
3
  import '../../../hooks/index.es6.js';
4
4
  import '../../../utils/index.es6.js';
@@ -13,18 +13,20 @@ const endpoint = () => {
13
13
  const tag = useTag();
14
14
  const props = useProps();
15
15
  const { docs, endpoints, } = useApi();
16
- const { children, deprecated, description, method, path, private: privateMode, summary, } = props;
16
+ const { children, deprecated, description, method, operationId, path, private: privateMode, summary, } = props;
17
17
  const { paths } = docs;
18
18
  if (!paths)
19
19
  throw Error('cannot find paths in docs');
20
20
  if (!paths[path]) {
21
21
  paths[path] = {};
22
22
  }
23
- // @ts-expect-error: it's always an object
24
23
  if (paths[path][method]) {
25
24
  throw Error(`You cannot use the same endpoints ${method}:${path}`);
26
25
  }
27
26
  const operation = {};
27
+ if (operationId) {
28
+ operation.operationId = operationId;
29
+ }
28
30
  if (summary) {
29
31
  operation.summary = summary;
30
32
  }
@@ -38,13 +40,11 @@ const endpoint = () => {
38
40
  operation.tags = [tag.name];
39
41
  }
40
42
  if (!privateMode) {
41
- // @ts-expect-error: it's always an object
42
43
  paths[path][method] = operation;
43
44
  }
44
45
  if (!endpoints[method]) {
45
46
  endpoints[method] = { key: '', plugins: new Set() };
46
47
  }
47
- // @ts-expect-error: it's always an object
48
48
  const endpoint = getEndpoint(path, endpoints[method]);
49
49
  // @ts-expect-error: it's always an object
50
50
  endpointContext.set(handler, { endpoint, operation, props });
@@ -12,27 +12,25 @@ var getEndpoint = require('../../../utils/getEndpoint/getEndpoint.js');
12
12
  var useEndpoint = require('../../../hooks/useEndpoint/useEndpoint.js');
13
13
  var useServerPlugins = require('../../../hooks/useServerPlugins/useServerPlugins.js');
14
14
 
15
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
-
17
- var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
18
-
19
15
  const endpoint = () => {
20
16
  const handler = innet.useNewHandler();
21
17
  const tag = useTag.useTag();
22
18
  const props = jsx.useProps();
23
19
  const { docs, endpoints, } = useApi.useApi();
24
- const { children, deprecated, description, method, path, private: privateMode, summary, } = props;
20
+ const { children, deprecated, description, method, operationId, path, private: privateMode, summary, } = props;
25
21
  const { paths } = docs;
26
22
  if (!paths)
27
23
  throw Error('cannot find paths in docs');
28
24
  if (!paths[path]) {
29
25
  paths[path] = {};
30
26
  }
31
- // @ts-expect-error: it's always an object
32
27
  if (paths[path][method]) {
33
28
  throw Error(`You cannot use the same endpoints ${method}:${path}`);
34
29
  }
35
30
  const operation = {};
31
+ if (operationId) {
32
+ operation.operationId = operationId;
33
+ }
36
34
  if (summary) {
37
35
  operation.summary = summary;
38
36
  }
@@ -46,19 +44,17 @@ const endpoint = () => {
46
44
  operation.tags = [tag.name];
47
45
  }
48
46
  if (!privateMode) {
49
- // @ts-expect-error: it's always an object
50
47
  paths[path][method] = operation;
51
48
  }
52
49
  if (!endpoints[method]) {
53
50
  endpoints[method] = { key: '', plugins: new Set() };
54
51
  }
55
- // @ts-expect-error: it's always an object
56
52
  const endpoint = getEndpoint.getEndpoint(path, endpoints[method]);
57
53
  // @ts-expect-error: it's always an object
58
54
  useEndpoint.endpointContext.set(handler, { endpoint, operation, props });
59
55
  // @ts-expect-error: it's always an object
60
56
  useServerPlugins.serverPlugins.set(handler, endpoint.plugins);
61
- innet__default["default"](children, handler);
57
+ innet.innet(children, handler);
62
58
  };
63
59
 
64
60
  exports.endpoint = endpoint;
@@ -1,4 +1,4 @@
1
- import innet, { useNewHandler } from 'innet';
1
+ import { useNewHandler, innet } from 'innet';
2
2
  import { useProps, useChildren, useContext } from '@innet/jsx';
3
3
  import '../../../hooks/index.es6.js';
4
4
  import { useApi } from '../../../hooks/useApi/useApi.es6.js';
@@ -16,7 +16,9 @@ const host = () => {
16
16
  target.servers = [];
17
17
  }
18
18
  const { servers } = operation || docs;
19
- const server = Object.assign({}, props);
19
+ const server = {
20
+ ...props,
21
+ };
20
22
  // @ts-expect-error: FIXME
21
23
  servers.push(server);
22
24
  handler[hostContext.key] = { server };