@innet/server 2.0.0-alpha.17 → 2.0.0-alpha.19
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 +4 -3
- package/handler/handler.d.ts +3 -1
- package/handler/handler.es6.js +2 -0
- package/handler/handler.js +2 -0
- package/hooks/useSchemaType/useSchemaType.d.ts +3 -2
- package/hooks/useSchemaType/useSchemaType.es6.js +2 -3
- package/hooks/useSchemaType/useSchemaType.js +2 -3
- package/index.es6.js +1 -1
- package/index.js +2 -2
- package/package.json +1 -1
- package/plugins/main/api/api.es6.js +7 -8
- package/plugins/main/api/api.js +7 -8
- package/plugins/request/cms/cms.es6.js +1 -1
- package/plugins/request/cms/cms.js +1 -1
- package/plugins/schema/any/any.d.ts +5 -0
- package/plugins/schema/any/any.es6.js +27 -0
- package/plugins/schema/any/any.js +31 -0
- package/plugins/schema/index.d.ts +1 -0
- package/plugins/schema/index.es6.js +1 -0
- package/plugins/schema/index.js +1 -0
- package/plugins/schema/object/object.es6.js +6 -0
- package/plugins/schema/object/object.js +6 -0
- package/utils/generateTypes/generateTypes.es6.js +29 -8
- package/utils/generateTypes/generateTypes.js +29 -8
- package/utils/rules/index.d.ts +0 -1
- package/utils/rules/index.es6.js +0 -1
- package/utils/rules/index.js +0 -1
- package/utils/rules/any/any.d.ts +0 -1
- package/utils/rules/any/any.es6.js +0 -5
- package/utils/rules/any/any.js +0 -9
- /package/{utils/rules → plugins/schema}/any/index.d.ts +0 -0
- /package/{utils/rules → plugins/schema}/any/index.es6.js +0 -0
- /package/{utils/rules → plugins/schema}/any/index.js +0 -0
package/README.md
CHANGED
|
@@ -247,8 +247,8 @@ export default (
|
|
|
247
247
|
|
|
248
248
|
[← back](#main)
|
|
249
249
|
|
|
250
|
-
`<api>` element MUST be placed in `<server>` element.
|
|
251
250
|
This element defines a REST API on the server.
|
|
251
|
+
This element MUST be placed in [\<server>](#server) element.
|
|
252
252
|
|
|
253
253
|
#### title
|
|
254
254
|
|
|
@@ -329,7 +329,7 @@ export default (
|
|
|
329
329
|
)
|
|
330
330
|
```
|
|
331
331
|
|
|
332
|
-
*default: 0.0.0
|
|
332
|
+
*default: `INNET_API_VERSION` || `'0.0.0'`*
|
|
333
333
|
|
|
334
334
|
#### prefix
|
|
335
335
|
|
|
@@ -3380,7 +3380,7 @@ export default (
|
|
|
3380
3380
|
|
|
3381
3381
|
#### dir
|
|
3382
3382
|
|
|
3383
|
-
By default, it
|
|
3383
|
+
By default, it equals `INNET_CMS_DIR` node env variable or the project folder.
|
|
3384
3384
|
If you try the previous example on [http://localhost/package.json](http://localhost/package.json)
|
|
3385
3385
|
you get the project `package.json` file.
|
|
3386
3386
|
|
|
@@ -3403,6 +3403,7 @@ you get the index file in `src` folder.
|
|
|
3403
3403
|
#### prefix
|
|
3404
3404
|
|
|
3405
3405
|
`<cms>` matches full `path`, you should take it into account if you add `prefix` on `<api>`.
|
|
3406
|
+
By default, it equals `INNET_CMS_PREFIX` node env variable or `/`.
|
|
3406
3407
|
|
|
3407
3408
|
*src/app.tsx*
|
|
3408
3409
|
```typescript jsx
|
package/handler/handler.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { context, type ContextProps, slot, type SlotProps, slots, type SlotsProps } from '@innet/jsx';
|
|
2
2
|
import { arraySync, async } from '@innet/utils';
|
|
3
|
-
import { type ApiProps, type ArrayProps, type BinaryProps, blacklist, type BlacklistProps, type BodyProps, type BooleanProps, cms, type CmsProps, type ContactProps, type CookieProps, type DateProps, type DevProps, type DtsProps, type EndpointProps, type ErrorProps, type FieldProps, file, type FileProps, type HeaderProps, type HostProps, type IntegerProps, type LicenseProps, type NullProps, type NumberProps, type ObjectProps, type ParamProps, preset, type PresetProps, type ProdProps, protection, type ProtectionProps, type ProxyProps, type RedirectProps, type RequestProps, type ResponseProps, type ServerProps, type StringProps, type SuccessProps, type SwaggerProps, type TagProps, type TupleProps, type UuidProps, type VariableProps, whitelist, type WhitelistProps } from '../plugins';
|
|
3
|
+
import { type AnyProps, type ApiProps, type ArrayProps, type BinaryProps, blacklist, type BlacklistProps, type BodyProps, type BooleanProps, cms, type CmsProps, type ContactProps, type CookieProps, type DateProps, type DevProps, type DtsProps, type EndpointProps, type ErrorProps, type FieldProps, file, type FileProps, type HeaderProps, type HostProps, type IntegerProps, type LicenseProps, type NullProps, type NumberProps, type ObjectProps, type ParamProps, preset, type PresetProps, type ProdProps, protection, type ProtectionProps, type ProxyProps, type RedirectProps, type RequestProps, type ResponseProps, type ServerProps, type StringProps, type SuccessProps, type SwaggerProps, type TagProps, type TupleProps, type UuidProps, type VariableProps, whitelist, type WhitelistProps } from '../plugins';
|
|
4
4
|
export declare const arrayPlugins: (typeof arraySync)[];
|
|
5
5
|
export declare const JSXPlugins: {
|
|
6
|
+
any: import("innet").HandlerPlugin;
|
|
6
7
|
api: import("innet").HandlerPlugin;
|
|
7
8
|
array: import("innet").HandlerPlugin;
|
|
8
9
|
binary: import("innet").HandlerPlugin;
|
|
@@ -54,6 +55,7 @@ export declare const handler: import("innet").Handler;
|
|
|
54
55
|
declare global {
|
|
55
56
|
namespace JSX {
|
|
56
57
|
interface IntrinsicElements {
|
|
58
|
+
any: AnyProps;
|
|
57
59
|
api: ApiProps;
|
|
58
60
|
array: ArrayProps;
|
|
59
61
|
binary: BinaryProps;
|
package/handler/handler.es6.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createHandler } from 'innet';
|
|
|
2
2
|
import { context, slot, slots, jsxPlugins, jsxComponent } from '@innet/jsx';
|
|
3
3
|
import { arraySync, async, promise, array as array$1, nullish, object as object$1, fn } from '@innet/utils';
|
|
4
4
|
import '../plugins/index.es6.js';
|
|
5
|
+
import { any } from '../plugins/schema/any/any.es6.js';
|
|
5
6
|
import { api } from '../plugins/main/api/api.es6.js';
|
|
6
7
|
import { array } from '../plugins/schema/array/array.es6.js';
|
|
7
8
|
import { binary } from '../plugins/schema/binary/binary.es6.js';
|
|
@@ -48,6 +49,7 @@ const arrayPlugins = [
|
|
|
48
49
|
arraySync,
|
|
49
50
|
];
|
|
50
51
|
const JSXPlugins = {
|
|
52
|
+
any,
|
|
51
53
|
api,
|
|
52
54
|
array,
|
|
53
55
|
binary,
|
package/handler/handler.js
CHANGED
|
@@ -6,6 +6,7 @@ var innet = require('innet');
|
|
|
6
6
|
var jsx = require('@innet/jsx');
|
|
7
7
|
var utils = require('@innet/utils');
|
|
8
8
|
require('../plugins/index.js');
|
|
9
|
+
var any = require('../plugins/schema/any/any.js');
|
|
9
10
|
var api = require('../plugins/main/api/api.js');
|
|
10
11
|
var array = require('../plugins/schema/array/array.js');
|
|
11
12
|
var binary = require('../plugins/schema/binary/binary.js');
|
|
@@ -52,6 +53,7 @@ const arrayPlugins = [
|
|
|
52
53
|
utils.arraySync,
|
|
53
54
|
];
|
|
54
55
|
const JSXPlugins = {
|
|
56
|
+
any: any.any,
|
|
55
57
|
api: api.api,
|
|
56
58
|
array: array.array,
|
|
57
59
|
binary: binary.binary,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ObjectType, type SchemaObject, type ValuesSchemaProps } from '../../types';
|
|
2
|
-
type
|
|
3
|
-
|
|
2
|
+
export type SchemaType = ObjectType | 'any';
|
|
3
|
+
type TypeMap<T extends SchemaType> = T extends 'number' | 'integer' ? 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, { values, ref, example, examples, ...options }?: undefined | ValuesSchemaProps<TypeMap<T>>): SchemaObject | undefined;
|
|
4
5
|
export {};
|
|
@@ -22,11 +22,10 @@ function useSchemaType(type, _a = {}) {
|
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
return (docs.components.schemas[ref] = Object.assign(Object.assign({}, options), { example,
|
|
25
|
-
examples,
|
|
26
|
-
type, enum: values }));
|
|
25
|
+
examples, type: type === 'any' ? undefined : type, enum: values }));
|
|
27
26
|
}
|
|
28
27
|
return useNewSchema(Object.assign(Object.assign({}, options), { example,
|
|
29
|
-
examples, enum: values, type: type }));
|
|
28
|
+
examples, enum: values, type: type === 'any' ? undefined : type }));
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
export { useSchemaType };
|
|
@@ -26,11 +26,10 @@ function useSchemaType(type, _a = {}) {
|
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
28
|
return (docs.components.schemas[ref] = Object.assign(Object.assign({}, options), { example,
|
|
29
|
-
examples,
|
|
30
|
-
type, enum: values }));
|
|
29
|
+
examples, type: type === 'any' ? undefined : type, enum: values }));
|
|
31
30
|
}
|
|
32
31
|
return useNewSchema.useNewSchema(Object.assign(Object.assign({}, options), { example,
|
|
33
|
-
examples, enum: values, type: type }));
|
|
32
|
+
examples, enum: values, type: type === 'any' ? undefined : type }));
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
exports.useSchemaType = useSchemaType;
|
package/index.es6.js
CHANGED
|
@@ -29,6 +29,7 @@ export { date } from './plugins/schema/date/date.es6.js';
|
|
|
29
29
|
export { tuple } from './plugins/schema/tuple/tuple.es6.js';
|
|
30
30
|
export { uuid } from './plugins/schema/uuid/uuid.es6.js';
|
|
31
31
|
export { binary } from './plugins/schema/binary/binary.es6.js';
|
|
32
|
+
export { any } from './plugins/schema/any/any.es6.js';
|
|
32
33
|
export { success, successStatuses } from './plugins/request/success/success.es6.js';
|
|
33
34
|
export { error, errorStatuses } from './plugins/request/error/error.es6.js';
|
|
34
35
|
export { proxy } from './plugins/request/proxy/proxy.es6.js';
|
|
@@ -77,7 +78,6 @@ export { minLength } from './utils/rules/minLength/minLength.es6.js';
|
|
|
77
78
|
export { max } from './utils/rules/max/max.es6.js';
|
|
78
79
|
export { min } from './utils/rules/min/min.es6.js';
|
|
79
80
|
export { defaultTo } from './utils/rules/defaultTo/defaultTo.es6.js';
|
|
80
|
-
export { any } from './utils/rules/any/any.es6.js';
|
|
81
81
|
export { bin } from './utils/rules/bin/bin.es6.js';
|
|
82
82
|
export { minBin } from './utils/rules/minBin/minBin.es6.js';
|
|
83
83
|
export { maxBin } from './utils/rules/maxBin/maxBin.es6.js';
|
package/index.js
CHANGED
|
@@ -33,6 +33,7 @@ var date = require('./plugins/schema/date/date.js');
|
|
|
33
33
|
var tuple = require('./plugins/schema/tuple/tuple.js');
|
|
34
34
|
var uuid = require('./plugins/schema/uuid/uuid.js');
|
|
35
35
|
var binary = require('./plugins/schema/binary/binary.js');
|
|
36
|
+
var any = require('./plugins/schema/any/any.js');
|
|
36
37
|
var success = require('./plugins/request/success/success.js');
|
|
37
38
|
var error = require('./plugins/request/error/error.js');
|
|
38
39
|
var proxy = require('./plugins/request/proxy/proxy.js');
|
|
@@ -81,7 +82,6 @@ var minLength = require('./utils/rules/minLength/minLength.js');
|
|
|
81
82
|
var max = require('./utils/rules/max/max.js');
|
|
82
83
|
var min = require('./utils/rules/min/min.js');
|
|
83
84
|
var defaultTo = require('./utils/rules/defaultTo/defaultTo.js');
|
|
84
|
-
var any = require('./utils/rules/any/any.js');
|
|
85
85
|
var bin = require('./utils/rules/bin/bin.js');
|
|
86
86
|
var minBin = require('./utils/rules/minBin/minBin.js');
|
|
87
87
|
var maxBin = require('./utils/rules/maxBin/maxBin.js');
|
|
@@ -154,6 +154,7 @@ exports.date = date.date;
|
|
|
154
154
|
exports.tuple = tuple.tuple;
|
|
155
155
|
exports.uuid = uuid.uuid;
|
|
156
156
|
exports.binary = binary.binary;
|
|
157
|
+
exports.any = any.any;
|
|
157
158
|
exports.success = success.success;
|
|
158
159
|
exports.successStatuses = success.successStatuses;
|
|
159
160
|
exports.error = error.error;
|
|
@@ -208,7 +209,6 @@ exports.minLength = minLength.minLength;
|
|
|
208
209
|
exports.max = max.max;
|
|
209
210
|
exports.min = min.min;
|
|
210
211
|
exports.defaultTo = defaultTo.defaultTo;
|
|
211
|
-
exports.any = any.any;
|
|
212
212
|
exports.bin = bin.bin;
|
|
213
213
|
exports.minBin = minBin.minBin;
|
|
214
214
|
exports.maxBin = maxBin.maxBin;
|
package/package.json
CHANGED
|
@@ -12,11 +12,10 @@ import { RulesError } from '../../../utils/rules/helpers.es6.js';
|
|
|
12
12
|
import { paramsContext } from '../../../hooks/useParams/useParams.es6.js';
|
|
13
13
|
|
|
14
14
|
const api = () => {
|
|
15
|
-
var _a;
|
|
16
15
|
const handler = useNewHandler();
|
|
17
16
|
const { props = {}, children } = useApp();
|
|
18
|
-
const { prefix = '', title = '', include, exclude } = props, rest = __rest(props, ["prefix", "title", "include", "exclude"]);
|
|
19
|
-
const info = Object.assign(Object.assign({}, rest), { version
|
|
17
|
+
const { prefix = '', title = '', include, exclude, version = process.env.INNET_API_VERSION || '0.0.0' } = props, rest = __rest(props, ["prefix", "title", "include", "exclude", "version"]);
|
|
18
|
+
const info = Object.assign(Object.assign({}, rest), { version, title });
|
|
20
19
|
const endpoints = {};
|
|
21
20
|
const docs = {
|
|
22
21
|
openapi: '3.1.0',
|
|
@@ -39,7 +38,7 @@ const api = () => {
|
|
|
39
38
|
serverPlugins.set(handler, plugins);
|
|
40
39
|
apiContext.set(handler, context);
|
|
41
40
|
useServerPlugin(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
var _b, _c, _d, _e, _f
|
|
41
|
+
var _a, _b, _c, _d, _e, _f;
|
|
43
42
|
const action = useAction();
|
|
44
43
|
if (!condition(action))
|
|
45
44
|
return;
|
|
@@ -53,7 +52,7 @@ const api = () => {
|
|
|
53
52
|
res.end();
|
|
54
53
|
return null;
|
|
55
54
|
}
|
|
56
|
-
const method = ((
|
|
55
|
+
const method = ((_b = (_a = req.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : 'get');
|
|
57
56
|
const rawSplitPath = url.slice(prefix.length).split('/').slice(1);
|
|
58
57
|
const splitPath = rawSplitPath.at(-1) ? rawSplitPath : rawSplitPath.slice(0, -1);
|
|
59
58
|
const endpoint = endpoints[method];
|
|
@@ -138,8 +137,8 @@ const api = () => {
|
|
|
138
137
|
return true;
|
|
139
138
|
});
|
|
140
139
|
}
|
|
141
|
-
if ((
|
|
142
|
-
if (!(yield run((
|
|
140
|
+
if ((_d = (_c = currentEndpoint.static) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.plugins) {
|
|
141
|
+
if (!(yield run((_e = currentEndpoint.static) === null || _e === void 0 ? void 0 : _e[key], params)))
|
|
143
142
|
continue;
|
|
144
143
|
return null;
|
|
145
144
|
}
|
|
@@ -154,7 +153,7 @@ const api = () => {
|
|
|
154
153
|
}
|
|
155
154
|
break;
|
|
156
155
|
}
|
|
157
|
-
if ((
|
|
156
|
+
if ((_f = currentEndpoint.static) === null || _f === void 0 ? void 0 : _f[key]) {
|
|
158
157
|
endpointQueue.push([deep + 1, currentEndpoint.static[key], params]);
|
|
159
158
|
}
|
|
160
159
|
if (currentEndpoint.dynamic) {
|
package/plugins/main/api/api.js
CHANGED
|
@@ -20,11 +20,10 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
20
20
|
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
21
21
|
|
|
22
22
|
const api = () => {
|
|
23
|
-
var _a;
|
|
24
23
|
const handler = innet.useNewHandler();
|
|
25
24
|
const { props = {}, children } = innet.useApp();
|
|
26
|
-
const { prefix = '', title = '', include, exclude } = props, rest = tslib.__rest(props, ["prefix", "title", "include", "exclude"]);
|
|
27
|
-
const info = Object.assign(Object.assign({}, rest), { version
|
|
25
|
+
const { prefix = '', title = '', include, exclude, version = process.env.INNET_API_VERSION || '0.0.0' } = props, rest = tslib.__rest(props, ["prefix", "title", "include", "exclude", "version"]);
|
|
26
|
+
const info = Object.assign(Object.assign({}, rest), { version, title });
|
|
28
27
|
const endpoints = {};
|
|
29
28
|
const docs = {
|
|
30
29
|
openapi: '3.1.0',
|
|
@@ -47,7 +46,7 @@ const api = () => {
|
|
|
47
46
|
useServerPlugins.serverPlugins.set(handler, plugins);
|
|
48
47
|
useApi.apiContext.set(handler, context);
|
|
49
48
|
useServerPlugin.useServerPlugin(() => tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
-
var _b, _c, _d, _e, _f
|
|
49
|
+
var _a, _b, _c, _d, _e, _f;
|
|
51
50
|
const action = useAction.useAction();
|
|
52
51
|
if (!condition(action))
|
|
53
52
|
return;
|
|
@@ -61,7 +60,7 @@ const api = () => {
|
|
|
61
60
|
res.end();
|
|
62
61
|
return null;
|
|
63
62
|
}
|
|
64
|
-
const method = ((
|
|
63
|
+
const method = ((_b = (_a = req.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : 'get');
|
|
65
64
|
const rawSplitPath = url.slice(prefix.length).split('/').slice(1);
|
|
66
65
|
const splitPath = rawSplitPath.at(-1) ? rawSplitPath : rawSplitPath.slice(0, -1);
|
|
67
66
|
const endpoint = endpoints[method];
|
|
@@ -146,8 +145,8 @@ const api = () => {
|
|
|
146
145
|
return true;
|
|
147
146
|
});
|
|
148
147
|
}
|
|
149
|
-
if ((
|
|
150
|
-
if (!(yield run((
|
|
148
|
+
if ((_d = (_c = currentEndpoint.static) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.plugins) {
|
|
149
|
+
if (!(yield run((_e = currentEndpoint.static) === null || _e === void 0 ? void 0 : _e[key], params)))
|
|
151
150
|
continue;
|
|
152
151
|
return null;
|
|
153
152
|
}
|
|
@@ -162,7 +161,7 @@ const api = () => {
|
|
|
162
161
|
}
|
|
163
162
|
break;
|
|
164
163
|
}
|
|
165
|
-
if ((
|
|
164
|
+
if ((_f = currentEndpoint.static) === null || _f === void 0 ? void 0 : _f[key]) {
|
|
166
165
|
endpointQueue.push([deep + 1, currentEndpoint.static[key], params]);
|
|
167
166
|
}
|
|
168
167
|
if (currentEndpoint.dynamic) {
|
|
@@ -7,7 +7,7 @@ import { usePath } from '../../../hooks/usePath/usePath.es6.js';
|
|
|
7
7
|
import { file } from '../file/file.es6.js';
|
|
8
8
|
|
|
9
9
|
function cms() {
|
|
10
|
-
const { prefix = '/', dir = '.' } = useProps() || {};
|
|
10
|
+
const { prefix = process.env.INNET_CMS_PREFIX || '/', dir = process.env.INNET_CMS_DIR || '.', } = useProps() || {};
|
|
11
11
|
const children = useChildren();
|
|
12
12
|
const handler = useHandler();
|
|
13
13
|
let url = usePath();
|
|
@@ -16,7 +16,7 @@ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
|
16
16
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
17
17
|
|
|
18
18
|
function cms() {
|
|
19
|
-
const { prefix = '/', dir = '.' } = jsx.useProps() || {};
|
|
19
|
+
const { prefix = process.env.INNET_CMS_PREFIX || '/', dir = process.env.INNET_CMS_DIR || '.', } = jsx.useProps() || {};
|
|
20
20
|
const children = jsx.useChildren();
|
|
21
21
|
const handler = innet.useHandler();
|
|
22
22
|
let url = usePath.usePath();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useProps } from '@innet/jsx';
|
|
2
|
+
import '../../../hooks/index.es6.js';
|
|
3
|
+
import '../../../hooks/useParentRule/index.es6.js';
|
|
4
|
+
import '../../../utils/index.es6.js';
|
|
5
|
+
import { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
|
|
6
|
+
import { defaultTo } from '../../../utils/rules/defaultTo/defaultTo.es6.js';
|
|
7
|
+
import { useParentRule } from '../../../hooks/useParentRule/useParentRule.es6.js';
|
|
8
|
+
import { useRule } from '../../../hooks/useRule/useRule.es6.js';
|
|
9
|
+
import { pipe } from '../../../utils/rules/pipe/pipe.es6.js';
|
|
10
|
+
|
|
11
|
+
const any = () => {
|
|
12
|
+
const props = useProps();
|
|
13
|
+
useSchemaType('any', props);
|
|
14
|
+
const rules = [];
|
|
15
|
+
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
16
|
+
rules.push(defaultTo(props.default));
|
|
17
|
+
}
|
|
18
|
+
if ((props === null || props === void 0 ? void 0 : props.default) === undefined) {
|
|
19
|
+
const parentRule = useParentRule();
|
|
20
|
+
useRule(parentRule(pipe(...rules)));
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
useRule(pipe(...rules));
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { any };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var jsx = require('@innet/jsx');
|
|
6
|
+
require('../../../hooks/index.js');
|
|
7
|
+
require('../../../hooks/useParentRule/index.js');
|
|
8
|
+
require('../../../utils/index.js');
|
|
9
|
+
var useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
|
|
10
|
+
var defaultTo = require('../../../utils/rules/defaultTo/defaultTo.js');
|
|
11
|
+
var useParentRule = require('../../../hooks/useParentRule/useParentRule.js');
|
|
12
|
+
var useRule = require('../../../hooks/useRule/useRule.js');
|
|
13
|
+
var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
14
|
+
|
|
15
|
+
const any = () => {
|
|
16
|
+
const props = jsx.useProps();
|
|
17
|
+
useSchemaType.useSchemaType('any', props);
|
|
18
|
+
const rules = [];
|
|
19
|
+
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
20
|
+
rules.push(defaultTo.defaultTo(props.default));
|
|
21
|
+
}
|
|
22
|
+
if ((props === null || props === void 0 ? void 0 : props.default) === undefined) {
|
|
23
|
+
const parentRule = useParentRule.useParentRule();
|
|
24
|
+
useRule.useRule(parentRule(pipe.pipe(...rules)));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
useRule.useRule(pipe.pipe(...rules));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
exports.any = any;
|
package/plugins/schema/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import innet, { useNewHandler } from 'innet';
|
|
2
2
|
import { useChildren, useProps } from '@innet/jsx';
|
|
3
|
+
import { callHandler } from '@innet/utils';
|
|
3
4
|
import '../../../hooks/index.es6.js';
|
|
4
5
|
import '../../../hooks/useParentRule/index.es6.js';
|
|
5
6
|
import '../../../utils/index.es6.js';
|
|
@@ -52,6 +53,11 @@ const object = () => {
|
|
|
52
53
|
});
|
|
53
54
|
parentRuleContext.reset(handler);
|
|
54
55
|
innet(children, handler);
|
|
56
|
+
innet(() => {
|
|
57
|
+
if (!Object.keys(schema.additionalProperties).length) {
|
|
58
|
+
delete schema.additionalProperties;
|
|
59
|
+
}
|
|
60
|
+
}, callHandler);
|
|
55
61
|
}
|
|
56
62
|
else if (props.ref) {
|
|
57
63
|
useRule(refRules[props.ref]);
|
|
@@ -4,6 +4,7 @@ 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');
|
|
7
8
|
require('../../../hooks/index.js');
|
|
8
9
|
require('../../../hooks/useParentRule/index.js');
|
|
9
10
|
require('../../../utils/index.js');
|
|
@@ -60,6 +61,11 @@ const object = () => {
|
|
|
60
61
|
});
|
|
61
62
|
useParentRule.parentRuleContext.reset(handler);
|
|
62
63
|
innet__default["default"](children, handler);
|
|
64
|
+
innet__default["default"](() => {
|
|
65
|
+
if (!Object.keys(schema.additionalProperties).length) {
|
|
66
|
+
delete schema.additionalProperties;
|
|
67
|
+
}
|
|
68
|
+
}, utils.callHandler);
|
|
63
69
|
}
|
|
64
70
|
else if (props.ref) {
|
|
65
71
|
useRule.useRule(refRules[props.ref]);
|
|
@@ -21,26 +21,47 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
|
|
|
21
21
|
if (['boolean', 'number', 'null'].includes(schema.type)) {
|
|
22
22
|
return `${schema.type}${lastChar}`;
|
|
23
23
|
}
|
|
24
|
+
if (schema.oneOf) {
|
|
25
|
+
let result = '';
|
|
26
|
+
for (const item of schema.oneOf) {
|
|
27
|
+
if (result) {
|
|
28
|
+
result += ' | ';
|
|
29
|
+
}
|
|
30
|
+
result += generateSchemaTypes(item, spaces + 2, '');
|
|
31
|
+
}
|
|
32
|
+
return result + lastChar;
|
|
33
|
+
}
|
|
24
34
|
if (schema.type === 'array') {
|
|
25
35
|
if (!schema.items)
|
|
26
36
|
return `any[]${lastChar}`;
|
|
27
37
|
return `Array<${generateSchemaTypes(schema.items, spaces + 2, '')}>${lastChar}`;
|
|
28
38
|
}
|
|
39
|
+
if (!schema.type) {
|
|
40
|
+
return `any${lastChar}`;
|
|
41
|
+
}
|
|
29
42
|
if (schema.type !== 'object') {
|
|
30
43
|
console.error('unknown type', schema);
|
|
31
44
|
return `any${lastChar}`;
|
|
32
45
|
}
|
|
33
46
|
let result = '{\n';
|
|
34
47
|
const required = schema.required || [];
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
const hasProps = Boolean(schema.properties && Object.keys(schema.properties).length);
|
|
49
|
+
const hasRestProps = Boolean(typeof schema.additionalProperties === 'object' &&
|
|
50
|
+
Object.keys(schema.additionalProperties).length);
|
|
51
|
+
if (hasProps) {
|
|
52
|
+
for (const key in schema.properties) {
|
|
53
|
+
const prop = schema.properties[key];
|
|
54
|
+
const splitter = required.includes(key) || hasDefault(prop)
|
|
55
|
+
? ':'
|
|
56
|
+
: '?:';
|
|
57
|
+
result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
|
|
58
|
+
}
|
|
41
59
|
}
|
|
42
|
-
if (
|
|
43
|
-
|
|
60
|
+
if (hasRestProps) {
|
|
61
|
+
const value = hasProps
|
|
62
|
+
? 'any\n'
|
|
63
|
+
: generateSchemaTypes(schema.additionalProperties, spaces + 2);
|
|
64
|
+
result += `${space}[key: string]: ${value}`;
|
|
44
65
|
}
|
|
45
66
|
return `${result}${space.slice(0, -2)}}${lastChar}`;
|
|
46
67
|
}
|
|
@@ -25,26 +25,47 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
|
|
|
25
25
|
if (['boolean', 'number', 'null'].includes(schema.type)) {
|
|
26
26
|
return `${schema.type}${lastChar}`;
|
|
27
27
|
}
|
|
28
|
+
if (schema.oneOf) {
|
|
29
|
+
let result = '';
|
|
30
|
+
for (const item of schema.oneOf) {
|
|
31
|
+
if (result) {
|
|
32
|
+
result += ' | ';
|
|
33
|
+
}
|
|
34
|
+
result += generateSchemaTypes(item, spaces + 2, '');
|
|
35
|
+
}
|
|
36
|
+
return result + lastChar;
|
|
37
|
+
}
|
|
28
38
|
if (schema.type === 'array') {
|
|
29
39
|
if (!schema.items)
|
|
30
40
|
return `any[]${lastChar}`;
|
|
31
41
|
return `Array<${generateSchemaTypes(schema.items, spaces + 2, '')}>${lastChar}`;
|
|
32
42
|
}
|
|
43
|
+
if (!schema.type) {
|
|
44
|
+
return `any${lastChar}`;
|
|
45
|
+
}
|
|
33
46
|
if (schema.type !== 'object') {
|
|
34
47
|
console.error('unknown type', schema);
|
|
35
48
|
return `any${lastChar}`;
|
|
36
49
|
}
|
|
37
50
|
let result = '{\n';
|
|
38
51
|
const required = schema.required || [];
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
const hasProps = Boolean(schema.properties && Object.keys(schema.properties).length);
|
|
53
|
+
const hasRestProps = Boolean(typeof schema.additionalProperties === 'object' &&
|
|
54
|
+
Object.keys(schema.additionalProperties).length);
|
|
55
|
+
if (hasProps) {
|
|
56
|
+
for (const key in schema.properties) {
|
|
57
|
+
const prop = schema.properties[key];
|
|
58
|
+
const splitter = required.includes(key) || hasDefault(prop)
|
|
59
|
+
? ':'
|
|
60
|
+
: '?:';
|
|
61
|
+
result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
|
|
62
|
+
}
|
|
45
63
|
}
|
|
46
|
-
if (
|
|
47
|
-
|
|
64
|
+
if (hasRestProps) {
|
|
65
|
+
const value = hasProps
|
|
66
|
+
? 'any\n'
|
|
67
|
+
: generateSchemaTypes(schema.additionalProperties, spaces + 2);
|
|
68
|
+
result += `${space}[key: string]: ${value}`;
|
|
48
69
|
}
|
|
49
70
|
return `${result}${space.slice(0, -2)}}${lastChar}`;
|
|
50
71
|
}
|
package/utils/rules/index.d.ts
CHANGED
package/utils/rules/index.es6.js
CHANGED
|
@@ -22,7 +22,6 @@ import './minLength/index.es6.js';
|
|
|
22
22
|
import './max/index.es6.js';
|
|
23
23
|
import './min/index.es6.js';
|
|
24
24
|
import './defaultTo/index.es6.js';
|
|
25
|
-
import './any/index.es6.js';
|
|
26
25
|
import './bin/index.es6.js';
|
|
27
26
|
import './minBin/index.es6.js';
|
|
28
27
|
import './maxBin/index.es6.js';
|
package/utils/rules/index.js
CHANGED
package/utils/rules/any/any.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function any(value: any): any;
|
package/utils/rules/any/any.js
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|