@innet/server 2.0.0-alpha.16 → 2.0.0-alpha.18
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.
- package/README.md +18 -15
- package/hooks/index.d.ts +1 -0
- package/hooks/index.es6.js +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useObjectSchemaContext/index.d.ts +1 -0
- package/hooks/useObjectSchemaContext/index.es6.js +1 -0
- package/hooks/useObjectSchemaContext/index.js +10 -0
- package/hooks/useObjectSchemaContext/useObjectSchemaContext.d.ts +3 -0
- package/hooks/useObjectSchemaContext/useObjectSchemaContext.es6.js +14 -0
- package/hooks/useObjectSchemaContext/useObjectSchemaContext.js +19 -0
- package/index.es6.js +1 -0
- package/index.js +3 -0
- package/package.json +1 -1
- package/plugins/main/api/api.es6.js +7 -8
- package/plugins/main/api/api.js +7 -8
- package/plugins/main/server/server.es6.js +2 -2
- package/plugins/main/server/server.js +2 -2
- package/plugins/main/tag/tag.es6.js +4 -1
- package/plugins/main/tag/tag.js +4 -1
- package/plugins/request/cms/cms.es6.js +1 -1
- package/plugins/request/cms/cms.js +1 -1
- package/plugins/schema/field/field.es6.js +3 -5
- package/plugins/schema/field/field.js +2 -4
- package/plugins/schema/object/object.es6.js +11 -4
- package/plugins/schema/object/object.js +11 -4
- package/plugins/utils/blacklist/blacklist.es6.js +1 -1
- package/plugins/utils/blacklist/blacklist.js +1 -1
- package/plugins/utils/dts/dts.es6.js +1 -1
- package/plugins/utils/dts/dts.js +1 -1
- package/plugins/utils/protection/protection.es6.js +1 -1
- package/plugins/utils/protection/protection.js +1 -1
- package/plugins/utils/swagger/swagger.es6.js +1 -1
- package/plugins/utils/swagger/swagger.js +1 -1
- package/plugins/utils/whitelist/whitelist.es6.js +1 -1
- package/plugins/utils/whitelist/whitelist.js +1 -1
- package/utils/generateTypes/generateTypes.es6.js +27 -6
- package/utils/generateTypes/generateTypes.js +27 -6
- package/utils/rules/objectOf/objectOf.d.ts +1 -1
- package/utils/rules/objectOf/objectOf.es6.js +11 -1
- 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 `
|
|
164
|
-
- [innetjs](https://www.npmjs.com/package/innetjs) allows you to use `
|
|
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 `
|
|
183
|
-
- [innetjs](https://www.npmjs.com/package/innetjs) allows you to use `
|
|
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
|
|
@@ -247,8 +247,8 @@ export default (
|
|
|
247
247
|
|
|
248
248
|
[← back](#main)
|
|
249
249
|
|
|
250
|
-
`<api>` element MUST be placed in `<server>` element.
|
|
251
250
|
This element defines a REST API on the server.
|
|
251
|
+
This element MUST be placed in [\<server>](#server) element.
|
|
252
252
|
|
|
253
253
|
#### title
|
|
254
254
|
|
|
@@ -329,7 +329,7 @@ export default (
|
|
|
329
329
|
)
|
|
330
330
|
```
|
|
331
331
|
|
|
332
|
-
*default: 0.0.0
|
|
332
|
+
*default: `INNET_API_VERSION` || `'0.0.0'`*
|
|
333
333
|
|
|
334
334
|
#### prefix
|
|
335
335
|
|
|
@@ -685,7 +685,7 @@ export default (
|
|
|
685
685
|
|
|
686
686
|
#### ip
|
|
687
687
|
|
|
688
|
-
`ip` prop sets black IPs. By default, it equals `
|
|
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 `
|
|
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 `
|
|
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 `
|
|
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 `
|
|
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 `
|
|
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
|
|
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
|
|
@@ -3378,7 +3380,7 @@ export default (
|
|
|
3378
3380
|
|
|
3379
3381
|
#### dir
|
|
3380
3382
|
|
|
3381
|
-
By default, it
|
|
3383
|
+
By default, it equals `INNET_CMS_DIR` node env variable or the project folder.
|
|
3382
3384
|
If you try the previous example on [http://localhost/package.json](http://localhost/package.json)
|
|
3383
3385
|
you get the project `package.json` file.
|
|
3384
3386
|
|
|
@@ -3401,6 +3403,7 @@ you get the index file in `src` folder.
|
|
|
3401
3403
|
#### prefix
|
|
3402
3404
|
|
|
3403
3405
|
`<cms>` matches full `path`, you should take it into account if you add `prefix` on `<api>`.
|
|
3406
|
+
By default, it equals `INNET_CMS_PREFIX` node env variable or `/`.
|
|
3404
3407
|
|
|
3405
3408
|
*src/app.tsx*
|
|
3406
3409
|
```typescript jsx
|
package/hooks/index.d.ts
CHANGED
package/hooks/index.es6.js
CHANGED
package/hooks/index.js
CHANGED
|
@@ -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
|
@@ -12,11 +12,10 @@ import { RulesError } from '../../../utils/rules/helpers.es6.js';
|
|
|
12
12
|
import { paramsContext } from '../../../hooks/useParams/useParams.es6.js';
|
|
13
13
|
|
|
14
14
|
const api = () => {
|
|
15
|
-
var _a;
|
|
16
15
|
const handler = useNewHandler();
|
|
17
16
|
const { props = {}, children } = useApp();
|
|
18
|
-
const { prefix = '', title = '', include, exclude } = props, rest = __rest(props, ["prefix", "title", "include", "exclude"]);
|
|
19
|
-
const info = Object.assign(Object.assign({}, rest), { version
|
|
17
|
+
const { prefix = '', title = '', include, exclude, version = process.env.INNET_API_VERSION || '0.0.0' } = props, rest = __rest(props, ["prefix", "title", "include", "exclude", "version"]);
|
|
18
|
+
const info = Object.assign(Object.assign({}, rest), { version, title });
|
|
20
19
|
const endpoints = {};
|
|
21
20
|
const docs = {
|
|
22
21
|
openapi: '3.1.0',
|
|
@@ -39,7 +38,7 @@ const api = () => {
|
|
|
39
38
|
serverPlugins.set(handler, plugins);
|
|
40
39
|
apiContext.set(handler, context);
|
|
41
40
|
useServerPlugin(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
var _b, _c, _d, _e, _f
|
|
41
|
+
var _a, _b, _c, _d, _e, _f;
|
|
43
42
|
const action = useAction();
|
|
44
43
|
if (!condition(action))
|
|
45
44
|
return;
|
|
@@ -53,7 +52,7 @@ const api = () => {
|
|
|
53
52
|
res.end();
|
|
54
53
|
return null;
|
|
55
54
|
}
|
|
56
|
-
const method = ((
|
|
55
|
+
const method = ((_b = (_a = req.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : 'get');
|
|
57
56
|
const rawSplitPath = url.slice(prefix.length).split('/').slice(1);
|
|
58
57
|
const splitPath = rawSplitPath.at(-1) ? rawSplitPath : rawSplitPath.slice(0, -1);
|
|
59
58
|
const endpoint = endpoints[method];
|
|
@@ -138,8 +137,8 @@ const api = () => {
|
|
|
138
137
|
return true;
|
|
139
138
|
});
|
|
140
139
|
}
|
|
141
|
-
if ((
|
|
142
|
-
if (!(yield run((
|
|
140
|
+
if ((_d = (_c = currentEndpoint.static) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.plugins) {
|
|
141
|
+
if (!(yield run((_e = currentEndpoint.static) === null || _e === void 0 ? void 0 : _e[key], params)))
|
|
143
142
|
continue;
|
|
144
143
|
return null;
|
|
145
144
|
}
|
|
@@ -154,7 +153,7 @@ const api = () => {
|
|
|
154
153
|
}
|
|
155
154
|
break;
|
|
156
155
|
}
|
|
157
|
-
if ((
|
|
156
|
+
if ((_f = currentEndpoint.static) === null || _f === void 0 ? void 0 : _f[key]) {
|
|
158
157
|
endpointQueue.push([deep + 1, currentEndpoint.static[key], params]);
|
|
159
158
|
}
|
|
160
159
|
if (currentEndpoint.dynamic) {
|
package/plugins/main/api/api.js
CHANGED
|
@@ -20,11 +20,10 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
20
20
|
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
21
21
|
|
|
22
22
|
const api = () => {
|
|
23
|
-
var _a;
|
|
24
23
|
const handler = innet.useNewHandler();
|
|
25
24
|
const { props = {}, children } = innet.useApp();
|
|
26
|
-
const { prefix = '', title = '', include, exclude } = props, rest = tslib.__rest(props, ["prefix", "title", "include", "exclude"]);
|
|
27
|
-
const info = Object.assign(Object.assign({}, rest), { version
|
|
25
|
+
const { prefix = '', title = '', include, exclude, version = process.env.INNET_API_VERSION || '0.0.0' } = props, rest = tslib.__rest(props, ["prefix", "title", "include", "exclude", "version"]);
|
|
26
|
+
const info = Object.assign(Object.assign({}, rest), { version, title });
|
|
28
27
|
const endpoints = {};
|
|
29
28
|
const docs = {
|
|
30
29
|
openapi: '3.1.0',
|
|
@@ -47,7 +46,7 @@ const api = () => {
|
|
|
47
46
|
useServerPlugins.serverPlugins.set(handler, plugins);
|
|
48
47
|
useApi.apiContext.set(handler, context);
|
|
49
48
|
useServerPlugin.useServerPlugin(() => tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
-
var _b, _c, _d, _e, _f
|
|
49
|
+
var _a, _b, _c, _d, _e, _f;
|
|
51
50
|
const action = useAction.useAction();
|
|
52
51
|
if (!condition(action))
|
|
53
52
|
return;
|
|
@@ -61,7 +60,7 @@ const api = () => {
|
|
|
61
60
|
res.end();
|
|
62
61
|
return null;
|
|
63
62
|
}
|
|
64
|
-
const method = ((
|
|
63
|
+
const method = ((_b = (_a = req.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : 'get');
|
|
65
64
|
const rawSplitPath = url.slice(prefix.length).split('/').slice(1);
|
|
66
65
|
const splitPath = rawSplitPath.at(-1) ? rawSplitPath : rawSplitPath.slice(0, -1);
|
|
67
66
|
const endpoint = endpoints[method];
|
|
@@ -146,8 +145,8 @@ const api = () => {
|
|
|
146
145
|
return true;
|
|
147
146
|
});
|
|
148
147
|
}
|
|
149
|
-
if ((
|
|
150
|
-
if (!(yield run((
|
|
148
|
+
if ((_d = (_c = currentEndpoint.static) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.plugins) {
|
|
149
|
+
if (!(yield run((_e = currentEndpoint.static) === null || _e === void 0 ? void 0 : _e[key], params)))
|
|
151
150
|
continue;
|
|
152
151
|
return null;
|
|
153
152
|
}
|
|
@@ -162,7 +161,7 @@ const api = () => {
|
|
|
162
161
|
}
|
|
163
162
|
break;
|
|
164
163
|
}
|
|
165
|
-
if ((
|
|
164
|
+
if ((_f = currentEndpoint.static) === null || _f === void 0 ? void 0 : _f[key]) {
|
|
166
165
|
endpointQueue.push([deep + 1, currentEndpoint.static[key], params]);
|
|
167
166
|
}
|
|
168
167
|
if (currentEndpoint.dynamic) {
|
|
@@ -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.
|
|
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.
|
|
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.
|
|
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.
|
|
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 =
|
|
14
|
+
const tag = { name };
|
|
15
|
+
if (description) {
|
|
16
|
+
tag.description = description;
|
|
17
|
+
}
|
|
15
18
|
if (!docs.tags) {
|
|
16
19
|
docs.tags = [tag];
|
|
17
20
|
}
|
package/plugins/main/tag/tag.js
CHANGED
|
@@ -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 =
|
|
22
|
+
const tag = { name };
|
|
23
|
+
if (description) {
|
|
24
|
+
tag.description = description;
|
|
25
|
+
}
|
|
23
26
|
if (!docs.tags) {
|
|
24
27
|
docs.tags = [tag];
|
|
25
28
|
}
|
|
@@ -7,7 +7,7 @@ import { usePath } from '../../../hooks/usePath/usePath.es6.js';
|
|
|
7
7
|
import { file } from '../file/file.es6.js';
|
|
8
8
|
|
|
9
9
|
function cms() {
|
|
10
|
-
const { prefix = '/', dir = '.' } = useProps() || {};
|
|
10
|
+
const { prefix = process.env.INNET_CMS_PREFIX || '/', dir = process.env.INNET_CMS_DIR || '.', } = useProps() || {};
|
|
11
11
|
const children = useChildren();
|
|
12
12
|
const handler = useHandler();
|
|
13
13
|
let url = usePath();
|
|
@@ -16,7 +16,7 @@ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
|
16
16
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
17
17
|
|
|
18
18
|
function cms() {
|
|
19
|
-
const { prefix = '/', dir = '.' } = jsx.useProps() || {};
|
|
19
|
+
const { prefix = process.env.INNET_CMS_PREFIX || '/', dir = process.env.INNET_CMS_DIR || '.', } = jsx.useProps() || {};
|
|
20
20
|
const children = jsx.useChildren();
|
|
21
21
|
const handler = innet.useHandler();
|
|
22
22
|
let url = usePath.usePath();
|
|
@@ -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 {
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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,
|
|
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.
|
|
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.
|
|
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/
|
|
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);
|
package/plugins/utils/dts/dts.js
CHANGED
|
@@ -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/
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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)
|
|
@@ -21,6 +21,16 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
|
|
|
21
21
|
if (['boolean', 'number', 'null'].includes(schema.type)) {
|
|
22
22
|
return `${schema.type}${lastChar}`;
|
|
23
23
|
}
|
|
24
|
+
if (schema.oneOf) {
|
|
25
|
+
let result = '';
|
|
26
|
+
for (const item of schema.oneOf) {
|
|
27
|
+
if (result) {
|
|
28
|
+
result += ' | ';
|
|
29
|
+
}
|
|
30
|
+
result += generateSchemaTypes(item, spaces + 2, '');
|
|
31
|
+
}
|
|
32
|
+
return result + lastChar;
|
|
33
|
+
}
|
|
24
34
|
if (schema.type === 'array') {
|
|
25
35
|
if (!schema.items)
|
|
26
36
|
return `any[]${lastChar}`;
|
|
@@ -32,12 +42,23 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
|
|
|
32
42
|
}
|
|
33
43
|
let result = '{\n';
|
|
34
44
|
const required = schema.required || [];
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
const hasProps = Boolean(schema.properties && Object.keys(schema.properties).length);
|
|
46
|
+
const hasRestProps = Boolean(typeof schema.additionalProperties === 'object' &&
|
|
47
|
+
Object.keys(schema.additionalProperties).length);
|
|
48
|
+
if (hasProps) {
|
|
49
|
+
for (const key in schema.properties) {
|
|
50
|
+
const prop = schema.properties[key];
|
|
51
|
+
const splitter = required.includes(key) || hasDefault(prop)
|
|
52
|
+
? ':'
|
|
53
|
+
: '?:';
|
|
54
|
+
result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (hasRestProps) {
|
|
58
|
+
const value = hasProps
|
|
59
|
+
? 'any\n'
|
|
60
|
+
: generateSchemaTypes(schema.additionalProperties, spaces + 2);
|
|
61
|
+
result += `${space}[key: string]: ${value}`;
|
|
41
62
|
}
|
|
42
63
|
return `${result}${space.slice(0, -2)}}${lastChar}`;
|
|
43
64
|
}
|
|
@@ -25,6 +25,16 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
|
|
|
25
25
|
if (['boolean', 'number', 'null'].includes(schema.type)) {
|
|
26
26
|
return `${schema.type}${lastChar}`;
|
|
27
27
|
}
|
|
28
|
+
if (schema.oneOf) {
|
|
29
|
+
let result = '';
|
|
30
|
+
for (const item of schema.oneOf) {
|
|
31
|
+
if (result) {
|
|
32
|
+
result += ' | ';
|
|
33
|
+
}
|
|
34
|
+
result += generateSchemaTypes(item, spaces + 2, '');
|
|
35
|
+
}
|
|
36
|
+
return result + lastChar;
|
|
37
|
+
}
|
|
28
38
|
if (schema.type === 'array') {
|
|
29
39
|
if (!schema.items)
|
|
30
40
|
return `any[]${lastChar}`;
|
|
@@ -36,12 +46,23 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
|
|
|
36
46
|
}
|
|
37
47
|
let result = '{\n';
|
|
38
48
|
const required = schema.required || [];
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
const hasProps = Boolean(schema.properties && Object.keys(schema.properties).length);
|
|
50
|
+
const hasRestProps = Boolean(typeof schema.additionalProperties === 'object' &&
|
|
51
|
+
Object.keys(schema.additionalProperties).length);
|
|
52
|
+
if (hasProps) {
|
|
53
|
+
for (const key in schema.properties) {
|
|
54
|
+
const prop = schema.properties[key];
|
|
55
|
+
const splitter = required.includes(key) || hasDefault(prop)
|
|
56
|
+
? ':'
|
|
57
|
+
: '?:';
|
|
58
|
+
result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (hasRestProps) {
|
|
62
|
+
const value = hasProps
|
|
63
|
+
? 'any\n'
|
|
64
|
+
: generateSchemaTypes(schema.additionalProperties, spaces + 2);
|
|
65
|
+
result += `${space}[key: string]: ${value}`;
|
|
45
66
|
}
|
|
46
67
|
return `${result}${space.slice(0, -2)}}${lastChar}`;
|
|
47
68
|
}
|
|
@@ -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
|
}
|