@innet/server 2.0.0-beta.15 → 2.0.0-beta.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innet/server",
3
- "version": "2.0.0-beta.15",
3
+ "version": "2.0.0-beta.16",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -15,67 +15,85 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
15
15
  if ('$ref' in schema) {
16
16
  return `Schemas.${schema.$ref.slice(21)}${lastChar}`;
17
17
  }
18
- if (schema.type === 'integer') {
19
- return `${schema.format === 'int64' ? 'bigint' : 'number'}${lastChar}`;
20
- }
21
- if (schema.type === 'string') {
22
- if (schema.format === 'date-time') {
23
- return `Date${lastChar}`;
18
+ const types = Array.isArray(schema.type) ? schema.type : [schema.type];
19
+ let scope = '';
20
+ for (let i = 0; i < types.length; i++) {
21
+ const type = types[i];
22
+ const operator = i ? ' | ' : '';
23
+ if (schema.oneOf) {
24
+ let result = '';
25
+ for (const item of schema.oneOf) {
26
+ if (result) {
27
+ result += ' | ';
28
+ }
29
+ result += generateSchemaTypes(item, spaces + 2, '');
30
+ }
31
+ scope += `${operator}${result}`;
32
+ continue;
24
33
  }
25
- if (schema.format === 'binary') {
26
- return `Bin${lastChar}`;
34
+ if (!type) {
35
+ scope += `${operator}any`;
36
+ continue;
27
37
  }
28
- return `string${lastChar}`;
29
- }
30
- if (['boolean', 'null', 'number'].includes(schema.type)) {
31
- return `${schema.type}${lastChar}`;
32
- }
33
- if (schema.oneOf) {
34
- let result = '';
35
- for (const item of schema.oneOf) {
36
- if (result) {
37
- result += ' | ';
38
+ if (type === 'integer') {
39
+ scope += `${operator}${schema.format === 'int64' ? 'bigint' : 'number'}`;
40
+ continue;
41
+ }
42
+ if (type === 'string') {
43
+ if (schema.format === 'date-time') {
44
+ scope += `${operator}Date`;
45
+ continue;
46
+ }
47
+ if (schema.format === 'binary') {
48
+ scope += `${operator}Bin`;
49
+ continue;
38
50
  }
39
- result += generateSchemaTypes(item, spaces + 2, '');
51
+ scope += `${operator}string`;
52
+ continue;
40
53
  }
41
- return result + lastChar;
42
- }
43
- if (schema.type === 'array') {
44
- if (!schema.items)
45
- return `any[]${lastChar}`;
46
- return `Array<${generateSchemaTypes(schema.items, spaces + 2, '')}>${lastChar}`;
47
- }
48
- if (!schema.type) {
49
- return `any${lastChar}`;
50
- }
51
- if (schema.type !== 'object') {
52
- console.error('unknown type', schema);
53
- return `any${lastChar}`;
54
- }
55
- let result = '{\n';
56
- const required = schema.required || [];
57
- const hasProps = Boolean(schema.properties && Object.keys(schema.properties).length);
58
- const hasRestProps = Boolean(typeof schema.additionalProperties === 'object' &&
59
- Object.keys(schema.additionalProperties).length);
60
- if (hasProps) {
61
- for (const key in schema.properties) {
62
- const prop = schema.properties[key];
63
- const splitter = required.includes(key) || hasDefault(prop)
64
- ? ':'
65
- : '?:';
66
- if ('deprecated' in prop && prop.deprecated) {
67
- result += `${space}/** @deprecated */\n`;
54
+ if (['boolean', 'null', 'number'].includes(type)) {
55
+ scope += `${operator}${type}`;
56
+ continue;
57
+ }
58
+ if (type === 'array') {
59
+ if (schema.type !== 'array' || !schema.items) {
60
+ scope += `${operator}any[]`;
61
+ continue;
68
62
  }
69
- result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
63
+ scope += `${operator}Array<${generateSchemaTypes(schema.items, spaces + 2, '')}>`;
64
+ continue;
70
65
  }
66
+ if (type !== 'object') {
67
+ console.error('Error: Unknown Type', schema);
68
+ scope += `${operator}any`;
69
+ continue;
70
+ }
71
+ let result = '{\n';
72
+ const required = schema.required || [];
73
+ const hasProps = Boolean(schema.properties && Object.keys(schema.properties).length);
74
+ const hasRestProps = Boolean(typeof schema.additionalProperties === 'object' &&
75
+ Object.keys(schema.additionalProperties).length);
76
+ if (hasProps) {
77
+ for (const key in schema.properties) {
78
+ const prop = schema.properties[key];
79
+ const splitter = required.includes(key) || hasDefault(prop)
80
+ ? ':'
81
+ : '?:';
82
+ if ('deprecated' in prop && prop.deprecated) {
83
+ result += `${space}/** @deprecated */\n`;
84
+ }
85
+ result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
86
+ }
87
+ }
88
+ if (hasRestProps) {
89
+ const value = hasProps
90
+ ? 'any\n'
91
+ : generateSchemaTypes(schema.additionalProperties, spaces + 2);
92
+ result += `${space}[key: string]: ${value}`;
93
+ }
94
+ scope += `${operator}${result}${space.slice(0, -2)}}`;
71
95
  }
72
- if (hasRestProps) {
73
- const value = hasProps
74
- ? 'any\n'
75
- : generateSchemaTypes(schema.additionalProperties, spaces + 2);
76
- result += `${space}[key: string]: ${value}`;
77
- }
78
- return `${result}${space.slice(0, -2)}}${lastChar}`;
96
+ return `${scope}${lastChar}`;
79
97
  }
80
98
  function generateTypes(docs, namespace = 'Api') {
81
99
  var _a;
@@ -19,67 +19,85 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
19
19
  if ('$ref' in schema) {
20
20
  return `Schemas.${schema.$ref.slice(21)}${lastChar}`;
21
21
  }
22
- if (schema.type === 'integer') {
23
- return `${schema.format === 'int64' ? 'bigint' : 'number'}${lastChar}`;
24
- }
25
- if (schema.type === 'string') {
26
- if (schema.format === 'date-time') {
27
- return `Date${lastChar}`;
22
+ const types = Array.isArray(schema.type) ? schema.type : [schema.type];
23
+ let scope = '';
24
+ for (let i = 0; i < types.length; i++) {
25
+ const type = types[i];
26
+ const operator = i ? ' | ' : '';
27
+ if (schema.oneOf) {
28
+ let result = '';
29
+ for (const item of schema.oneOf) {
30
+ if (result) {
31
+ result += ' | ';
32
+ }
33
+ result += generateSchemaTypes(item, spaces + 2, '');
34
+ }
35
+ scope += `${operator}${result}`;
36
+ continue;
28
37
  }
29
- if (schema.format === 'binary') {
30
- return `Bin${lastChar}`;
38
+ if (!type) {
39
+ scope += `${operator}any`;
40
+ continue;
31
41
  }
32
- return `string${lastChar}`;
33
- }
34
- if (['boolean', 'null', 'number'].includes(schema.type)) {
35
- return `${schema.type}${lastChar}`;
36
- }
37
- if (schema.oneOf) {
38
- let result = '';
39
- for (const item of schema.oneOf) {
40
- if (result) {
41
- result += ' | ';
42
+ if (type === 'integer') {
43
+ scope += `${operator}${schema.format === 'int64' ? 'bigint' : 'number'}`;
44
+ continue;
45
+ }
46
+ if (type === 'string') {
47
+ if (schema.format === 'date-time') {
48
+ scope += `${operator}Date`;
49
+ continue;
50
+ }
51
+ if (schema.format === 'binary') {
52
+ scope += `${operator}Bin`;
53
+ continue;
42
54
  }
43
- result += generateSchemaTypes(item, spaces + 2, '');
55
+ scope += `${operator}string`;
56
+ continue;
44
57
  }
45
- return result + lastChar;
46
- }
47
- if (schema.type === 'array') {
48
- if (!schema.items)
49
- return `any[]${lastChar}`;
50
- return `Array<${generateSchemaTypes(schema.items, spaces + 2, '')}>${lastChar}`;
51
- }
52
- if (!schema.type) {
53
- return `any${lastChar}`;
54
- }
55
- if (schema.type !== 'object') {
56
- console.error('unknown type', schema);
57
- return `any${lastChar}`;
58
- }
59
- let result = '{\n';
60
- const required = schema.required || [];
61
- const hasProps = Boolean(schema.properties && Object.keys(schema.properties).length);
62
- const hasRestProps = Boolean(typeof schema.additionalProperties === 'object' &&
63
- Object.keys(schema.additionalProperties).length);
64
- if (hasProps) {
65
- for (const key in schema.properties) {
66
- const prop = schema.properties[key];
67
- const splitter = required.includes(key) || hasDefault(prop)
68
- ? ':'
69
- : '?:';
70
- if ('deprecated' in prop && prop.deprecated) {
71
- result += `${space}/** @deprecated */\n`;
58
+ if (['boolean', 'null', 'number'].includes(type)) {
59
+ scope += `${operator}${type}`;
60
+ continue;
61
+ }
62
+ if (type === 'array') {
63
+ if (schema.type !== 'array' || !schema.items) {
64
+ scope += `${operator}any[]`;
65
+ continue;
72
66
  }
73
- result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
67
+ scope += `${operator}Array<${generateSchemaTypes(schema.items, spaces + 2, '')}>`;
68
+ continue;
74
69
  }
70
+ if (type !== 'object') {
71
+ console.error('Error: Unknown Type', schema);
72
+ scope += `${operator}any`;
73
+ continue;
74
+ }
75
+ let result = '{\n';
76
+ const required = schema.required || [];
77
+ const hasProps = Boolean(schema.properties && Object.keys(schema.properties).length);
78
+ const hasRestProps = Boolean(typeof schema.additionalProperties === 'object' &&
79
+ Object.keys(schema.additionalProperties).length);
80
+ if (hasProps) {
81
+ for (const key in schema.properties) {
82
+ const prop = schema.properties[key];
83
+ const splitter = required.includes(key) || hasDefault(prop)
84
+ ? ':'
85
+ : '?:';
86
+ if ('deprecated' in prop && prop.deprecated) {
87
+ result += `${space}/** @deprecated */\n`;
88
+ }
89
+ result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
90
+ }
91
+ }
92
+ if (hasRestProps) {
93
+ const value = hasProps
94
+ ? 'any\n'
95
+ : generateSchemaTypes(schema.additionalProperties, spaces + 2);
96
+ result += `${space}[key: string]: ${value}`;
97
+ }
98
+ scope += `${operator}${result}${space.slice(0, -2)}}`;
75
99
  }
76
- if (hasRestProps) {
77
- const value = hasProps
78
- ? 'any\n'
79
- : generateSchemaTypes(schema.additionalProperties, spaces + 2);
80
- result += `${space}[key: string]: ${value}`;
81
- }
82
- return `${result}${space.slice(0, -2)}}${lastChar}`;
100
+ return `${scope}${lastChar}`;
83
101
  }
84
102
  function generateTypes(docs, namespace = 'Api') {
85
103
  var _a;