@innet/server 2.0.0-alpha.4 → 2.0.0-alpha.6
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 +15 -8
- package/example/schemas/todo/TodoSchema/TodoSchema.d.ts +2 -2
- package/package.json +1 -1
- package/plugins/schema/boolean/boolean.es6.js +2 -4
- package/plugins/schema/boolean/boolean.js +1 -3
- package/utils/generateTypes/generateTypes.es6.js +11 -2
- package/utils/generateTypes/generateTypes.js +11 -2
- package/utils/rules/objectOf/objectOf.es6.js +4 -1
- package/utils/rules/objectOf/objectOf.js +4 -1
package/README.md
CHANGED
|
@@ -396,22 +396,29 @@ export default (
|
|
|
396
396
|
)
|
|
397
397
|
```
|
|
398
398
|
|
|
399
|
-
|
|
400
|
-
|
|
399
|
+
You do not need to import types, use `Api` namespace everywhere.
|
|
401
400
|
Here is an example of generated types usage.
|
|
402
401
|
|
|
403
|
-
*src/GetPartner.tsx*
|
|
404
402
|
```typescript jsx
|
|
405
403
|
import { useParams } from '@innet/server'
|
|
406
404
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
405
|
+
import { todos } from '../todos'
|
|
406
|
+
|
|
407
|
+
export function DeleteTodo () {
|
|
408
|
+
const { todoId } = useParams<Api.Endpoints['DELETE:/todos/{todoId}']['Params']>()
|
|
409
|
+
|
|
410
|
+
const todoIndex = todos.findIndex(({ id }) => id === todoId)
|
|
411
|
+
|
|
412
|
+
if (todoIndex === -1) {
|
|
413
|
+
return <error code='todoNotFound' status={404} />
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
todos.splice(todoIndex, 1)
|
|
417
|
+
|
|
418
|
+
return <success />
|
|
410
419
|
}
|
|
411
420
|
```
|
|
412
421
|
|
|
413
|
-
You do not need to import types, they generate as namespaces.
|
|
414
|
-
|
|
415
422
|
## API Info
|
|
416
423
|
|
|
417
424
|
The API information elements are here.
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { useProps
|
|
1
|
+
import { useProps } from '@innet/jsx';
|
|
2
2
|
import '../../../hooks/index.es6.js';
|
|
3
3
|
import '../../../hooks/useParentRule/index.es6.js';
|
|
4
4
|
import '../../../utils/index.es6.js';
|
|
5
5
|
import { useBlock } from '../../../hooks/useBlock/useBlock.es6.js';
|
|
6
6
|
import { useSchemaType } from '../../../hooks/useSchemaType/useSchemaType.es6.js';
|
|
7
|
-
import { paramContext } from '../../../hooks/useParam/useParam.es6.js';
|
|
8
7
|
import { defaultTo } from '../../../utils/rules/defaultTo/defaultTo.es6.js';
|
|
9
8
|
import { useParentRule } from '../../../hooks/useParentRule/useParentRule.es6.js';
|
|
10
9
|
import { useRule } from '../../../hooks/useRule/useRule.es6.js';
|
|
@@ -14,12 +13,11 @@ const boolean = () => {
|
|
|
14
13
|
useBlock('path');
|
|
15
14
|
const props = useProps();
|
|
16
15
|
useSchemaType('boolean', props);
|
|
17
|
-
const param = useContext(paramContext);
|
|
18
16
|
const rules = [];
|
|
19
17
|
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
20
18
|
rules.push(defaultTo(props.default));
|
|
21
19
|
}
|
|
22
|
-
rules.push(
|
|
20
|
+
rules.push(val => val === 'true' || (val === 'false' ? false : Boolean(val)));
|
|
23
21
|
if ((props === null || props === void 0 ? void 0 : props.default) === undefined) {
|
|
24
22
|
const parentRule = useParentRule();
|
|
25
23
|
useRule(parentRule(pipe(...rules)));
|
|
@@ -8,7 +8,6 @@ require('../../../hooks/useParentRule/index.js');
|
|
|
8
8
|
require('../../../utils/index.js');
|
|
9
9
|
var useBlock = require('../../../hooks/useBlock/useBlock.js');
|
|
10
10
|
var useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
|
|
11
|
-
var useParam = require('../../../hooks/useParam/useParam.js');
|
|
12
11
|
var defaultTo = require('../../../utils/rules/defaultTo/defaultTo.js');
|
|
13
12
|
var useParentRule = require('../../../hooks/useParentRule/useParentRule.js');
|
|
14
13
|
var useRule = require('../../../hooks/useRule/useRule.js');
|
|
@@ -18,12 +17,11 @@ const boolean = () => {
|
|
|
18
17
|
useBlock.useBlock('path');
|
|
19
18
|
const props = jsx.useProps();
|
|
20
19
|
useSchemaType.useSchemaType('boolean', props);
|
|
21
|
-
const param = jsx.useContext(useParam.paramContext);
|
|
22
20
|
const rules = [];
|
|
23
21
|
if ((props === null || props === void 0 ? void 0 : props.default) !== undefined) {
|
|
24
22
|
rules.push(defaultTo.defaultTo(props.default));
|
|
25
23
|
}
|
|
26
|
-
rules.push(
|
|
24
|
+
rules.push(val => val === 'true' || (val === 'false' ? false : Boolean(val)));
|
|
27
25
|
if ((props === null || props === void 0 ? void 0 : props.default) === undefined) {
|
|
28
26
|
const parentRule = useParentRule.useParentRule();
|
|
29
27
|
useRule.useRule(parentRule(pipe.pipe(...rules)));
|
|
@@ -9,7 +9,16 @@ function generateSchemaTypes(schema, spaces = 2) {
|
|
|
9
9
|
if (schema.type === 'integer') {
|
|
10
10
|
return `${schema.format === 'int64' ? 'bigint' : 'number'}\n`;
|
|
11
11
|
}
|
|
12
|
-
if (
|
|
12
|
+
if (schema.type === 'string') {
|
|
13
|
+
if (schema.format === 'date-time') {
|
|
14
|
+
return 'Date\n';
|
|
15
|
+
}
|
|
16
|
+
if (schema.format === 'binary') {
|
|
17
|
+
return 'Bin\n';
|
|
18
|
+
}
|
|
19
|
+
return 'string\n';
|
|
20
|
+
}
|
|
21
|
+
if (['boolean', 'number', 'null'].includes(schema.type)) {
|
|
13
22
|
return `${schema.type}\n`;
|
|
14
23
|
}
|
|
15
24
|
if (schema.type === 'array') {
|
|
@@ -34,7 +43,7 @@ function generateSchemaTypes(schema, spaces = 2) {
|
|
|
34
43
|
}
|
|
35
44
|
function generateTypes(docs) {
|
|
36
45
|
var _a;
|
|
37
|
-
let result = 'declare namespace Api {\n';
|
|
46
|
+
let result = 'declare namespace Api {\n export interface Bin {\n filename: string\n fieldName: string\n originalFilename: string\n path: string\n type: string\n disposition: string\n size: number\n extension?: string\n }\n';
|
|
38
47
|
const schemas = (_a = docs.components) === null || _a === void 0 ? void 0 : _a.schemas;
|
|
39
48
|
const paths = docs.paths;
|
|
40
49
|
if (schemas) {
|
|
@@ -13,7 +13,16 @@ function generateSchemaTypes(schema, spaces = 2) {
|
|
|
13
13
|
if (schema.type === 'integer') {
|
|
14
14
|
return `${schema.format === 'int64' ? 'bigint' : 'number'}\n`;
|
|
15
15
|
}
|
|
16
|
-
if (
|
|
16
|
+
if (schema.type === 'string') {
|
|
17
|
+
if (schema.format === 'date-time') {
|
|
18
|
+
return 'Date\n';
|
|
19
|
+
}
|
|
20
|
+
if (schema.format === 'binary') {
|
|
21
|
+
return 'Bin\n';
|
|
22
|
+
}
|
|
23
|
+
return 'string\n';
|
|
24
|
+
}
|
|
25
|
+
if (['boolean', 'number', 'null'].includes(schema.type)) {
|
|
17
26
|
return `${schema.type}\n`;
|
|
18
27
|
}
|
|
19
28
|
if (schema.type === 'array') {
|
|
@@ -38,7 +47,7 @@ function generateSchemaTypes(schema, spaces = 2) {
|
|
|
38
47
|
}
|
|
39
48
|
function generateTypes(docs) {
|
|
40
49
|
var _a;
|
|
41
|
-
let result = 'declare namespace Api {\n';
|
|
50
|
+
let result = 'declare namespace Api {\n export interface Bin {\n filename: string\n fieldName: string\n originalFilename: string\n path: string\n type: string\n disposition: string\n size: number\n extension?: string\n }\n';
|
|
42
51
|
const schemas = (_a = docs.components) === null || _a === void 0 ? void 0 : _a.schemas;
|
|
43
52
|
const paths = docs.paths;
|
|
44
53
|
if (schemas) {
|
|
@@ -7,7 +7,10 @@ function objectOf(map) {
|
|
|
7
7
|
}
|
|
8
8
|
const result = {};
|
|
9
9
|
for (const key in map) {
|
|
10
|
-
|
|
10
|
+
const val = map[key](value[key], Object.assign(Object.assign({}, data), { key: addKey(key, data) }));
|
|
11
|
+
if (val !== undefined) {
|
|
12
|
+
result[key] = val;
|
|
13
|
+
}
|
|
11
14
|
}
|
|
12
15
|
return result;
|
|
13
16
|
};
|
|
@@ -11,7 +11,10 @@ function objectOf(map) {
|
|
|
11
11
|
}
|
|
12
12
|
const result = {};
|
|
13
13
|
for (const key in map) {
|
|
14
|
-
|
|
14
|
+
const val = map[key](value[key], Object.assign(Object.assign({}, data), { key: helpers.addKey(key, data) }));
|
|
15
|
+
if (val !== undefined) {
|
|
16
|
+
result[key] = val;
|
|
17
|
+
}
|
|
15
18
|
}
|
|
16
19
|
return result;
|
|
17
20
|
};
|