@innet/server 2.0.0-beta.2 → 2.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1869 -3651
- package/handler/handler.d.ts +5 -2
- package/handler/handler.es6.js +2 -0
- package/handler/handler.js +2 -0
- package/hooks/index.d.ts +25 -23
- package/hooks/index.es6.js +25 -23
- package/hooks/index.js +25 -23
- package/hooks/useAction/useAction.es6.js +1 -1
- package/hooks/useAction/useAction.js +1 -1
- package/hooks/useApi/useApi.d.ts +2 -0
- package/hooks/useData/index.d.ts +1 -0
- package/hooks/useData/index.es6.js +1 -0
- package/hooks/useData/index.js +9 -0
- package/hooks/useData/useData.d.ts +6 -0
- package/hooks/useData/useData.es6.js +29 -0
- package/hooks/useData/useData.js +33 -0
- package/hooks/useEffect/index.d.ts +1 -0
- package/hooks/useEffect/index.es6.js +1 -0
- package/hooks/useEffect/index.js +9 -0
- package/hooks/useEffect/useEffect.d.ts +2 -0
- package/hooks/useEffect/useEffect.es6.js +8 -0
- package/hooks/useEffect/useEffect.js +12 -0
- package/hooks/useSchemaType/useSchemaType.d.ts +2 -2
- package/hooks/useSchemaType/useSchemaType.es6.js +13 -4
- package/hooks/useSchemaType/useSchemaType.js +13 -4
- package/hooks/useSearch/useSearch.es6.js +1 -1
- package/hooks/useSearch/useSearch.js +1 -1
- package/hooks/useServer/useServer.d.ts +2 -0
- package/index.d.ts +2 -2
- package/index.es6.js +90 -86
- package/index.js +204 -193
- package/package.json +5 -4
- package/plugins/handler/serverFn/serverFn.es6.js +1 -1
- package/plugins/handler/serverFn/serverFn.js +1 -5
- package/plugins/index.d.ts +2 -2
- package/plugins/index.es6.js +2 -2
- package/plugins/index.js +2 -2
- package/plugins/main/api/api.es6.js +6 -5
- package/plugins/main/api/api.js +8 -11
- package/plugins/main/body/body.es6.js +4 -4
- package/plugins/main/body/body.js +4 -8
- package/plugins/main/endpoint/endpoint.es6.js +4 -4
- package/plugins/main/endpoint/endpoint.js +4 -8
- package/plugins/main/host/host.es6.js +1 -1
- package/plugins/main/host/host.js +1 -5
- package/plugins/main/index.d.ts +8 -8
- package/plugins/main/index.es6.js +8 -8
- package/plugins/main/index.js +8 -8
- package/plugins/main/param/param.es6.js +1 -1
- package/plugins/main/param/param.js +1 -5
- package/plugins/main/preset/preset.es6.js +1 -1
- package/plugins/main/preset/preset.js +1 -5
- package/plugins/main/response/response.d.ts +2 -1
- package/plugins/main/response/response.es6.js +1 -1
- package/plugins/main/response/response.js +1 -5
- package/plugins/main/server/server.d.ts +4 -0
- package/plugins/main/server/server.es6.js +5 -3
- package/plugins/main/server/server.js +6 -5
- package/plugins/main/tag/index.es6.js +1 -1
- package/plugins/main/tag/index.js +1 -0
- package/plugins/main/tag/tag.d.ts +8 -1
- package/plugins/main/tag/tag.es6.js +20 -3
- package/plugins/main/tag/tag.js +20 -6
- package/plugins/request/cms/cms.es6.js +1 -1
- package/plugins/request/cms/cms.js +2 -3
- package/plugins/request/error/error.es6.js +7 -3
- package/plugins/request/error/error.js +7 -3
- package/plugins/request/file/file.es6.js +2 -2
- package/plugins/request/file/file.js +2 -3
- package/plugins/request/header/header.es6.js +1 -1
- package/plugins/request/header/header.js +1 -1
- package/plugins/request/index.d.ts +5 -5
- package/plugins/request/index.es6.js +5 -5
- package/plugins/request/index.js +5 -5
- package/plugins/request/success/success.es6.js +6 -4
- package/plugins/request/success/success.js +6 -4
- package/plugins/schema/any/any.d.ts +2 -2
- package/plugins/schema/array/array.d.ts +5 -2
- package/plugins/schema/array/array.es6.js +14 -5
- package/plugins/schema/array/array.js +15 -10
- package/plugins/schema/binary/binary.d.ts +4 -0
- package/plugins/schema/boolean/boolean.d.ts +3 -2
- package/plugins/schema/date/date.d.ts +3 -2
- package/plugins/schema/date/date.es6.js +2 -2
- package/plugins/schema/date/date.js +2 -2
- package/plugins/schema/field/field.d.ts +4 -0
- package/plugins/schema/field/field.es6.js +16 -3
- package/plugins/schema/field/field.js +16 -7
- package/plugins/schema/index.d.ts +8 -8
- package/plugins/schema/index.es6.js +8 -8
- package/plugins/schema/index.js +8 -8
- package/plugins/schema/integer/integer.d.ts +39 -2
- package/plugins/schema/integer/integer.es6.js +25 -10
- package/plugins/schema/integer/integer.js +25 -10
- package/plugins/schema/null/null.d.ts +2 -2
- package/plugins/schema/number/number.d.ts +34 -2
- package/plugins/schema/number/number.es6.js +23 -7
- package/plugins/schema/number/number.js +22 -6
- package/plugins/schema/object/object.d.ts +2 -2
- package/plugins/schema/object/object.es6.js +8 -6
- package/plugins/schema/object/object.js +8 -10
- package/plugins/schema/string/string.d.ts +29 -2
- package/plugins/schema/string/string.es6.js +11 -5
- package/plugins/schema/string/string.js +10 -4
- package/plugins/schema/tuple/tuple.d.ts +2 -2
- package/plugins/schema/tuple/tuple.es6.js +4 -4
- package/plugins/schema/tuple/tuple.js +4 -8
- package/plugins/schema/uuid/uuid.d.ts +2 -2
- package/plugins/schema/uuid/uuid.es6.js +2 -2
- package/plugins/schema/uuid/uuid.js +1 -1
- package/plugins/utils/dts/dts.es6.js +5 -2
- package/plugins/utils/dts/dts.js +5 -2
- package/plugins/utils/env/env.es6.js +1 -1
- package/plugins/utils/env/env.js +1 -5
- package/plugins/utils/index.d.ts +3 -2
- package/plugins/utils/index.es6.js +3 -2
- package/plugins/utils/index.js +3 -2
- package/plugins/utils/swagger/swagger.d.ts +1 -0
- package/plugins/utils/swagger/swagger.es6.js +1 -0
- package/plugins/utils/swagger/swagger.js +1 -0
- package/plugins/utils/ui/index.d.ts +1 -0
- package/plugins/utils/ui/index.es6.js +1 -0
- package/plugins/utils/ui/index.js +10 -0
- package/plugins/utils/ui/rapidoc.html.es6.js +3 -0
- package/plugins/utils/ui/rapidoc.html.js +7 -0
- package/plugins/utils/ui/redoc.html.es6.js +3 -0
- package/plugins/utils/ui/redoc.html.js +7 -0
- package/plugins/utils/ui/scalar.html.es6.js +3 -0
- package/plugins/utils/ui/scalar.html.js +7 -0
- package/plugins/utils/ui/swagger.html.es6.js +3 -0
- package/plugins/utils/ui/swagger.html.js +7 -0
- package/plugins/utils/ui/ui.d.ts +13 -0
- package/plugins/utils/ui/ui.es6.js +45 -0
- package/plugins/utils/ui/ui.js +50 -0
- package/types.d.ts +23 -3
- package/utils/generateTypes/generateTypes.es6.js +105 -76
- package/utils/generateTypes/generateTypes.js +105 -76
- package/utils/getSafeSchema/getSafeSchema.d.ts +2 -0
- package/utils/getSafeSchema/getSafeSchema.es6.js +5 -0
- package/utils/getSafeSchema/getSafeSchema.js +9 -0
- package/utils/getSafeSchema/index.d.ts +1 -0
- package/utils/getSafeSchema/index.es6.js +1 -0
- package/utils/getSafeSchema/index.js +9 -0
- package/utils/index.d.ts +9 -8
- package/utils/index.es6.js +9 -8
- package/utils/index.js +9 -8
- package/utils/rules/index.d.ts +17 -17
- package/utils/rules/index.es6.js +17 -17
- package/utils/rules/index.js +18 -18
- package/utils/rules/values/index.es6.js +1 -1
- package/utils/rules/values/index.js +1 -0
- package/utils/rules/values/values.d.ts +3 -1
- package/utils/rules/values/values.es6.js +4 -1
- package/utils/rules/values/values.js +4 -0
|
@@ -12,7 +12,6 @@ var useThrow = require('../../../hooks/useThrow/useThrow.js');
|
|
|
12
12
|
|
|
13
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
14
|
|
|
15
|
-
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
16
15
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
17
16
|
var mime__default = /*#__PURE__*/_interopDefaultLegacy(mime);
|
|
18
17
|
|
|
@@ -21,7 +20,7 @@ function file() {
|
|
|
21
20
|
const { children, ...props } = jsx.useProps();
|
|
22
21
|
const res = useResponse.useResponse();
|
|
23
22
|
if (!res) {
|
|
24
|
-
useThrow.useThrow('<{type}> MUST be in <
|
|
23
|
+
useThrow.useThrow('<{type}> MUST be in <return> or <preset>');
|
|
25
24
|
}
|
|
26
25
|
const { path } = props;
|
|
27
26
|
if (fs__default["default"].existsSync(path)) {
|
|
@@ -40,7 +39,7 @@ function file() {
|
|
|
40
39
|
return;
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
|
-
|
|
42
|
+
innet.innet(children, handler);
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
exports.file = file;
|
|
@@ -6,7 +6,7 @@ import { useThrow } from '../../../hooks/useThrow/useThrow.es6.js';
|
|
|
6
6
|
const header = () => {
|
|
7
7
|
const res = useResponse();
|
|
8
8
|
if (!res) {
|
|
9
|
-
useThrow('<{type}> MUST be in <
|
|
9
|
+
useThrow('<{type}> MUST be in <return> or <preset>');
|
|
10
10
|
}
|
|
11
11
|
const { key, value, } = useProps();
|
|
12
12
|
res.setHeader(key, value);
|
|
@@ -10,7 +10,7 @@ var useThrow = require('../../../hooks/useThrow/useThrow.js');
|
|
|
10
10
|
const header = () => {
|
|
11
11
|
const res = useResponse.useResponse();
|
|
12
12
|
if (!res) {
|
|
13
|
-
useThrow.useThrow('<{type}> MUST be in <
|
|
13
|
+
useThrow.useThrow('<{type}> MUST be in <return> or <preset>');
|
|
14
14
|
}
|
|
15
15
|
const { key, value, } = jsx.useProps();
|
|
16
16
|
res.setHeader(key, value);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './cms';
|
|
2
|
+
export * from './cookie';
|
|
2
3
|
export * from './error';
|
|
4
|
+
export * from './file';
|
|
5
|
+
export * from './header';
|
|
3
6
|
export * from './proxy';
|
|
4
7
|
export * from './redirect';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './cookie';
|
|
7
|
-
export * from './file';
|
|
8
|
-
export * from './cms';
|
|
8
|
+
export * from './success';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import './
|
|
1
|
+
import './cms/index.es6.js';
|
|
2
|
+
import './cookie/index.es6.js';
|
|
2
3
|
import './error/index.es6.js';
|
|
4
|
+
import './file/index.es6.js';
|
|
5
|
+
import './header/index.es6.js';
|
|
3
6
|
import './proxy/index.es6.js';
|
|
4
7
|
import './redirect/index.es6.js';
|
|
5
|
-
import './
|
|
6
|
-
import './cookie/index.es6.js';
|
|
7
|
-
import './file/index.es6.js';
|
|
8
|
-
import './cms/index.es6.js';
|
|
8
|
+
import './success/index.es6.js';
|
package/plugins/request/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./
|
|
3
|
+
require('./cms/index.js');
|
|
4
|
+
require('./cookie/index.js');
|
|
4
5
|
require('./error/index.js');
|
|
6
|
+
require('./file/index.js');
|
|
7
|
+
require('./header/index.js');
|
|
5
8
|
require('./proxy/index.js');
|
|
6
9
|
require('./redirect/index.js');
|
|
7
|
-
require('./
|
|
8
|
-
require('./cookie/index.js');
|
|
9
|
-
require('./file/index.js');
|
|
10
|
-
require('./cms/index.js');
|
|
10
|
+
require('./success/index.js');
|
|
11
11
|
|
|
@@ -28,13 +28,15 @@ const success = () => {
|
|
|
28
28
|
? 'text/plain'
|
|
29
29
|
: 'application/json');
|
|
30
30
|
const content = contentType === 'application/json' ? JSONString(child) : String(child);
|
|
31
|
-
res.setHeader('Content-Type', contentType
|
|
32
|
-
|
|
31
|
+
res.setHeader('Content-Type', contentType === 'application/json'
|
|
32
|
+
? 'application/json; charset=utf-8'
|
|
33
|
+
: contentType);
|
|
34
|
+
res.setHeader('Content-Length', Buffer.byteLength(content));
|
|
33
35
|
if (contentType === 'application/json') {
|
|
34
|
-
res.write(
|
|
36
|
+
res.write(content, 'utf-8');
|
|
35
37
|
}
|
|
36
38
|
else {
|
|
37
|
-
res.write(
|
|
39
|
+
res.write(content);
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
res.end();
|
|
@@ -32,13 +32,15 @@ const success = () => {
|
|
|
32
32
|
? 'text/plain'
|
|
33
33
|
: 'application/json');
|
|
34
34
|
const content = contentType === 'application/json' ? JSONString.JSONString(child) : String(child);
|
|
35
|
-
res.setHeader('Content-Type', contentType
|
|
36
|
-
|
|
35
|
+
res.setHeader('Content-Type', contentType === 'application/json'
|
|
36
|
+
? 'application/json; charset=utf-8'
|
|
37
|
+
: contentType);
|
|
38
|
+
res.setHeader('Content-Length', Buffer.byteLength(content));
|
|
37
39
|
if (contentType === 'application/json') {
|
|
38
|
-
res.write(
|
|
40
|
+
res.write(content, 'utf-8');
|
|
39
41
|
}
|
|
40
42
|
else {
|
|
41
|
-
res.write(
|
|
43
|
+
res.write(content);
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
res.end();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
|
-
import { type
|
|
3
|
-
export interface AnyProps extends
|
|
2
|
+
import { type SchemaProps } from '../../../types';
|
|
3
|
+
export interface AnyProps extends SchemaProps<any> {
|
|
4
4
|
}
|
|
5
5
|
export declare const any: HandlerPlugin;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
|
-
import { type
|
|
3
|
-
export interface ArrayProps extends
|
|
2
|
+
import { type SchemaProps } from '../../../types';
|
|
3
|
+
export interface ArrayProps extends SchemaProps<any[]> {
|
|
4
4
|
children?: any;
|
|
5
|
+
maxItems?: number;
|
|
6
|
+
minItems?: number;
|
|
7
|
+
uniqueItems?: boolean;
|
|
5
8
|
}
|
|
6
9
|
export declare const array: HandlerPlugin;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useNewHandler, innet } from 'innet';
|
|
2
2
|
import { useContext, useProps } from '@innet/jsx';
|
|
3
|
-
import { callHandler } from '@innet/utils';
|
|
4
3
|
import '../../../hooks/index.es6.js';
|
|
5
4
|
import '../../../hooks/useParentRule/index.es6.js';
|
|
6
5
|
import '../../../utils/index.es6.js';
|
|
@@ -13,16 +12,26 @@ import { defaultTo } from '../../../utils/rules/defaultTo/defaultTo.es6.js';
|
|
|
13
12
|
import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
14
13
|
import { arrayOf } from '../../../utils/rules/arrayOf/arrayOf.es6.js';
|
|
15
14
|
import { oneOf } from '../../../utils/rules/oneOf/oneOf.es6.js';
|
|
15
|
+
import { useEffect } from '../../../hooks/useEffect/useEffect.es6.js';
|
|
16
16
|
|
|
17
17
|
const array = () => {
|
|
18
18
|
useBlock('path');
|
|
19
19
|
const setRule = useContext(ruleContext);
|
|
20
20
|
const handler = useNewHandler();
|
|
21
|
-
const { children, ...props } = useProps();
|
|
21
|
+
const { children, maxItems, minItems, uniqueItems, ...props } = useProps();
|
|
22
22
|
const schema = useSchemaType('array', props);
|
|
23
23
|
const fieldSchema = {};
|
|
24
24
|
handler[schemaContext.key] = fieldSchema;
|
|
25
25
|
schema.items = fieldSchema;
|
|
26
|
+
if (maxItems) {
|
|
27
|
+
schema.maxItems = maxItems;
|
|
28
|
+
}
|
|
29
|
+
if (minItems) {
|
|
30
|
+
schema.minItems = minItems;
|
|
31
|
+
}
|
|
32
|
+
if (uniqueItems) {
|
|
33
|
+
schema.uniqueItems = uniqueItems;
|
|
34
|
+
}
|
|
26
35
|
if (setRule) {
|
|
27
36
|
let oneOfRulesMap;
|
|
28
37
|
const rules = [];
|
|
@@ -44,11 +53,11 @@ const array = () => {
|
|
|
44
53
|
}
|
|
45
54
|
});
|
|
46
55
|
innet(children, handler);
|
|
47
|
-
|
|
56
|
+
useEffect(() => {
|
|
48
57
|
if (!oneOfRulesMap && setRule) {
|
|
49
58
|
setRule(rootRule(e => e));
|
|
50
59
|
}
|
|
51
|
-
}
|
|
60
|
+
});
|
|
52
61
|
return;
|
|
53
62
|
}
|
|
54
63
|
innet(children, handler);
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var innet = require('innet');
|
|
6
6
|
var jsx = require('@innet/jsx');
|
|
7
|
-
var utils = require('@innet/utils');
|
|
8
7
|
require('../../../hooks/index.js');
|
|
9
8
|
require('../../../hooks/useParentRule/index.js');
|
|
10
9
|
require('../../../utils/index.js');
|
|
@@ -17,20 +16,26 @@ var defaultTo = require('../../../utils/rules/defaultTo/defaultTo.js');
|
|
|
17
16
|
var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
18
17
|
var arrayOf = require('../../../utils/rules/arrayOf/arrayOf.js');
|
|
19
18
|
var oneOf = require('../../../utils/rules/oneOf/oneOf.js');
|
|
20
|
-
|
|
21
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
|
-
|
|
23
|
-
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
19
|
+
var useEffect = require('../../../hooks/useEffect/useEffect.js');
|
|
24
20
|
|
|
25
21
|
const array = () => {
|
|
26
22
|
useBlock.useBlock('path');
|
|
27
23
|
const setRule = jsx.useContext(useRule.ruleContext);
|
|
28
24
|
const handler = innet.useNewHandler();
|
|
29
|
-
const { children, ...props } = jsx.useProps();
|
|
25
|
+
const { children, maxItems, minItems, uniqueItems, ...props } = jsx.useProps();
|
|
30
26
|
const schema = useSchemaType.useSchemaType('array', props);
|
|
31
27
|
const fieldSchema = {};
|
|
32
28
|
handler[useSchemaContext.schemaContext.key] = fieldSchema;
|
|
33
29
|
schema.items = fieldSchema;
|
|
30
|
+
if (maxItems) {
|
|
31
|
+
schema.maxItems = maxItems;
|
|
32
|
+
}
|
|
33
|
+
if (minItems) {
|
|
34
|
+
schema.minItems = minItems;
|
|
35
|
+
}
|
|
36
|
+
if (uniqueItems) {
|
|
37
|
+
schema.uniqueItems = uniqueItems;
|
|
38
|
+
}
|
|
34
39
|
if (setRule) {
|
|
35
40
|
let oneOfRulesMap;
|
|
36
41
|
const rules = [];
|
|
@@ -51,15 +56,15 @@ const array = () => {
|
|
|
51
56
|
setRule(rootRule(oneOf.oneOf(oneOfRulesMap)));
|
|
52
57
|
}
|
|
53
58
|
});
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
innet.innet(children, handler);
|
|
60
|
+
useEffect.useEffect(() => {
|
|
56
61
|
if (!oneOfRulesMap && setRule) {
|
|
57
62
|
setRule(rootRule(e => e));
|
|
58
63
|
}
|
|
59
|
-
}
|
|
64
|
+
});
|
|
60
65
|
return;
|
|
61
66
|
}
|
|
62
|
-
|
|
67
|
+
innet.innet(children, handler);
|
|
63
68
|
};
|
|
64
69
|
|
|
65
70
|
exports.array = array;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
export interface BinaryProps {
|
|
3
3
|
accept?: string;
|
|
4
|
+
deprecated: boolean;
|
|
4
5
|
description?: string;
|
|
5
6
|
max?: number;
|
|
6
7
|
min?: number;
|
|
8
|
+
readOnly: boolean;
|
|
7
9
|
ref?: string;
|
|
10
|
+
title?: string;
|
|
11
|
+
writeOnly: boolean;
|
|
8
12
|
}
|
|
9
13
|
export declare const binary: HandlerPlugin;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
|
-
import { type
|
|
3
|
-
export interface BooleanProps extends
|
|
2
|
+
import { type SchemaProps } from '../../../types';
|
|
3
|
+
export interface BooleanProps extends SchemaProps<boolean> {
|
|
4
|
+
const?: boolean;
|
|
4
5
|
}
|
|
5
6
|
export declare const boolean: HandlerPlugin;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
|
-
import { type
|
|
2
|
+
import { type SchemaProps } from '../../../types';
|
|
3
3
|
import { type DateFormat } from '../../../utils';
|
|
4
|
-
export interface DateProps extends
|
|
4
|
+
export interface DateProps extends Omit<SchemaProps<DateFormat>, 'value'> {
|
|
5
|
+
const?: string;
|
|
5
6
|
max?: DateFormat;
|
|
6
7
|
min?: DateFormat;
|
|
7
8
|
}
|
|
@@ -4,10 +4,10 @@ import '../../../hooks/useParentRule/index.es6.js';
|
|
|
4
4
|
import '../../../utils/index.es6.js';
|
|
5
5
|
import '../../../utils/dateFormat/index.es6.js';
|
|
6
6
|
import { dateFormat } from '../../../utils/dateFormat/dateFormat.es6.js';
|
|
7
|
+
import { getArrayValues, values } from '../../../utils/rules/values/values.es6.js';
|
|
7
8
|
import { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
|
|
8
9
|
import { defaultTo } from '../../../utils/rules/defaultTo/defaultTo.es6.js';
|
|
9
10
|
import { dateTo } from '../../../utils/rules/dateTo/dateTo.es6.js';
|
|
10
|
-
import { values } from '../../../utils/rules/values/values.es6.js';
|
|
11
11
|
import { minDate } from '../../../utils/rules/minDate/minDate.es6.js';
|
|
12
12
|
import { maxDate } from '../../../utils/rules/maxDate/maxDate.es6.js';
|
|
13
13
|
import { useParentRule } from '../../../hooks/useParentRule/useParentRule.es6.js';
|
|
@@ -20,7 +20,7 @@ const date = () => {
|
|
|
20
20
|
const normMax = dateFormat(max);
|
|
21
21
|
const normDefault = dateFormat(defaultValue);
|
|
22
22
|
const normExample = dateFormat(example);
|
|
23
|
-
const normValues = values$1
|
|
23
|
+
const normValues = values$1 && getArrayValues(values$1, dateFormat);
|
|
24
24
|
// @ts-expect-error: FIXME
|
|
25
25
|
const stringValues = normValues === null || normValues === void 0 ? void 0 : normValues.map(value => value.toISOString());
|
|
26
26
|
const normExamples = examples === null || examples === void 0 ? void 0 : examples.map(dateFormat);
|
|
@@ -8,10 +8,10 @@ require('../../../hooks/useParentRule/index.js');
|
|
|
8
8
|
require('../../../utils/index.js');
|
|
9
9
|
require('../../../utils/dateFormat/index.js');
|
|
10
10
|
var dateFormat = require('../../../utils/dateFormat/dateFormat.js');
|
|
11
|
+
var values = require('../../../utils/rules/values/values.js');
|
|
11
12
|
var useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
|
|
12
13
|
var defaultTo = require('../../../utils/rules/defaultTo/defaultTo.js');
|
|
13
14
|
var dateTo = require('../../../utils/rules/dateTo/dateTo.js');
|
|
14
|
-
var values = require('../../../utils/rules/values/values.js');
|
|
15
15
|
var minDate = require('../../../utils/rules/minDate/minDate.js');
|
|
16
16
|
var maxDate = require('../../../utils/rules/maxDate/maxDate.js');
|
|
17
17
|
var useParentRule = require('../../../hooks/useParentRule/useParentRule.js');
|
|
@@ -24,7 +24,7 @@ const date = () => {
|
|
|
24
24
|
const normMax = dateFormat.dateFormat(max);
|
|
25
25
|
const normDefault = dateFormat.dateFormat(defaultValue);
|
|
26
26
|
const normExample = dateFormat.dateFormat(example);
|
|
27
|
-
const normValues = values$1
|
|
27
|
+
const normValues = values$1 && values.getArrayValues(values$1, dateFormat.dateFormat);
|
|
28
28
|
// @ts-expect-error: FIXME
|
|
29
29
|
const stringValues = normValues === null || normValues === void 0 ? void 0 : normValues.map(value => value.toISOString());
|
|
30
30
|
const normExamples = examples === null || examples === void 0 ? void 0 : examples.map(dateFormat.dateFormat);
|
|
@@ -2,7 +2,11 @@ import { type HandlerPlugin } from 'innet';
|
|
|
2
2
|
export interface FieldProps {
|
|
3
3
|
children?: any;
|
|
4
4
|
deprecated?: boolean;
|
|
5
|
+
description?: string;
|
|
5
6
|
key: string;
|
|
6
7
|
optional?: boolean;
|
|
8
|
+
readOnly?: boolean;
|
|
9
|
+
title?: string;
|
|
10
|
+
writeOnly?: boolean;
|
|
7
11
|
}
|
|
8
12
|
export declare const field: HandlerPlugin;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useNewHandler, innet } from 'innet';
|
|
2
2
|
import { useProps } from '@innet/jsx';
|
|
3
3
|
import '../../../hooks/index.es6.js';
|
|
4
4
|
import '../../../utils/index.es6.js';
|
|
5
|
+
import { getSafeSchema } from '../../../utils/getSafeSchema/getSafeSchema.es6.js';
|
|
5
6
|
import { useObjectSchemaContext } from '../../../hooks/useObjectSchemaContext/useObjectSchemaContext.es6.js';
|
|
6
7
|
import { schemaContext } from '../../../hooks/useSchemaContext/useSchemaContext.es6.js';
|
|
7
8
|
import { useObjectRule, objectRuleContext } from '../../../hooks/useObjectRule/useObjectRule.es6.js';
|
|
@@ -10,8 +11,8 @@ import { required } from '../../../utils/rules/required/required.es6.js';
|
|
|
10
11
|
|
|
11
12
|
const field = () => {
|
|
12
13
|
const handler = useNewHandler();
|
|
13
|
-
const { children, deprecated, key, optional, } = useProps();
|
|
14
|
-
const schema = useObjectSchemaContext();
|
|
14
|
+
const { children, deprecated, description, key, optional, readOnly, title, writeOnly, } = useProps();
|
|
15
|
+
const schema = getSafeSchema(useObjectSchemaContext());
|
|
15
16
|
if (!schema.properties) {
|
|
16
17
|
schema.properties = {};
|
|
17
18
|
}
|
|
@@ -23,6 +24,18 @@ const field = () => {
|
|
|
23
24
|
if (deprecated) {
|
|
24
25
|
fieldSchema.deprecated = true;
|
|
25
26
|
}
|
|
27
|
+
if (title) {
|
|
28
|
+
fieldSchema.title = title;
|
|
29
|
+
}
|
|
30
|
+
if (description) {
|
|
31
|
+
fieldSchema.description = description;
|
|
32
|
+
}
|
|
33
|
+
if (readOnly) {
|
|
34
|
+
fieldSchema.readOnly = true;
|
|
35
|
+
}
|
|
36
|
+
if (writeOnly) {
|
|
37
|
+
fieldSchema.writeOnly = true;
|
|
38
|
+
}
|
|
26
39
|
schema.properties[key] = fieldSchema;
|
|
27
40
|
if (!optional) {
|
|
28
41
|
if (!schema.required) {
|
|
@@ -6,20 +6,17 @@ var innet = require('innet');
|
|
|
6
6
|
var jsx = require('@innet/jsx');
|
|
7
7
|
require('../../../hooks/index.js');
|
|
8
8
|
require('../../../utils/index.js');
|
|
9
|
+
var getSafeSchema = require('../../../utils/getSafeSchema/getSafeSchema.js');
|
|
9
10
|
var useObjectSchemaContext = require('../../../hooks/useObjectSchemaContext/useObjectSchemaContext.js');
|
|
10
11
|
var useSchemaContext = require('../../../hooks/useSchemaContext/useSchemaContext.js');
|
|
11
12
|
var useObjectRule = require('../../../hooks/useObjectRule/useObjectRule.js');
|
|
12
13
|
var useRule = require('../../../hooks/useRule/useRule.js');
|
|
13
14
|
var required = require('../../../utils/rules/required/required.js');
|
|
14
15
|
|
|
15
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
|
-
|
|
17
|
-
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
18
|
-
|
|
19
16
|
const field = () => {
|
|
20
17
|
const handler = innet.useNewHandler();
|
|
21
|
-
const { children, deprecated, key, optional, } = jsx.useProps();
|
|
22
|
-
const schema = useObjectSchemaContext.useObjectSchemaContext();
|
|
18
|
+
const { children, deprecated, description, key, optional, readOnly, title, writeOnly, } = jsx.useProps();
|
|
19
|
+
const schema = getSafeSchema.getSafeSchema(useObjectSchemaContext.useObjectSchemaContext());
|
|
23
20
|
if (!schema.properties) {
|
|
24
21
|
schema.properties = {};
|
|
25
22
|
}
|
|
@@ -31,6 +28,18 @@ const field = () => {
|
|
|
31
28
|
if (deprecated) {
|
|
32
29
|
fieldSchema.deprecated = true;
|
|
33
30
|
}
|
|
31
|
+
if (title) {
|
|
32
|
+
fieldSchema.title = title;
|
|
33
|
+
}
|
|
34
|
+
if (description) {
|
|
35
|
+
fieldSchema.description = description;
|
|
36
|
+
}
|
|
37
|
+
if (readOnly) {
|
|
38
|
+
fieldSchema.readOnly = true;
|
|
39
|
+
}
|
|
40
|
+
if (writeOnly) {
|
|
41
|
+
fieldSchema.writeOnly = true;
|
|
42
|
+
}
|
|
34
43
|
schema.properties[key] = fieldSchema;
|
|
35
44
|
if (!optional) {
|
|
36
45
|
if (!schema.required) {
|
|
@@ -48,7 +57,7 @@ const field = () => {
|
|
|
48
57
|
}
|
|
49
58
|
});
|
|
50
59
|
useObjectRule.objectRuleContext.set(handler, null);
|
|
51
|
-
|
|
60
|
+
innet.innet(children, handler);
|
|
52
61
|
};
|
|
53
62
|
|
|
54
63
|
exports.field = field;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './field';
|
|
3
|
-
export * from './number';
|
|
4
|
-
export * from './integer';
|
|
5
|
-
export * from './string';
|
|
1
|
+
export * from './any';
|
|
6
2
|
export * from './array';
|
|
3
|
+
export * from './binary';
|
|
7
4
|
export * from './boolean';
|
|
8
|
-
export * from './null';
|
|
9
5
|
export * from './date';
|
|
6
|
+
export * from './field';
|
|
7
|
+
export * from './integer';
|
|
8
|
+
export * from './null';
|
|
9
|
+
export * from './number';
|
|
10
|
+
export * from './object';
|
|
11
|
+
export * from './string';
|
|
10
12
|
export * from './tuple';
|
|
11
13
|
export * from './uuid';
|
|
12
|
-
export * from './binary';
|
|
13
|
-
export * from './any';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import './
|
|
2
|
-
import './field/index.es6.js';
|
|
3
|
-
import './number/index.es6.js';
|
|
4
|
-
import './integer/index.es6.js';
|
|
5
|
-
import './string/index.es6.js';
|
|
1
|
+
import './any/index.es6.js';
|
|
6
2
|
import './array/index.es6.js';
|
|
3
|
+
import './binary/index.es6.js';
|
|
7
4
|
import './boolean/index.es6.js';
|
|
8
|
-
import './null/index.es6.js';
|
|
9
5
|
import './date/index.es6.js';
|
|
6
|
+
import './field/index.es6.js';
|
|
7
|
+
import './integer/index.es6.js';
|
|
8
|
+
import './null/index.es6.js';
|
|
9
|
+
import './number/index.es6.js';
|
|
10
|
+
import './object/index.es6.js';
|
|
11
|
+
import './string/index.es6.js';
|
|
10
12
|
import './tuple/index.es6.js';
|
|
11
13
|
import './uuid/index.es6.js';
|
|
12
|
-
import './binary/index.es6.js';
|
|
13
|
-
import './any/index.es6.js';
|
package/plugins/schema/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./
|
|
4
|
-
require('./field/index.js');
|
|
5
|
-
require('./number/index.js');
|
|
6
|
-
require('./integer/index.js');
|
|
7
|
-
require('./string/index.js');
|
|
3
|
+
require('./any/index.js');
|
|
8
4
|
require('./array/index.js');
|
|
5
|
+
require('./binary/index.js');
|
|
9
6
|
require('./boolean/index.js');
|
|
10
|
-
require('./null/index.js');
|
|
11
7
|
require('./date/index.js');
|
|
8
|
+
require('./field/index.js');
|
|
9
|
+
require('./integer/index.js');
|
|
10
|
+
require('./null/index.js');
|
|
11
|
+
require('./number/index.js');
|
|
12
|
+
require('./object/index.js');
|
|
13
|
+
require('./string/index.js');
|
|
12
14
|
require('./tuple/index.js');
|
|
13
15
|
require('./uuid/index.js');
|
|
14
|
-
require('./binary/index.js');
|
|
15
|
-
require('./any/index.js');
|
|
16
16
|
|
|
@@ -1,8 +1,45 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
|
-
import { type IntegerFormats, type
|
|
3
|
-
export interface IntegerProps extends
|
|
2
|
+
import { type IntegerFormats, type SchemaProps } from '../../../types';
|
|
3
|
+
export interface IntegerProps extends SchemaProps<bigint | number> {
|
|
4
|
+
/**
|
|
5
|
+
* The `exclusiveMaximum` keyword is used to restrict the value to be less than the specified number.
|
|
6
|
+
* @example For example, the following value is valid:
|
|
7
|
+
* ```tsx
|
|
8
|
+
* <integer exclusiveMaximum={10} />
|
|
9
|
+
* ```
|
|
10
|
+
* @see https://swagger.io/docs/specification/v3_0/data-models/data-types/#numbers
|
|
11
|
+
* */
|
|
12
|
+
exclusiveMaximum?: bigint | boolean | number;
|
|
13
|
+
/**
|
|
14
|
+
* The `exclusiveMinimum` keyword is used to restrict the value to be greater than the specified number.
|
|
15
|
+
* @example For example, the following value is valid:
|
|
16
|
+
* ```tsx
|
|
17
|
+
* <integer exclusiveMinimum={10} />
|
|
18
|
+
* ```
|
|
19
|
+
* @see https://swagger.io/docs/specification/v3_0/data-models/data-types/#numbers
|
|
20
|
+
* */
|
|
21
|
+
exclusiveMinimum?: bigint | boolean | number;
|
|
22
|
+
/**
|
|
23
|
+
* An optional format modifier serves as a hint at the contents and format of the string.
|
|
24
|
+
* @example For example, the following value is valid:
|
|
25
|
+
* ```tsx
|
|
26
|
+
* <integer format='int64' />
|
|
27
|
+
* ```
|
|
28
|
+
* @see https://swagger.io/docs/specification/data-models/data-types/#numbers
|
|
29
|
+
* */
|
|
4
30
|
format?: IntegerFormats;
|
|
31
|
+
/** Validate the integer number value by maximum. */
|
|
5
32
|
max?: bigint | number;
|
|
33
|
+
/** Validate the integer number value by minimum. */
|
|
6
34
|
min?: bigint | number;
|
|
35
|
+
/**
|
|
36
|
+
* The `multipleOf` keyword is used to restrict the value to be a multiple of the specified number.
|
|
37
|
+
* @example For example, the following value is valid:
|
|
38
|
+
* ```tsx
|
|
39
|
+
* <number multipleOf={2} />
|
|
40
|
+
* ```
|
|
41
|
+
* @see https://swagger.io/docs/specification/v3_0/data-models/data-types/#numbers
|
|
42
|
+
* */
|
|
43
|
+
multipleOf?: bigint | number;
|
|
7
44
|
}
|
|
8
45
|
export declare const integer: HandlerPlugin;
|
|
@@ -2,9 +2,9 @@ import { useProps } from '@innet/jsx';
|
|
|
2
2
|
import '../../../hooks/index.es6.js';
|
|
3
3
|
import '../../../utils/index.es6.js';
|
|
4
4
|
import { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
|
|
5
|
+
import { getArrayValues, values } from '../../../utils/rules/values/values.es6.js';
|
|
5
6
|
import { defaultTo } from '../../../utils/rules/defaultTo/defaultTo.es6.js';
|
|
6
7
|
import { int } from '../../../utils/rules/int/int.es6.js';
|
|
7
|
-
import { values } from '../../../utils/rules/values/values.es6.js';
|
|
8
8
|
import { min } from '../../../utils/rules/min/min.es6.js';
|
|
9
9
|
import { max } from '../../../utils/rules/max/max.es6.js';
|
|
10
10
|
import { useRule } from '../../../hooks/useRule/useRule.es6.js';
|
|
@@ -12,27 +12,42 @@ import { optional } from '../../../utils/rules/optional/optional.es6.js';
|
|
|
12
12
|
import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
13
13
|
|
|
14
14
|
const integer = () => {
|
|
15
|
-
const { default: defaultValue, example, examples, format = 'int32', max: max$1, min: min$1, values: values$1, ...props } = useProps() || {};
|
|
15
|
+
const { default: defaultValue, example, examples, exclusiveMaximum, exclusiveMinimum, format = 'int32', max: max$1, min: min$1, multipleOf, values: values$1, ...props } = useProps() || {};
|
|
16
16
|
const schema = useSchemaType('integer', {
|
|
17
17
|
...props,
|
|
18
18
|
default: defaultValue !== undefined ? Number(defaultValue) : undefined,
|
|
19
19
|
example: example !== undefined ? Number(example) : undefined,
|
|
20
20
|
examples: examples === null || examples === void 0 ? void 0 : examples.map(Number),
|
|
21
|
-
|
|
21
|
+
value: props.value !== undefined ? Number(props.value) : undefined,
|
|
22
|
+
values: values$1 && getArrayValues(values$1, Number),
|
|
22
23
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
if (schema) {
|
|
25
|
+
if (format) {
|
|
26
|
+
schema.format = format;
|
|
27
|
+
}
|
|
28
|
+
if (min$1 !== undefined) {
|
|
29
|
+
schema.minimum = Number(min$1);
|
|
30
|
+
}
|
|
31
|
+
if (max$1 !== undefined) {
|
|
32
|
+
schema.maximum = Number(max$1);
|
|
33
|
+
}
|
|
34
|
+
if (exclusiveMinimum) {
|
|
35
|
+
schema.exclusiveMinimum = typeof exclusiveMinimum === 'boolean' ? exclusiveMinimum : Number(exclusiveMinimum);
|
|
36
|
+
}
|
|
37
|
+
if (exclusiveMaximum) {
|
|
38
|
+
schema.exclusiveMaximum = typeof exclusiveMaximum === 'boolean' ? exclusiveMaximum : Number(exclusiveMaximum);
|
|
39
|
+
}
|
|
40
|
+
if (multipleOf !== undefined) {
|
|
41
|
+
schema.multipleOf = Number(multipleOf);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
29
44
|
const rules = [];
|
|
30
45
|
if (defaultValue !== undefined) {
|
|
31
46
|
rules.push(defaultTo(defaultValue));
|
|
32
47
|
}
|
|
33
48
|
rules.push(int(format));
|
|
34
49
|
if (values$1) {
|
|
35
|
-
rules.push(values(values$1
|
|
50
|
+
rules.push(values(getArrayValues(values$1, int(format))));
|
|
36
51
|
}
|
|
37
52
|
if (min$1 !== undefined) {
|
|
38
53
|
rules.push(min(min$1));
|