@innet/server 2.0.0-beta.22 → 2.0.0-beta.23
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/hooks/useSchemaType/useSchemaType.d.ts +2 -3
- package/index.es6.js +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/plugins/schema/any/any.d.ts +1 -2
- package/plugins/schema/array/array.d.ts +3 -3
- package/plugins/schema/boolean/boolean.d.ts +1 -3
- package/plugins/schema/date/date.d.ts +3 -3
- package/plugins/schema/date/date.es6.js +4 -3
- package/plugins/schema/date/date.js +4 -3
- package/plugins/schema/integer/integer.d.ts +2 -2
- package/plugins/schema/integer/integer.es6.js +2 -2
- package/plugins/schema/integer/integer.js +2 -2
- package/plugins/schema/null/null.d.ts +1 -2
- package/plugins/schema/number/number.d.ts +2 -2
- package/plugins/schema/number/number.es6.js +1 -1
- package/plugins/schema/number/number.js +1 -1
- package/plugins/schema/object/object.d.ts +3 -3
- package/plugins/schema/string/string.d.ts +2 -2
- package/plugins/schema/tuple/tuple.d.ts +3 -3
- package/plugins/schema/uuid/uuid.d.ts +1 -3
- package/plugins/schema/uuid/uuid.es6.js +6 -3
- package/plugins/schema/uuid/uuid.js +6 -3
- package/{types.d.ts → types/appTypes.d.ts} +11 -7
- package/types/index.d.ts +2 -0
- package/types/index.es6.js +2 -0
- package/types/index.js +5 -0
- package/types/isoDate.d.ts +1 -0
- package/types/isoDate.es6.js +1 -0
- package/types/isoDate.js +2 -0
- package/utils/dateFormat/dateFormat.d.ts +1 -1
- package/utils/dateFormat/dateFormat.es6.js +1 -1
- package/utils/dateFormat/dateFormat.js +1 -1
- package/utils/rules/dateTo/dateTo.d.ts +3 -1
- package/utils/rules/values/values.d.ts +2 -2
- package/utils/rules/values/values.es6.js +3 -2
- package/utils/rules/values/values.js +3 -2
- /package/{types.es6.js → types/appTypes.es6.js} +0 -0
- /package/{types.js → types/appTypes.js} +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type ObjectType, type SchemaObject, type SchemaProps } from '../../types';
|
|
2
2
|
export type SchemaType = 'any' | ObjectType;
|
|
3
|
-
type
|
|
4
|
-
export declare function useSchemaType<T extends SchemaType>(type: T, { example, examples, nullable, ref, value, values, ...options }?: SchemaProps<
|
|
5
|
-
export {};
|
|
3
|
+
export type SchemaTypeMap<T extends SchemaType> = T extends 'integer' | 'number' ? number : T extends 'string' ? string : T extends 'object' ? object : T extends 'array' ? any[] : T extends 'boolean' ? boolean : T extends 'null' ? null : T extends 'any' ? any : unknown;
|
|
4
|
+
export declare function useSchemaType<T extends SchemaType>(type: T, { example, examples, nullable, ref, value, values, ...options }?: SchemaProps<SchemaTypeMap<T>> | undefined): SchemaObject | undefined;
|
package/index.es6.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import './handler/index.es6.js';
|
|
2
2
|
import './hooks/index.es6.js';
|
|
3
3
|
import './plugins/index.es6.js';
|
|
4
|
-
import './types.es6.js';
|
|
4
|
+
import './types/index.es6.js';
|
|
5
5
|
import './utils/index.es6.js';
|
|
6
6
|
export { JSXPlugins, arrayPlugins, handler as default, fnPlugins, handler, objectPlugins, promisePlugins } from './handler/handler.es6.js';
|
|
7
7
|
export { actionContext, useAction } from './hooks/useAction/useAction.es6.js';
|
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
require('./handler/index.js');
|
|
6
6
|
require('./hooks/index.js');
|
|
7
7
|
require('./plugins/index.js');
|
|
8
|
-
require('./types.js');
|
|
8
|
+
require('./types/index.js');
|
|
9
9
|
require('./utils/index.js');
|
|
10
10
|
var handler = require('./handler/handler.js');
|
|
11
11
|
var useAction = require('./hooks/useAction/useAction.js');
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
import { type SchemaProps } from '../../../types';
|
|
3
|
-
export
|
|
4
|
-
children?:
|
|
3
|
+
export type ArrayProps = SchemaProps<any[]> & {
|
|
4
|
+
children?: JSX.Element;
|
|
5
5
|
maxItems?: number;
|
|
6
6
|
minItems?: number;
|
|
7
7
|
uniqueItems?: boolean;
|
|
8
|
-
}
|
|
8
|
+
};
|
|
9
9
|
export declare const array: HandlerPlugin;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
import { type SchemaProps } from '../../../types';
|
|
3
|
-
export
|
|
4
|
-
const?: boolean;
|
|
5
|
-
}
|
|
3
|
+
export type BooleanProps = SchemaProps<boolean>;
|
|
6
4
|
export declare const boolean: HandlerPlugin;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
import { type SchemaProps } from '../../../types';
|
|
3
|
-
import { type DateFormat } from '../../../utils';
|
|
4
|
-
export
|
|
3
|
+
import { type DateFormat, type DefaultDateFormat } from '../../../utils';
|
|
4
|
+
export type DateProps = SchemaProps<DateFormat, DefaultDateFormat> & {
|
|
5
5
|
max?: DateFormat;
|
|
6
6
|
min?: DateFormat;
|
|
7
|
-
}
|
|
7
|
+
};
|
|
8
8
|
export declare const date: HandlerPlugin;
|
|
@@ -20,11 +20,11 @@ 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 && getArrayValues(values$1
|
|
23
|
+
const normValues = values$1 && getArrayValues(values$1).map(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);
|
|
27
|
-
const
|
|
27
|
+
const params = {
|
|
28
28
|
...props,
|
|
29
29
|
default: defaultValue === 'now' ? undefined : normDefault === null || normDefault === void 0 ? void 0 : normDefault.toISOString(),
|
|
30
30
|
example: normExample === null || normExample === void 0 ? void 0 : normExample.toISOString(),
|
|
@@ -32,7 +32,8 @@ const date = () => {
|
|
|
32
32
|
// @ts-expect-error: FIXME
|
|
33
33
|
examples: normExamples === null || normExamples === void 0 ? void 0 : normExamples.map(example => example.toISOString()),
|
|
34
34
|
values: stringValues,
|
|
35
|
-
}
|
|
35
|
+
};
|
|
36
|
+
const schema = useSchemaType('string', params);
|
|
36
37
|
const rules = [];
|
|
37
38
|
if (defaultValue !== undefined) {
|
|
38
39
|
rules.push(defaultTo(defaultValue === 'now' ? () => new Date(Date.now()) : normDefault));
|
|
@@ -24,11 +24,11 @@ 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 && values.getArrayValues(values$1
|
|
27
|
+
const normValues = values$1 && values.getArrayValues(values$1).map(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);
|
|
31
|
-
const
|
|
31
|
+
const params = {
|
|
32
32
|
...props,
|
|
33
33
|
default: defaultValue === 'now' ? undefined : normDefault === null || normDefault === void 0 ? void 0 : normDefault.toISOString(),
|
|
34
34
|
example: normExample === null || normExample === void 0 ? void 0 : normExample.toISOString(),
|
|
@@ -36,7 +36,8 @@ const date = () => {
|
|
|
36
36
|
// @ts-expect-error: FIXME
|
|
37
37
|
examples: normExamples === null || normExamples === void 0 ? void 0 : normExamples.map(example => example.toISOString()),
|
|
38
38
|
values: stringValues,
|
|
39
|
-
}
|
|
39
|
+
};
|
|
40
|
+
const schema = useSchemaType.useSchemaType('string', params);
|
|
40
41
|
const rules = [];
|
|
41
42
|
if (defaultValue !== undefined) {
|
|
42
43
|
rules.push(defaultTo.defaultTo(defaultValue === 'now' ? () => new Date(Date.now()) : normDefault));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
import { type IntegerFormats, type SchemaProps } from '../../../types';
|
|
3
|
-
export
|
|
3
|
+
export type IntegerProps = SchemaProps<bigint | number> & {
|
|
4
4
|
/**
|
|
5
5
|
* The `exclusiveMaximum` keyword is used to restrict the value to be less than the specified number.
|
|
6
6
|
* @example For example, the following value is valid:
|
|
@@ -41,5 +41,5 @@ export interface IntegerProps extends SchemaProps<bigint | number> {
|
|
|
41
41
|
* @see https://swagger.io/docs/specification/v3_0/data-models/data-types/#numbers
|
|
42
42
|
* */
|
|
43
43
|
multipleOf?: bigint | number;
|
|
44
|
-
}
|
|
44
|
+
};
|
|
45
45
|
export declare const integer: HandlerPlugin;
|
|
@@ -19,7 +19,7 @@ const integer = () => {
|
|
|
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
|
|
22
|
+
values: values$1 && getArrayValues(values$1).map(Number),
|
|
23
23
|
});
|
|
24
24
|
if (schema) {
|
|
25
25
|
if (format) {
|
|
@@ -47,7 +47,7 @@ const integer = () => {
|
|
|
47
47
|
}
|
|
48
48
|
rules.push(int(format));
|
|
49
49
|
if (values$1) {
|
|
50
|
-
rules.push(values(getArrayValues(values$1
|
|
50
|
+
rules.push(values(getArrayValues(values$1).filter((v) => v !== null).map(v => int(format)(v))));
|
|
51
51
|
}
|
|
52
52
|
if (min$1 !== undefined) {
|
|
53
53
|
rules.push(min(min$1));
|
|
@@ -23,7 +23,7 @@ const integer = () => {
|
|
|
23
23
|
example: example !== undefined ? Number(example) : undefined,
|
|
24
24
|
examples: examples === null || examples === void 0 ? void 0 : examples.map(Number),
|
|
25
25
|
value: props.value !== undefined ? Number(props.value) : undefined,
|
|
26
|
-
values: values$1 && values.getArrayValues(values$1
|
|
26
|
+
values: values$1 && values.getArrayValues(values$1).map(Number),
|
|
27
27
|
});
|
|
28
28
|
if (schema) {
|
|
29
29
|
if (format) {
|
|
@@ -51,7 +51,7 @@ const integer = () => {
|
|
|
51
51
|
}
|
|
52
52
|
rules.push(int.int(format));
|
|
53
53
|
if (values$1) {
|
|
54
|
-
rules.push(values.values(values.getArrayValues(values$1
|
|
54
|
+
rules.push(values.values(values.getArrayValues(values$1).filter((v) => v !== null).map(v => int.int(format)(v))));
|
|
55
55
|
}
|
|
56
56
|
if (min$1 !== undefined) {
|
|
57
57
|
rules.push(min.min(min$1));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
import { type SchemaProps } from '../../../types';
|
|
3
|
-
export
|
|
3
|
+
export type NumberProps = SchemaProps<number> & {
|
|
4
4
|
/**
|
|
5
5
|
* The `exclusiveMaximum` keyword is used to restrict the value to be less than the specified number.
|
|
6
6
|
* @example For example, the following value is valid:
|
|
@@ -37,5 +37,5 @@ export interface NumberProps extends SchemaProps<number> {
|
|
|
37
37
|
* @see https://swagger.io/docs/specification/v3_0/data-models/data-types/#numbers
|
|
38
38
|
* */
|
|
39
39
|
multipleOf?: number;
|
|
40
|
-
}
|
|
40
|
+
};
|
|
41
41
|
export declare const number: HandlerPlugin;
|
|
@@ -45,7 +45,7 @@ const number = () => {
|
|
|
45
45
|
}
|
|
46
46
|
rules.push(num.num);
|
|
47
47
|
if (props.values) {
|
|
48
|
-
rules.push(values.values(values.getArrayValues(props.values
|
|
48
|
+
rules.push(values.values(values.getArrayValues(props.values).map(Number)));
|
|
49
49
|
}
|
|
50
50
|
if (min$1 !== undefined) {
|
|
51
51
|
rules.push(min.min(min$1));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
import { type SchemaProps } from '../../../types';
|
|
3
|
-
export
|
|
4
|
-
children?:
|
|
5
|
-
}
|
|
3
|
+
export type ObjectProps = SchemaProps<object> & {
|
|
4
|
+
children?: JSX.Element;
|
|
5
|
+
};
|
|
6
6
|
export declare const object: HandlerPlugin;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
import { type SchemaProps } from '../../../types';
|
|
3
|
-
export
|
|
3
|
+
export type StringProps = SchemaProps<string> & {
|
|
4
4
|
/**
|
|
5
5
|
* An optional format modifier serves as a hint at the contents and format of the string.
|
|
6
6
|
* @see https://swagger.io/docs/specification/v3_0/data-models/data-types/#strings
|
|
@@ -32,5 +32,5 @@ export interface StringProps extends SchemaProps<string> {
|
|
|
32
32
|
* The `patternId` keyword is used to reference a pattern from the OpenAPI specification.
|
|
33
33
|
* */
|
|
34
34
|
patternId?: string;
|
|
35
|
-
}
|
|
35
|
+
};
|
|
36
36
|
export declare const string: HandlerPlugin;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
import { type SchemaProps } from '../../../types';
|
|
3
|
-
export
|
|
4
|
-
children?:
|
|
5
|
-
}
|
|
3
|
+
export type TupleProps = SchemaProps<any[]> & {
|
|
4
|
+
children?: JSX.Element;
|
|
5
|
+
};
|
|
6
6
|
export declare const tuple: HandlerPlugin;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
import { type SchemaProps } from '../../../types';
|
|
3
|
-
export
|
|
4
|
-
default?: 'new' | string;
|
|
5
|
-
}
|
|
3
|
+
export type UuidProps = SchemaProps<string, 'new' | string>;
|
|
6
4
|
export declare const uuid: HandlerPlugin;
|
|
@@ -12,10 +12,13 @@ import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
|
12
12
|
|
|
13
13
|
const uuid = () => {
|
|
14
14
|
const { default: defaultValue, ...props } = useProps();
|
|
15
|
-
const
|
|
15
|
+
const params = {
|
|
16
16
|
...props,
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
};
|
|
18
|
+
if (defaultValue !== 'new') {
|
|
19
|
+
params.default = defaultValue;
|
|
20
|
+
}
|
|
21
|
+
const schema = useSchemaType('string', params);
|
|
19
22
|
// @ts-expect-error: FIXME
|
|
20
23
|
schema.format = 'uuid';
|
|
21
24
|
if (defaultValue === 'new') {
|
|
@@ -16,10 +16,13 @@ var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
|
16
16
|
|
|
17
17
|
const uuid = () => {
|
|
18
18
|
const { default: defaultValue, ...props } = jsx.useProps();
|
|
19
|
-
const
|
|
19
|
+
const params = {
|
|
20
20
|
...props,
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
};
|
|
22
|
+
if (defaultValue !== 'new') {
|
|
23
|
+
params.default = defaultValue;
|
|
24
|
+
}
|
|
25
|
+
const schema = useSchemaType.useSchemaType('string', params);
|
|
23
26
|
// @ts-expect-error: FIXME
|
|
24
27
|
schema.format = 'uuid';
|
|
25
28
|
if (defaultValue === 'new') {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { OpenAPIV3_1 as API } from 'openapi-types';
|
|
2
|
-
import type { ApiErrorValue } from '
|
|
3
|
-
import { type ServerPlugin } from '
|
|
4
|
-
import { type ResponseStatus } from '
|
|
5
|
-
import { type Rule, type RulesErrors } from '
|
|
2
|
+
import type { ApiErrorValue } from '../constants';
|
|
3
|
+
import { type ServerPlugin } from '../hooks';
|
|
4
|
+
import { type ResponseStatus } from '../plugins';
|
|
5
|
+
import { type Rule, type RulesErrors } from '../utils/rules';
|
|
6
6
|
export type TagObject = API.TagObject;
|
|
7
7
|
export type Document = API.Document;
|
|
8
8
|
export type ServerObject = API.ServerObject;
|
|
@@ -59,13 +59,13 @@ export interface ServerStartParams {
|
|
|
59
59
|
port: number;
|
|
60
60
|
}
|
|
61
61
|
export type SchemaValues<T> = (T extends (number | string) ? Record<T, string> : never) | T[];
|
|
62
|
-
export interface
|
|
63
|
-
default?:
|
|
62
|
+
export interface BaseSchemaProps<T, D = T> {
|
|
63
|
+
default?: D;
|
|
64
64
|
deprecated?: boolean;
|
|
65
65
|
description?: string;
|
|
66
66
|
example?: T;
|
|
67
67
|
examples?: T[];
|
|
68
|
-
nullable?:
|
|
68
|
+
nullable?: false;
|
|
69
69
|
readOnly?: boolean;
|
|
70
70
|
ref?: string;
|
|
71
71
|
title?: string;
|
|
@@ -73,6 +73,10 @@ export interface SchemaProps<T> {
|
|
|
73
73
|
values?: SchemaValues<T>;
|
|
74
74
|
writeOnly?: boolean;
|
|
75
75
|
}
|
|
76
|
+
export interface NullableSchemaProps<T, D = T> extends Omit<BaseSchemaProps<T | null, D | null>, 'nullable'> {
|
|
77
|
+
nullable: true;
|
|
78
|
+
}
|
|
79
|
+
export type SchemaProps<T, D = T> = BaseSchemaProps<T, D> | NullableSchemaProps<T, D>;
|
|
76
80
|
export type TResponse = Record<ResponseStatus, unknown>;
|
|
77
81
|
export interface TEndpoint {
|
|
78
82
|
body?: unknown;
|
package/types/index.d.ts
ADDED
package/types/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ISODate = `${number}-${number}-${number}` | `${number}-${number}-${number}T${number}:${number}:${number}${'+' | '-'}${number}:${number}` | `${number}-${number}-${number}T${number}:${number}:${number}` | `${number}-${number}-${number}T${number}:${number}:${number}Z`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/types/isoDate.js
ADDED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type DateFormat = 'now' | Date | number | string;
|
|
2
|
-
export declare function dateFormat(date?: DateFormat): Date | undefined;
|
|
2
|
+
export declare function dateFormat(date?: DateFormat | null): Date | undefined;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ISODate } from '../../../types';
|
|
2
|
+
export type DateFormat = Date | ISODate | number;
|
|
3
|
+
export type DefaultDateFormat = 'now' | DateFormat;
|
|
2
4
|
export declare function dateTo(value: any, data?: object): Date;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function getArrayValues<T
|
|
1
|
+
import type { SchemaValues } from '../../../types';
|
|
2
|
+
export declare function getArrayValues<T extends Record<number | string, unknown> | unknown[]>(values: T): T extends SchemaValues<infer V> ? V[] : never;
|
|
3
3
|
export declare function values<T>(values: T[]): (value: any, data?: object) => any;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { RulesError } from '../helpers.es6.js';
|
|
2
2
|
|
|
3
|
-
function getArrayValues(values
|
|
4
|
-
|
|
3
|
+
function getArrayValues(values) {
|
|
4
|
+
// @ts-expect-error TODO: Fix types
|
|
5
|
+
return Array.isArray(values) ? values : Object.keys(values);
|
|
5
6
|
}
|
|
6
7
|
function values(values) {
|
|
7
8
|
return (value, data) => {
|
|
@@ -4,8 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var helpers = require('../helpers.js');
|
|
6
6
|
|
|
7
|
-
function getArrayValues(values
|
|
8
|
-
|
|
7
|
+
function getArrayValues(values) {
|
|
8
|
+
// @ts-expect-error TODO: Fix types
|
|
9
|
+
return Array.isArray(values) ? values : Object.keys(values);
|
|
9
10
|
}
|
|
10
11
|
function values(values) {
|
|
11
12
|
return (value, data) => {
|
|
File without changes
|
|
File without changes
|