@innet/server 2.0.0-beta.26 → 2.0.0-beta.28
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 +9 -4
- package/plugins/schema/array/array.js +9 -4
- package/plugins/schema/binary/binary.d.ts +3 -8
- package/plugins/schema/binary/binary.es6.js +12 -5
- package/plugins/schema/binary/binary.js +11 -4
- package/plugins/schema/boolean/boolean.es6.js +13 -5
- package/plugins/schema/boolean/boolean.js +12 -4
- package/plugins/schema/date/date.es6.js +12 -4
- package/plugins/schema/date/date.js +11 -3
- package/plugins/schema/integer/integer.es6.js +12 -4
- package/plugins/schema/integer/integer.js +11 -3
- package/plugins/schema/null/null.es6.js +8 -2
- package/plugins/schema/null/null.js +7 -1
- package/plugins/schema/number/number.es6.js +12 -4
- package/plugins/schema/number/number.js +11 -3
- package/plugins/schema/object/object.es6.js +36 -29
- package/plugins/schema/object/object.js +35 -28
- package/plugins/schema/string/string.es6.js +10 -3
- package/plugins/schema/string/string.js +9 -2
- package/plugins/schema/tuple/tuple.es6.js +29 -23
- package/plugins/schema/tuple/tuple.js +28 -22
- package/plugins/schema/uuid/uuid.es6.js +12 -4
- package/plugins/schema/uuid/uuid.js +11 -3
- 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
|
@@ -1,25 +1,30 @@
|
|
|
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';
|
|
17
|
+
import { oneOf } from '../../../utils/rules/oneOf/oneOf.es6.js';
|
|
18
|
+
import { nullable } from '../../../utils/rules/nullable/nullable.es6.js';
|
|
14
19
|
import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
15
20
|
import { useRule, ruleContext } from '../../../hooks/useRule/useRule.es6.js';
|
|
16
21
|
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
22
|
|
|
20
23
|
const object = () => {
|
|
21
24
|
useBlock('path');
|
|
22
25
|
const { children, ...props } = useProps();
|
|
26
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
27
|
+
const hasRules = !isBody || !props.readOnly;
|
|
23
28
|
const { refRules } = useApi();
|
|
24
29
|
const schema = useSchemaType('object', props);
|
|
25
30
|
const handler = useNewHandler();
|
|
@@ -28,39 +33,41 @@ const object = () => {
|
|
|
28
33
|
objectSchemaContext.set(handler, schema);
|
|
29
34
|
schemaContext.set(handler, schema.additionalProperties);
|
|
30
35
|
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
36
|
useEffect(() => {
|
|
57
37
|
const safeSchema = getSafeSchema(schema);
|
|
58
38
|
if (!Object.keys(safeSchema.additionalProperties).length) {
|
|
59
39
|
delete safeSchema.additionalProperties;
|
|
60
40
|
}
|
|
61
41
|
});
|
|
42
|
+
if (hasRules) {
|
|
43
|
+
const rules = [];
|
|
44
|
+
const rulesMap = {};
|
|
45
|
+
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
46
|
+
rules.push(defaultTo(props.default));
|
|
47
|
+
}
|
|
48
|
+
let childRule = v => v;
|
|
49
|
+
const restRule = (value, data) => childRule(value, data);
|
|
50
|
+
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
51
|
+
rules.push(objectOf(rulesMap, restRule));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const parentRule = useParentRule();
|
|
55
|
+
rules.push(parentRule(objectOf(rulesMap, restRule)));
|
|
56
|
+
}
|
|
57
|
+
const rule = props.nullable ? oneOf([nullable, pipe(...rules)]) : pipe(...rules);
|
|
58
|
+
if (props.ref) {
|
|
59
|
+
refRules[props.ref] = rule;
|
|
60
|
+
}
|
|
61
|
+
useRule(rule);
|
|
62
|
+
objectRuleContext.set(handler, rulesMap);
|
|
63
|
+
ruleContext.set(handler, rule => {
|
|
64
|
+
childRule = rule;
|
|
65
|
+
});
|
|
66
|
+
parentRuleContext.reset(handler);
|
|
67
|
+
}
|
|
68
|
+
innet(children, handler);
|
|
62
69
|
}
|
|
63
|
-
else if (props.ref) {
|
|
70
|
+
else if (props.ref && hasRules) {
|
|
64
71
|
useRule(refRules[props.ref]);
|
|
65
72
|
}
|
|
66
73
|
};
|
|
@@ -8,22 +8,27 @@ 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');
|
|
21
|
+
var oneOf = require('../../../utils/rules/oneOf/oneOf.js');
|
|
22
|
+
var nullable = require('../../../utils/rules/nullable/nullable.js');
|
|
18
23
|
var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
19
24
|
var useRule = require('../../../hooks/useRule/useRule.js');
|
|
20
25
|
var useObjectRule = require('../../../hooks/useObjectRule/useObjectRule.js');
|
|
21
|
-
var useEffect = require('../../../hooks/useEffect/useEffect.js');
|
|
22
|
-
var getSafeSchema = require('../../../utils/getSafeSchema/getSafeSchema.js');
|
|
23
26
|
|
|
24
27
|
const object = () => {
|
|
25
28
|
useBlock.useBlock('path');
|
|
26
29
|
const { children, ...props } = jsx.useProps();
|
|
30
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
31
|
+
const hasRules = !isBody || !props.readOnly;
|
|
27
32
|
const { refRules } = useApi.useApi();
|
|
28
33
|
const schema = useSchemaType.useSchemaType('object', props);
|
|
29
34
|
const handler = innet.useNewHandler();
|
|
@@ -32,39 +37,41 @@ const object = () => {
|
|
|
32
37
|
useObjectSchemaContext.objectSchemaContext.set(handler, schema);
|
|
33
38
|
useSchemaContext.schemaContext.set(handler, schema.additionalProperties);
|
|
34
39
|
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
40
|
useEffect.useEffect(() => {
|
|
61
41
|
const safeSchema = getSafeSchema.getSafeSchema(schema);
|
|
62
42
|
if (!Object.keys(safeSchema.additionalProperties).length) {
|
|
63
43
|
delete safeSchema.additionalProperties;
|
|
64
44
|
}
|
|
65
45
|
});
|
|
46
|
+
if (hasRules) {
|
|
47
|
+
const rules = [];
|
|
48
|
+
const rulesMap = {};
|
|
49
|
+
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
50
|
+
rules.push(defaultTo.defaultTo(props.default));
|
|
51
|
+
}
|
|
52
|
+
let childRule = v => v;
|
|
53
|
+
const restRule = (value, data) => childRule(value, data);
|
|
54
|
+
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
55
|
+
rules.push(objectOf.objectOf(rulesMap, restRule));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const parentRule = useParentRule.useParentRule();
|
|
59
|
+
rules.push(parentRule(objectOf.objectOf(rulesMap, restRule)));
|
|
60
|
+
}
|
|
61
|
+
const rule = props.nullable ? oneOf.oneOf([nullable.nullable, pipe.pipe(...rules)]) : pipe.pipe(...rules);
|
|
62
|
+
if (props.ref) {
|
|
63
|
+
refRules[props.ref] = rule;
|
|
64
|
+
}
|
|
65
|
+
useRule.useRule(rule);
|
|
66
|
+
useObjectRule.objectRuleContext.set(handler, rulesMap);
|
|
67
|
+
useRule.ruleContext.set(handler, rule => {
|
|
68
|
+
childRule = rule;
|
|
69
|
+
});
|
|
70
|
+
useParentRule.parentRuleContext.reset(handler);
|
|
71
|
+
}
|
|
72
|
+
innet.innet(children, handler);
|
|
66
73
|
}
|
|
67
|
-
else if (props.ref) {
|
|
74
|
+
else if (props.ref && hasRules) {
|
|
68
75
|
useRule.useRule(refRules[props.ref]);
|
|
69
76
|
}
|
|
70
77
|
};
|
|
@@ -1,14 +1,17 @@
|
|
|
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';
|
|
10
11
|
import { maxLength } from '../../../utils/rules/maxLength/maxLength.es6.js';
|
|
11
12
|
import { pattern } from '../../../utils/rules/pattern/pattern.es6.js';
|
|
13
|
+
import { oneOf } from '../../../utils/rules/oneOf/oneOf.es6.js';
|
|
14
|
+
import { nullable } from '../../../utils/rules/nullable/nullable.es6.js';
|
|
12
15
|
import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
13
16
|
import { useRule } from '../../../hooks/useRule/useRule.es6.js';
|
|
14
17
|
import { useParentRule } from '../../../hooks/useParentRule/useParentRule.es6.js';
|
|
@@ -17,6 +20,8 @@ const string = () => {
|
|
|
17
20
|
const { format, max, min, pattern: pattern$1, patternId, ...props } = useProps() || {};
|
|
18
21
|
const { refRules } = useApi();
|
|
19
22
|
const schema = useSchemaType('string', props);
|
|
23
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
24
|
+
const hasRules = !isBody || !props.readOnly;
|
|
20
25
|
if (schema) {
|
|
21
26
|
const rules = [];
|
|
22
27
|
if (format !== undefined) {
|
|
@@ -44,7 +49,9 @@ const string = () => {
|
|
|
44
49
|
schema.pattern = String(pattern$1);
|
|
45
50
|
rules.push(pattern(pattern$1, patternId));
|
|
46
51
|
}
|
|
47
|
-
|
|
52
|
+
if (!hasRules)
|
|
53
|
+
return;
|
|
54
|
+
const rule = props.nullable ? oneOf([nullable, pipe(...rules)]) : pipe(...rules);
|
|
48
55
|
if (props.ref) {
|
|
49
56
|
refRules[props.ref] = rule;
|
|
50
57
|
}
|
|
@@ -56,7 +63,7 @@ const string = () => {
|
|
|
56
63
|
useRule(parentRule(rule));
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
|
-
else if (props.ref) {
|
|
66
|
+
else if (props.ref && hasRules) {
|
|
60
67
|
if (props.default !== undefined) {
|
|
61
68
|
useRule(refRules[props.ref]);
|
|
62
69
|
}
|
|
@@ -8,11 +8,14 @@ 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');
|
|
14
15
|
var maxLength = require('../../../utils/rules/maxLength/maxLength.js');
|
|
15
16
|
var pattern = require('../../../utils/rules/pattern/pattern.js');
|
|
17
|
+
var oneOf = require('../../../utils/rules/oneOf/oneOf.js');
|
|
18
|
+
var nullable = require('../../../utils/rules/nullable/nullable.js');
|
|
16
19
|
var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
17
20
|
var useRule = require('../../../hooks/useRule/useRule.js');
|
|
18
21
|
var useParentRule = require('../../../hooks/useParentRule/useParentRule.js');
|
|
@@ -21,6 +24,8 @@ const string = () => {
|
|
|
21
24
|
const { format, max, min, pattern: pattern$1, patternId, ...props } = jsx.useProps() || {};
|
|
22
25
|
const { refRules } = useApi.useApi();
|
|
23
26
|
const schema = useSchemaType.useSchemaType('string', props);
|
|
27
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
28
|
+
const hasRules = !isBody || !props.readOnly;
|
|
24
29
|
if (schema) {
|
|
25
30
|
const rules = [];
|
|
26
31
|
if (format !== undefined) {
|
|
@@ -48,7 +53,9 @@ const string = () => {
|
|
|
48
53
|
schema.pattern = String(pattern$1);
|
|
49
54
|
rules.push(pattern.pattern(pattern$1, patternId));
|
|
50
55
|
}
|
|
51
|
-
|
|
56
|
+
if (!hasRules)
|
|
57
|
+
return;
|
|
58
|
+
const rule = props.nullable ? oneOf.oneOf([nullable.nullable, pipe.pipe(...rules)]) : pipe.pipe(...rules);
|
|
52
59
|
if (props.ref) {
|
|
53
60
|
refRules[props.ref] = rule;
|
|
54
61
|
}
|
|
@@ -60,7 +67,7 @@ const string = () => {
|
|
|
60
67
|
useRule.useRule(parentRule(rule));
|
|
61
68
|
}
|
|
62
69
|
}
|
|
63
|
-
else if (props.ref) {
|
|
70
|
+
else if (props.ref && hasRules) {
|
|
64
71
|
if (props.default !== undefined) {
|
|
65
72
|
useRule.useRule(refRules[props.ref]);
|
|
66
73
|
}
|
|
@@ -1,16 +1,19 @@
|
|
|
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 { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
|
|
8
9
|
import { schemaContext } from '../../../hooks/useSchemaContext/useSchemaContext.es6.js';
|
|
9
10
|
import { defaultTo } from '../../../utils/rules/defaultTo/defaultTo.es6.js';
|
|
10
11
|
import { tupleOf } from '../../../utils/rules/tupleOf/tupleOf.es6.js';
|
|
11
12
|
import { useParentRule, parentRuleContext } from '../../../hooks/useParentRule/useParentRule.es6.js';
|
|
12
|
-
import {
|
|
13
|
+
import { oneOf } from '../../../utils/rules/oneOf/oneOf.es6.js';
|
|
14
|
+
import { nullable } from '../../../utils/rules/nullable/nullable.es6.js';
|
|
13
15
|
import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
16
|
+
import { useRule, ruleContext } from '../../../hooks/useRule/useRule.es6.js';
|
|
14
17
|
import { required } from '../../../utils/rules/required/required.es6.js';
|
|
15
18
|
import { useEffect } from '../../../hooks/useEffect/useEffect.es6.js';
|
|
16
19
|
|
|
@@ -18,35 +21,38 @@ const tuple = () => {
|
|
|
18
21
|
useBlock('path');
|
|
19
22
|
const handler = useNewHandler();
|
|
20
23
|
const { children, ...props } = useProps();
|
|
24
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
25
|
+
const hasRules = !isBody || !props.readOnly;
|
|
21
26
|
const schema = useSchemaType('array', props);
|
|
22
27
|
if (schema) {
|
|
23
28
|
const schemas = [];
|
|
24
29
|
handler[schemaContext.key] = schemas;
|
|
25
30
|
// @ts-expect-error: FIXME
|
|
26
31
|
schema.prefixItems = schemas;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
if (hasRules) {
|
|
33
|
+
const rulesMap = [];
|
|
34
|
+
const rules = [];
|
|
35
|
+
if (props.default !== undefined) {
|
|
36
|
+
rules.push(defaultTo(props.default));
|
|
37
|
+
rules.push(tupleOf(rulesMap));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const parentRule = useParentRule();
|
|
41
|
+
rules.push(parentRule(tupleOf(rulesMap)));
|
|
42
|
+
}
|
|
43
|
+
const rule = props.nullable ? oneOf([nullable, pipe(...rules)]) : pipe(...rules);
|
|
44
|
+
useRule(rule);
|
|
45
|
+
parentRuleContext.set(handler, rule => required(rule));
|
|
46
|
+
ruleContext.set(handler, rule => {
|
|
47
|
+
rulesMap.push(rule);
|
|
48
|
+
});
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (!rulesMap.length) {
|
|
51
|
+
throw Error('<tuple> MUST have content');
|
|
52
|
+
}
|
|
53
|
+
});
|
|
38
54
|
}
|
|
39
|
-
useRule(pipe(...rules));
|
|
40
|
-
parentRuleContext.set(handler, rule => required(rule));
|
|
41
|
-
ruleContext.set(handler, rule => {
|
|
42
|
-
rulesMap.push(rule);
|
|
43
|
-
});
|
|
44
55
|
innet(children, handler);
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
if (!rulesMap.length) {
|
|
47
|
-
throw Error('<tuple> MUST have content');
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
56
|
}
|
|
51
57
|
};
|
|
52
58
|
|
|
@@ -8,13 +8,16 @@ 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 useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
|
|
12
13
|
var useSchemaContext = require('../../../hooks/useSchemaContext/useSchemaContext.js');
|
|
13
14
|
var defaultTo = require('../../../utils/rules/defaultTo/defaultTo.js');
|
|
14
15
|
var tupleOf = require('../../../utils/rules/tupleOf/tupleOf.js');
|
|
15
16
|
var useParentRule = require('../../../hooks/useParentRule/useParentRule.js');
|
|
16
|
-
var
|
|
17
|
+
var oneOf = require('../../../utils/rules/oneOf/oneOf.js');
|
|
18
|
+
var nullable = require('../../../utils/rules/nullable/nullable.js');
|
|
17
19
|
var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
20
|
+
var useRule = require('../../../hooks/useRule/useRule.js');
|
|
18
21
|
var required = require('../../../utils/rules/required/required.js');
|
|
19
22
|
var useEffect = require('../../../hooks/useEffect/useEffect.js');
|
|
20
23
|
|
|
@@ -22,35 +25,38 @@ const tuple = () => {
|
|
|
22
25
|
useBlock.useBlock('path');
|
|
23
26
|
const handler = innet.useNewHandler();
|
|
24
27
|
const { children, ...props } = jsx.useProps();
|
|
28
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
29
|
+
const hasRules = !isBody || !props.readOnly;
|
|
25
30
|
const schema = useSchemaType.useSchemaType('array', props);
|
|
26
31
|
if (schema) {
|
|
27
32
|
const schemas = [];
|
|
28
33
|
handler[useSchemaContext.schemaContext.key] = schemas;
|
|
29
34
|
// @ts-expect-error: FIXME
|
|
30
35
|
schema.prefixItems = schemas;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
if (hasRules) {
|
|
37
|
+
const rulesMap = [];
|
|
38
|
+
const rules = [];
|
|
39
|
+
if (props.default !== undefined) {
|
|
40
|
+
rules.push(defaultTo.defaultTo(props.default));
|
|
41
|
+
rules.push(tupleOf.tupleOf(rulesMap));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const parentRule = useParentRule.useParentRule();
|
|
45
|
+
rules.push(parentRule(tupleOf.tupleOf(rulesMap)));
|
|
46
|
+
}
|
|
47
|
+
const rule = props.nullable ? oneOf.oneOf([nullable.nullable, pipe.pipe(...rules)]) : pipe.pipe(...rules);
|
|
48
|
+
useRule.useRule(rule);
|
|
49
|
+
useParentRule.parentRuleContext.set(handler, rule => required.required(rule));
|
|
50
|
+
useRule.ruleContext.set(handler, rule => {
|
|
51
|
+
rulesMap.push(rule);
|
|
52
|
+
});
|
|
53
|
+
useEffect.useEffect(() => {
|
|
54
|
+
if (!rulesMap.length) {
|
|
55
|
+
throw Error('<tuple> MUST have content');
|
|
56
|
+
}
|
|
57
|
+
});
|
|
42
58
|
}
|
|
43
|
-
useRule.useRule(pipe.pipe(...rules));
|
|
44
|
-
useParentRule.parentRuleContext.set(handler, rule => required.required(rule));
|
|
45
|
-
useRule.ruleContext.set(handler, rule => {
|
|
46
|
-
rulesMap.push(rule);
|
|
47
|
-
});
|
|
48
59
|
innet.innet(children, handler);
|
|
49
|
-
useEffect.useEffect(() => {
|
|
50
|
-
if (!rulesMap.length) {
|
|
51
|
-
throw Error('<tuple> MUST have content');
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
60
|
}
|
|
55
61
|
};
|
|
56
62
|
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
import { useProps } from '@innet/jsx';
|
|
1
|
+
import { useProps, useContext } from '@innet/jsx';
|
|
2
2
|
import { v4 } from 'uuid';
|
|
3
3
|
import '../../../hooks/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 { uuidTo } from '../../../utils/rules/uuidTo/uuidTo.es6.js';
|
|
8
9
|
import { values, getArrayValues } from '../../../utils/rules/values/values.es6.js';
|
|
10
|
+
import { oneOf } from '../../../utils/rules/oneOf/oneOf.es6.js';
|
|
11
|
+
import { nullable } from '../../../utils/rules/nullable/nullable.es6.js';
|
|
12
|
+
import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
9
13
|
import { useRule } from '../../../hooks/useRule/useRule.es6.js';
|
|
10
14
|
import { optional } from '../../../utils/rules/optional/optional.es6.js';
|
|
11
|
-
import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
12
15
|
|
|
13
16
|
const uuid = () => {
|
|
14
17
|
const { default: defaultValue, ...props } = useProps();
|
|
18
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
19
|
+
const hasRules = !isBody || !props.readOnly;
|
|
15
20
|
const params = {
|
|
16
21
|
...props,
|
|
17
22
|
};
|
|
@@ -25,6 +30,8 @@ const uuid = () => {
|
|
|
25
30
|
// @ts-expect-error: FIXME
|
|
26
31
|
schema['x-default'] = defaultValue;
|
|
27
32
|
}
|
|
33
|
+
if (!hasRules)
|
|
34
|
+
return;
|
|
28
35
|
const rules = [];
|
|
29
36
|
if (defaultValue !== undefined) {
|
|
30
37
|
rules.push(defaultTo(defaultValue === 'new' ? v4 : defaultValue));
|
|
@@ -33,11 +40,12 @@ const uuid = () => {
|
|
|
33
40
|
if (props.values) {
|
|
34
41
|
rules.push(values(getArrayValues(props.values)));
|
|
35
42
|
}
|
|
43
|
+
const rule = props.nullable ? oneOf([nullable, pipe(...rules)]) : pipe(...rules);
|
|
36
44
|
if (defaultValue === undefined) {
|
|
37
|
-
useRule(optional(
|
|
45
|
+
useRule(optional(rule));
|
|
38
46
|
}
|
|
39
47
|
else {
|
|
40
|
-
useRule(
|
|
48
|
+
useRule(rule);
|
|
41
49
|
}
|
|
42
50
|
};
|
|
43
51
|
|
|
@@ -6,16 +6,21 @@ var jsx = require('@innet/jsx');
|
|
|
6
6
|
var uuid$1 = require('uuid');
|
|
7
7
|
require('../../../hooks/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 uuidTo = require('../../../utils/rules/uuidTo/uuidTo.js');
|
|
12
13
|
var values = require('../../../utils/rules/values/values.js');
|
|
14
|
+
var oneOf = require('../../../utils/rules/oneOf/oneOf.js');
|
|
15
|
+
var nullable = require('../../../utils/rules/nullable/nullable.js');
|
|
16
|
+
var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
13
17
|
var useRule = require('../../../hooks/useRule/useRule.js');
|
|
14
18
|
var optional = require('../../../utils/rules/optional/optional.js');
|
|
15
|
-
var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
16
19
|
|
|
17
20
|
const uuid = () => {
|
|
18
21
|
const { default: defaultValue, ...props } = jsx.useProps();
|
|
22
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
23
|
+
const hasRules = !isBody || !props.readOnly;
|
|
19
24
|
const params = {
|
|
20
25
|
...props,
|
|
21
26
|
};
|
|
@@ -29,6 +34,8 @@ const uuid = () => {
|
|
|
29
34
|
// @ts-expect-error: FIXME
|
|
30
35
|
schema['x-default'] = defaultValue;
|
|
31
36
|
}
|
|
37
|
+
if (!hasRules)
|
|
38
|
+
return;
|
|
32
39
|
const rules = [];
|
|
33
40
|
if (defaultValue !== undefined) {
|
|
34
41
|
rules.push(defaultTo.defaultTo(defaultValue === 'new' ? uuid$1.v4 : defaultValue));
|
|
@@ -37,11 +44,12 @@ const uuid = () => {
|
|
|
37
44
|
if (props.values) {
|
|
38
45
|
rules.push(values.values(values.getArrayValues(props.values)));
|
|
39
46
|
}
|
|
47
|
+
const rule = props.nullable ? oneOf.oneOf([nullable.nullable, pipe.pipe(...rules)]) : pipe.pipe(...rules);
|
|
40
48
|
if (defaultValue === undefined) {
|
|
41
|
-
useRule.useRule(optional.optional(
|
|
49
|
+
useRule.useRule(optional.optional(rule));
|
|
42
50
|
}
|
|
43
51
|
else {
|
|
44
|
-
useRule.useRule(
|
|
52
|
+
useRule.useRule(rule);
|
|
45
53
|
}
|
|
46
54
|
};
|
|
47
55
|
|
package/types/appTypes.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { OpenAPIV3_1 as API } from 'openapi-types';
|
|
1
|
+
import type { OpenAPIV3_1 as API, OpenAPIV3_1 } from 'openapi-types';
|
|
2
2
|
import type { ApiErrorValue } from '../constants';
|
|
3
3
|
import { type ServerPlugin } from '../hooks';
|
|
4
4
|
import { type ResponseStatus } from '../plugins';
|
|
@@ -58,6 +58,8 @@ export interface ServerStartParams {
|
|
|
58
58
|
https: boolean;
|
|
59
59
|
port: number;
|
|
60
60
|
}
|
|
61
|
+
export type ApiErrorSchema = Record<ApiErrorValue, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject>;
|
|
62
|
+
export type ApiErrorSchemaRefs = Record<ApiErrorValue, string>;
|
|
61
63
|
export type SchemaValues<T> = (T extends (number | string) ? Record<T, string> : never) | T[];
|
|
62
64
|
export interface BaseSchemaProps<T, D = T> {
|
|
63
65
|
default?: D;
|
|
@@ -1 +1,5 @@
|
|
|
1
|
+
import type { OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
import { type RulesErrors } from './types';
|
|
3
|
+
export declare const inValidationValues: ["body", "query", "cookie", "header", "path"];
|
|
1
4
|
export declare const rulesErrors: readonly ["oneOf", "number", "date", "uuid", "integer", "minimum", "boolean", "minDate", "maxDate", "maximum", "minLength", "maxLength", "values", "object", "array", "tuple", "required", "null", "pattern", "string", "binary", "binaryAccept", "minBin", "maxBin"];
|
|
5
|
+
export declare const rulesErrorSchemas: Record<RulesErrors, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject>;
|