@innet/server 2.0.0-alpha.0 → 2.0.0-alpha.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 (111) hide show
  1. package/README.md +309 -29
  2. package/example/requests/index.d.ts +1 -1
  3. package/example/requests/todo/AddTodo/AddTodo.d.ts +1 -0
  4. package/example/requests/todo/AddTodo/index.d.ts +1 -0
  5. package/example/requests/todo/DeleteTodo/DeleteTodo.d.ts +1 -0
  6. package/example/requests/todo/DeleteTodo/index.d.ts +1 -0
  7. package/example/requests/todo/EditTodo/EditTodo.d.ts +1 -0
  8. package/example/requests/todo/EditTodo/index.d.ts +1 -0
  9. package/example/requests/todo/GetTodo/GetTodo.d.ts +1 -0
  10. package/example/requests/todo/GetTodo/index.d.ts +1 -0
  11. package/example/requests/todo/GetTodos/GetTodos.d.ts +1 -0
  12. package/example/requests/todo/GetTodos/index.d.ts +1 -0
  13. package/example/requests/todo/index.d.ts +5 -0
  14. package/example/requests/todo/todos.d.ts +1 -0
  15. package/example/schemas/app/ListQueryParams/ListQueryParams.d.ts +1 -0
  16. package/example/schemas/app/ListQueryParams/index.d.ts +1 -0
  17. package/example/schemas/app/ListSchema/ListSchema.d.ts +4 -1
  18. package/example/schemas/app/index.d.ts +1 -0
  19. package/example/schemas/index.d.ts +1 -3
  20. package/example/schemas/todo/TodoSchema/TodoSchema.d.ts +4 -0
  21. package/example/schemas/todo/TodoSchema/index.d.ts +1 -0
  22. package/example/schemas/todo/index.d.ts +1 -0
  23. package/example/tags/Todo/Todo.d.ts +1 -0
  24. package/example/tags/Todo/index.d.ts +1 -0
  25. package/example/tags/index.d.ts +1 -1
  26. package/handler/handler.d.ts +3 -1
  27. package/handler/handler.es6.js +2 -0
  28. package/handler/handler.js +2 -0
  29. package/hooks/index.d.ts +2 -0
  30. package/hooks/index.es6.js +2 -0
  31. package/hooks/index.js +2 -0
  32. package/hooks/useClientIp/index.d.ts +1 -0
  33. package/hooks/useClientIp/index.es6.js +1 -0
  34. package/hooks/useClientIp/index.js +9 -0
  35. package/hooks/useClientIp/useClientIp.d.ts +1 -0
  36. package/hooks/useClientIp/useClientIp.es6.js +9 -0
  37. package/hooks/useClientIp/useClientIp.js +13 -0
  38. package/hooks/useComponentName/useComponentName.d.ts +1 -1
  39. package/hooks/useRequestPlugin/index.d.ts +1 -0
  40. package/hooks/useRequestPlugin/index.es6.js +1 -0
  41. package/hooks/useRequestPlugin/index.js +9 -0
  42. package/hooks/useRequestPlugin/useRequestPlugin.d.ts +2 -0
  43. package/hooks/useRequestPlugin/useRequestPlugin.es6.js +13 -0
  44. package/hooks/useRequestPlugin/useRequestPlugin.js +17 -0
  45. package/index.es6.js +4 -0
  46. package/index.js +9 -0
  47. package/package.json +2 -2
  48. package/plugins/main/api/api.es6.js +18 -11
  49. package/plugins/main/api/api.js +18 -11
  50. package/plugins/main/response/response.d.ts +1 -1
  51. package/plugins/main/response/response.es6.js +1 -1
  52. package/plugins/main/response/response.js +1 -1
  53. package/plugins/main/server/server.es6.js +10 -4
  54. package/plugins/main/server/server.js +10 -4
  55. package/plugins/request/cookie/cookie.es6.js +3 -19
  56. package/plugins/request/cookie/cookie.js +3 -23
  57. package/plugins/request/success/success.d.ts +1 -0
  58. package/plugins/request/success/success.es6.js +13 -4
  59. package/plugins/request/success/success.js +13 -4
  60. package/plugins/schema/boolean/boolean.es6.js +2 -4
  61. package/plugins/schema/boolean/boolean.js +1 -3
  62. package/plugins/utils/dts/dts.d.ts +1 -2
  63. package/plugins/utils/dts/dts.es6.js +6 -25
  64. package/plugins/utils/dts/dts.js +5 -29
  65. package/plugins/utils/index.d.ts +1 -0
  66. package/plugins/utils/index.es6.js +1 -0
  67. package/plugins/utils/index.js +1 -0
  68. package/plugins/utils/protection/index.d.ts +1 -0
  69. package/plugins/utils/protection/index.es6.js +1 -0
  70. package/plugins/utils/protection/index.js +9 -0
  71. package/plugins/utils/protection/protection.d.ts +8 -0
  72. package/plugins/utils/protection/protection.es6.js +34 -0
  73. package/plugins/utils/protection/protection.js +38 -0
  74. package/plugins/utils/swagger/swagger.es6.js +7 -11
  75. package/plugins/utils/swagger/swagger.js +7 -11
  76. package/types.d.ts +2 -3
  77. package/utils/action/Action.d.ts +7 -4
  78. package/utils/action/Action.es6.js +25 -3
  79. package/utils/action/Action.js +26 -4
  80. package/utils/generateTypes/generateTypes.d.ts +3 -0
  81. package/utils/generateTypes/generateTypes.es6.js +102 -0
  82. package/utils/generateTypes/generateTypes.js +107 -0
  83. package/utils/generateTypes/generateTypes.test.d.ts +1 -0
  84. package/utils/generateTypes/index.d.ts +1 -0
  85. package/utils/generateTypes/index.es6.js +1 -0
  86. package/utils/generateTypes/index.js +10 -0
  87. package/utils/index.d.ts +1 -0
  88. package/utils/index.es6.js +1 -0
  89. package/utils/index.js +1 -0
  90. package/utils/rules/objectOf/objectOf.es6.js +4 -1
  91. package/utils/rules/objectOf/objectOf.js +4 -1
  92. package/example/requests/partners/EditPartner/EditPartner.d.ts +0 -1
  93. package/example/requests/partners/EditPartner/index.d.ts +0 -1
  94. package/example/requests/partners/GetPartner/GetPartner.d.ts +0 -1
  95. package/example/requests/partners/GetPartner/index.d.ts +0 -1
  96. package/example/requests/partners/GetPartners/GetPartners.d.ts +0 -1
  97. package/example/requests/partners/GetPartners/index.d.ts +0 -1
  98. package/example/requests/partners/index.d.ts +0 -3
  99. package/example/schemas/address/AddressSchema/AddressSchema.d.ts +0 -1
  100. package/example/schemas/address/AddressSchema/index.d.ts +0 -1
  101. package/example/schemas/address/index.d.ts +0 -1
  102. package/example/schemas/location/LocationSchema/LocationSchema.d.ts +0 -1
  103. package/example/schemas/location/LocationSchema/index.d.ts +0 -1
  104. package/example/schemas/location/index.d.ts +0 -1
  105. package/example/schemas/partner/EditPartnerSchema/EditPartnerSchema.d.ts +0 -1
  106. package/example/schemas/partner/EditPartnerSchema/index.d.ts +0 -1
  107. package/example/schemas/partner/PartnerSchema/PartnerSchema.d.ts +0 -1
  108. package/example/schemas/partner/PartnerSchema/index.d.ts +0 -1
  109. package/example/schemas/partner/index.d.ts +0 -2
  110. package/example/tags/Partner/Partner.d.ts +0 -1
  111. package/example/tags/Partner/index.d.ts +0 -1
