@innet/server 2.0.0-beta.26 → 2.0.0-beta.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constants.d.ts +3 -0
- package/constants.es6.js +28 -1
- package/constants.js +29 -0
- package/hooks/index.d.ts +1 -1
- package/hooks/index.es6.js +1 -1
- package/hooks/index.js +1 -1
- package/hooks/useBodyContext/index.d.ts +1 -0
- package/hooks/useBodyContext/index.es6.js +1 -0
- package/hooks/useBodyContext/index.js +10 -0
- package/hooks/useBodyContext/useBodyContext.d.ts +6 -0
- package/hooks/{useBodyFile/useBodyFile.es6.js → useBodyContext/useBodyContext.es6.js} +6 -6
- package/hooks/{useBodyFile/useBodyFile.js → useBodyContext/useBodyContext.js} +7 -7
- package/index.es6.js +2 -2
- package/index.js +5 -3
- package/package.json +1 -1
- package/plugins/main/api/api.d.ts +7 -0
- package/plugins/main/api/api.es6.js +2 -4
- package/plugins/main/api/api.js +2 -4
- package/plugins/main/body/body.es6.js +6 -4
- package/plugins/main/body/body.js +6 -4
- package/plugins/main/endpoint/endpoint.d.ts +2 -0
- package/plugins/main/endpoint/endpoint.es6.js +78 -2
- package/plugins/main/endpoint/endpoint.js +78 -2
- package/plugins/schema/any/any.es6.js +6 -1
- package/plugins/schema/any/any.js +5 -0
- package/plugins/schema/array/array.es6.js +4 -1
- package/plugins/schema/array/array.js +4 -1
- package/plugins/schema/binary/binary.es6.js +7 -3
- package/plugins/schema/binary/binary.js +6 -2
- package/plugins/schema/boolean/boolean.es6.js +6 -1
- package/plugins/schema/boolean/boolean.js +5 -0
- package/plugins/schema/date/date.es6.js +6 -1
- package/plugins/schema/date/date.js +5 -0
- package/plugins/schema/integer/integer.es6.js +6 -1
- package/plugins/schema/integer/integer.js +5 -0
- package/plugins/schema/null/null.es6.js +8 -2
- package/plugins/schema/null/null.js +7 -1
- package/plugins/schema/number/number.es6.js +6 -1
- package/plugins/schema/number/number.js +5 -0
- package/plugins/schema/object/object.es6.js +34 -29
- package/plugins/schema/object/object.js +33 -28
- package/plugins/schema/string/string.es6.js +7 -2
- package/plugins/schema/string/string.js +6 -1
- package/plugins/schema/tuple/tuple.es6.js +27 -22
- package/plugins/schema/tuple/tuple.js +26 -21
- package/plugins/schema/uuid/uuid.es6.js +6 -1
- package/plugins/schema/uuid/uuid.js +5 -0
- package/types/appTypes.d.ts +3 -1
- package/utils/rules/constants.d.ts +4 -0
- package/utils/rules/constants.es6.js +547 -1
- package/utils/rules/constants.js +548 -0
- package/utils/rules/index.es6.js +1 -1
- package/utils/rules/index.js +2 -0
- package/hooks/useBodyFile/index.d.ts +0 -1
- package/hooks/useBodyFile/index.es6.js +0 -1
- package/hooks/useBodyFile/index.js +0 -10
- package/hooks/useBodyFile/useBodyFile.d.ts +0 -3
|
@@ -1,9 +1,10 @@
|
|
|
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';
|
|
@@ -18,35 +19,39 @@ const tuple = () => {
|
|
|
18
19
|
useBlock('path');
|
|
19
20
|
const handler = useNewHandler();
|
|
20
21
|
const { children, ...props } = useProps();
|
|
22
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
23
|
+
const hasRules = !isBody || !props.readOnly;
|
|
21
24
|
const schema = useSchemaType('array', props);
|
|
22
25
|
if (schema) {
|
|
23
26
|
const schemas = [];
|
|
24
27
|
handler[schemaContext.key] = schemas;
|
|
25
28
|
// @ts-expect-error: FIXME
|
|
26
29
|
schema.prefixItems = schemas;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
if (hasRules) {
|
|
31
|
+
const rulesMap = [];
|
|
32
|
+
const rules = [];
|
|
33
|
+
if (props.default !== undefined) {
|
|
34
|
+
rules.push(defaultTo(props.default));
|
|
35
|
+
}
|
|
36
|
+
if (props.default !== undefined) {
|
|
37
|
+
rules.push(tupleOf(rulesMap));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const parentRule = useParentRule();
|
|
41
|
+
rules.push(parentRule(tupleOf(rulesMap)));
|
|
42
|
+
}
|
|
43
|
+
useRule(pipe(...rules));
|
|
44
|
+
parentRuleContext.set(handler, rule => required(rule));
|
|
45
|
+
ruleContext.set(handler, rule => {
|
|
46
|
+
rulesMap.push(rule);
|
|
47
|
+
});
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!rulesMap.length) {
|
|
50
|
+
throw Error('<tuple> MUST have content');
|
|
51
|
+
}
|
|
52
|
+
});
|
|
38
53
|
}
|
|
39
|
-
useRule(pipe(...rules));
|
|
40
|
-
parentRuleContext.set(handler, rule => required(rule));
|
|
41
|
-
ruleContext.set(handler, rule => {
|
|
42
|
-
rulesMap.push(rule);
|
|
43
|
-
});
|
|
44
54
|
innet(children, handler);
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
if (!rulesMap.length) {
|
|
47
|
-
throw Error('<tuple> MUST have content');
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
55
|
}
|
|
51
56
|
};
|
|
52
57
|
|
|
@@ -8,6 +8,7 @@ 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');
|
|
@@ -22,35 +23,39 @@ const tuple = () => {
|
|
|
22
23
|
useBlock.useBlock('path');
|
|
23
24
|
const handler = innet.useNewHandler();
|
|
24
25
|
const { children, ...props } = jsx.useProps();
|
|
26
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
27
|
+
const hasRules = !isBody || !props.readOnly;
|
|
25
28
|
const schema = useSchemaType.useSchemaType('array', props);
|
|
26
29
|
if (schema) {
|
|
27
30
|
const schemas = [];
|
|
28
31
|
handler[useSchemaContext.schemaContext.key] = schemas;
|
|
29
32
|
// @ts-expect-error: FIXME
|
|
30
33
|
schema.prefixItems = schemas;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
if (hasRules) {
|
|
35
|
+
const rulesMap = [];
|
|
36
|
+
const rules = [];
|
|
37
|
+
if (props.default !== undefined) {
|
|
38
|
+
rules.push(defaultTo.defaultTo(props.default));
|
|
39
|
+
}
|
|
40
|
+
if (props.default !== undefined) {
|
|
41
|
+
rules.push(tupleOf.tupleOf(rulesMap));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const parentRule = useParentRule.useParentRule();
|
|
45
|
+
rules.push(parentRule(tupleOf.tupleOf(rulesMap)));
|
|
46
|
+
}
|
|
47
|
+
useRule.useRule(pipe.pipe(...rules));
|
|
48
|
+
useParentRule.parentRuleContext.set(handler, rule => required.required(rule));
|
|
49
|
+
useRule.ruleContext.set(handler, rule => {
|
|
50
|
+
rulesMap.push(rule);
|
|
51
|
+
});
|
|
52
|
+
useEffect.useEffect(() => {
|
|
53
|
+
if (!rulesMap.length) {
|
|
54
|
+
throw Error('<tuple> MUST have content');
|
|
55
|
+
}
|
|
56
|
+
});
|
|
42
57
|
}
|
|
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
58
|
innet.innet(children, handler);
|
|
49
|
-
useEffect.useEffect(() => {
|
|
50
|
-
if (!rulesMap.length) {
|
|
51
|
-
throw Error('<tuple> MUST have content');
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
59
|
}
|
|
55
60
|
};
|
|
56
61
|
|
|
@@ -1,7 +1,8 @@
|
|
|
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';
|
|
@@ -12,6 +13,8 @@ import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
|
12
13
|
|
|
13
14
|
const uuid = () => {
|
|
14
15
|
const { default: defaultValue, ...props } = useProps();
|
|
16
|
+
const isBody = Boolean(useContext(bodyContext));
|
|
17
|
+
const hasRules = !isBody || !props.readOnly;
|
|
15
18
|
const params = {
|
|
16
19
|
...props,
|
|
17
20
|
};
|
|
@@ -25,6 +28,8 @@ const uuid = () => {
|
|
|
25
28
|
// @ts-expect-error: FIXME
|
|
26
29
|
schema['x-default'] = defaultValue;
|
|
27
30
|
}
|
|
31
|
+
if (!hasRules)
|
|
32
|
+
return;
|
|
28
33
|
const rules = [];
|
|
29
34
|
if (defaultValue !== undefined) {
|
|
30
35
|
rules.push(defaultTo(defaultValue === 'new' ? v4 : defaultValue));
|
|
@@ -6,6 +6,7 @@ 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');
|
|
@@ -16,6 +17,8 @@ var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
|
16
17
|
|
|
17
18
|
const uuid = () => {
|
|
18
19
|
const { default: defaultValue, ...props } = jsx.useProps();
|
|
20
|
+
const isBody = Boolean(jsx.useContext(useBodyContext.bodyContext));
|
|
21
|
+
const hasRules = !isBody || !props.readOnly;
|
|
19
22
|
const params = {
|
|
20
23
|
...props,
|
|
21
24
|
};
|
|
@@ -29,6 +32,8 @@ const uuid = () => {
|
|
|
29
32
|
// @ts-expect-error: FIXME
|
|
30
33
|
schema['x-default'] = defaultValue;
|
|
31
34
|
}
|
|
35
|
+
if (!hasRules)
|
|
36
|
+
return;
|
|
32
37
|
const rules = [];
|
|
33
38
|
if (defaultValue !== undefined) {
|
|
34
39
|
rules.push(defaultTo.defaultTo(defaultValue === 'new' ? uuid$1.v4 : defaultValue));
|
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>;
|