@innet/server 2.0.0-alpha.15 → 2.0.0-alpha.17

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 (38) hide show
  1. package/README.md +14 -12
  2. package/hooks/index.d.ts +1 -0
  3. package/hooks/index.es6.js +1 -0
  4. package/hooks/index.js +1 -0
  5. package/hooks/useObjectSchemaContext/index.d.ts +1 -0
  6. package/hooks/useObjectSchemaContext/index.es6.js +1 -0
  7. package/hooks/useObjectSchemaContext/index.js +10 -0
  8. package/hooks/useObjectSchemaContext/useObjectSchemaContext.d.ts +3 -0
  9. package/hooks/useObjectSchemaContext/useObjectSchemaContext.es6.js +14 -0
  10. package/hooks/useObjectSchemaContext/useObjectSchemaContext.js +19 -0
  11. package/index.es6.js +1 -0
  12. package/index.js +3 -0
  13. package/package.json +1 -1
  14. package/plugins/main/server/server.es6.js +2 -2
  15. package/plugins/main/server/server.js +2 -2
  16. package/plugins/main/tag/tag.es6.js +4 -1
  17. package/plugins/main/tag/tag.js +4 -1
  18. package/plugins/request/proxy/proxy.es6.js +1 -1
  19. package/plugins/request/proxy/proxy.js +1 -1
  20. package/plugins/schema/field/field.es6.js +3 -5
  21. package/plugins/schema/field/field.js +2 -4
  22. package/plugins/schema/object/object.es6.js +11 -4
  23. package/plugins/schema/object/object.js +11 -4
  24. package/plugins/utils/blacklist/blacklist.es6.js +1 -1
  25. package/plugins/utils/blacklist/blacklist.js +1 -1
  26. package/plugins/utils/dts/dts.es6.js +1 -1
  27. package/plugins/utils/dts/dts.js +1 -1
  28. package/plugins/utils/protection/protection.es6.js +1 -1
  29. package/plugins/utils/protection/protection.js +1 -1
  30. package/plugins/utils/swagger/swagger.es6.js +1 -1
  31. package/plugins/utils/swagger/swagger.js +1 -1
  32. package/plugins/utils/whitelist/whitelist.es6.js +1 -1
  33. package/plugins/utils/whitelist/whitelist.js +1 -1
  34. package/utils/generateTypes/generateTypes.es6.js +3 -0
  35. package/utils/generateTypes/generateTypes.js +3 -0
  36. package/utils/rules/objectOf/objectOf.d.ts +1 -1
  37. package/utils/rules/objectOf/objectOf.es6.js +11 -1
  38. package/utils/rules/objectOf/objectOf.js +11 -1