package/index.es6.js CHANGED
@@ -41,6 +41,7 @@ export { swagger } from './plugins/utils/swagger/swagger.es6.js';
41
41
  export { dts } from './plugins/utils/dts/dts.es6.js';
42
42
  export { dev } from './plugins/utils/dev/dev.es6.js';
43
43
  export { prod } from './plugins/utils/prod/prod.es6.js';
44
+ export { protection } from './plugins/utils/protection/protection.es6.js';
44
45
  export { serverFn } from './plugins/handler/serverFn/serverFn.es6.js';
45
46
  export { EMPTY_SEARCH, parseSearch } from './utils/parseSearch/parseSearch.es6.js';
46
47
  export { stringifySearch } from './utils/stringifySearch/stringifySearch.es6.js';
@@ -81,6 +82,7 @@ export { maxBin } from './utils/rules/maxBin/maxBin.es6.js';
81
82
  export { binaryAccept } from './utils/rules/binaryAccept/binaryAccept.es6.js';
82
83
  export { JSONString } from './utils/JSONString/JSONString.es6.js';
83
84
  export { Bin } from './utils/FileData/Bin.es6.js';
85
+ export { generateSchemaTypes, generateTypes } from './utils/generateTypes/generateTypes.es6.js';
84
86
  export { serverContext, useServer } from './hooks/useServer/useServer.es6.js';
85
87
  export { apiContext, useApi } from './hooks/useApi/useApi.es6.js';
86
88
  export { hostContext, useHost } from './hooks/useHost/useHost.es6.js';
@@ -106,3 +108,5 @@ export { ruleContext, useRule, useSetRule } from './hooks/useRule/useRule.es6.js
106
108
  export { objectRuleContext, useObjectRule } from './hooks/useObjectRule/useObjectRule.es6.js';
