@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 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 looks at project folder.
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
@@ -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;
@@ -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,
@@ -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 TypeMap<T extends ObjectType> = 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 : unknown;
3
- export declare function useSchemaType<T extends ObjectType>(type: T, { values, ref, example, examples, ...options }?: undefined | ValuesSchemaProps<TypeMap<T>>): SchemaObject | undefined;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innet/server",
3
- "version": "2.0.0-alpha.17",
3
+ "version": "2.0.0-alpha.19",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -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: (_a = rest.version) !== null && _a !== void 0 ? _a : '0.0.0', title });
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, _g;
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 = ((_c = (_b = req.method) === null || _b === void 0 ? void 0 : _b.toLowerCase()) !== null && _c !== void 0 ? _c : 'get');
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 ((_e = (_d = currentEndpoint.static) === null || _d === void 0 ? void 0 : _d[key]) === null || _e === void 0 ? void 0 : _e.plugins) {
142
- if (!(yield run((_f = currentEndpoint.static) === null || _f === void 0 ? void 0 : _f[key], params)))
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 ((_g = currentEndpoint.static) === null || _g === void 0 ? void 0 : _g[key]) {
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) {
@@ -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: (_a = rest.version) !== null && _a !== void 0 ? _a : '0.0.0', title });
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, _g;
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 = ((_c = (_b = req.method) === null || _b === void 0 ? void 0 : _b.toLowerCase()) !== null && _c !== void 0 ? _c : 'get');
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 ((_e = (_d = currentEndpoint.static) === null || _d === void 0 ? void 0 : _d[key]) === null || _e === void 0 ? void 0 : _e.plugins) {
150
- if (!(yield run((_f = currentEndpoint.static) === null || _f === void 0 ? void 0 : _f[key], params)))
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 ((_g = currentEndpoint.static) === null || _g === void 0 ? void 0 : _g[key]) {
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,5 @@
1
+ import { type HandlerPlugin } from 'innet';
2
+ import { type BaseSchemaProps } from '../../../types';
3
+ export interface AnyProps extends BaseSchemaProps<boolean> {
4
+ }
5
+ export declare const any: HandlerPlugin;
@@ -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;
@@ -10,3 +10,4 @@ export * from './date';
10
10
  export * from './tuple';
11
11
  export * from './uuid';
12
12
  export * from './binary';
13
+ export * from './any';
@@ -10,3 +10,4 @@ import './date/index.es6.js';
10
10
  import './tuple/index.es6.js';
11
11
  import './uuid/index.es6.js';
12
12
  import './binary/index.es6.js';
13
+ import './any/index.es6.js';
@@ -12,4 +12,5 @@ require('./date/index.js');
12
12
  require('./tuple/index.js');
13
13
  require('./uuid/index.js');
14
14
  require('./binary/index.js');
15
+ require('./any/index.js');
15
16
 
@@ -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
- for (const key in schema.properties) {
36
- const prop = schema.properties[key];
37
- const splitter = required.includes(key) || hasDefault(prop)
38
- ? ':'
39
- : '?:';
40
- result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
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 (typeof schema.additionalProperties === 'object' && Object.keys(schema.additionalProperties).length) {
43
- result += `${space}[key: string]: any\n`;
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
- for (const key in schema.properties) {
40
- const prop = schema.properties[key];
41
- const splitter = required.includes(key) || hasDefault(prop)
42
- ? ':'
43
- : '?:';
44
- result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
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 (typeof schema.additionalProperties === 'object' && Object.keys(schema.additionalProperties).length) {
47
- result += `${space}[key: string]: any\n`;
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
  }
@@ -22,7 +22,6 @@ export * from './minLength';
22
22
  export * from './max';
23
23
  export * from './min';
24
24
  export * from './defaultTo';
25
- export * from './any';
26
25
  export * from './bin';
27
26
  export * from './minBin';
28
27
  export * from './maxBin';
@@ -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';
@@ -26,7 +26,6 @@ require('./minLength/index.js');
26
26
  require('./max/index.js');
27
27
  require('./min/index.js');
28
28
  require('./defaultTo/index.js');
29
- require('./any/index.js');
30
29
  require('./bin/index.js');
31
30
  require('./minBin/index.js');
32
31
  require('./maxBin/index.js');
@@ -1 +0,0 @@
1
- export declare function any(value: any): any;
@@ -1,5 +0,0 @@
1
- function any(value) {
2
- return value;
3
- }
4
-
5
- export { any };
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function any(value) {
6
- return value;
7
- }
8
-
9
- exports.any = any;
File without changes
File without changes