package/README.md CHANGED
@@ -160,8 +160,8 @@ export default (
160
160
  ```
161
161
 
162
162
  - By default, it uses port `80` for `http` and port `442` for `https`.
163
- - You can use `PORT` environment variable to set it up on CI level.
164
- - [innetjs](https://www.npmjs.com/package/innetjs) allows you to use `PORT` in `.env` file of local environment.
163
+ - You can use `INNET_PORT` environment variable to set it up on CI level.
164
+ - [innetjs](https://www.npmjs.com/package/innetjs) allows you to use `INNET_PORT` in `.env` file of local environment.
165
165
 
166
166
  #### ssl
167
167
 
@@ -179,8 +179,8 @@ export default (
179
179
  )
180
180
  ```
181
181
 
182
- - You can use `SSL_KEY` and `SSL_CRT` environment variables to set it up on CI level.
183
- - [innetjs](https://www.npmjs.com/package/innetjs) allows you to use `SSL_KEY` and `SSL_CRT` in `.env` file.
182
+ - You can use `INNET_SSL_KEY` and `INNET_SSL_CRT` environment variables to set it up on CI level.
183
+ - [innetjs](https://www.npmjs.com/package/innetjs) allows you to use `INNET_SSL_KEY` and `INNET_SSL_CRT` in `.env` file.
184
184
  - You can add `localhost.key` and `localhost.crt` files in your project folder.
185
185
 
186
186
  #### onStart
@@ -685,7 +685,7 @@ export default (
685
685
 
686
686
  #### ip
687
687
 
688
- `ip` prop sets black IPs. By default, it equals `BLACKLIST_IP` node environment variable.
688
+ `ip` prop sets black IPs. By default, it equals `INNET_BLACKLIST_IP` node environment variable.
689
689
 
690
690
  You can split IPs by `,` char.
691
691
 
@@ -726,7 +726,7 @@ export default (
726
726
 
727
727
  #### ip
728
728
 
729
- `ip` prop sets white IPs. By default, it equals `WHITELIST_IP` node environment variable.
729
+ `ip` prop sets white IPs. By default, it equals `INNET_WHITELIST_IP` node environment variable.
730
730
 
731
731
  You can split IPs by `,` char.
732
732
 
@@ -800,7 +800,7 @@ export default (
800
800
  This prop sets how much time protection is qualified.
801
801
 
802
802
  By default, the prop equals a year.
803
- You can use `PROTECTION_MAX_AGE` env to set default `maxAge`.
803
+ You can use `INNET_PROTECTION_MAX_AGE` env to set default `maxAge`.
804
804
 
805
805
  *src/app.tsx*
806
806
  ```typescript jsx
@@ -824,7 +824,7 @@ export default (
824
824
 
825
825
  This prop sets a list of IP addresses (split by `,`) to ignore the protection.
826
826
 
827
- You can use `PROTECTED_IP` env to set default `excludeIp`.
827
+ You can use `INNET_PROTECTED_IP` env to set default `excludeIp`.
828
828
 
829
829
  *src/app.tsx*
830
830
  ```typescript jsx
@@ -849,7 +849,7 @@ export default (
849
849
  This prop sets a cookie field name used to store protection of a user.
850
850
 
851
851
  By default, it equals `protection`.
852
- You can use `PROTECTION_COOKIE_KEY` env to set default `cookieKey`.
852
+ You can use `INNET_PROTECTION_COOKIE_KEY` env to set default `cookieKey`.
853
853
 
854
854
  *src/app.tsx*
855
855
  ```typescript jsx
@@ -874,7 +874,7 @@ export default (
874
874
  This prop sets a search query field name used to check protection.
875
875
 
876
876
  By default, it equals `protection`.
877
- You can use `PROTECTION_SEARCH_KEY` env to set default `searchKey`.
877
+ You can use `INNET_PROTECTION_SEARCH_KEY` env to set default `searchKey`.
878
878
 
879
879
  *src/app.tsx*
880
880
  ```typescript jsx
@@ -2908,7 +2908,9 @@ export default (
2908
2908
  <api>
2909
2909
  <endpoint method='post' path='/users'>
2910
2910
  <body>
2911
- <object />
2911
+ <object>
2912
+ <string />
2913
+ </object>
2912
2914
  </body>
2913
2915
  </endpoint>
2914
2916
  </api>
@@ -2987,7 +2989,7 @@ The element MUST be placed inside [\<object>](#object).
2987
2989
  It defines a `field` of an `object` value for a parent element.
2988
2990
  `@innet/server` formats and validate the value automatically (real-time).
2989
2991
 
2990
- `key` is REQUIRED prop of `<field>`, it defines a field name of the `<object>`.
2992
+ `key` is REQUIRED prop of `<field>`, it defines a field name of the [\<object>](#object).
2991
2993
 
2992
2994
  *src/app.tsx*
2993
2995
  ```typescript jsx
package/hooks/index.d.ts CHANGED
@@ -26,3 +26,4 @@ export * from './usePath';
26
26
  export * from './useServerPlugin';
27
27
  export * from './useClientIp';
28
28
  export * from './useServerPlugins';
29
+ export * from './useObjectSchemaContext';
@@ -26,3 +26,4 @@ import './usePath/index.es6.js';
26
26
  import './useServerPlugin/index.es6.js';
27
27
  import './useClientIp/index.es6.js';
28
28
  import './useServerPlugins/index.es6.js';
29
+ import './useObjectSchemaContext/index.es6.js';
package/hooks/index.js CHANGED
@@ -28,4 +28,5 @@ require('./usePath/index.js');
28
28
  require('./useServerPlugin/index.js');
29
29
  require('./useClientIp/index.js');
30
30
  require('./useServerPlugins/index.js');
31
+ require('./useObjectSchemaContext/index.js');
31
32
 
@@ -0,0 +1 @@
1
+ export * from './useObjectSchemaContext';
@@ -0,0 +1 @@
1
+ export { objectSchemaContext, useObjectSchemaContext } from './useObjectSchemaContext.es6.js';
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var useObjectSchemaContext = require('./useObjectSchemaContext.js');
6
+
7
+
8
+
9
+ exports.objectSchemaContext = useObjectSchemaContext.objectSchemaContext;
10
+ exports.useObjectSchemaContext = useObjectSchemaContext.useObjectSchemaContext;
@@ -0,0 +1,3 @@
1
+ import { Context } from '@innet/jsx';
2
+ export declare const objectSchemaContext: Context<import("openapi-types").OpenAPIV3_1.SchemaObject, import("openapi-types").OpenAPIV3_1.SchemaObject | undefined>;
3
+ export declare function useObjectSchemaContext(): import("openapi-types").OpenAPIV3_1.SchemaObject;
@@ -0,0 +1,14 @@
1
+ import { Context, useContext } from '@innet/jsx';
2
+ import '../useThrow/index.es6.js';
3
+ import { useThrow } from '../useThrow/useThrow.es6.js';
4
+
5
+ const objectSchemaContext = new Context();
6
+ function useObjectSchemaContext() {
7
+ const schema = useContext(objectSchemaContext);
8
+ if (!schema) {
9
+ useThrow('Use <{type}> in <object>');
10
+ }
11
+ return schema;
12
+ }
13
+
14
+ export { objectSchemaContext, useObjectSchemaContext };
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsx = require('@innet/jsx');
6
+ require('../useThrow/index.js');
7
+ var useThrow = require('../useThrow/useThrow.js');
8
+
9
+ const objectSchemaContext = new jsx.Context();
10
+ function useObjectSchemaContext() {
11
+ const schema = jsx.useContext(objectSchemaContext);
12
+ if (!schema) {
13
+ useThrow.useThrow('Use <{type}> in <object>');
14
+ }
15
+ return schema;
16
+ }
17
+
18
+ exports.objectSchemaContext = objectSchemaContext;
19
+ exports.useObjectSchemaContext = useObjectSchemaContext;
package/index.es6.js CHANGED
@@ -113,3 +113,4 @@ export { usePath } from './hooks/usePath/usePath.es6.js';
113
113
  export { useServerPlugin } from './hooks/useServerPlugin/useServerPlugin.es6.js';
114
114
  export { useClientIp } from './hooks/useClientIp/useClientIp.es6.js';
115
115
  export { serverPlugins, useServerPlugins } from './hooks/useServerPlugins/useServerPlugins.es6.js';
116
+ export { objectSchemaContext, useObjectSchemaContext } from './hooks/useObjectSchemaContext/useObjectSchemaContext.es6.js';
package/index.js CHANGED
@@ -117,6 +117,7 @@ var usePath = require('./hooks/usePath/usePath.js');
117
117
  var useServerPlugin = require('./hooks/useServerPlugin/useServerPlugin.js');
118
118
  var useClientIp = require('./hooks/useClientIp/useClientIp.js');
119
119
  var useServerPlugins = require('./hooks/useServerPlugins/useServerPlugins.js');
120
+ var useObjectSchemaContext = require('./hooks/useObjectSchemaContext/useObjectSchemaContext.js');
120
121
 
121
122
 
122
123
 
@@ -258,3 +259,5 @@ exports.useServerPlugin = useServerPlugin.useServerPlugin;
258
259
  exports.useClientIp = useClientIp.useClientIp;
259
260
  exports.serverPlugins = useServerPlugins.serverPlugins;
260
261
  exports.useServerPlugins = useServerPlugins.useServerPlugins;
262
+ exports.objectSchemaContext = useObjectSchemaContext.objectSchemaContext;
263
+ exports.useObjectSchemaContext = useObjectSchemaContext.useObjectSchemaContext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innet/server",
3
- "version": "2.0.0-alpha.15",
3
+ "version": "2.0.0-alpha.17",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -18,7 +18,7 @@ const server = () => {
18
18
  const handler = useNewHandler();
19
19
  const { props = {}, children } = useApp();
20
20
  const { env } = process;
21
- 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;
21
+ let { ssl: { key = (_a = env.INNET_SSL_KEY) !== null && _a !== void 0 ? _a : 'localhost.key', cert = (_b = env.INNET_SSL_CRT) !== null && _b !== void 0 ? _b : 'localhost.crt', } = {}, } = props;
22
22
  try {
23
23
  if (!isInvalidPath(key)) {
24
24
  key = fs.readFileSync(key).toString();
@@ -32,7 +32,7 @@ const server = () => {
32
32
  cert = '';
33
33
  }
34
34
  const https = Boolean(key && cert);
35
- const { port = Number((_c = env.PORT) !== null && _c !== void 0 ? _c : (https ? 442 : 80)), onStart, onError, onRequest, onClose, } = props;
35
+ const { port = Number((_c = env.INNET_PORT) !== null && _c !== void 0 ? _c : (https ? 442 : 80)), onStart, onError, onRequest, onClose, } = props;
36
36
  const plugins = new Set();
37
37
  const server = https ? http2.createServer({ key, cert }) : http.createServer();
38
38
  serverContext.set(handler, { server, port });
@@ -29,7 +29,7 @@ const server = () => {
29
29
  const handler = innet.useNewHandler();
30
30
  const { props = {}, children } = innet.useApp();
31
31
  const { env } = process;
32
- 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;
32
+ let { ssl: { key = (_a = env.INNET_SSL_KEY) !== null && _a !== void 0 ? _a : 'localhost.key', cert = (_b = env.INNET_SSL_CRT) !== null && _b !== void 0 ? _b : 'localhost.crt', } = {}, } = props;
33
33
  try {
34
34
  if (!isInvalidPath(key)) {
35
35
  key = fs__default["default"].readFileSync(key).toString();
@@ -43,7 +43,7 @@ const server = () => {
43
43
  cert = '';
44
44
  }
45
45
  const https = Boolean(key && cert);
46
- const { port = Number((_c = env.PORT) !== null && _c !== void 0 ? _c : (https ? 442 : 80)), onStart, onError, onRequest, onClose, } = props;
46
+ const { port = Number((_c = env.INNET_PORT) !== null && _c !== void 0 ? _c : (https ? 442 : 80)), onStart, onError, onRequest, onClose, } = props;
47
47
  const plugins = new Set();
48
48
  const server = https ? http2__default["default"].createServer({ key, cert }) : http__default["default"].createServer();
49
49
  useServer.serverContext.set(handler, { server, port });
@@ -11,7 +11,10 @@ const tag = () => {
11
11
  const { name, description } = useProps();
12
12
  const children = useChildren();
13
13
  const { docs } = useApi();
14
- const tag = description ? { name, description } : { name };
14
+ const tag = { name };
15
+ if (description) {
16
+ tag.description = description;
17
+ }
15
18
  if (!docs.tags) {
16
19
  docs.tags = [tag];
17
20
  }
@@ -19,7 +19,10 @@ const tag = () => {
19
19
  const { name, description } = jsx.useProps();
20
20
  const children = jsx.useChildren();
21
21
  const { docs } = useApi.useApi();
22
- const tag = description ? { name, description } : { name };
22
+ const tag = { name };
23
+ if (description) {
24
+ tag.description = description;
25
+ }
23
26
  if (!docs.tags) {
24
27
  docs.tags = [tag];
25
28
  }
@@ -6,7 +6,7 @@ import { useResponse } from '../../../hooks/useResponse/useResponse.es6.js';
6
6
  import { useThrow } from '../../../hooks/useThrow/useThrow.es6.js';
7
7
 
8
8
  const proxy = () => {
9
- const { to, secure, onProxyRes } = useProps();
9
+ const { to, secure = false, onProxyRes } = useProps();
10
10
  const req = useRequest();
11
11
  const res = useResponse();
12
12
  if (!req || !res) {
@@ -14,7 +14,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
14
14
  var httpProxy__default = /*#__PURE__*/_interopDefaultLegacy(httpProxy);
15
15
 
16
16
  const proxy = () => {
17
- const { to, secure, onProxyRes } = jsx.useProps();
17
+ const { to, secure = false, onProxyRes } = jsx.useProps();
18
18
  const req = useRequest.useRequest();
19
19
  const res = useResponse.useResponse();
20
20
  if (!req || !res) {
@@ -2,7 +2,8 @@ import innet, { useNewHandler } from 'innet';
2
2
  import { useProps, useChildren } from '@innet/jsx';
3
3
  import '../../../hooks/index.es6.js';
4
4
  import '../../../utils/index.es6.js';
5
- import { useSchemaContext, schemaContext } from '../../../hooks/useSchemaContext/useSchemaContext.es6.js';
5
+ import { useObjectSchemaContext } from '../../../hooks/useObjectSchemaContext/useObjectSchemaContext.es6.js';
6
+ import { schemaContext } from '../../../hooks/useSchemaContext/useSchemaContext.es6.js';
6
7
  import { useObjectRule, objectRuleContext } from '../../../hooks/useObjectRule/useObjectRule.es6.js';
7
8
  import { ruleContext } from '../../../hooks/useRule/useRule.es6.js';
8
9
  import { required } from '../../../utils/rules/required/required.es6.js';
@@ -10,11 +11,8 @@ import { required } from '../../../utils/rules/required/required.es6.js';
10
11
  const field = () => {
11
12
  const handler = useNewHandler();
12
13
  const { key, optional } = useProps();
13
- const schema = useSchemaContext();
14
+ const schema = useObjectSchemaContext();
14
15
  const children = useChildren();
15
- if (Array.isArray(schema) || (schema === null || schema === void 0 ? void 0 : schema.type) !== 'object') {
16
- throw Error('Use <field> inside <object>');
17
- }
18
16
  if (!schema.properties) {
19
17
  schema.properties = {};
20
18
  }
@@ -6,6 +6,7 @@ var innet = require('innet');
6
6
  var jsx = require('@innet/jsx');
7
7
  require('../../../hooks/index.js');
8
8
  require('../../../utils/index.js');
9
+ var useObjectSchemaContext = require('../../../hooks/useObjectSchemaContext/useObjectSchemaContext.js');
9
10
  var useSchemaContext = require('../../../hooks/useSchemaContext/useSchemaContext.js');
10
11
  var useObjectRule = require('../../../hooks/useObjectRule/useObjectRule.js');
11
12
  var useRule = require('../../../hooks/useRule/useRule.js');
@@ -18,11 +19,8 @@ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
18
19
  const field = () => {
19
20
  const handler = innet.useNewHandler();
20
21
  const { key, optional } = jsx.useProps();
21
- const schema = useSchemaContext.useSchemaContext();
22
+ const schema = useObjectSchemaContext.useObjectSchemaContext();
22
23
  const children = jsx.useChildren();
23
- if (Array.isArray(schema) || (schema === null || schema === void 0 ? void 0 : schema.type) !== 'object') {
24
- throw Error('Use <field> inside <object>');
25
- }
26
24
  if (!schema.properties) {
27
25
  schema.properties = {};
28
26
  }
@@ -6,6 +6,7 @@ import '../../../utils/index.es6.js';
6
6
  import { useBlock } from '../../../hooks/useBlock/useBlock.es6.js';
7
7
  import { useApi } from '../../../hooks/useApi/useApi.es6.js';
8
8
  import { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
9
+ import { objectSchemaContext } from '../../../hooks/useObjectSchemaContext/useObjectSchemaContext.es6.js';
9
10
  import { schemaContext } from '../../../hooks/useSchemaContext/useSchemaContext.es6.js';
10
11
  import { parentRuleContext, useParentRule } from '../../../hooks/useParentRule/useParentRule.es6.js';
11
12
  import { defaultTo } from '../../../utils/rules/defaultTo/defaultTo.es6.js';
@@ -22,19 +23,23 @@ const object = () => {
22
23
  const schema = useSchemaType('object', props);
23
24
  const handler = useNewHandler();
24
25
  if (schema) {
25
- schemaContext.set(handler, schema);
26
+ schema.additionalProperties = {};
27
+ objectSchemaContext.set(handler, schema);
28
+ schemaContext.set(handler, schema.additionalProperties);
26
29
  parentRuleContext.reset(handler);
27
30
  const rules = [];
28
31
  const rulesMap = {};
29
32
  if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
30
33
  rules.push(defaultTo(props.default));
31
34
  }
35
+ let childRule = v => v;
36
+ const restRule = (value, data) => childRule(value, data);
32
37
  if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
33
- rules.push(objectOf(rulesMap));
38
+ rules.push(objectOf(rulesMap, restRule));
34
39
  }
35
40
  else {
36
41
  const parentRule = useParentRule();
37
- rules.push(parentRule(objectOf(rulesMap)));
42
+ rules.push(parentRule(objectOf(rulesMap, restRule)));
38
43
  }
39
44
  const rule = pipe(...rules);
40
45
  if (props.ref) {
@@ -42,7 +47,9 @@ const object = () => {
42
47
  }
43
48
  useRule(rule);
44
49
  objectRuleContext.set(handler, rulesMap);
45
- ruleContext.set(handler, null);
50
+ ruleContext.set(handler, rule => {
51
+ childRule = rule;
52
+ });
46
53
  parentRuleContext.reset(handler);
47
54
  innet(children, handler);
48
55
  }
@@ -10,6 +10,7 @@ require('../../../utils/index.js');
10
10
  var useBlock = require('../../../hooks/useBlock/useBlock.js');
11
11
  var useApi = require('../../../hooks/useApi/useApi.js');
12
12
  var useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
13
+ var useObjectSchemaContext = require('../../../hooks/useObjectSchemaContext/useObjectSchemaContext.js');
13
14
  var useSchemaContext = require('../../../hooks/useSchemaContext/useSchemaContext.js');
14
15
  var useParentRule = require('../../../hooks/useParentRule/useParentRule.js');
15
16
  var defaultTo = require('../../../utils/rules/defaultTo/defaultTo.js');
@@ -30,19 +31,23 @@ const object = () => {
30
31
  const schema = useSchemaType.useSchemaType('object', props);
31
32
  const handler = innet.useNewHandler();
32
33
  if (schema) {
33
- useSchemaContext.schemaContext.set(handler, schema);
34
+ schema.additionalProperties = {};
35
+ useObjectSchemaContext.objectSchemaContext.set(handler, schema);
36
+ useSchemaContext.schemaContext.set(handler, schema.additionalProperties);
34
37
  useParentRule.parentRuleContext.reset(handler);
35
38
  const rules = [];
36
39
  const rulesMap = {};
37
40
  if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
38
41
  rules.push(defaultTo.defaultTo(props.default));
39
42
  }
43
+ let childRule = v => v;
44
+ const restRule = (value, data) => childRule(value, data);
40
45
  if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
41
- rules.push(objectOf.objectOf(rulesMap));
46
+ rules.push(objectOf.objectOf(rulesMap, restRule));
42
47
  }
43
48
  else {
44
49
  const parentRule = useParentRule.useParentRule();
45
- rules.push(parentRule(objectOf.objectOf(rulesMap)));
50
+ rules.push(parentRule(objectOf.objectOf(rulesMap, restRule)));
46
51
  }
47
52
  const rule = pipe.pipe(...rules);
48
53
  if (props.ref) {
@@ -50,7 +55,9 @@ const object = () => {
50
55
  }
51
56
  useRule.useRule(rule);
52
57
  useObjectRule.objectRuleContext.set(handler, rulesMap);
53
- useRule.ruleContext.set(handler, null);
58
+ useRule.ruleContext.set(handler, rule => {
59
+ childRule = rule;
60
+ });
54
61
  useParentRule.parentRuleContext.reset(handler);
55
62
  innet__default["default"](children, handler);
56
63
  }
@@ -4,7 +4,7 @@ import { useServerPlugin } from '../../../hooks/useServerPlugin/useServerPlugin.
4
4
  import { useAction } from '../../../hooks/useAction/useAction.es6.js';
5
5
 
6
6
  function blacklist() {
7
- const { ip = process.env.BLACKLIST_IP, } = useProps() || {};
7
+ const { ip = process.env.INNET_BLACKLIST_IP, } = useProps() || {};
8
8
  const children = useChildren();
9
9
  const ips = typeof ip === 'string' ? ip.split(',') : ip;
10
10
  useServerPlugin(() => {
@@ -8,7 +8,7 @@ var useServerPlugin = require('../../../hooks/useServerPlugin/useServerPlugin.js
8
8
  var useAction = require('../../../hooks/useAction/useAction.js');
9
9
 
10
10
  function blacklist() {
11
- const { ip = process.env.BLACKLIST_IP, } = jsx.useProps() || {};
11
+ const { ip = process.env.INNET_BLACKLIST_IP, } = jsx.useProps() || {};
12
12
  const children = jsx.useChildren();
13
13
  const ips = typeof ip === 'string' ? ip.split(',') : ip;
14
14
  useServerPlugin.useServerPlugin(() => {
@@ -6,7 +6,7 @@ import { useApi } from '../../../hooks/useApi/useApi.es6.js';
6
6
  import { generateTypes } from '../../../utils/generateTypes/generateTypes.es6.js';
7
7
 
8
8
  const dts = () => {
9
- const { path = 'src/api.d.ts', namespace } = useProps() || {};
9
+ const { path = process.env.INNET_DTS_PATH || 'src/apiTypes.d.ts', namespace = process.env.INNET_DTS_NAMESPACE, } = useProps() || {};
10
10
  const { docs } = useApi();
11
11
  promises.writeFile(path, generateTypes(docs, namespace)).catch(e => {
12
12
  console.error(e);
@@ -10,7 +10,7 @@ var useApi = require('../../../hooks/useApi/useApi.js');
10
10
  var generateTypes = require('../../../utils/generateTypes/generateTypes.js');
11
11
 
12
12
  const dts = () => {
13
- const { path = 'src/api.d.ts', namespace } = jsx.useProps() || {};
13
+ const { path = process.env.INNET_DTS_PATH || 'src/apiTypes.d.ts', namespace = process.env.INNET_DTS_NAMESPACE, } = jsx.useProps() || {};
14
14
  const { docs } = useApi.useApi();
15
15
  fs.promises.writeFile(path, generateTypes.generateTypes(docs, namespace)).catch(e => {
16
16
  console.error(e);
@@ -4,7 +4,7 @@ import { useServerPlugin } from '../../../hooks/useServerPlugin/useServerPlugin.
4
4
  import { useAction } from '../../../hooks/useAction/useAction.es6.js';
5
5
 
6
6
  function protection() {
7
- const { maxAge = Number(process.env.PROTECTION_MAX_AGE) || 365 * 24 * 60 * 60, value = process.env.PROTECTION, excludeIp = process.env.PROTECTED_IP, cookieKey = process.env.PROTECTION_COOKIE_KEY || 'protection', searchKey = process.env.PROTECTION_SEARCH_KEY || 'protection', } = useProps() || {};
7
+ const { maxAge = Number(process.env.INNET_PROTECTION_MAX_AGE) || 365 * 24 * 60 * 60, value = process.env.INNET_PROTECTION, excludeIp = process.env.INNET_PROTECTED_IP, cookieKey = process.env.INNET_PROTECTION_COOKIE_KEY || 'protection', searchKey = process.env.INNET_PROTECTION_SEARCH_KEY || 'protection', } = useProps() || {};
8
8
  const children = useChildren();
9
9
  if (!value)
10
10
  return;
@@ -8,7 +8,7 @@ var useServerPlugin = require('../../../hooks/useServerPlugin/useServerPlugin.js
8
8
  var useAction = require('../../../hooks/useAction/useAction.js');
9
9
 
10
10
  function protection() {
11
- const { maxAge = Number(process.env.PROTECTION_MAX_AGE) || 365 * 24 * 60 * 60, value = process.env.PROTECTION, excludeIp = process.env.PROTECTED_IP, cookieKey = process.env.PROTECTION_COOKIE_KEY || 'protection', searchKey = process.env.PROTECTION_SEARCH_KEY || 'protection', } = jsx.useProps() || {};
11
+ const { maxAge = Number(process.env.INNET_PROTECTION_MAX_AGE) || 365 * 24 * 60 * 60, value = process.env.INNET_PROTECTION, excludeIp = process.env.INNET_PROTECTED_IP, cookieKey = process.env.INNET_PROTECTION_COOKIE_KEY || 'protection', searchKey = process.env.INNET_PROTECTION_SEARCH_KEY || 'protection', } = jsx.useProps() || {};
12
12
  const children = jsx.useChildren();
13
13
  if (!value)
14
14
  return;
@@ -6,7 +6,7 @@ import { useServerPlugin } from '../../../hooks/useServerPlugin/useServerPlugin.
6
6
  import { useAction } from '../../../hooks/useAction/useAction.es6.js';
7
7
 
8
8
  const swagger = () => {
9
- const { path = '/swagger-ui' } = useProps() || {};
9
+ const { path = process.env.INNET_SWAGGER_PATH || '/swagger-ui', } = useProps() || {};
10
10
  const { docs, prefix } = useApi();
11
11
  let swaggerResponse;
12
12
  useServerPlugin(() => {
@@ -10,7 +10,7 @@ var useServerPlugin = require('../../../hooks/useServerPlugin/useServerPlugin.js
10
10
  var useAction = require('../../../hooks/useAction/useAction.js');
11
11
 
12
12
  const swagger = () => {
13
- const { path = '/swagger-ui' } = jsx.useProps() || {};
13
+ const { path = process.env.INNET_SWAGGER_PATH || '/swagger-ui', } = jsx.useProps() || {};
14
14
  const { docs, prefix } = useApi.useApi();
15
15
  let swaggerResponse;
16
16
  useServerPlugin.useServerPlugin(() => {
@@ -4,7 +4,7 @@ import { useServerPlugin } from '../../../hooks/useServerPlugin/useServerPlugin.
4
4
  import { useAction } from '../../../hooks/useAction/useAction.es6.js';
5
5
 
6
6
  function whitelist() {
7
- const { ip = process.env.WHITELIST_IP, } = useProps() || {};
7
+ const { ip = process.env.INNET_WHITELIST_IP, } = useProps() || {};
8
8
  const children = useChildren();
9
9
  const ips = typeof ip === 'string' ? ip.split(',') : ip;
10
10
  if (!ips)
@@ -8,7 +8,7 @@ var useServerPlugin = require('../../../hooks/useServerPlugin/useServerPlugin.js
8
8
  var useAction = require('../../../hooks/useAction/useAction.js');
9
9
 
10
10
  function whitelist() {
11
- const { ip = process.env.WHITELIST_IP, } = jsx.useProps() || {};
11
+ const { ip = process.env.INNET_WHITELIST_IP, } = jsx.useProps() || {};
12
12
  const children = jsx.useChildren();
13
13
  const ips = typeof ip === 'string' ? ip.split(',') : ip;
14
14
  if (!ips)
@@ -39,6 +39,9 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
39
39
  : '?:';
40
40
  result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
41
41
  }
42
+ if (typeof schema.additionalProperties === 'object' && Object.keys(schema.additionalProperties).length) {
43
+ result += `${space}[key: string]: any\n`;
44
+ }
42
45
  return `${result}${space.slice(0, -2)}}${lastChar}`;
43
46
  }
44
47
  function generateTypes(docs, namespace = 'Api') {
@@ -43,6 +43,9 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
43
43
  : '?:';
44
44
  result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
45
45
  }
46
+ if (typeof schema.additionalProperties === 'object' && Object.keys(schema.additionalProperties).length) {
47
+ result += `${space}[key: string]: any\n`;
48
+ }
46
49
  return `${result}${space.slice(0, -2)}}${lastChar}`;
47
50
  }
48
51
  function generateTypes(docs, namespace = 'Api') {
@@ -1,3 +1,3 @@
1
1
  import { type Rule } from '../types';
2
2
  export type ObjectOf = Record<string, Rule>;
3
- export declare function objectOf(map: ObjectOf): (value: any, data?: Record<string, any>) => any;
3
+ export declare function objectOf(map: ObjectOf, rest?: Rule): (value: any, data?: Record<string, any>) => any;
@@ -1,6 +1,6 @@
1
1
  import { RulesError, addKey } from '../helpers.es6.js';
2
2
 
3
- function objectOf(map) {
3
+ function objectOf(map, rest) {
4
4
  return (value, data) => {
5
5
  if (value === null || typeof value !== 'object') {
6
6
  throw new RulesError('object', Object.assign({ value }, data));
@@ -12,6 +12,16 @@ function objectOf(map) {
12
12
  result[key] = val;
13
13
  }
14
14
  }
15
+ if (rest) {
16
+ for (const key in value) {
17
+ if (key in map)
18
+ continue;
19
+ const val = rest(value[key], Object.assign(Object.assign({}, data), { key: addKey(key, data) }));
20
+ if (val !== undefined) {
21
+ result[key] = val;
22
+ }
23
+ }
24
+ }
15
25
  return result;
16
26
  };
17
27
  }
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var helpers = require('../helpers.js');
6
6
 
7
- function objectOf(map) {
7
+ function objectOf(map, rest) {
8
8
  return (value, data) => {
9
9
  if (value === null || typeof value !== 'object') {
10
10
  throw new helpers.RulesError('object', Object.assign({ value }, data));
@@ -16,6 +16,16 @@ function objectOf(map) {
16
16
  result[key] = val;
17
17
  }
18
18
  }
19
+ if (rest) {
20
+ for (const key in value) {
21
+ if (key in map)
22
+ continue;
23
+ const val = rest(value[key], Object.assign(Object.assign({}, data), { key: helpers.addKey(key, data) }));
24
+ if (val !== undefined) {
25
+ result[key] = val;
26
+ }
27
+ }
28
+ }
19
29
  return result;
20
30
  };
21
31
  }