107
109
  export { bodyFileContext, useBodyFile } from './hooks/useBodyFile/useBodyFile.es6.js';
108
110
  export { usePath } from './hooks/usePath/usePath.es6.js';
111
+ export { useRequestPlugin } from './hooks/useRequestPlugin/useRequestPlugin.es6.js';
112
+ export { useClientIp } from './hooks/useClientIp/useClientIp.es6.js';
package/index.js CHANGED
@@ -45,6 +45,7 @@ var swagger = require('./plugins/utils/swagger/swagger.js');
45
45
  var dts = require('./plugins/utils/dts/dts.js');
46
46
  var dev = require('./plugins/utils/dev/dev.js');
47
47
  var prod = require('./plugins/utils/prod/prod.js');
48
+ var protection = require('./plugins/utils/protection/protection.js');
48
49
  var serverFn = require('./plugins/handler/serverFn/serverFn.js');
49
50
  var parseSearch = require('./utils/parseSearch/parseSearch.js');
50
51
  var stringifySearch = require('./utils/stringifySearch/stringifySearch.js');
@@ -85,6 +86,7 @@ var maxBin = require('./utils/rules/maxBin/maxBin.js');
85
86
  var binaryAccept = require('./utils/rules/binaryAccept/binaryAccept.js');
86
87
  var JSONString = require('./utils/JSONString/JSONString.js');
87
88
  var Bin = require('./utils/FileData/Bin.js');
89
+ var generateTypes = require('./utils/generateTypes/generateTypes.js');
88
90
  var useServer = require('./hooks/useServer/useServer.js');
89
91
  var useApi = require('./hooks/useApi/useApi.js');
90
92
  var useHost = require('./hooks/useHost/useHost.js');
@@ -110,6 +112,8 @@ var useRule = require('./hooks/useRule/useRule.js');
110
112
  var useObjectRule = require('./hooks/useObjectRule/useObjectRule.js');
111
113
  var useBodyFile = require('./hooks/useBodyFile/useBodyFile.js');
112
114
  var usePath = require('./hooks/usePath/usePath.js');
115
+ var useRequestPlugin = require('./hooks/useRequestPlugin/useRequestPlugin.js');
116
+ var useClientIp = require('./hooks/useClientIp/useClientIp.js');
113
117
 
114
118
 
115
119
 
@@ -160,6 +164,7 @@ exports.swagger = swagger.swagger;
160
164
  exports.dts = dts.dts;
161
165
  exports.dev = dev.dev;
162
166
  exports.prod = prod.prod;
167
+ exports.protection = protection.protection;
163
168
  exports.serverFn = serverFn.serverFn;
164
169
  exports.EMPTY_SEARCH = parseSearch.EMPTY_SEARCH;
165
170
  exports.parseSearch = parseSearch.parseSearch;
@@ -203,6 +208,8 @@ exports.maxBin = maxBin.maxBin;
203
208
  exports.binaryAccept = binaryAccept.binaryAccept;
204
209
  exports.JSONString = JSONString.JSONString;
205
210
  exports.Bin = Bin.Bin;
211
+ exports.generateSchemaTypes = generateTypes.generateSchemaTypes;
212
+ exports.generateTypes = generateTypes.generateTypes;
206
213
  exports.serverContext = useServer.serverContext;
207
214
  exports.useServer = useServer.useServer;
208
215
  exports.apiContext = useApi.apiContext;
@@ -243,3 +250,5 @@ exports.useObjectRule = useObjectRule.useObjectRule;
243
250
  exports.bodyFileContext = useBodyFile.bodyFileContext;
244
251
  exports.useBodyFile = useBodyFile.useBodyFile;
245
252
  exports.usePath = usePath.usePath;
253
+ exports.useRequestPlugin = useRequestPlugin.useRequestPlugin;
254
+ exports.useClientIp = useClientIp.useClientIp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innet/server",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.0-alpha.10",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -42,7 +42,6 @@
42
42
  "@types/multiparty": "^0.0.33",
43
43
  "@types/qs": "^6.9.7",
44
44
  "cookie": "^0.5.0",
45
- "dtsgenerator": "^3.18.0",
46
45
  "http-proxy": "^1.18.1",
47
46
  "innet": "^2.0.0-alpha.3",
48
47
  "is-invalid-path": "^1.0.2",
@@ -50,6 +49,7 @@
50
49
  "multiparty": "^4.2.3",
51
50
  "openapi-types": "^12.1.3",
52
51
  "qs": "^6.11.2",
52
+ "request-ip": "^3.3.0",
53
53
  "string_decoder": "^1.3.0",
54
54
  "tslib": "^2.6.1",
55
55
  "uuid": "^9.0.0",
