@innet/server 2.0.0-alpha.18 → 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.
@@ -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.18",
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",
@@ -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]);
@@ -36,6 +36,9 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
36
36
  return `any[]${lastChar}`;
37
37
  return `Array<${generateSchemaTypes(schema.items, spaces + 2, '')}>${lastChar}`;
38
38
  }
39
+ if (!schema.type) {
40
+ return `any${lastChar}`;
41
+ }
39
42
  if (schema.type !== 'object') {
40
43
  console.error('unknown type', schema);
41
44
  return `any${lastChar}`;
@@ -40,6 +40,9 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
40
40
  return `any[]${lastChar}`;
41
41
  return `Array<${generateSchemaTypes(schema.items, spaces + 2, '')}>${lastChar}`;
42
42
  }
43
+ if (!schema.type) {
44
+ return `any${lastChar}`;
45
+ }
43
46
  if (schema.type !== 'object') {
44
47
  console.error('unknown type', schema);
45
48
  return `any${lastChar}`;
@@ -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