@innet/server 2.0.0-beta.5 → 2.0.0-beta.7

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 CHANGED
@@ -581,7 +581,7 @@ This section contains elements of utils.
581
581
 
582
582
  [← back](#index)
583
583
 
584
- [\<swagger>](#swagger)
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
- ### \<swagger>
593
+ ### \<ui>
594
594
 
595
595
  [← back](#utils)
596
596
 
597
- Use `<swagger>` element to add Swagger UI documentation.
598
- `<swagger>` element MUST be placed in `<api>` element.
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
- <swagger />
605
+ <ui />
606
606
  </api>
607
607
  </server>
608
608
  )
609
609
  ```
610
610
 
611
- Open http://localhost:80/swagger-ui
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
- You can change the Swagger UI URL path by `path` property of `<swagger>` element.
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):
637
+
638
+ *src/app.tsx*
639
+ ```typescript jsx
640
+ export default (
641
+ <server>
642
+ <api>
643
+ <ui
644
+ params={{
645
+ docExpansion: 'full',
646
+ filter: true,
647
+ showExtensions: true,
648
+ }}
649
+ />
650
+ </api>
651
+ </server>
652
+ )
653
+ ```
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.
615
724
 
616
725
  *src/app.tsx*
617
726
  ```typescript jsx
618
727
  export default (
619
728
  <server>
620
729
  <api>
621
- <swagger path='/swagger' />
730
+ <ui path='/docs' />
622
731
  </api>
623
732
  </server>
624
733
  )
625
734
  ```
626
735
 
736
+ *default: `INNET_UI_PATH` || `'/ui'`*
737
+
627
738
  ### \<env>
628
739
 
629
740
  [← back](#utils)
@@ -1445,6 +1556,34 @@ export default (
1445
1556
  )
1446
1557
  ```
1447
1558
 
1559
+ #### group
1560
+
1561
+ You can organize tags into groups using the `group` property.
1562
+ This adds tag groups support to the OpenAPI specification,
1563
+ which is displayed in documentation viewers.
1564
+
1565
+ *src/app.tsx*
1566
+ ```typescript jsx
1567
+ export default (
1568
+ <server>
1569
+ <api>
1570
+ <tag group='Authentication' name='auth'>
1571
+ <endpoint method='post' path='/login' />
1572
+ <endpoint method='post' path='/logout' />
1573
+ </tag>
1574
+ <tag group='Users' name='users'>
1575
+ <endpoint method='get' path='/users' />
1576
+ <endpoint method='post' path='/users' />
1577
+ </tag>
1578
+ </api>
1579
+ </server>
1580
+ )
1581
+ ```
1582
+
1583
+ This will create tag groups in your OpenAPI documentation:
1584
+ - **Authentication** group containing the `auth` tag
1585
+ - **Users** group containing the `users` tag
1586
+
1448
1587
  ### \<param>
1449
1588
 
1450
1589
  [← back](#endpoints)
@@ -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;
@@ -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,
@@ -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
@@ -49,7 +49,7 @@ export { preset } from './plugins/main/preset/preset.es6.js';
49
49
  export { response, statuses } from './plugins/main/response/response.es6.js';
50
50
  export { returnPlugin } from './plugins/main/return/return.es6.js';
51
51
  export { server } from './plugins/main/server/server.es6.js';
52
- export { tag } from './plugins/main/tag/tag.es6.js';
52
+ export { TAG_GROUP_NAME, tag } from './plugins/main/tag/tag.es6.js';
53
53
  export { variable } from './plugins/main/variable/variable.es6.js';
54
54
  export { cms } from './plugins/request/cms/cms.es6.js';
55
55
  export { cookie } from './plugins/request/cookie/cookie.es6.js';
@@ -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');
@@ -195,6 +196,7 @@ exports.response = response.response;
195
196
  exports.statuses = response.statuses;
196
197
  exports.returnPlugin = _return.returnPlugin;
197
198
  exports.server = server.server;
199
+ exports.TAG_GROUP_NAME = tag.TAG_GROUP_NAME;
198
200
  exports.tag = tag.tag;
199
201
  exports.variable = variable.variable;
200
202
  exports.cms = cms.cms;
@@ -226,6 +228,8 @@ exports.dts = dts.dts;
226
228
  exports.env = env.env;
227
229
  exports.protection = protection.protection;
228
230
  exports.swagger = swagger.swagger;
231
+ exports.ui = ui.ui;
232
+ exports.uiPresets = ui.uiPresets;
229
233
  exports.whitelist = whitelist.whitelist;
230
234
  exports.Bin = Bin.Bin;
231
235
  exports.JSONString = JSONString.JSONString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innet/server",
3
- "version": "2.0.0-beta.5",
3
+ "version": "2.0.0-beta.7",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -1 +1 @@
1
- export { tag } from './tag.es6.js';
1
+ export { TAG_GROUP_NAME, tag } from './tag.es6.js';
@@ -6,4 +6,5 @@ var tag = require('./tag.js');
6
6
 
7
7
 
8
8
 
9
+ exports.TAG_GROUP_NAME = tag.TAG_GROUP_NAME;
9
10
  exports.tag = tag.tag;
@@ -1,4 +1,9 @@
1
1
  import { type HandlerPlugin } from 'innet';
2
+ export interface TagGroup {
3
+ name: string;
4
+ tags: string[];
5
+ }
6
+ export declare const TAG_GROUP_NAME = "x-tagGroups";
2
7
  export interface TagProps {
3
8
  children?: any;
4
9
  /**
@@ -6,7 +11,9 @@ export interface TagProps {
6
11
  * [CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
7
12
  * */
8
13
  description?: string;
9
- /** The name of the tag. */
14
+ /** A name of the tag group. */
15
+ group?: string;
16
+ /** A name of the tag. */
10
17
  name: string;
11
18
  }
12
19
  export declare const tag: HandlerPlugin;
@@ -4,11 +4,12 @@ import '../../../hooks/index.es6.js';
4
4
  import { tagContext } from '../../../hooks/useTag/useTag.es6.js';
5
5
  import { useApi } from '../../../hooks/useApi/useApi.es6.js';
6
6
 
7
+ const TAG_GROUP_NAME = 'x-tagGroups';
7
8
  const tag = () => {
8
9
  if (useContext(tagContext)) {
9
10
  throw Error('You cannot use a <tag> inside another one');
10
11
  }
11
- const { children, description, name, } = useProps();
12
+ const { children, description, group, name, } = useProps();
12
13
  const { docs } = useApi();
13
14
  const tag = { name };
14
15
  if (description) {
@@ -23,9 +24,25 @@ const tag = () => {
23
24
  else {
24
25
  throw Error(`You cannot use two tags with the same name (${name})`);
25
26
  }
27
+ if (group) {
28
+ if (docs[TAG_GROUP_NAME]) {
29
+ const groups = docs[TAG_GROUP_NAME];
30
+ const tagGroup = groups.find(({ name }) => name === group);
31
+ if (tagGroup) {
32
+ tagGroup.tags.push(name);
33
+ }
34
+ else {
35
+ groups.push({ name: group, tags: [name] });
36
+ }
37
+ }
38
+ else {
39
+ // @ts-expect-error Custom field
40
+ docs[TAG_GROUP_NAME] = [{ name: group, tags: [name] }];
41
+ }
42
+ }
26
43
  const handler = useNewHandler();
27
44
  handler[tagContext.key] = tag;
28
45
  innet(children, handler);
29
46
  };
30
47
 
31
- export { tag };
48
+ export { TAG_GROUP_NAME, tag };
@@ -8,11 +8,12 @@ require('../../../hooks/index.js');
8
8
  var useTag = require('../../../hooks/useTag/useTag.js');
9
9
  var useApi = require('../../../hooks/useApi/useApi.js');
10
10
 
11
+ const TAG_GROUP_NAME = 'x-tagGroups';
11
12
  const tag = () => {
12
13
  if (jsx.useContext(useTag.tagContext)) {
13
14
  throw Error('You cannot use a <tag> inside another one');
14
15
  }
15
- const { children, description, name, } = jsx.useProps();
16
+ const { children, description, group, name, } = jsx.useProps();
16
17
  const { docs } = useApi.useApi();
17
18
  const tag = { name };
18
19
  if (description) {
@@ -27,9 +28,26 @@ const tag = () => {
27
28
  else {
28
29
  throw Error(`You cannot use two tags with the same name (${name})`);
29
30
  }
31
+ if (group) {
32
+ if (docs[TAG_GROUP_NAME]) {
33
+ const groups = docs[TAG_GROUP_NAME];
34
+ const tagGroup = groups.find(({ name }) => name === group);
35
+ if (tagGroup) {
36
+ tagGroup.tags.push(name);
37
+ }
38
+ else {
39
+ groups.push({ name: group, tags: [name] });
40
+ }
41
+ }
42
+ else {
43
+ // @ts-expect-error Custom field
44
+ docs[TAG_GROUP_NAME] = [{ name: group, tags: [name] }];
45
+ }
46
+ }
30
47
  const handler = innet.useNewHandler();
31
48
  handler[useTag.tagContext.key] = tag;
32
49
  innet.innet(children, handler);
33
50
  };
34
51
 
52
+ exports.TAG_GROUP_NAME = TAG_GROUP_NAME;
35
53
  exports.tag = tag;
@@ -3,4 +3,5 @@ export * from './dts';
3
3
  export * from './env';
4
4
  export * from './protection';
5
5
  export * from './swagger';
6
+ export * from './ui';
6
7
  export * from './whitelist';
@@ -3,4 +3,5 @@ import './dts/index.es6.js';
3
3
  import './env/index.es6.js';
4
4
  import './protection/index.es6.js';
5
5
  import './swagger/index.es6.js';
6
+ import './ui/index.es6.js';
6
7
  import './whitelist/index.es6.js';
@@ -5,5 +5,6 @@ require('./dts/index.js');
5
5
  require('./env/index.js');
6
6
  require('./protection/index.js');
7
7
  require('./swagger/index.js');
8
+ require('./ui/index.js');
8
9
  require('./whitelist/index.js');
9
10
 
@@ -2,4 +2,5 @@ import { type HandlerPlugin } from 'innet';
2
2
  export interface SwaggerProps {
3
3
  path?: string;
4
4
  }
5
+ /** @deprecated Use <ui> */
5
6
  export declare const swagger: HandlerPlugin;
@@ -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,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var ui = require('./ui.js');
6
+
7
+
8
+
9
+ exports.ui = ui.ui;
10
+ exports.uiPresets = ui.uiPresets;
@@ -0,0 +1,3 @@
1
+ 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";
2
+
3
+ export { rapidoc as default };
@@ -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;