@@ -7,12 +7,12 @@ import '../../../utils/rules/index.es6.js';
7
7
  import { useServer } from '../../../hooks/useServer/useServer.es6.js';
8
8
  import { apiContext } from '../../../hooks/useApi/useApi.es6.js';
9
9
  import { Action } from '../../../utils/action/Action.es6.js';
10
- import { JSONString } from '../../../utils/JSONString/JSONString.es6.js';
11
- import { RulesError } from '../../../utils/rules/helpers.es6.js';
12
10
  import { responseContext } from '../../../hooks/useResponse/useResponse.es6.js';
13
11
  import { requestContext } from '../../../hooks/useRequest/useRequest.es6.js';
14
- import { paramsContext } from '../../../hooks/useParams/useParams.es6.js';
15
12
  import { actionContext } from '../../../hooks/useAction/useAction.es6.js';
13
+ import { JSONString } from '../../../utils/JSONString/JSONString.es6.js';
14
+ import { RulesError } from '../../../utils/rules/helpers.es6.js';
15
+ import { paramsContext } from '../../../hooks/useParams/useParams.es6.js';
16
16
 
17
17
  const api = () => {
18
18
  var _a;
@@ -34,18 +34,29 @@ const api = () => {
34
34
  var _b, _c, _d, _e, _f, _g;
35
35
  if (res.writableEnded)
36
36
  return;
37
- const action = new Action(req);
37
+ const action = new Action(req, res);
38
38
  const path = action.parsedUrl.path;
39
39
  const url = path.endsWith('/') ? path.slice(0, -1) : path;
40
+ if (!url.startsWith(prefix)) {
41
+ return;
42
+ }
43
+ for (const requestPlugin of requestPlugins) {
44
+ const result = requestPlugin(action);
45
+ if (!result)
46
+ continue;
47
+ const newHandler = Object.create(handler);
48
+ responseContext.set(newHandler, res);
49
+ requestContext.set(newHandler, req);
50
+ actionContext.set(newHandler, action);
51
+ innet(result, newHandler);
52
+ return;
53
+ }
40
54
  if (url === (prefix || '')) {
41
55
  res.setHeader('Content-Type', 'application/json');
42
56
  res.write(JSONString(docs));
43
57
  res.end();
44
58
  return;
45
59
  }
46
- if (!url.startsWith(prefix)) {
47
- return;
48
- }
49
60
  const method = ((_c = (_b = req.method) === null || _b === void 0 ? void 0 : _b.toLowerCase()) !== null && _c !== void 0 ? _c : 'get');
50
61
  const rawSplitPath = url.slice(prefix.length).split('/').slice(1);
51
62
  const splitPath = rawSplitPath.at(-1) ? rawSplitPath : rawSplitPath.slice(0, -1);
@@ -154,10 +165,6 @@ const api = () => {
154
165
  }
155
166
  }
156
167
  }
157
- for (const requestPlugin of requestPlugins) {
158
- if (requestPlugin(req, res))
159
- return;
160
- }
161
168
  if (context.fallback) {
162
169
  const newHandler = Object.create(context.fallback.handler);
163
170
  responseContext.set(newHandler, res);
@@ -11,12 +11,12 @@ require('../../../utils/rules/index.js');
11
11
  var useServer = require('../../../hooks/useServer/useServer.js');
12
12
  var useApi = require('../../../hooks/useApi/useApi.js');
13
13
  var Action = require('../../../utils/action/Action.js');
14
- var JSONString = require('../../../utils/JSONString/JSONString.js');
15
- var helpers = require('../../../utils/rules/helpers.js');
16
14
  var useResponse = require('../../../hooks/useResponse/useResponse.js');
17
15
  var useRequest = require('../../../hooks/useRequest/useRequest.js');
18
- var useParams = require('../../../hooks/useParams/useParams.js');
19
16
  var useAction = require('../../../hooks/useAction/useAction.js');
17
+ var JSONString = require('../../../utils/JSONString/JSONString.js');
18
+ var helpers = require('../../../utils/rules/helpers.js');
19
+ var useParams = require('../../../hooks/useParams/useParams.js');
20
20
 
21
21
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
22
22
 
@@ -42,18 +42,29 @@ const api = () => {
42
42
  var _b, _c, _d, _e, _f, _g;
43
43
  if (res.writableEnded)
44
44
  return;
45
- const action = new Action.Action(req);
45
+ const action = new Action.Action(req, res);
46
46
  const path = action.parsedUrl.path;
47
47
  const url = path.endsWith('/') ? path.slice(0, -1) : path;
48
+ if (!url.startsWith(prefix)) {
49
+ return;
50
+ }
51
+ for (const requestPlugin of requestPlugins) {
52
+ const result = requestPlugin(action);
53
+ if (!result)
54
+ continue;
55
+ const newHandler = Object.create(handler);
56
+ useResponse.responseContext.set(newHandler, res);
57
+ useRequest.requestContext.set(newHandler, req);
58
+ useAction.actionContext.set(newHandler, action);
59
+ innet__default["default"](result, newHandler);
60
+ return;
61
+ }
48
62
  if (url === (prefix || '')) {
49
63
  res.setHeader('Content-Type', 'application/json');
50
64
  res.write(JSONString.JSONString(docs));
51
65
  res.end();
52
66
  return;
53
67
  }
54
- if (!url.startsWith(prefix)) {
55
- return;
56
- }
57
68
  const method = ((_c = (_b = req.method) === null || _b === void 0 ? void 0 : _b.toLowerCase()) !== null && _c !== void 0 ? _c : 'get');
58
69
  const rawSplitPath = url.slice(prefix.length).split('/').slice(1);
59
70
  const splitPath = rawSplitPath.at(-1) ? rawSplitPath : rawSplitPath.slice(0, -1);
@@ -162,10 +173,6 @@ const api = () => {
162
173
  }
163
174
  }
164
175
  }
