@innet/server 2.0.0-beta.26 → 2.0.0-beta.27
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/constants.d.ts +3 -0
- package/constants.es6.js +28 -1
- package/constants.js +29 -0
- package/hooks/index.d.ts +1 -1
- package/hooks/index.es6.js +1 -1
- package/hooks/index.js +1 -1
- package/hooks/useBodyContext/index.d.ts +1 -0
- package/hooks/useBodyContext/index.es6.js +1 -0
- package/hooks/useBodyContext/index.js +10 -0
- package/hooks/useBodyContext/useBodyContext.d.ts +6 -0
- package/hooks/{useBodyFile/useBodyFile.es6.js → useBodyContext/useBodyContext.es6.js} +6 -6
- package/hooks/{useBodyFile/useBodyFile.js → useBodyContext/useBodyContext.js} +7 -7
- package/index.es6.js +2 -2
- package/index.js +5 -3
- package/package.json +1 -1
- package/plugins/main/api/api.d.ts +7 -0
- package/plugins/main/api/api.es6.js +2 -4
- package/plugins/main/api/api.js +2 -4
- package/plugins/main/body/body.es6.js +6 -4
- package/plugins/main/body/body.js +6 -4
- package/plugins/main/endpoint/endpoint.d.ts +2 -0
- package/plugins/main/endpoint/endpoint.es6.js +78 -2
- package/plugins/main/endpoint/endpoint.js +78 -2
- package/plugins/schema/any/any.es6.js +6 -1
- package/plugins/schema/any/any.js +5 -0
- package/plugins/schema/array/array.es6.js +4 -1
- package/plugins/schema/array/array.js +4 -1
- package/plugins/schema/binary/binary.es6.js +7 -3
- package/plugins/schema/binary/binary.js +6 -2
- package/plugins/schema/boolean/boolean.es6.js +6 -1
- package/plugins/schema/boolean/boolean.js +5 -0
- package/plugins/schema/date/date.es6.js +6 -1
- package/plugins/schema/date/date.js +5 -0
- package/plugins/schema/integer/integer.es6.js +6 -1
- package/plugins/schema/integer/integer.js +5 -0
- package/plugins/schema/null/null.es6.js +8 -2
- package/plugins/schema/null/null.js +7 -1
- package/plugins/schema/number/number.es6.js +6 -1
- package/plugins/schema/number/number.js +5 -0
- package/plugins/schema/object/object.es6.js +34 -29
- package/plugins/schema/object/object.js +33 -28
- package/plugins/schema/string/string.es6.js +7 -2
- package/plugins/schema/string/string.js +6 -1
- package/plugins/schema/tuple/tuple.es6.js +27 -22
- package/plugins/schema/tuple/tuple.js +26 -21
- package/plugins/schema/uuid/uuid.es6.js +6 -1
- package/plugins/schema/uuid/uuid.js +5 -0
- package/types/appTypes.d.ts +3 -1
- package/utils/rules/constants.d.ts +4 -0
- package/utils/rules/constants.es6.js +547 -1
- package/utils/rules/constants.js +548 -0
- package/utils/rules/index.es6.js +1 -1
- package/utils/rules/index.js +2 -0
- package/hooks/useBodyFile/index.d.ts +0 -1
- package/hooks/useBodyFile/index.es6.js +0 -1
- package/hooks/useBodyFile/index.js +0 -10
- package/hooks/useBodyFile/useBodyFile.d.ts +0 -3
|
@@ -6,6 +6,7 @@ import '../../../utils/index.es6.js';
|
|
|
6
6
|
import { useBlock } from '../../../hooks/useBlock/useBlock.es6.js';
|
|
7
7
|
import { ruleContext } from '../../../hooks/useRule/useRule.es6.js';
|
|
8
8
|
import { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
|
|
9
|
+
import { bodyContext } from '../../../hooks/useBodyContext/useBodyContext.es6.js';
|
|
9
10
|
import { schemaContext } from '../../../hooks/useSchemaContext/useSchemaContext.es6.js';
|
|
10
11
|
import { useParentRule, parentRuleContext } from '../../../hooks/useParentRule/useParentRule.es6.js';
|
|
11
12
|
import { defaultTo } from '../../../utils/rules/defaultTo/defaultTo.es6.js';
|
|
@@ -20,6 +21,8 @@ const array = () => {
|
|
|
20
21
|
const handler = useNewHandler();
|
|
21
22
|
const { children, maxItems, minItems, uniqueItems, ...props } = useProps();
|
|
22
23
|
const schema = useSchemaType('array', props);
|
|
24
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
25
|
+
const hasRules = !isBody || !props.readOnly;
|
|
23
26
|
const fieldSchema = {};
|
|
24
27
|
handler[schemaContext.key] = fieldSchema;
|
|
25
28
|
schema.items = fieldSchema;
|
|
@@ -32,7 +35,7 @@ const array = () => {
|
|
|
32
35
|
if (uniqueItems) {
|
|
33
36
|
schema.uniqueItems = uniqueItems;
|
|
34
37
|
}
|
|
35
|
-
if (setRule) {
|
|
38
|
+
if (setRule && hasRules) {
|
|
36
39
|
let oneOfRulesMap;
|
|
37
40
|
const rules = [];
|
|
38
41
|
const parentRule = useParentRule();
|
|
@@ -10,6 +10,7 @@ require('../../../utils/index.js');
|
|
|
10
10
|
var useBlock = require('../../../hooks/useBlock/useBlock.js');
|
|
11
11
|
var useRule = require('../../../hooks/useRule/useRule.js');
|
|
12
12
|
var useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
|
|
13
|
+
var useBodyContext = require('../../../hooks/useBodyContext/useBodyContext.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');
|
|
@@ -24,6 +25,8 @@ const array = () => {
|
|
|
24
25
|
const handler = innet.useNewHandler();
|
|
25
26
|
const { children, maxItems, minItems, uniqueItems, ...props } = jsx.useProps();
|
|
26
27
|
const schema = useSchemaType.useSchemaType('array', props);
|
|
28
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
29
|
+
const hasRules = !isBody || !props.readOnly;
|
|
27
30
|
const fieldSchema = {};
|
|
28
31
|
handler[useSchemaContext.schemaContext.key] = fieldSchema;
|
|
29
32
|
schema.items = fieldSchema;
|
|
@@ -36,7 +39,7 @@ const array = () => {
|
|
|
36
39
|
if (uniqueItems) {
|
|
37
40
|
schema.uniqueItems = uniqueItems;
|
|
38
41
|
}
|
|
39
|
-
if (setRule) {
|
|
42
|
+
if (setRule && hasRules) {
|
|
40
43
|
let oneOfRulesMap;
|
|
41
44
|
const rules = [];
|
|
42
45
|
const parentRule = useParentRule.useParentRule();
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useProps } from '@innet/jsx';
|
|
1
|
+
import { useProps, useContext } 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
|
-
import {
|
|
6
|
+
import { useBodyContext, bodyContext } from '../../../hooks/useBodyContext/useBodyContext.es6.js';
|
|
7
7
|
import { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
|
|
8
8
|
import { bin } from '../../../utils/rules/bin/bin.es6.js';
|
|
9
9
|
import { minBin } from '../../../utils/rules/minBin/minBin.es6.js';
|
|
@@ -15,12 +15,16 @@ import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
|
15
15
|
|
|
16
16
|
const binary = () => {
|
|
17
17
|
useBlock('path');
|
|
18
|
-
|
|
18
|
+
useBodyContext().useFile();
|
|
19
19
|
const props = useProps();
|
|
20
20
|
const schema = useSchemaType('string', props);
|
|
21
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
22
|
+
const hasRules = !isBody || !props.readOnly;
|
|
21
23
|
if (schema) {
|
|
22
24
|
schema.format = 'binary';
|
|
23
25
|
}
|
|
26
|
+
if (!hasRules)
|
|
27
|
+
return;
|
|
24
28
|
const rules = [];
|
|
25
29
|
rules.push(bin);
|
|
26
30
|
if (props === null || props === void 0 ? void 0 : props.min) {
|
|
@@ -7,7 +7,7 @@ require('../../../hooks/index.js');
|
|
|
7
7
|
require('../../../hooks/useParentRule/index.js');
|
|
8
8
|
require('../../../utils/index.js');
|
|
9
9
|
var useBlock = require('../../../hooks/useBlock/useBlock.js');
|
|
10
|
-
var
|
|
10
|
+
var useBodyContext = require('../../../hooks/useBodyContext/useBodyContext.js');
|
|
11
11
|
var useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
|
|
12
12
|
var bin = require('../../../utils/rules/bin/bin.js');
|
|
13
13
|
var minBin = require('../../../utils/rules/minBin/minBin.js');
|
|
@@ -19,12 +19,16 @@ var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
|
19
19
|
|
|
20
20
|
const binary = () => {
|
|
21
21
|
useBlock.useBlock('path');
|
|
22
|
-
|
|
22
|
+
useBodyContext.useBodyContext().useFile();
|
|
23
23
|
const props = jsx.useProps();
|
|
24
24
|
const schema = useSchemaType.useSchemaType('string', props);
|
|
25
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
26
|
+
const hasRules = !isBody || !props.readOnly;
|
|
25
27
|
if (schema) {
|
|
26
28
|
schema.format = 'binary';
|
|
27
29
|
}
|
|
30
|
+
if (!hasRules)
|
|
31
|
+
return;
|
|
28
32
|
const rules = [];
|
|
29
33
|
rules.push(bin.bin);
|
|
30
34
|
if (props === null || props === void 0 ? void 0 : props.min) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { useProps } from '@innet/jsx';
|
|
1
|
+
import { useProps, useContext } 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 { bodyContext } from '../../../hooks/useBodyContext/useBodyContext.es6.js';
|
|
7
8
|
import { defaultTo } from '../../../utils/rules/defaultTo/defaultTo.es6.js';
|
|
8
9
|
import { useParentRule } from '../../../hooks/useParentRule/useParentRule.es6.js';
|
|
9
10
|
import { useRule } from '../../../hooks/useRule/useRule.es6.js';
|
|
@@ -13,6 +14,10 @@ const boolean = () => {
|
|
|
13
14
|
useBlock('path');
|
|
14
15
|
const props = useProps();
|
|
15
16
|
useSchemaType('boolean', props);
|
|
17
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
18
|
+
const hasRules = !isBody || !props.readOnly;
|
|
19
|
+
if (!hasRules)
|
|
20
|
+
return;
|
|
16
21
|
const rules = [];
|
|
17
22
|
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
18
23
|
rules.push(defaultTo(props.default));
|
|
@@ -8,6 +8,7 @@ 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 useBodyContext = require('../../../hooks/useBodyContext/useBodyContext.js');
|
|
11
12
|
var defaultTo = require('../../../utils/rules/defaultTo/defaultTo.js');
|
|
12
13
|
var useParentRule = require('../../../hooks/useParentRule/useParentRule.js');
|
|
13
14
|
var useRule = require('../../../hooks/useRule/useRule.js');
|
|
@@ -17,6 +18,10 @@ const boolean = () => {
|
|
|
17
18
|
useBlock.useBlock('path');
|
|
18
19
|
const props = jsx.useProps();
|
|
19
20
|
useSchemaType.useSchemaType('boolean', props);
|
|
21
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
22
|
+
const hasRules = !isBody || !props.readOnly;
|
|
23
|
+
if (!hasRules)
|
|
24
|
+
return;
|
|
20
25
|
const rules = [];
|
|
21
26
|
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
22
27
|
rules.push(defaultTo.defaultTo(props.default));
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { useProps } from '@innet/jsx';
|
|
1
|
+
import { useProps, useContext } 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 '../../../utils/dateFormat/index.es6.js';
|
|
6
|
+
import { bodyContext } from '../../../hooks/useBodyContext/useBodyContext.es6.js';
|
|
6
7
|
import { dateFormat } from '../../../utils/dateFormat/dateFormat.es6.js';
|
|
7
8
|
import { getArrayValues, values } from '../../../utils/rules/values/values.es6.js';
|
|
8
9
|
import { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
|
|
@@ -16,6 +17,8 @@ import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
|
16
17
|
|
|
17
18
|
const date = () => {
|
|
18
19
|
const { default: defaultValue, example, examples, max, min, value, values: values$1, ...props } = useProps() || {};
|
|
20
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
21
|
+
const hasRules = !isBody || !props.readOnly;
|
|
19
22
|
const normMin = dateFormat(min);
|
|
20
23
|
const normMax = dateFormat(max);
|
|
21
24
|
const normDefault = dateFormat(defaultValue);
|
|
@@ -58,6 +61,8 @@ const date = () => {
|
|
|
58
61
|
// @ts-expect-error: FIXME
|
|
59
62
|
schema['x-default'] = 'now';
|
|
60
63
|
}
|
|
64
|
+
if (!hasRules)
|
|
65
|
+
return;
|
|
61
66
|
if (defaultValue === undefined) {
|
|
62
67
|
const parentRule = useParentRule();
|
|
63
68
|
useRule(parentRule(pipe(...rules)));
|
|
@@ -7,6 +7,7 @@ require('../../../hooks/index.js');
|
|
|
7
7
|
require('../../../hooks/useParentRule/index.js');
|
|
8
8
|
require('../../../utils/index.js');
|
|
9
9
|
require('../../../utils/dateFormat/index.js');
|
|
10
|
+
var useBodyContext = require('../../../hooks/useBodyContext/useBodyContext.js');
|
|
10
11
|
var dateFormat = require('../../../utils/dateFormat/dateFormat.js');
|
|
11
12
|
var values = require('../../../utils/rules/values/values.js');
|
|
12
13
|
var useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
|
|
@@ -20,6 +21,8 @@ var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
|
20
21
|
|
|
21
22
|
const date = () => {
|
|
22
23
|
const { default: defaultValue, example, examples, max, min, value, values: values$1, ...props } = jsx.useProps() || {};
|
|
24
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
25
|
+
const hasRules = !isBody || !props.readOnly;
|
|
23
26
|
const normMin = dateFormat.dateFormat(min);
|
|
24
27
|
const normMax = dateFormat.dateFormat(max);
|
|
25
28
|
const normDefault = dateFormat.dateFormat(defaultValue);
|
|
@@ -62,6 +65,8 @@ const date = () => {
|
|
|
62
65
|
// @ts-expect-error: FIXME
|
|
63
66
|
schema['x-default'] = 'now';
|
|
64
67
|
}
|
|
68
|
+
if (!hasRules)
|
|
69
|
+
return;
|
|
65
70
|
if (defaultValue === undefined) {
|
|
66
71
|
const parentRule = useParentRule.useParentRule();
|
|
67
72
|
useRule.useRule(parentRule(pipe.pipe(...rules)));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { useProps } from '@innet/jsx';
|
|
1
|
+
import { useProps, useContext } from '@innet/jsx';
|
|
2
2
|
import '../../../hooks/index.es6.js';
|
|
3
3
|
import '../../../utils/index.es6.js';
|
|
4
|
+
import { bodyContext } from '../../../hooks/useBodyContext/useBodyContext.es6.js';
|
|
4
5
|
import { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
|
|
5
6
|
import { getArrayValues, values } from '../../../utils/rules/values/values.es6.js';
|
|
6
7
|
import { defaultTo } from '../../../utils/rules/defaultTo/defaultTo.es6.js';
|
|
@@ -13,6 +14,8 @@ import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
|
13
14
|
|
|
14
15
|
const integer = () => {
|
|
15
16
|
const { default: defaultValue, example, examples, exclusiveMaximum, exclusiveMinimum, format = 'int32', max: max$1, min: min$1, multipleOf, values: values$1, ...props } = useProps() || {};
|
|
17
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
18
|
+
const hasRules = !isBody || !props.readOnly;
|
|
16
19
|
const schema = useSchemaType('integer', {
|
|
17
20
|
...props,
|
|
18
21
|
default: defaultValue !== undefined ? Number(defaultValue) : undefined,
|
|
@@ -41,6 +44,8 @@ const integer = () => {
|
|
|
41
44
|
schema.multipleOf = Number(multipleOf);
|
|
42
45
|
}
|
|
43
46
|
}
|
|
47
|
+
if (!hasRules)
|
|
48
|
+
return;
|
|
44
49
|
const rules = [];
|
|
45
50
|
if (defaultValue !== undefined) {
|
|
46
51
|
rules.push(defaultTo(defaultValue));
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var jsx = require('@innet/jsx');
|
|
6
6
|
require('../../../hooks/index.js');
|
|
7
7
|
require('../../../utils/index.js');
|
|
8
|
+
var useBodyContext = require('../../../hooks/useBodyContext/useBodyContext.js');
|
|
8
9
|
var useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
|
|
9
10
|
var values = require('../../../utils/rules/values/values.js');
|
|
10
11
|
var defaultTo = require('../../../utils/rules/defaultTo/defaultTo.js');
|
|
@@ -17,6 +18,8 @@ var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
|
17
18
|
|
|
18
19
|
const integer = () => {
|
|
19
20
|
const { default: defaultValue, example, examples, exclusiveMaximum, exclusiveMinimum, format = 'int32', max: max$1, min: min$1, multipleOf, values: values$1, ...props } = jsx.useProps() || {};
|
|
21
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
22
|
+
const hasRules = !isBody || !props.readOnly;
|
|
20
23
|
const schema = useSchemaType.useSchemaType('integer', {
|
|
21
24
|
...props,
|
|
22
25
|
default: defaultValue !== undefined ? Number(defaultValue) : undefined,
|
|
@@ -45,6 +48,8 @@ const integer = () => {
|
|
|
45
48
|
schema.multipleOf = Number(multipleOf);
|
|
46
49
|
}
|
|
47
50
|
}
|
|
51
|
+
if (!hasRules)
|
|
52
|
+
return;
|
|
48
53
|
const rules = [];
|
|
49
54
|
if (defaultValue !== undefined) {
|
|
50
55
|
rules.push(defaultTo.defaultTo(defaultValue));
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import { useProps } from '@innet/jsx';
|
|
1
|
+
import { useProps, useContext } from '@innet/jsx';
|
|
2
2
|
import '../../../hooks/index.es6.js';
|
|
3
3
|
import '../../../utils/index.es6.js';
|
|
4
4
|
import { useBlock } from '../../../hooks/useBlock/useBlock.es6.js';
|
|
5
5
|
import { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
|
|
6
|
+
import { bodyContext } from '../../../hooks/useBodyContext/useBodyContext.es6.js';
|
|
6
7
|
import { useRule } from '../../../hooks/useRule/useRule.es6.js';
|
|
7
8
|
import { nullable } from '../../../utils/rules/nullable/nullable.es6.js';
|
|
8
9
|
|
|
9
10
|
const nullPlugin = () => {
|
|
10
11
|
useBlock('path', 'query', 'cookie', 'header');
|
|
11
|
-
|
|
12
|
+
const props = useProps();
|
|
13
|
+
useSchemaType('null', props);
|
|
14
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
15
|
+
const hasRules = !isBody || !props.readOnly;
|
|
16
|
+
if (!hasRules)
|
|
17
|
+
return;
|
|
12
18
|
useRule(nullable);
|
|
13
19
|
};
|
|
14
20
|
|
|
@@ -7,12 +7,18 @@ require('../../../hooks/index.js');
|
|
|
7
7
|
require('../../../utils/index.js');
|
|
8
8
|
var useBlock = require('../../../hooks/useBlock/useBlock.js');
|
|
9
9
|
var useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
|
|
10
|
+
var useBodyContext = require('../../../hooks/useBodyContext/useBodyContext.js');
|
|
10
11
|
var useRule = require('../../../hooks/useRule/useRule.js');
|
|
11
12
|
var nullable = require('../../../utils/rules/nullable/nullable.js');
|
|
12
13
|
|
|
13
14
|
const nullPlugin = () => {
|
|
14
15
|
useBlock.useBlock('path', 'query', 'cookie', 'header');
|
|
15
|
-
|
|
16
|
+
const props = jsx.useProps();
|
|
17
|
+
useSchemaType.useSchemaType('null', props);
|
|
18
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
19
|
+
const hasRules = !isBody || !props.readOnly;
|
|
20
|
+
if (!hasRules)
|
|
21
|
+
return;
|
|
16
22
|
useRule.useRule(nullable.nullable);
|
|
17
23
|
};
|
|
18
24
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { useProps } from '@innet/jsx';
|
|
1
|
+
import { useProps, useContext } 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
|
+
import { bodyContext } from '../../../hooks/useBodyContext/useBodyContext.es6.js';
|
|
5
6
|
import { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
|
|
6
7
|
import { defaultTo } from '../../../utils/rules/defaultTo/defaultTo.es6.js';
|
|
7
8
|
import { num } from '../../../utils/rules/num/num.es6.js';
|
|
@@ -14,6 +15,8 @@ import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
|
14
15
|
|
|
15
16
|
const number = () => {
|
|
16
17
|
const { exclusiveMaximum, exclusiveMinimum, format, max: max$1, min: min$1, multipleOf, ...props } = useProps() || {};
|
|
18
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
19
|
+
const hasRules = !isBody || !props.readOnly;
|
|
17
20
|
const schema = useSchemaType('number', props);
|
|
18
21
|
if (schema) {
|
|
19
22
|
if (format !== undefined) {
|
|
@@ -35,6 +38,8 @@ const number = () => {
|
|
|
35
38
|
schema.multipleOf = Number(multipleOf);
|
|
36
39
|
}
|
|
37
40
|
}
|
|
41
|
+
if (!hasRules)
|
|
42
|
+
return;
|
|
38
43
|
const rules = [];
|
|
39
44
|
if (props.default !== undefined) {
|
|
40
45
|
rules.push(defaultTo(props.default));
|
|
@@ -6,6 +6,7 @@ var jsx = require('@innet/jsx');
|
|
|
6
6
|
require('../../../hooks/index.js');
|
|
7
7
|
require('../../../hooks/useParentRule/index.js');
|
|
8
8
|
require('../../../utils/index.js');
|
|
9
|
+
var useBodyContext = require('../../../hooks/useBodyContext/useBodyContext.js');
|
|
9
10
|
var useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
|
|
10
11
|
var defaultTo = require('../../../utils/rules/defaultTo/defaultTo.js');
|
|
11
12
|
var num = require('../../../utils/rules/num/num.js');
|
|
@@ -18,6 +19,8 @@ var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
|
18
19
|
|
|
19
20
|
const number = () => {
|
|
20
21
|
const { exclusiveMaximum, exclusiveMinimum, format, max: max$1, min: min$1, multipleOf, ...props } = jsx.useProps() || {};
|
|
22
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
23
|
+
const hasRules = !isBody || !props.readOnly;
|
|
21
24
|
const schema = useSchemaType.useSchemaType('number', props);
|
|
22
25
|
if (schema) {
|
|
23
26
|
if (format !== undefined) {
|
|
@@ -39,6 +42,8 @@ const number = () => {
|
|
|
39
42
|
schema.multipleOf = Number(multipleOf);
|
|
40
43
|
}
|
|
41
44
|
}
|
|
45
|
+
if (!hasRules)
|
|
46
|
+
return;
|
|
42
47
|
const rules = [];
|
|
43
48
|
if (props.default !== undefined) {
|
|
44
49
|
rules.push(defaultTo.defaultTo(props.default));
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import { useNewHandler, innet } from 'innet';
|
|
2
|
-
import { useProps } from '@innet/jsx';
|
|
2
|
+
import { useProps, useContext } from '@innet/jsx';
|
|
3
3
|
import '../../../hooks/index.es6.js';
|
|
4
4
|
import '../../../hooks/useParentRule/index.es6.js';
|
|
5
5
|
import '../../../utils/index.es6.js';
|
|
6
6
|
import { useBlock } from '../../../hooks/useBlock/useBlock.es6.js';
|
|
7
|
+
import { bodyContext } from '../../../hooks/useBodyContext/useBodyContext.es6.js';
|
|
7
8
|
import { useApi } from '../../../hooks/useApi/useApi.es6.js';
|
|
8
9
|
import { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
|
|
9
10
|
import { objectSchemaContext } from '../../../hooks/useObjectSchemaContext/useObjectSchemaContext.es6.js';
|
|
10
11
|
import { schemaContext } from '../../../hooks/useSchemaContext/useSchemaContext.es6.js';
|
|
11
12
|
import { parentRuleContext, useParentRule } from '../../../hooks/useParentRule/useParentRule.es6.js';
|
|
13
|
+
import { useEffect } from '../../../hooks/useEffect/useEffect.es6.js';
|
|
14
|
+
import { getSafeSchema } from '../../../utils/getSafeSchema/getSafeSchema.es6.js';
|
|
12
15
|
import { defaultTo } from '../../../utils/rules/defaultTo/defaultTo.es6.js';
|
|
13
16
|
import { objectOf } from '../../../utils/rules/objectOf/objectOf.es6.js';
|
|
14
17
|
import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
15
18
|
import { useRule, ruleContext } from '../../../hooks/useRule/useRule.es6.js';
|
|
16
19
|
import { objectRuleContext } from '../../../hooks/useObjectRule/useObjectRule.es6.js';
|
|
17
|
-
import { useEffect } from '../../../hooks/useEffect/useEffect.es6.js';
|
|
18
|
-
import { getSafeSchema } from '../../../utils/getSafeSchema/getSafeSchema.es6.js';
|
|
19
20
|
|
|
20
21
|
const object = () => {
|
|
21
22
|
useBlock('path');
|
|
22
23
|
const { children, ...props } = useProps();
|
|
24
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
25
|
+
const hasRules = !isBody || !props.readOnly;
|
|
23
26
|
const { refRules } = useApi();
|
|
24
27
|
const schema = useSchemaType('object', props);
|
|
25
28
|
const handler = useNewHandler();
|
|
@@ -28,39 +31,41 @@ const object = () => {
|
|
|
28
31
|
objectSchemaContext.set(handler, schema);
|
|
29
32
|
schemaContext.set(handler, schema.additionalProperties);
|
|
30
33
|
parentRuleContext.reset(handler);
|
|
31
|
-
const rules = [];
|
|
32
|
-
const rulesMap = {};
|
|
33
|
-
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
34
|
-
rules.push(defaultTo(props.default));
|
|
35
|
-
}
|
|
36
|
-
let childRule = v => v;
|
|
37
|
-
const restRule = (value, data) => childRule(value, data);
|
|
38
|
-
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
39
|
-
rules.push(objectOf(rulesMap, restRule));
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
const parentRule = useParentRule();
|
|
43
|
-
rules.push(parentRule(objectOf(rulesMap, restRule)));
|
|
44
|
-
}
|
|
45
|
-
const rule = pipe(...rules);
|
|
46
|
-
if (props.ref) {
|
|
47
|
-
refRules[props.ref] = rule;
|
|
48
|
-
}
|
|
49
|
-
useRule(rule);
|
|
50
|
-
objectRuleContext.set(handler, rulesMap);
|
|
51
|
-
ruleContext.set(handler, rule => {
|
|
52
|
-
childRule = rule;
|
|
53
|
-
});
|
|
54
|
-
parentRuleContext.reset(handler);
|
|
55
|
-
innet(children, handler);
|
|
56
34
|
useEffect(() => {
|
|
57
35
|
const safeSchema = getSafeSchema(schema);
|
|
58
36
|
if (!Object.keys(safeSchema.additionalProperties).length) {
|
|
59
37
|
delete safeSchema.additionalProperties;
|
|
60
38
|
}
|
|
61
39
|
});
|
|
40
|
+
if (hasRules) {
|
|
41
|
+
const rules = [];
|
|
42
|
+
const rulesMap = {};
|
|
43
|
+
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
44
|
+
rules.push(defaultTo(props.default));
|
|
45
|
+
}
|
|
46
|
+
let childRule = v => v;
|
|
47
|
+
const restRule = (value, data) => childRule(value, data);
|
|
48
|
+
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
49
|
+
rules.push(objectOf(rulesMap, restRule));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const parentRule = useParentRule();
|
|
53
|
+
rules.push(parentRule(objectOf(rulesMap, restRule)));
|
|
54
|
+
}
|
|
55
|
+
const rule = pipe(...rules);
|
|
56
|
+
if (props.ref) {
|
|
57
|
+
refRules[props.ref] = rule;
|
|
58
|
+
}
|
|
59
|
+
useRule(rule);
|
|
60
|
+
objectRuleContext.set(handler, rulesMap);
|
|
61
|
+
ruleContext.set(handler, rule => {
|
|
62
|
+
childRule = rule;
|
|
63
|
+
});
|
|
64
|
+
parentRuleContext.reset(handler);
|
|
65
|
+
}
|
|
66
|
+
innet(children, handler);
|
|
62
67
|
}
|
|
63
|
-
else if (props.ref) {
|
|
68
|
+
else if (props.ref && hasRules) {
|
|
64
69
|
useRule(refRules[props.ref]);
|
|
65
70
|
}
|
|
66
71
|
};
|
|
@@ -8,22 +8,25 @@ require('../../../hooks/index.js');
|
|
|
8
8
|
require('../../../hooks/useParentRule/index.js');
|
|
9
9
|
require('../../../utils/index.js');
|
|
10
10
|
var useBlock = require('../../../hooks/useBlock/useBlock.js');
|
|
11
|
+
var useBodyContext = require('../../../hooks/useBodyContext/useBodyContext.js');
|
|
11
12
|
var useApi = require('../../../hooks/useApi/useApi.js');
|
|
12
13
|
var useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
|
|
13
14
|
var useObjectSchemaContext = require('../../../hooks/useObjectSchemaContext/useObjectSchemaContext.js');
|
|
14
15
|
var useSchemaContext = require('../../../hooks/useSchemaContext/useSchemaContext.js');
|
|
15
16
|
var useParentRule = require('../../../hooks/useParentRule/useParentRule.js');
|
|
17
|
+
var useEffect = require('../../../hooks/useEffect/useEffect.js');
|
|
18
|
+
var getSafeSchema = require('../../../utils/getSafeSchema/getSafeSchema.js');
|
|
16
19
|
var defaultTo = require('../../../utils/rules/defaultTo/defaultTo.js');
|
|
17
20
|
var objectOf = require('../../../utils/rules/objectOf/objectOf.js');
|
|
18
21
|
var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
19
22
|
var useRule = require('../../../hooks/useRule/useRule.js');
|
|
20
23
|
var useObjectRule = require('../../../hooks/useObjectRule/useObjectRule.js');
|
|
21
|
-
var useEffect = require('../../../hooks/useEffect/useEffect.js');
|
|
22
|
-
var getSafeSchema = require('../../../utils/getSafeSchema/getSafeSchema.js');
|
|
23
24
|
|
|
24
25
|
const object = () => {
|
|
25
26
|
useBlock.useBlock('path');
|
|
26
27
|
const { children, ...props } = jsx.useProps();
|
|
28
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
29
|
+
const hasRules = !isBody || !props.readOnly;
|
|
27
30
|
const { refRules } = useApi.useApi();
|
|
28
31
|
const schema = useSchemaType.useSchemaType('object', props);
|
|
29
32
|
const handler = innet.useNewHandler();
|
|
@@ -32,39 +35,41 @@ const object = () => {
|
|
|
32
35
|
useObjectSchemaContext.objectSchemaContext.set(handler, schema);
|
|
33
36
|
useSchemaContext.schemaContext.set(handler, schema.additionalProperties);
|
|
34
37
|
useParentRule.parentRuleContext.reset(handler);
|
|
35
|
-
const rules = [];
|
|
36
|
-
const rulesMap = {};
|
|
37
|
-
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
38
|
-
rules.push(defaultTo.defaultTo(props.default));
|
|
39
|
-
}
|
|
40
|
-
let childRule = v => v;
|
|
41
|
-
const restRule = (value, data) => childRule(value, data);
|
|
42
|
-
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
43
|
-
rules.push(objectOf.objectOf(rulesMap, restRule));
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
const parentRule = useParentRule.useParentRule();
|
|
47
|
-
rules.push(parentRule(objectOf.objectOf(rulesMap, restRule)));
|
|
48
|
-
}
|
|
49
|
-
const rule = pipe.pipe(...rules);
|
|
50
|
-
if (props.ref) {
|
|
51
|
-
refRules[props.ref] = rule;
|
|
52
|
-
}
|
|
53
|
-
useRule.useRule(rule);
|
|
54
|
-
useObjectRule.objectRuleContext.set(handler, rulesMap);
|
|
55
|
-
useRule.ruleContext.set(handler, rule => {
|
|
56
|
-
childRule = rule;
|
|
57
|
-
});
|
|
58
|
-
useParentRule.parentRuleContext.reset(handler);
|
|
59
|
-
innet.innet(children, handler);
|
|
60
38
|
useEffect.useEffect(() => {
|
|
61
39
|
const safeSchema = getSafeSchema.getSafeSchema(schema);
|
|
62
40
|
if (!Object.keys(safeSchema.additionalProperties).length) {
|
|
63
41
|
delete safeSchema.additionalProperties;
|
|
64
42
|
}
|
|
65
43
|
});
|
|
44
|
+
if (hasRules) {
|
|
45
|
+
const rules = [];
|
|
46
|
+
const rulesMap = {};
|
|
47
|
+
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
48
|
+
rules.push(defaultTo.defaultTo(props.default));
|
|
49
|
+
}
|
|
50
|
+
let childRule = v => v;
|
|
51
|
+
const restRule = (value, data) => childRule(value, data);
|
|
52
|
+
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
53
|
+
rules.push(objectOf.objectOf(rulesMap, restRule));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const parentRule = useParentRule.useParentRule();
|
|
57
|
+
rules.push(parentRule(objectOf.objectOf(rulesMap, restRule)));
|
|
58
|
+
}
|
|
59
|
+
const rule = pipe.pipe(...rules);
|
|
60
|
+
if (props.ref) {
|
|
61
|
+
refRules[props.ref] = rule;
|
|
62
|
+
}
|
|
63
|
+
useRule.useRule(rule);
|
|
64
|
+
useObjectRule.objectRuleContext.set(handler, rulesMap);
|
|
65
|
+
useRule.ruleContext.set(handler, rule => {
|
|
66
|
+
childRule = rule;
|
|
67
|
+
});
|
|
68
|
+
useParentRule.parentRuleContext.reset(handler);
|
|
69
|
+
}
|
|
70
|
+
innet.innet(children, handler);
|
|
66
71
|
}
|
|
67
|
-
else if (props.ref) {
|
|
72
|
+
else if (props.ref && hasRules) {
|
|
68
73
|
useRule.useRule(refRules[props.ref]);
|
|
69
74
|
}
|
|
70
75
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { useProps } from '@innet/jsx';
|
|
1
|
+
import { useProps, useContext } 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 { useApi } from '../../../hooks/useApi/useApi.es6.js';
|
|
6
6
|
import { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
|
|
7
|
+
import { bodyContext } from '../../../hooks/useBodyContext/useBodyContext.es6.js';
|
|
7
8
|
import { defaultTo } from '../../../utils/rules/defaultTo/defaultTo.es6.js';
|
|
8
9
|
import { values, getArrayValues } from '../../../utils/rules/values/values.es6.js';
|
|
9
10
|
import { minLength } from '../../../utils/rules/minLength/minLength.es6.js';
|
|
@@ -17,6 +18,8 @@ const string = () => {
|
|
|
17
18
|
const { format, max, min, pattern: pattern$1, patternId, ...props } = useProps() || {};
|
|
18
19
|
const { refRules } = useApi();
|
|
19
20
|
const schema = useSchemaType('string', props);
|
|
21
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
22
|
+
const hasRules = !isBody || !props.readOnly;
|
|
20
23
|
if (schema) {
|
|
21
24
|
const rules = [];
|
|
22
25
|
if (format !== undefined) {
|
|
@@ -44,6 +47,8 @@ const string = () => {
|
|
|
44
47
|
schema.pattern = String(pattern$1);
|
|
45
48
|
rules.push(pattern(pattern$1, patternId));
|
|
46
49
|
}
|
|
50
|
+
if (!hasRules)
|
|
51
|
+
return;
|
|
47
52
|
const rule = pipe(...rules);
|
|
48
53
|
if (props.ref) {
|
|
49
54
|
refRules[props.ref] = rule;
|
|
@@ -56,7 +61,7 @@ const string = () => {
|
|
|
56
61
|
useRule(parentRule(rule));
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
|
-
else if (props.ref) {
|
|
64
|
+
else if (props.ref && hasRules) {
|
|
60
65
|
if (props.default !== undefined) {
|
|
61
66
|
useRule(refRules[props.ref]);
|
|
62
67
|
}
|
|
@@ -8,6 +8,7 @@ require('../../../hooks/useParentRule/index.js');
|
|
|
8
8
|
require('../../../utils/index.js');
|
|
9
9
|
var useApi = require('../../../hooks/useApi/useApi.js');
|
|
10
10
|
var useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
|
|
11
|
+
var useBodyContext = require('../../../hooks/useBodyContext/useBodyContext.js');
|
|
11
12
|
var defaultTo = require('../../../utils/rules/defaultTo/defaultTo.js');
|
|
12
13
|
var values = require('../../../utils/rules/values/values.js');
|
|
13
14
|
var minLength = require('../../../utils/rules/minLength/minLength.js');
|
|
@@ -21,6 +22,8 @@ const string = () => {
|
|
|
21
22
|
const { format, max, min, pattern: pattern$1, patternId, ...props } = jsx.useProps() || {};
|
|
22
23
|
const { refRules } = useApi.useApi();
|
|
23
24
|
const schema = useSchemaType.useSchemaType('string', props);
|
|
25
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
26
|
+
const hasRules = !isBody || !props.readOnly;
|
|
24
27
|
if (schema) {
|
|
25
28
|
const rules = [];
|
|
26
29
|
if (format !== undefined) {
|
|
@@ -48,6 +51,8 @@ const string = () => {
|
|
|
48
51
|
schema.pattern = String(pattern$1);
|
|
49
52
|
rules.push(pattern.pattern(pattern$1, patternId));
|
|
50
53
|
}
|
|
54
|
+
if (!hasRules)
|
|
55
|
+
return;
|
|
51
56
|
const rule = pipe.pipe(...rules);
|
|
52
57
|
if (props.ref) {
|
|
53
58
|
refRules[props.ref] = rule;
|
|
@@ -60,7 +65,7 @@ const string = () => {
|
|
|
60
65
|
useRule.useRule(parentRule(rule));
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
|
-
else if (props.ref) {
|
|
68
|
+
else if (props.ref && hasRules) {
|
|
64
69
|
if (props.default !== undefined) {
|
|
65
70
|
useRule.useRule(refRules[props.ref]);
|
|
66
71
|
}
|