@innet/server 2.0.0-alpha.12 → 2.0.0-alpha.14
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 +457 -367
- package/handler/handler.d.ts +3 -3
- package/handler/handler.es6.js +2 -2
- package/handler/handler.js +2 -2
- package/hooks/index.d.ts +2 -1
- package/hooks/index.es6.js +2 -1
- package/hooks/index.js +2 -1
- package/hooks/useAction/useAction.es6.js +1 -1
- package/hooks/useAction/useAction.js +1 -1
- package/hooks/useApi/useApi.d.ts +1 -3
- package/hooks/useEndpoint/useEndpoint.es6.js +3 -1
- package/hooks/useEndpoint/useEndpoint.js +3 -1
- package/hooks/useRequest/index.es6.js +1 -1
- package/hooks/useRequest/index.js +0 -1
- package/hooks/useRequest/useRequest.d.ts +1 -4
- package/hooks/useRequest/useRequest.es6.js +4 -4
- package/hooks/useRequest/useRequest.js +3 -4
- package/hooks/useResponse/index.es6.js +1 -1
- package/hooks/useResponse/index.js +0 -1
- package/hooks/useResponse/useResponse.d.ts +1 -4
- package/hooks/useResponse/useResponse.es6.js +4 -4
- package/hooks/useResponse/useResponse.js +3 -4
- package/hooks/useServer/useServer.d.ts +1 -0
- package/hooks/useServer/useServer.es6.js +3 -1
- package/hooks/useServer/useServer.js +3 -1
- package/hooks/useServerPlugin/index.d.ts +1 -0
- package/hooks/useServerPlugin/index.es6.js +1 -0
- package/hooks/useServerPlugin/index.js +9 -0
- package/hooks/useServerPlugin/useServerPlugin.d.ts +2 -0
- package/hooks/useServerPlugin/useServerPlugin.es6.js +13 -0
- package/hooks/useServerPlugin/useServerPlugin.js +17 -0
- package/hooks/useServerPlugins/index.d.ts +1 -0
- package/hooks/useServerPlugins/index.es6.js +1 -0
- package/hooks/useServerPlugins/index.js +10 -0
- package/hooks/useServerPlugins/useServerPlugins.d.ts +4 -0
- package/hooks/useServerPlugins/useServerPlugins.es6.js +14 -0
- package/hooks/useServerPlugins/useServerPlugins.js +19 -0
- package/index.es6.js +5 -4
- package/index.js +7 -6
- package/package.json +1 -1
- package/plugins/main/api/api.d.ts +2 -0
- package/plugins/main/api/api.es6.js +44 -52
- package/plugins/main/api/api.js +43 -51
- package/plugins/main/endpoint/endpoint.es6.js +4 -1
- package/plugins/main/endpoint/endpoint.js +4 -1
- package/plugins/main/index.d.ts +1 -1
- package/plugins/main/index.es6.js +1 -1
- package/plugins/main/index.js +1 -1
- package/plugins/main/preset/index.d.ts +1 -0
- package/plugins/main/preset/index.es6.js +1 -0
- package/plugins/main/{fallback → preset}/index.js +2 -2
- package/plugins/main/preset/preset.d.ts +3 -0
- package/plugins/main/preset/preset.es6.js +13 -0
- package/plugins/main/preset/preset.js +21 -0
- package/plugins/main/request/request.es6.js +2 -13
- package/plugins/main/request/request.js +2 -13
- package/plugins/main/response/response.d.ts +1 -0
- package/plugins/main/response/response.es6.js +7 -7
- package/plugins/main/response/response.js +7 -7
- package/plugins/main/server/server.d.ts +3 -3
- package/plugins/main/server/server.es6.js +28 -6
- package/plugins/main/server/server.js +28 -6
- package/plugins/request/success/success.d.ts +1 -1
- package/plugins/request/success/success.es6.js +4 -4
- package/plugins/request/success/success.js +4 -4
- package/plugins/utils/blacklist/blacklist.es6.js +4 -3
- package/plugins/utils/blacklist/blacklist.js +4 -3
- package/plugins/utils/dts/dts.d.ts +2 -1
- package/plugins/utils/dts/dts.es6.js +2 -2
- package/plugins/utils/dts/dts.js +2 -2
- package/plugins/utils/protection/protection.es6.js +4 -2
- package/plugins/utils/protection/protection.js +4 -2
- package/plugins/utils/swagger/swagger.es6.js +5 -3
- package/plugins/utils/swagger/swagger.js +5 -3
- package/plugins/utils/whitelist/whitelist.es6.js +4 -2
- package/plugins/utils/whitelist/whitelist.js +4 -2
- package/types.d.ts +2 -9
- package/utils/action/Action.es6.js +12 -10
- package/utils/action/Action.js +12 -10
- package/utils/generateTypes/generateTypes.d.ts +2 -2
- package/utils/generateTypes/generateTypes.es6.js +40 -15
- package/utils/generateTypes/generateTypes.js +40 -15
- package/utils/getEndpoint/getEndpoint.es6.js +2 -2
- package/utils/getEndpoint/getEndpoint.js +2 -2
- package/hooks/useRequestPlugin/index.d.ts +0 -1
- package/hooks/useRequestPlugin/index.es6.js +0 -1
- package/hooks/useRequestPlugin/index.js +0 -9
- package/hooks/useRequestPlugin/useRequestPlugin.d.ts +0 -2
- package/hooks/useRequestPlugin/useRequestPlugin.es6.js +0 -13
- package/hooks/useRequestPlugin/useRequestPlugin.js +0 -17
- package/plugins/main/fallback/fallback.d.ts +0 -4
- package/plugins/main/fallback/fallback.es6.js +0 -19
- package/plugins/main/fallback/fallback.js +0 -23
- package/plugins/main/fallback/index.d.ts +0 -1
- package/plugins/main/fallback/index.es6.js +0 -1
|
@@ -5,34 +5,34 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
function hasDefault(target) {
|
|
6
6
|
return Boolean(target && ('default' in target || 'x-default' in target));
|
|
7
7
|
}
|
|
8
|
-
function generateSchemaTypes(schema, spaces = 2) {
|
|
8
|
+
function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
|
|
9
9
|
const space = [...new Array(spaces)].map(() => ' ').join('');
|
|
10
10
|
if ('$ref' in schema) {
|
|
11
|
-
return `Schemas.${schema.$ref.slice(21)}
|
|
11
|
+
return `Schemas.${schema.$ref.slice(21)}${lastChar}`;
|
|
12
12
|
}
|
|
13
13
|
if (schema.type === 'integer') {
|
|
14
|
-
return `${schema.format === 'int64' ? 'bigint' : 'number'}
|
|
14
|
+
return `${schema.format === 'int64' ? 'bigint' : 'number'}${lastChar}`;
|
|
15
15
|
}
|
|
16
16
|
if (schema.type === 'string') {
|
|
17
17
|
if (schema.format === 'date-time') {
|
|
18
|
-
return
|
|
18
|
+
return `Date${lastChar}`;
|
|
19
19
|
}
|
|
20
20
|
if (schema.format === 'binary') {
|
|
21
|
-
return
|
|
21
|
+
return `Bin${lastChar}`;
|
|
22
22
|
}
|
|
23
|
-
return
|
|
23
|
+
return `string${lastChar}`;
|
|
24
24
|
}
|
|
25
25
|
if (['boolean', 'number', 'null'].includes(schema.type)) {
|
|
26
|
-
return `${schema.type}
|
|
26
|
+
return `${schema.type}${lastChar}`;
|
|
27
27
|
}
|
|
28
28
|
if (schema.type === 'array') {
|
|
29
29
|
if (!schema.items)
|
|
30
|
-
return
|
|
31
|
-
return `
|
|
30
|
+
return `any[]${lastChar}`;
|
|
31
|
+
return `Array<${generateSchemaTypes(schema.items, spaces + 2, '')}>${lastChar}`;
|
|
32
32
|
}
|
|
33
33
|
if (schema.type !== 'object') {
|
|
34
34
|
console.error('unknown type', schema);
|
|
35
|
-
return
|
|
35
|
+
return `any${lastChar}`;
|
|
36
36
|
}
|
|
37
37
|
let result = '{\n';
|
|
38
38
|
const required = schema.required || [];
|
|
@@ -43,11 +43,22 @@ function generateSchemaTypes(schema, spaces = 2) {
|
|
|
43
43
|
: '?:';
|
|
44
44
|
result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
|
|
45
45
|
}
|
|
46
|
-
return `${result}${space.slice(0, -2)}}
|
|
46
|
+
return `${result}${space.slice(0, -2)}}${lastChar}`;
|
|
47
47
|
}
|
|
48
|
-
function generateTypes(docs) {
|
|
48
|
+
function generateTypes(docs, namespace = 'Api') {
|
|
49
49
|
var _a;
|
|
50
|
-
let result =
|
|
50
|
+
let result = `declare namespace ${namespace} {
|
|
51
|
+
export interface Bin {
|
|
52
|
+
filename: string
|
|
53
|
+
fieldName: string
|
|
54
|
+
originalFilename: string
|
|
55
|
+
path: string
|
|
56
|
+
type: string
|
|
57
|
+
disposition: string
|
|
58
|
+
size: number
|
|
59
|
+
extension?: string
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
51
62
|
const schemas = (_a = docs.components) === null || _a === void 0 ? void 0 : _a.schemas;
|
|
52
63
|
const paths = docs.paths;
|
|
53
64
|
if (schemas) {
|
|
@@ -94,8 +105,22 @@ function generateTypes(docs) {
|
|
|
94
105
|
if (requestBody) {
|
|
95
106
|
result += ` Body: ${generateSchemaTypes(requestBody.content['multipart/form-data'].schema, 8)}`;
|
|
96
107
|
}
|
|
97
|
-
if (responses
|
|
98
|
-
result +=
|
|
108
|
+
if (responses) {
|
|
109
|
+
result += ' Response: {\n';
|
|
110
|
+
for (const key in responses) {
|
|
111
|
+
let multiple = false;
|
|
112
|
+
const response = responses[key];
|
|
113
|
+
result += ` ['${key}']: `;
|
|
114
|
+
for (const type in response.content) {
|
|
115
|
+
if (multiple) {
|
|
116
|
+
result += ' | ';
|
|
117
|
+
}
|
|
118
|
+
result += generateSchemaTypes(response.content[type].schema, 10, '');
|
|
119
|
+
multiple = true;
|
|
120
|
+
}
|
|
121
|
+
result += '\n';
|
|
122
|
+
}
|
|
123
|
+
result += ' }\n';
|
|
99
124
|
}
|
|
100
125
|
result += ' }\n';
|
|
101
126
|
}
|
|
@@ -8,7 +8,7 @@ function getEndpoint(path, parentEndpoint) {
|
|
|
8
8
|
parentEndpoint.static = {};
|
|
9
9
|
}
|
|
10
10
|
if (!parentEndpoint.static[key]) {
|
|
11
|
-
parentEndpoint.static[key] = { key };
|
|
11
|
+
parentEndpoint.static[key] = { key, plugins: new Set() };
|
|
12
12
|
}
|
|
13
13
|
parentEndpoint = parentEndpoint.static[key];
|
|
14
14
|
if (deep + 1 === splitPath.length) {
|
|
@@ -19,7 +19,7 @@ function getEndpoint(path, parentEndpoint) {
|
|
|
19
19
|
if (!parentEndpoint.dynamic) {
|
|
20
20
|
parentEndpoint.dynamic = [];
|
|
21
21
|
}
|
|
22
|
-
const newEndpoint = { key };
|
|
22
|
+
const newEndpoint = { key, plugins: new Set() };
|
|
23
23
|
parentEndpoint.dynamic.push(newEndpoint);
|
|
24
24
|
parentEndpoint = newEndpoint;
|
|
25
25
|
if (deep + 1 === splitPath.length) {
|
|
@@ -12,7 +12,7 @@ function getEndpoint(path, parentEndpoint) {
|
|
|
12
12
|
parentEndpoint.static = {};
|
|
13
13
|
}
|
|
14
14
|
if (!parentEndpoint.static[key]) {
|
|
15
|
-
parentEndpoint.static[key] = { key };
|
|
15
|
+
parentEndpoint.static[key] = { key, plugins: new Set() };
|
|
16
16
|
}
|
|
17
17
|
parentEndpoint = parentEndpoint.static[key];
|
|
18
18
|
if (deep + 1 === splitPath.length) {
|
|
@@ -23,7 +23,7 @@ function getEndpoint(path, parentEndpoint) {
|
|
|
23
23
|
if (!parentEndpoint.dynamic) {
|
|
24
24
|
parentEndpoint.dynamic = [];
|
|
25
25
|
}
|
|
26
|
-
const newEndpoint = { key };
|
|
26
|
+
const newEndpoint = { key, plugins: new Set() };
|
|
27
27
|
parentEndpoint.dynamic.push(newEndpoint);
|
|
28
28
|
parentEndpoint = newEndpoint;
|
|
29
29
|
if (deep + 1 === splitPath.length) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useRequestPlugin';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useRequestPlugin } from './useRequestPlugin.es6.js';
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { onDestroy } from 'watch-state';
|
|
2
|
-
import '../useApi/index.es6.js';
|
|
3
|
-
import { useApi } from '../useApi/useApi.es6.js';
|
|
4
|
-
|
|
5
|
-
function useRequestPlugin(listener) {
|
|
6
|
-
const { requestPlugins } = useApi();
|
|
7
|
-
requestPlugins.add(listener);
|
|
8
|
-
onDestroy(() => {
|
|
9
|
-
requestPlugins.delete(listener);
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { useRequestPlugin };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var watchState = require('watch-state');
|
|
6
|
-
require('../useApi/index.js');
|
|
7
|
-
var useApi = require('../useApi/useApi.js');
|
|
8
|
-
|
|
9
|
-
function useRequestPlugin(listener) {
|
|
10
|
-
const { requestPlugins } = useApi.useApi();
|
|
11
|
-
requestPlugins.add(listener);
|
|
12
|
-
watchState.onDestroy(() => {
|
|
13
|
-
requestPlugins.delete(listener);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
exports.useRequestPlugin = useRequestPlugin;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { useHandler } from 'innet';
|
|
2
|
-
import { useChildren } from '@innet/jsx';
|
|
3
|
-
import '../../../hooks/index.es6.js';
|
|
4
|
-
import { useApi } from '../../../hooks/useApi/useApi.es6.js';
|
|
5
|
-
|
|
6
|
-
const fallback = () => {
|
|
7
|
-
const api = useApi();
|
|
8
|
-
if (!api) {
|
|
9
|
-
throw Error('Use <fallback> inside <api>');
|
|
10
|
-
}
|
|
11
|
-
if (api.fallback) {
|
|
12
|
-
throw Error('<fallback> MUST be used once on an <api>');
|
|
13
|
-
}
|
|
14
|
-
const children = useChildren();
|
|
15
|
-
const handler = useHandler();
|
|
16
|
-
api.fallback = { children, handler };
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export { fallback };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var innet = require('innet');
|
|
6
|
-
var jsx = require('@innet/jsx');
|
|
7
|
-
require('../../../hooks/index.js');
|
|
8
|
-
var useApi = require('../../../hooks/useApi/useApi.js');
|
|
9
|
-
|
|
10
|
-
const fallback = () => {
|
|
11
|
-
const api = useApi.useApi();
|
|
12
|
-
if (!api) {
|
|
13
|
-
throw Error('Use <fallback> inside <api>');
|
|
14
|
-
}
|
|
15
|
-
if (api.fallback) {
|
|
16
|
-
throw Error('<fallback> MUST be used once on an <api>');
|
|
17
|
-
}
|
|
18
|
-
const children = jsx.useChildren();
|
|
19
|
-
const handler = innet.useHandler();
|
|
20
|
-
api.fallback = { children, handler };
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
exports.fallback = fallback;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './fallback';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { fallback } from './fallback.es6.js';
|