165
- for (const requestPlugin of requestPlugins) {
166
- if (requestPlugin(req, res))
167
- return;
168
- }
169
176
  if (context.fallback) {
170
177
  const newHandler = Object.create(context.fallback.handler);
171
178
  useResponse.responseContext.set(newHandler, res);
@@ -4,7 +4,7 @@ export interface ResponseProps {
4
4
  * A description of the response.
5
5
  * [CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
6
6
  * */
7
- description: string;
7
+ description?: string;
8
8
  /**
9
9
  * Any [HTTP status code](https://swagger.io/specification/#http-codes) can be used as the property.
10
10
  * To define a range of response codes, this field MAY contain the uppercase wildcard character X.
@@ -9,7 +9,7 @@ import { getOrAdd } from '../../../utils/getOrAdd/getOrAdd.es6.js';
9
9
  import { ruleContext } from '../../../hooks/useRule/useRule.es6.js';
10
10
 
11
11
  const response = () => {
12
- const { description, status = 'default' } = useProps();
12
+ const { description = '', status = 'default' } = useProps() || {};
13
13
  const { operation, props: { path } } = useEndpoint();
14
14
  const children = useChildren();
15
15
  const handler = useNewHandler();
@@ -17,7 +17,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
17
17
  var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
18
18
 
19
19
  const response = () => {
20
- const { description, status = 'default' } = jsx.useProps();
20
+ const { description = '', status = 'default' } = jsx.useProps() || {};
21
21
  const { operation, props: { path } } = useEndpoint.useEndpoint();
22
22
  const children = jsx.useChildren();
23
23
  const handler = innet.useNewHandler();
@@ -14,11 +14,17 @@ const server = () => {
14
14
  const { props = {}, children } = useApp();
15
15
  const { env } = process;
16
16
  let { ssl: { key = (_a = env.SSL_KEY) !== null && _a !== void 0 ? _a : 'localhost.key', cert = (_b = env.SSL_CRT) !== null && _b !== void 0 ? _b : 'localhost.crt', } = {}, } = props;
17
- if (!isInvalidPath(key)) {
18
- key = fs.readFileSync(key).toString();
17
+ try {
18
+ if (!isInvalidPath(key)) {
19
+ key = fs.readFileSync(key).toString();
20
+ }
21
+ if (!isInvalidPath(cert)) {
22
+ cert = fs.readFileSync(cert).toString();
23
+ }
19
24
  }
20
- if (!isInvalidPath(cert)) {
21
- cert = fs.readFileSync(cert).toString();
25
+ catch (_d) {
26
+ key = '';
27
+ cert = '';
22
28
  }
23
29
  const https = Boolean(key && cert);
24
30
  const { port = Number((_c = env.PORT) !== null && _c !== void 0 ? _c : (https ? 442 : 80)), onStart, onError, onRequest, } = props;
@@ -25,11 +25,17 @@ const server = () => {
25
25
  const { props = {}, children } = innet.useApp();
26
26
  const { env } = process;
27
27
  let { ssl: { key = (_a = env.SSL_KEY) !== null && _a !== void 0 ? _a : 'localhost.key', cert = (_b = env.SSL_CRT) !== null && _b !== void 0 ? _b : 'localhost.crt', } = {}, } = props;
28
- if (!isInvalidPath(key)) {
29
- key = fs__default["default"].readFileSync(key).toString();
28
+ try {
29
+ if (!isInvalidPath(key)) {
30
+ key = fs__default["default"].readFileSync(key).toString();
31
+ }
32
+ if (!isInvalidPath(cert)) {
33
+ cert = fs__default["default"].readFileSync(cert).toString();
34
+ }
30
35
  }
31
- if (!isInvalidPath(cert)) {
32
- cert = fs__default["default"].readFileSync(cert).toString();
36
+ catch (_d) {
37
+ key = '';
38
+ cert = '';
33
39
  }
34
40
  const https = Boolean(key && cert);
35
41
  const { port = Number((_c = env.PORT) !== null && _c !== void 0 ? _c : (https ? 442 : 80)), onStart, onError, onRequest, } = props;
@@ -1,28 +1,12 @@
1
1
  import { __rest } from 'tslib';
2
2
  import { useProps } from '@innet/jsx';
3
- import cookie$1 from 'cookie';
4
3
  import '../../../hooks/index.es6.js';
5
- import { useResponse } from '../../../hooks/useResponse/useResponse.es6.js';
6
- import { useThrow } from '../../../hooks/useThrow/useThrow.es6.js';
4
+ import { useAction } from '../../../hooks/useAction/useAction.es6.js';
7
5
 
8
6
  const cookie = () => {
9
- const res = useResponse();
10
- if (!res) {
11
- useThrow('<{type}> MUST be in <request> or <fallback>');
12
- }
7
+ const action = useAction();
13
8
  const _a = useProps(), { key, value } = _a, opt = __rest(_a, ["key", "value"]);
14
- let cookies = res.getHeader('Set-Cookie');
15
- if (typeof cookies === 'string') {
16
- cookies = [cookies];
17
- }
18
- const normValue = typeof value === 'string' ? cookie$1.serialize(key, value, opt) : `${key}=; max-age=0`;
19
- if (cookies) {
20
- cookies.push(normValue);
21
- }
22
- else {
23
- cookies = normValue;
24
- }
25
- res.setHeader('Set-Cookie', cookies);
9
+ action.setCookie(key, value, opt);
26
10
  };
27
11
 
28
12
  export { cookie };
@@ -4,33 +4,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var tslib = require('tslib');
6
6
  var jsx = require('@innet/jsx');
7
- var cookie$1 = require('cookie');
8
7
  require('../../../hooks/index.js');
9
- var useResponse = require('../../../hooks/useResponse/useResponse.js');
10
- var useThrow = require('../../../hooks/useThrow/useThrow.js');
11
-
12
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
-
14
- var cookie__default = /*#__PURE__*/_interopDefaultLegacy(cookie$1);
8
+ var useAction = require('../../../hooks/useAction/useAction.js');
15
9
 
16
10
  const cookie = () => {
17
- const res = useResponse.useResponse();
18
- if (!res) {
19
- useThrow.useThrow('<{type}> MUST be in <request> or <fallback>');
20
- }
11
+ const action = useAction.useAction();
21
12
  const _a = jsx.useProps(), { key, value } = _a, opt = tslib.__rest(_a, ["key", "value"]);
22
- let cookies = res.getHeader('Set-Cookie');
23
- if (typeof cookies === 'string') {
24
- cookies = [cookies];
25
- }
26
- const normValue = typeof value === 'string' ? cookie__default["default"].serialize(key, value, opt) : `${key}=; max-age=0`;
27
- if (cookies) {
28
- cookies.push(normValue);
29
- }
30
- else {
31
- cookies = normValue;
32
- }
33
- res.setHeader('Set-Cookie', cookies);
13
+ action.setCookie(key, value, opt);
34
14
  };
35
15
 
36
16
  exports.cookie = cookie;
@@ -13,5 +13,6 @@ export declare const successStatuses: {
13
13
  export type SuccessStatuses = keyof typeof successStatuses;
14
14
  export interface SuccessProps {
15
15
  status?: SuccessStatuses | number;
16
+ contentType?: string;
16
17
  }
17
18
  export declare const success: HandlerPlugin;
@@ -17,15 +17,24 @@ const successStatuses = {
17
17
  };
18
18
  const success = () => {
19
19
  const children = useChildren();
20
- const props = useProps();
20
+ const { status, contentType } = useProps() || {};
21
21
  const res = useResponse();
22
- const status = props === null || props === void 0 ? void 0 : props.status;
23
22
  if (!res) {
24
23
  throw Error('<success> MUST be in <request>');
25
24
  }
26
25
  res.statusCode = typeof status === 'string' ? successStatuses[status] : status !== null && status !== void 0 ? status : ((children) ? 200 : 204);
27
- if (children) {
28
- res.write(JSONString(children[0]));
26
+ if (children === null || children === void 0 ? void 0 : children[0]) {
27
+ const child = children[0];
28
+ const type = contentType || (['string', 'number', 'boolean', 'bigint'].includes(typeof child)
29
+ ? 'text/plain'
30
+ : 'application/json');
31
+ res.setHeader('Content-Type', type);
32
+ if (type === 'application/json') {
33
+ res.write(JSONString(child));
34
+ }
35
+ else {
36
+ res.write(String(child));
37
+ }
29
38
  }
30
39
  res.end();
31
40
  };
@@ -21,15 +21,24 @@ const successStatuses = {
21
21
  };
22
22
  const success = () => {
23
23
  const children = jsx.useChildren();
24
- const props = jsx.useProps();
24
+ const { status, contentType } = jsx.useProps() || {};
25
25
  const res = useResponse.useResponse();
26
- const status = props === null || props === void 0 ? void 0 : props.status;
27
26
  if (!res) {
28
27
  throw Error('<success> MUST be in <request>');
29
28
  }
30
29
  res.statusCode = typeof status === 'string' ? successStatuses[status] : status !== null && status !== void 0 ? status : ((children) ? 200 : 204);
31
- if (children) {
32
- res.write(JSONString.JSONString(children[0]));
30
+ if (children === null || children === void 0 ? void 0 : children[0]) {
31
+ const child = children[0];
32
+ const type = contentType || (['string', 'number', 'boolean', 'bigint'].includes(typeof child)
33
+ ? 'text/plain'
34
+ : 'application/json');
35
+ res.setHeader('Content-Type', type);
36
+ if (type === 'application/json') {
37
+ res.write(JSONString.JSONString(child));
38
+ }
39
+ else {
40
+ res.write(String(child));
41
+ }
33
42
  }
34
43
  res.end();
35
44
  };
@@ -1,10 +1,9 @@
1
- import { useProps, useContext } from '@innet/jsx';
1
+ import { useProps } from '@innet/jsx';
2
2
  import '../../../hooks/index.es6.js';
3
3
  import '../../../hooks/useParentRule/index.es6.js';
4
4
  import '../../../utils/index.es6.js';
5
5
  import { useBlock } from '../../../hooks/useBlock/useBlock.es6.js';
6
6
  import { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
7
- import { paramContext } from '../../../hooks/useParam/useParam.es6.js';
8
7
  import { defaultTo } from '../../../utils/rules/defaultTo/defaultTo.es6.js';
9
8
  import { useParentRule } from '../../../hooks/useParentRule/useParentRule.es6.js';
10
9
  import { useRule } from '../../../hooks/useRule/useRule.es6.js';
@@ -14,12 +13,11 @@ const boolean = () => {
14
13
  useBlock('path');
15
14
  const props = useProps();
16
15
  useSchemaType('boolean', props);
17
- const param = useContext(paramContext);
18
16
  const rules = [];
19
17
  if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
20
18
  rules.push(defaultTo(props.default));
21
19
  }
22
- rules.push(param ? val => val === 'true' || (val === 'false' ? false : Boolean(val)) : Boolean);
20
+ rules.push(val => val === 'true' || (val === 'false' ? false : Boolean(val)));
23
21
  if ((props === null || props === void 0 ? void 0 : props.default) === undefined) {
24
22
  const parentRule = useParentRule();
25
23
  useRule(parentRule(pipe(...rules)));
@@ -8,7 +8,6 @@ require('../../../hooks/useParentRule/index.js');
8
8
  require('../../../utils/index.js');
9
9
  var useBlock = require('../../../hooks/useBlock/useBlock.js');
10
10
  var useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
11
- var useParam = require('../../../hooks/useParam/useParam.js');
12
11
  var defaultTo = require('../../../utils/rules/defaultTo/defaultTo.js');
13
12
  var useParentRule = require('../../../hooks/useParentRule/useParentRule.js');
14
13
  var useRule = require('../../../hooks/useRule/useRule.js');
@@ -18,12 +17,11 @@ const boolean = () => {
18
17
  useBlock.useBlock('path');
19
18
  const props = jsx.useProps();
20
19
  useSchemaType.useSchemaType('boolean', props);
21
- const param = jsx.useContext(useParam.paramContext);
22
20
  const rules = [];
23
21
  if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
24
22
  rules.push(defaultTo.defaultTo(props.default));
25
23
  }
26
- rules.push(param ? val => val === 'true' || (val === 'false' ? false : Boolean(val)) : Boolean);
24
+ rules.push(val => val === 'true' || (val === 'false' ? false : Boolean(val)));
27
25
  if ((props === null || props === void 0 ? void 0 : props.default) === undefined) {
28
26
  const parentRule = useParentRule.useParentRule();
29
27
  useRule.useRule(parentRule(pipe.pipe(...rules)));
@@ -1,6 +1,5 @@
1
1
  import { type HandlerPlugin } from 'innet';
2
- import { type Config } from 'dtsgenerator/dist/core/config';
3
- export interface DtsProps extends Partial<Config> {
2
+ export interface DtsProps {
4
3
  path: string;
5
4
  }
6
5
  export declare const dts: HandlerPlugin;
@@ -1,34 +1,15 @@
1
- import { __rest, __awaiter } from 'tslib';
2
1
  import { useProps } from '@innet/jsx';
3
- import dtsGenerator, { parseSchema } from 'dtsgenerator';
4
- import fs from 'node:fs';
2
+ import { promises } from 'node:fs';
5
3
  import '../../../hooks/index.es6.js';
4
+ import '../../../utils/index.es6.js';
6
5
  import { useApi } from '../../../hooks/useApi/useApi.es6.js';
6
+ import { generateTypes } from '../../../utils/generateTypes/generateTypes.es6.js';
7
7
 
8
8
  const dts = () => {
9
- const _a = useProps(), { path } = _a, config = __rest(_a, ["path"]);
9
+ const { path } = useProps();
10
10
  const { docs } = useApi();
11
- dtsGenerator({
12
- contents: [parseSchema(JSON.parse(JSON.stringify(docs)))],
13
- config,
14
- }).then((content) => __awaiter(void 0, void 0, void 0, function* () {
15
- yield fs.promises.writeFile(path, `interface Bin {
16
- filename: string
17
- fieldName: string
18
- originalFilename: string
19
- path: string
20
- type: string
21
- disposition: string
22
- size: number
23
- extension?: string
24
- }
25
- ${content
26
- .replaceAll(';', '')
27
- .replaceAll('number // int64', 'bigint')
28
- .replaceAll('string // binary', 'Bin')
29
- .replaceAll('string // date-time', 'Date')}`);
30
- })).catch(error => {
31
- console.warn(error);
11
+ promises.writeFile(path, generateTypes(docs)).catch(e => {
12
+ console.error(e);
32
13
  });
33
14
  };
34
15
 
@@ -2,42 +2,18 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib = require('tslib');
6
5
  var jsx = require('@innet/jsx');
7
- var dtsGenerator = require('dtsgenerator');
8
6
  var fs = require('node:fs');
9
7
  require('../../../hooks/index.js');
8
+ require('../../../utils/index.js');
10
9
  var useApi = require('../../../hooks/useApi/useApi.js');
11
-
12
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
-
14
- var dtsGenerator__default = /*#__PURE__*/_interopDefaultLegacy(dtsGenerator);
15
- var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
10
+ var generateTypes = require('../../../utils/generateTypes/generateTypes.js');
16
11
 
17
12
  const dts = () => {
18
- const _a = jsx.useProps(), { path } = _a, config = tslib.__rest(_a, ["path"]);
13
+ const { path } = jsx.useProps();
19
14
  const { docs } = useApi.useApi();
20
- dtsGenerator__default["default"]({
21
- contents: [dtsGenerator.parseSchema(JSON.parse(JSON.stringify(docs)))],
22
- config,
23
- }).then((content) => tslib.__awaiter(void 0, void 0, void 0, function* () {
24
- yield fs__default["default"].promises.writeFile(path, `interface Bin {
25
- filename: string
26
- fieldName: string
27
- originalFilename: string
28
- path: string
29
- type: string
30
- disposition: string
31
- size: number
32
- extension?: string
33
- }
34
- ${content
35
- .replaceAll(';', '')
36
- .replaceAll('number // int64', 'bigint')
37
- .replaceAll('string // binary', 'Bin')
38
- .replaceAll('string // date-time', 'Date')}`);
39
- })).catch(error => {
40
- console.warn(error);
15
+ fs.promises.writeFile(path, generateTypes.generateTypes(docs)).catch(e => {
16
+ console.error(e);
41
17
  });
42
18
  };
43
19
 
@@ -2,3 +2,4 @@ export * from './swagger';
2
2
  export * from './dts';
3
3
  export * from './dev';
4
4
  export * from './prod';
5
+ export * from './protection';
@@ -2,3 +2,4 @@ import './swagger/index.es6.js';
2
2
  import './dts/index.es6.js';
3
3
  import './dev/index.es6.js';
4
4
  import './prod/index.es6.js';
5
+ import './protection/index.es6.js';
@@ -4,4 +4,5 @@ require('./swagger/index.js');
4
4
  require('./dts/index.js');
5
5
  require('./dev/index.js');
6
6
  require('./prod/index.js');
7
+ require('./protection/index.js');
7
8
 
@@ -0,0 +1 @@
1
+ export * from './protection';
@@ -0,0 +1 @@
1
+ export { protection } from './protection.es6.js';
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var protection = require('./protection.js');
6
+
7
+
8
+
9
+ exports.protection = protection.protection;
@@ -0,0 +1,8 @@
1
+ export interface ProtectionProps {
2
+ value?: string;
3
+ maxAge?: number;
4
+ excludeIp?: string | string[];
5
+ cookieKey?: string;
6
+ searchKey?: string;
7
+ }
8
+ export declare function protection(): void;