@innet/server 2.0.0-beta.25 → 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/hooks/useData/useData.d.ts +1 -1
- package/hooks/useData/useData.es6.js +4 -4
- package/hooks/useData/useData.js +4 -4
- 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
|
@@ -4,20 +4,56 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var innet = require('innet');
|
|
6
6
|
var jsx = require('@innet/jsx');
|
|
7
|
+
var constants = require('../../../constants.js');
|
|
7
8
|
require('../../../hooks/index.js');
|
|
8
9
|
require('../../../utils/index.js');
|
|
9
10
|
var useTag = require('../../../hooks/useTag/useTag.js');
|
|
10
11
|
var useApi = require('../../../hooks/useApi/useApi.js');
|
|
11
12
|
var getEndpoint = require('../../../utils/getEndpoint/getEndpoint.js');
|
|
13
|
+
var useEffect = require('../../../hooks/useEffect/useEffect.js');
|
|
12
14
|
var useEndpoint = require('../../../hooks/useEndpoint/useEndpoint.js');
|
|
13
15
|
var useServerPlugins = require('../../../hooks/useServerPlugins/useServerPlugins.js');
|
|
14
16
|
|
|
17
|
+
function addErrorRequest(errorSchema, response) {
|
|
18
|
+
if (!response) {
|
|
19
|
+
return {
|
|
20
|
+
content: {
|
|
21
|
+
'application/json': {
|
|
22
|
+
schema: errorSchema,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (!('content' in response)) {
|
|
28
|
+
console.error('Cannot find content in response: ', response);
|
|
29
|
+
return response;
|
|
30
|
+
}
|
|
31
|
+
if (!('application/json' in response.content)) {
|
|
32
|
+
response.content['application/json'] = {
|
|
33
|
+
schema: errorSchema,
|
|
34
|
+
};
|
|
35
|
+
return response;
|
|
36
|
+
}
|
|
37
|
+
const schema = response.content['application/json'].schema;
|
|
38
|
+
if (!schema) {
|
|
39
|
+
response.content['application/json'].schema = errorSchema;
|
|
40
|
+
return response;
|
|
41
|
+
}
|
|
42
|
+
if ('oneOf' in schema) {
|
|
43
|
+
schema.oneOf.push(errorSchema);
|
|
44
|
+
return response;
|
|
45
|
+
}
|
|
46
|
+
response.content['application/json'].schema = {
|
|
47
|
+
oneOf: [schema, errorSchema],
|
|
48
|
+
};
|
|
49
|
+
return response;
|
|
50
|
+
}
|
|
15
51
|
const endpoint = () => {
|
|
16
52
|
const handler = innet.useNewHandler();
|
|
17
53
|
const tag = useTag.useTag();
|
|
18
54
|
const props = jsx.useProps();
|
|
19
|
-
const { docs, endpoints, } = useApi.useApi();
|
|
20
|
-
const { children, deprecated, description, method, operationId, path, private: privateMode, summary, } = props;
|
|
55
|
+
const { docs, endpoints, props: apiProps, } = useApi.useApi();
|
|
56
|
+
const { children, deprecated, description, method, operationId, path, private: privateMode, schemaGeneration = apiProps.schemaGeneration, summary, } = props;
|
|
21
57
|
const { paths } = docs;
|
|
22
58
|
if (!paths)
|
|
23
59
|
throw Error('cannot find paths in docs');
|
|
@@ -50,6 +86,46 @@ const endpoint = () => {
|
|
|
50
86
|
endpoints[method] = { key: '', plugins: new Set() };
|
|
51
87
|
}
|
|
52
88
|
const endpoint = getEndpoint.getEndpoint(path, endpoints[method]);
|
|
89
|
+
if (schemaGeneration) {
|
|
90
|
+
useEffect.useEffect(() => {
|
|
91
|
+
var _a, _b, _c, _d, _e;
|
|
92
|
+
if (operation.requestBody || ((_a = operation.parameters) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
93
|
+
if (!operation.responses) {
|
|
94
|
+
operation.responses = {};
|
|
95
|
+
}
|
|
96
|
+
if (!docs.components) {
|
|
97
|
+
docs.components = {};
|
|
98
|
+
}
|
|
99
|
+
if (!docs.components.schemas) {
|
|
100
|
+
docs.components.schemas = {};
|
|
101
|
+
}
|
|
102
|
+
const ref = (_c = (_b = apiProps.errorShemaRefs) === null || _b === void 0 ? void 0 : _b.requestValidation) !== null && _c !== void 0 ? _c : 'ApiValidationError';
|
|
103
|
+
if (!(ref in docs.components.schemas)) {
|
|
104
|
+
docs.components.schemas[ref] = (_e = (_d = apiProps.errorShema) === null || _d === void 0 ? void 0 : _d.requestValidation) !== null && _e !== void 0 ? _e : constants.defaultRequestValidationSchema;
|
|
105
|
+
}
|
|
106
|
+
operation.responses[400] = addErrorRequest({ $ref: `#/components/schemas/${ref}` }, operation.responses[400]);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
useEffect.useEffect(() => {
|
|
110
|
+
var _a, _b, _c, _d;
|
|
111
|
+
if (operation.requestBody) {
|
|
112
|
+
if (!operation.responses) {
|
|
113
|
+
operation.responses = {};
|
|
114
|
+
}
|
|
115
|
+
if (!docs.components) {
|
|
116
|
+
docs.components = {};
|
|
117
|
+
}
|
|
118
|
+
if (!docs.components.schemas) {
|
|
119
|
+
docs.components.schemas = {};
|
|
120
|
+
}
|
|
121
|
+
const ref = (_b = (_a = apiProps.errorShemaRefs) === null || _a === void 0 ? void 0 : _a.requestValidation) !== null && _b !== void 0 ? _b : 'ApiRequestBodyContentTypeError';
|
|
122
|
+
if (!(ref in docs.components.schemas)) {
|
|
123
|
+
docs.components.schemas[ref] = (_d = (_c = apiProps.errorShema) === null || _c === void 0 ? void 0 : _c.requestBodyContentType) !== null && _d !== void 0 ? _d : constants.defaultRequestBodyContentTypeSchema;
|
|
124
|
+
}
|
|
125
|
+
operation.responses[400] = addErrorRequest({ $ref: `#/components/schemas/${ref}` }, operation.responses[400]);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
53
129
|
// @ts-expect-error: it's always an object
|
|
54
130
|
useEndpoint.endpointContext.set(handler, { endpoint, operation, props });
|
|
55
131
|
// @ts-expect-error: it's always an object
|
|
@@ -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 { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
|
|
6
|
+
import { bodyContext } from '../../../hooks/useBodyContext/useBodyContext.es6.js';
|
|
6
7
|
import { defaultTo } from '../../../utils/rules/defaultTo/defaultTo.es6.js';
|
|
7
8
|
import { useParentRule } from '../../../hooks/useParentRule/useParentRule.es6.js';
|
|
8
9
|
import { useRule } from '../../../hooks/useRule/useRule.es6.js';
|
|
@@ -11,6 +12,10 @@ import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
|
11
12
|
const any = () => {
|
|
12
13
|
const props = useProps();
|
|
13
14
|
useSchemaType('any', props);
|
|
15
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
16
|
+
const hasRules = !isBody || !props.readOnly;
|
|
17
|
+
if (!hasRules)
|
|
18
|
+
return;
|
|
14
19
|
const rules = [];
|
|
15
20
|
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
16
21
|
rules.push(defaultTo(props.default));
|
|
@@ -7,6 +7,7 @@ require('../../../hooks/index.js');
|
|
|
7
7
|
require('../../../hooks/useParentRule/index.js');
|
|
8
8
|
require('../../../utils/index.js');
|
|
9
9
|
var useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
|
|
10
|
+
var useBodyContext = require('../../../hooks/useBodyContext/useBodyContext.js');
|
|
10
11
|
var defaultTo = require('../../../utils/rules/defaultTo/defaultTo.js');
|
|
11
12
|
var useParentRule = require('../../../hooks/useParentRule/useParentRule.js');
|
|
12
13
|
var useRule = require('../../../hooks/useRule/useRule.js');
|
|
@@ -15,6 +16,10 @@ var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
|
15
16
|
const any = () => {
|
|
16
17
|
const props = jsx.useProps();
|
|
17
18
|
useSchemaType.useSchemaType('any', props);
|
|
19
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
20
|
+
const hasRules = !isBody || !props.readOnly;
|
|
21
|
+
if (!hasRules)
|
|
22
|
+
return;
|
|
18
23
|
const rules = [];
|
|
19
24
|
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
20
25
|
rules.push(defaultTo.defaultTo(props.default));
|
|
@@ -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
|
};
|