@innet/server 2.0.0-beta.5 → 2.0.0-beta.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 +120 -9
- package/handler/handler.d.ts +4 -1
- package/handler/handler.es6.js +2 -0
- package/handler/handler.js +2 -0
- package/index.es6.js +1 -0
- package/index.js +3 -0
- package/package.json +1 -1
- package/plugins/utils/index.d.ts +1 -0
- package/plugins/utils/index.es6.js +1 -0
- package/plugins/utils/index.js +1 -0
- package/plugins/utils/swagger/swagger.d.ts +1 -0
- package/plugins/utils/swagger/swagger.es6.js +1 -0
- package/plugins/utils/swagger/swagger.js +1 -0
- package/plugins/utils/ui/index.d.ts +1 -0
- package/plugins/utils/ui/index.es6.js +1 -0
- package/plugins/utils/ui/index.js +10 -0
- package/plugins/utils/ui/rapidoc.html.es6.js +3 -0
- package/plugins/utils/ui/rapidoc.html.js +7 -0
- package/plugins/utils/ui/redoc.html.es6.js +3 -0
- package/plugins/utils/ui/redoc.html.js +7 -0
- package/plugins/utils/ui/scalar.html.es6.js +3 -0
- package/plugins/utils/ui/scalar.html.js +7 -0
- package/plugins/utils/ui/swagger.html.es6.js +3 -0
- package/plugins/utils/ui/swagger.html.js +7 -0
- package/plugins/utils/ui/ui.d.ts +13 -0
- package/plugins/utils/ui/ui.es6.js +45 -0
- package/plugins/utils/ui/ui.js +50 -0
package/README.md
CHANGED
|
@@ -581,7 +581,7 @@ This section contains elements of utils.
|
|
|
581
581
|
|
|
582
582
|
[← back](#index)
|
|
583
583
|
|
|
584
|
-
[\<
|
|
584
|
+
[\<ui>](#ui)
|
|
585
585
|
[\<env>](#env)
|
|
586
586
|
[\<dts>](#dts)
|
|
587
587
|
[\<blacklist>](#blacklist)
|
|
@@ -590,40 +590,151 @@ This section contains elements of utils.
|
|
|
590
590
|
|
|
591
591
|
---
|
|
592
592
|
|
|
593
|
-
### \<
|
|
593
|
+
### \<ui>
|
|
594
594
|
|
|
595
595
|
[← back](#utils)
|
|
596
596
|
|
|
597
|
-
Use `<
|
|
598
|
-
`<
|
|
597
|
+
Use `<ui>` element to add API documentation UI. This element supports multiple documentation viewers including Swagger UI, RapiDoc, ReDoc, and Scalar.
|
|
598
|
+
`<ui>` element MUST be placed in `<api>` element.
|
|
599
599
|
|
|
600
600
|
*src/app.tsx*
|
|
601
601
|
```typescript jsx
|
|
602
602
|
export default (
|
|
603
603
|
<server>
|
|
604
604
|
<api>
|
|
605
|
-
<
|
|
605
|
+
<ui />
|
|
606
606
|
</api>
|
|
607
607
|
</server>
|
|
608
608
|
)
|
|
609
609
|
```
|
|
610
610
|
|
|
611
|
-
Open http://localhost:80/
|
|
612
|
-
You will see Swagger UI documentation.
|
|
611
|
+
Open http://localhost:80/ui
|
|
612
|
+
You will see Swagger UI documentation by default.
|
|
613
613
|
|
|
614
|
-
|
|
614
|
+
#### html
|
|
615
|
+
|
|
616
|
+
You can provide custom HTML template for the documentation viewer.
|
|
617
|
+
Built-in presets are available: `uiPresets.swagger`, `uiPresets.rapidoc`, `uiPresets.redoc`, `uiPresets.scalar`.
|
|
618
|
+
|
|
619
|
+
*src/app.tsx*
|
|
620
|
+
```typescript jsx
|
|
621
|
+
import { uiPresets } from '@innet/server'
|
|
622
|
+
|
|
623
|
+
export default (
|
|
624
|
+
<server>
|
|
625
|
+
<api>
|
|
626
|
+
<ui html={uiPresets.rapidoc} />
|
|
627
|
+
</api>
|
|
628
|
+
</server>
|
|
629
|
+
)
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
#### params
|
|
633
|
+
|
|
634
|
+
You can pass additional parameters to the documentation viewer. Parameters depend on the selected UI library.
|
|
635
|
+
|
|
636
|
+
For **Swagger UI** (default):
|
|
615
637
|
|
|
616
638
|
*src/app.tsx*
|
|
617
639
|
```typescript jsx
|
|
618
640
|
export default (
|
|
619
641
|
<server>
|
|
620
642
|
<api>
|
|
621
|
-
<
|
|
643
|
+
<ui
|
|
644
|
+
params={{
|
|
645
|
+
docExpansion: 'full',
|
|
646
|
+
filter: true,
|
|
647
|
+
showExtensions: true,
|
|
648
|
+
}}
|
|
649
|
+
/>
|
|
622
650
|
</api>
|
|
623
651
|
</server>
|
|
624
652
|
)
|
|
625
653
|
```
|
|
626
654
|
|
|
655
|
+
For **Scalar**:
|
|
656
|
+
|
|
657
|
+
*src/app.tsx*
|
|
658
|
+
```typescript jsx
|
|
659
|
+
import { uiPresets } from '@innet/server'
|
|
660
|
+
|
|
661
|
+
export default (
|
|
662
|
+
<server>
|
|
663
|
+
<api>
|
|
664
|
+
<ui
|
|
665
|
+
html={uiPresets.scalar}
|
|
666
|
+
params={{
|
|
667
|
+
theme: 'moon',
|
|
668
|
+
layout: 'classic',
|
|
669
|
+
}}
|
|
670
|
+
/>
|
|
671
|
+
</api>
|
|
672
|
+
</server>
|
|
673
|
+
)
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
For **RapiDoc**:
|
|
677
|
+
|
|
678
|
+
*src/app.tsx*
|
|
679
|
+
```typescript jsx
|
|
680
|
+
import { uiPresets } from '@innet/server'
|
|
681
|
+
|
|
682
|
+
export default (
|
|
683
|
+
<server>
|
|
684
|
+
<api>
|
|
685
|
+
<ui
|
|
686
|
+
html={uiPresets.rapidoc}
|
|
687
|
+
params={{
|
|
688
|
+
theme: 'dark',
|
|
689
|
+
layout: 'row',
|
|
690
|
+
showHeader: 'false',
|
|
691
|
+
}}
|
|
692
|
+
/>
|
|
693
|
+
</api>
|
|
694
|
+
</server>
|
|
695
|
+
)
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
For **ReDoc**:
|
|
699
|
+
|
|
700
|
+
*src/app.tsx*
|
|
701
|
+
```typescript jsx
|
|
702
|
+
import { uiPresets } from '@innet/server'
|
|
703
|
+
|
|
704
|
+
export default (
|
|
705
|
+
<server>
|
|
706
|
+
<api>
|
|
707
|
+
<ui
|
|
708
|
+
html={uiPresets.redoc}
|
|
709
|
+
params={{
|
|
710
|
+
disableSearch: 'true',
|
|
711
|
+
hideDownloadButton: 'true',
|
|
712
|
+
nativeScrollbars: 'true',
|
|
713
|
+
theme: '{"sidebar": {"backgroundColor": "#d1e5ef"}}',
|
|
714
|
+
}}
|
|
715
|
+
/>
|
|
716
|
+
</api>
|
|
717
|
+
</server>
|
|
718
|
+
)
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
#### path
|
|
722
|
+
|
|
723
|
+
You can change the documentation UI URL path by `path` property of `<ui>` element.
|
|
724
|
+
|
|
725
|
+
*src/app.tsx*
|
|
726
|
+
```typescript jsx
|
|
727
|
+
export default (
|
|
728
|
+
<server>
|
|
729
|
+
<api>
|
|
730
|
+
<ui path='/docs' />
|
|
731
|
+
</api>
|
|
732
|
+
</server>
|
|
733
|
+
)
|
|
734
|
+
```
|
|
735
|
+
|
|
736
|
+
*default: `INNET_UI_PATH` || `'/ui'`*
|
|
737
|
+
|
|
627
738
|
### \<env>
|
|
628
739
|
|
|
629
740
|
[← back](#utils)
|
package/handler/handler.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type JSXElement } from '@innet/jsx';
|
|
2
2
|
import { arraySync, async } from '@innet/utils';
|
|
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 DtsProps, type EndpointProps, type EnvProps, 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, protection, type ProtectionProps, type ProxyProps, type RedirectProps, type ResponseProps, type ReturnProps, 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 DtsProps, type EndpointProps, type EnvProps, 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, protection, type ProtectionProps, type ProxyProps, type RedirectProps, type ResponseProps, type ReturnProps, type ServerProps, type StringProps, type SuccessProps, type SwaggerProps, type TagProps, type TupleProps, type UiProps, type UuidProps, type VariableProps, whitelist, type WhitelistProps } from '../plugins';
|
|
4
4
|
export declare const arrayPlugins: (typeof arraySync)[];
|
|
5
5
|
export declare const JSXPlugins: {
|
|
6
6
|
any: import("innet").HandlerPlugin;
|
|
@@ -40,6 +40,7 @@ export declare const JSXPlugins: {
|
|
|
40
40
|
swagger: import("innet").HandlerPlugin;
|
|
41
41
|
tag: import("innet").HandlerPlugin;
|
|
42
42
|
tuple: import("innet").HandlerPlugin;
|
|
43
|
+
ui: import("innet").HandlerPlugin;
|
|
43
44
|
uuid: import("innet").HandlerPlugin;
|
|
44
45
|
variable: import("innet").HandlerPlugin;
|
|
45
46
|
whitelist: typeof whitelist;
|
|
@@ -92,9 +93,11 @@ declare global {
|
|
|
92
93
|
server: ServerProps;
|
|
93
94
|
string: StringProps;
|
|
94
95
|
success: SuccessProps;
|
|
96
|
+
/** @deprecated Use <ui> */
|
|
95
97
|
swagger: SwaggerProps;
|
|
96
98
|
tag: TagProps;
|
|
97
99
|
tuple: TupleProps;
|
|
100
|
+
ui: UiProps;
|
|
98
101
|
uuid: UuidProps;
|
|
99
102
|
variable: VariableProps;
|
|
100
103
|
whitelist: WhitelistProps;
|
package/handler/handler.es6.js
CHANGED
|
@@ -39,6 +39,7 @@ import { success } from '../plugins/request/success/success.es6.js';
|
|
|
39
39
|
import { swagger } from '../plugins/utils/swagger/swagger.es6.js';
|
|
40
40
|
import { tag } from '../plugins/main/tag/tag.es6.js';
|
|
41
41
|
import { tuple } from '../plugins/schema/tuple/tuple.es6.js';
|
|
42
|
+
import { ui } from '../plugins/utils/ui/ui.es6.js';
|
|
42
43
|
import { uuid } from '../plugins/schema/uuid/uuid.es6.js';
|
|
43
44
|
import { variable } from '../plugins/main/variable/variable.es6.js';
|
|
44
45
|
import { whitelist } from '../plugins/utils/whitelist/whitelist.es6.js';
|
|
@@ -85,6 +86,7 @@ const JSXPlugins = {
|
|
|
85
86
|
swagger,
|
|
86
87
|
tag,
|
|
87
88
|
tuple,
|
|
89
|
+
ui,
|
|
88
90
|
uuid,
|
|
89
91
|
variable,
|
|
90
92
|
whitelist,
|
package/handler/handler.js
CHANGED
|
@@ -43,6 +43,7 @@ var success = require('../plugins/request/success/success.js');
|
|
|
43
43
|
var swagger = require('../plugins/utils/swagger/swagger.js');
|
|
44
44
|
var tag = require('../plugins/main/tag/tag.js');
|
|
45
45
|
var tuple = require('../plugins/schema/tuple/tuple.js');
|
|
46
|
+
var ui = require('../plugins/utils/ui/ui.js');
|
|
46
47
|
var uuid = require('../plugins/schema/uuid/uuid.js');
|
|
47
48
|
var variable = require('../plugins/main/variable/variable.js');
|
|
48
49
|
var whitelist = require('../plugins/utils/whitelist/whitelist.js');
|
|
@@ -89,6 +90,7 @@ const JSXPlugins = {
|
|
|
89
90
|
swagger: swagger.swagger,
|
|
90
91
|
tag: tag.tag,
|
|
91
92
|
tuple: tuple.tuple,
|
|
93
|
+
ui: ui.ui,
|
|
92
94
|
uuid: uuid.uuid,
|
|
93
95
|
variable: variable.variable,
|
|
94
96
|
whitelist: whitelist.whitelist,
|
package/index.es6.js
CHANGED
|
@@ -77,6 +77,7 @@ export { dts } from './plugins/utils/dts/dts.es6.js';
|
|
|
77
77
|
export { env } from './plugins/utils/env/env.es6.js';
|
|
78
78
|
export { protection } from './plugins/utils/protection/protection.es6.js';
|
|
79
79
|
export { swagger } from './plugins/utils/swagger/swagger.es6.js';
|
|
80
|
+
export { ui, uiPresets } from './plugins/utils/ui/ui.es6.js';
|
|
80
81
|
export { whitelist } from './plugins/utils/whitelist/whitelist.es6.js';
|
|
81
82
|
export { Bin } from './utils/FileData/Bin.es6.js';
|
|
82
83
|
export { JSONString } from './utils/JSONString/JSONString.es6.js';
|
package/index.js
CHANGED
|
@@ -81,6 +81,7 @@ var dts = require('./plugins/utils/dts/dts.js');
|
|
|
81
81
|
var env = require('./plugins/utils/env/env.js');
|
|
82
82
|
var protection = require('./plugins/utils/protection/protection.js');
|
|
83
83
|
var swagger = require('./plugins/utils/swagger/swagger.js');
|
|
84
|
+
var ui = require('./plugins/utils/ui/ui.js');
|
|
84
85
|
var whitelist = require('./plugins/utils/whitelist/whitelist.js');
|
|
85
86
|
var Bin = require('./utils/FileData/Bin.js');
|
|
86
87
|
var JSONString = require('./utils/JSONString/JSONString.js');
|
|
@@ -226,6 +227,8 @@ exports.dts = dts.dts;
|
|
|
226
227
|
exports.env = env.env;
|
|
227
228
|
exports.protection = protection.protection;
|
|
228
229
|
exports.swagger = swagger.swagger;
|
|
230
|
+
exports.ui = ui.ui;
|
|
231
|
+
exports.uiPresets = ui.uiPresets;
|
|
229
232
|
exports.whitelist = whitelist.whitelist;
|
|
230
233
|
exports.Bin = Bin.Bin;
|
|
231
234
|
exports.JSONString = JSONString.JSONString;
|
package/package.json
CHANGED
package/plugins/utils/index.d.ts
CHANGED
package/plugins/utils/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { useApi } from '../../../hooks/useApi/useApi.es6.js';
|
|
|
5
5
|
import { useServerPlugin } from '../../../hooks/useServerPlugin/useServerPlugin.es6.js';
|
|
6
6
|
import { useAction } from '../../../hooks/useAction/useAction.es6.js';
|
|
7
7
|
|
|
8
|
+
/** @deprecated Use <ui> */
|
|
8
9
|
const swagger = () => {
|
|
9
10
|
const { path = process.env.INNET_SWAGGER_PATH || '/swagger-ui', } = useProps() || {};
|
|
10
11
|
const { docs, prefix, } = useApi();
|
|
@@ -9,6 +9,7 @@ var useApi = require('../../../hooks/useApi/useApi.js');
|
|
|
9
9
|
var useServerPlugin = require('../../../hooks/useServerPlugin/useServerPlugin.js');
|
|
10
10
|
var useAction = require('../../../hooks/useAction/useAction.js');
|
|
11
11
|
|
|
12
|
+
/** @deprecated Use <ui> */
|
|
12
13
|
const swagger = () => {
|
|
13
14
|
const { path = process.env.INNET_SWAGGER_PATH || '/swagger-ui', } = jsx.useProps() || {};
|
|
14
15
|
const { docs, prefix, } = useApi.useApi();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ui';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ui, uiPresets } from './ui.es6.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var rapidoc = "<!doctype html>\n<html>\n<head>\n <script type=\"module\" src=\"https://unpkg.com/rapidoc/dist/rapidoc-min.js\"></script>\n</head>\n<body>\n<rapi-doc spec-url=\"{apiUrl}\" {attributes}></rapi-doc>\n</body>\n</html>\n";
|
|
6
|
+
|
|
7
|
+
exports["default"] = rapidoc;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var redoc = "<!DOCTYPE html>\n<html>\n<head>\n <title>Redoc CE</title>\n <meta charset=\"utf-8\"/>\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <link href=\"https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700\" rel=\"stylesheet\">\n <style>\n body {\n margin: 0;\n padding: 0;\n }\n </style>\n</head>\n<body>\n<redoc spec-url='{apiUrl}' {attributes}></redoc>\n<script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"> </script>\n</body>\n</html>\n";
|
|
2
|
+
|
|
3
|
+
export { redoc as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var redoc = "<!DOCTYPE html>\n<html>\n<head>\n <title>Redoc CE</title>\n <meta charset=\"utf-8\"/>\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <link href=\"https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700\" rel=\"stylesheet\">\n <style>\n body {\n margin: 0;\n padding: 0;\n }\n </style>\n</head>\n<body>\n<redoc spec-url='{apiUrl}' {attributes}></redoc>\n<script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"> </script>\n</body>\n</html>\n";
|
|
6
|
+
|
|
7
|
+
exports["default"] = redoc;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var scalar = "<!doctype html>\n<html>\n<head>\n <title>API Reference</title>\n <meta charset=\"utf-8\" />\n <meta\n name=\"viewport\"\n content=\"width=device-width, initial-scale=1\" />\n</head>\n<body>\n<div id=\"app\"></div>\n<script src=\"https://cdn.jsdelivr.net/npm/@scalar/api-reference\"></script>\n<script>\n Scalar.createApiReference('#app', {\n url: '{apiUrl}',\n ...{params}\n })\n</script>\n</body>\n</html>\n";
|
|
2
|
+
|
|
3
|
+
export { scalar as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var scalar = "<!doctype html>\n<html>\n<head>\n <title>API Reference</title>\n <meta charset=\"utf-8\" />\n <meta\n name=\"viewport\"\n content=\"width=device-width, initial-scale=1\" />\n</head>\n<body>\n<div id=\"app\"></div>\n<script src=\"https://cdn.jsdelivr.net/npm/@scalar/api-reference\"></script>\n<script>\n Scalar.createApiReference('#app', {\n url: '{apiUrl}',\n ...{params}\n })\n</script>\n</body>\n</html>\n";
|
|
6
|
+
|
|
7
|
+
exports["default"] = scalar;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var swagger = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <meta\n name=\"description\"\n content=\"SwaggerUI\"\n />\n <title>SwaggerUI</title>\n <link rel=\"stylesheet\" href=\"https://unpkg.com/swagger-ui-dist/swagger-ui.css\" />\n</head>\n<body>\n<div id=\"swagger-ui\"></div>\n<script src=\"https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js\" crossorigin></script>\n<script>\n window.onload = () => {\n window.ui = SwaggerUIBundle({\n url: \"{apiUrl}\",\n dom_id: '#swagger-ui',\n ...{params}\n });\n };\n</script>\n</body>\n</html>\n";
|
|
2
|
+
|
|
3
|
+
export { swagger as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var swagger = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <meta\n name=\"description\"\n content=\"SwaggerUI\"\n />\n <title>SwaggerUI</title>\n <link rel=\"stylesheet\" href=\"https://unpkg.com/swagger-ui-dist/swagger-ui.css\" />\n</head>\n<body>\n<div id=\"swagger-ui\"></div>\n<script src=\"https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js\" crossorigin></script>\n<script>\n window.onload = () => {\n window.ui = SwaggerUIBundle({\n url: \"{apiUrl}\",\n dom_id: '#swagger-ui',\n ...{params}\n });\n };\n</script>\n</body>\n</html>\n";
|
|
6
|
+
|
|
7
|
+
exports["default"] = swagger;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type HandlerPlugin } from 'innet';
|
|
2
|
+
export declare const uiPresets: {
|
|
3
|
+
rapidoc: string;
|
|
4
|
+
redoc: string;
|
|
5
|
+
scalar: string;
|
|
6
|
+
swagger: string;
|
|
7
|
+
};
|
|
8
|
+
export interface UiProps {
|
|
9
|
+
html?: string;
|
|
10
|
+
params?: Record<string, any>;
|
|
11
|
+
path?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const ui: HandlerPlugin;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { placeholder } from '@cantinc/utils';
|
|
2
|
+
import { useProps } from '@innet/jsx';
|
|
3
|
+
import '../../../hooks/index.es6.js';
|
|
4
|
+
import rapidoc from './rapidoc.html.es6.js';
|
|
5
|
+
import redoc from './redoc.html.es6.js';
|
|
6
|
+
import scalar from './scalar.html.es6.js';
|
|
7
|
+
import swagger from './swagger.html.es6.js';
|
|
8
|
+
import { useApi } from '../../../hooks/useApi/useApi.es6.js';
|
|
9
|
+
import { useServerPlugin } from '../../../hooks/useServerPlugin/useServerPlugin.es6.js';
|
|
10
|
+
import { useAction } from '../../../hooks/useAction/useAction.es6.js';
|
|
11
|
+
|
|
12
|
+
function camelToDash(str) {
|
|
13
|
+
return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
14
|
+
}
|
|
15
|
+
const uiPresets = { rapidoc, redoc, scalar, swagger };
|
|
16
|
+
const ui = () => {
|
|
17
|
+
const { html = uiPresets.swagger, params = {}, path = process.env.INNET_UI_PATH || '/ui', } = useProps() || {};
|
|
18
|
+
const { docs, prefix, } = useApi();
|
|
19
|
+
let cache = '';
|
|
20
|
+
useServerPlugin(() => {
|
|
21
|
+
const action = useAction();
|
|
22
|
+
if (action.path === prefix + path) {
|
|
23
|
+
if (!cache) {
|
|
24
|
+
const attributes = Object
|
|
25
|
+
.keys(params)
|
|
26
|
+
.reduce((res, key) => {
|
|
27
|
+
return `${res} ${camelToDash(key)}='${String(params[key])}'`;
|
|
28
|
+
}, '');
|
|
29
|
+
cache = placeholder(html, {
|
|
30
|
+
apiUrl: prefix,
|
|
31
|
+
attributes,
|
|
32
|
+
docs: JSON.stringify(docs),
|
|
33
|
+
params: JSON.stringify(params),
|
|
34
|
+
...params,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
action.res.statusCode = 200;
|
|
38
|
+
action.res.write(cache);
|
|
39
|
+
action.res.end();
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { ui, uiPresets };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var utils = require('@cantinc/utils');
|
|
6
|
+
var jsx = require('@innet/jsx');
|
|
7
|
+
require('../../../hooks/index.js');
|
|
8
|
+
var rapidoc = require('./rapidoc.html.js');
|
|
9
|
+
var redoc = require('./redoc.html.js');
|
|
10
|
+
var scalar = require('./scalar.html.js');
|
|
11
|
+
var swagger = require('./swagger.html.js');
|
|
12
|
+
var useApi = require('../../../hooks/useApi/useApi.js');
|
|
13
|
+
var useServerPlugin = require('../../../hooks/useServerPlugin/useServerPlugin.js');
|
|
14
|
+
var useAction = require('../../../hooks/useAction/useAction.js');
|
|
15
|
+
|
|
16
|
+
function camelToDash(str) {
|
|
17
|
+
return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
18
|
+
}
|
|
19
|
+
const uiPresets = { rapidoc: rapidoc["default"], redoc: redoc["default"], scalar: scalar["default"], swagger: swagger["default"] };
|
|
20
|
+
const ui = () => {
|
|
21
|
+
const { html = uiPresets.swagger, params = {}, path = process.env.INNET_UI_PATH || '/ui', } = jsx.useProps() || {};
|
|
22
|
+
const { docs, prefix, } = useApi.useApi();
|
|
23
|
+
let cache = '';
|
|
24
|
+
useServerPlugin.useServerPlugin(() => {
|
|
25
|
+
const action = useAction.useAction();
|
|
26
|
+
if (action.path === prefix + path) {
|
|
27
|
+
if (!cache) {
|
|
28
|
+
const attributes = Object
|
|
29
|
+
.keys(params)
|
|
30
|
+
.reduce((res, key) => {
|
|
31
|
+
return `${res} ${camelToDash(key)}='${String(params[key])}'`;
|
|
32
|
+
}, '');
|
|
33
|
+
cache = utils.placeholder(html, {
|
|
34
|
+
apiUrl: prefix,
|
|
35
|
+
attributes,
|
|
36
|
+
docs: JSON.stringify(docs),
|
|
37
|
+
params: JSON.stringify(params),
|
|
38
|
+
...params,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
action.res.statusCode = 200;
|
|
42
|
+
action.res.write(cache);
|
|
43
|
+
action.res.end();
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
exports.ui = ui;
|
|
50
|
+
exports.uiPresets = uiPresets;
|