@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.
Files changed (95) hide show
  1. package/README.md +457 -367
  2. package/handler/handler.d.ts +3 -3
  3. package/handler/handler.es6.js +2 -2
  4. package/handler/handler.js +2 -2
  5. package/hooks/index.d.ts +2 -1
  6. package/hooks/index.es6.js +2 -1
  7. package/hooks/index.js +2 -1
  8. package/hooks/useAction/useAction.es6.js +1 -1
  9. package/hooks/useAction/useAction.js +1 -1
  10. package/hooks/useApi/useApi.d.ts +1 -3
  11. package/hooks/useEndpoint/useEndpoint.es6.js +3 -1
  12. package/hooks/useEndpoint/useEndpoint.js +3 -1
  13. package/hooks/useRequest/index.es6.js +1 -1
  14. package/hooks/useRequest/index.js +0 -1
  15. package/hooks/useRequest/useRequest.d.ts +1 -4
  16. package/hooks/useRequest/useRequest.es6.js +4 -4
  17. package/hooks/useRequest/useRequest.js +3 -4
  18. package/hooks/useResponse/index.es6.js +1 -1
  19. package/hooks/useResponse/index.js +0 -1
  20. package/hooks/useResponse/useResponse.d.ts +1 -4
  21. package/hooks/useResponse/useResponse.es6.js +4 -4
  22. package/hooks/useResponse/useResponse.js +3 -4
  23. package/hooks/useServer/useServer.d.ts +1 -0
  24. package/hooks/useServer/useServer.es6.js +3 -1
  25. package/hooks/useServer/useServer.js +3 -1
  26. package/hooks/useServerPlugin/index.d.ts +1 -0
  27. package/hooks/useServerPlugin/index.es6.js +1 -0
  28. package/hooks/useServerPlugin/index.js +9 -0
  29. package/hooks/useServerPlugin/useServerPlugin.d.ts +2 -0
  30. package/hooks/useServerPlugin/useServerPlugin.es6.js +13 -0
  31. package/hooks/useServerPlugin/useServerPlugin.js +17 -0
  32. package/hooks/useServerPlugins/index.d.ts +1 -0
  33. package/hooks/useServerPlugins/index.es6.js +1 -0
  34. package/hooks/useServerPlugins/index.js +10 -0
  35. package/hooks/useServerPlugins/useServerPlugins.d.ts +4 -0
  36. package/hooks/useServerPlugins/useServerPlugins.es6.js +14 -0
  37. package/hooks/useServerPlugins/useServerPlugins.js +19 -0
  38. package/index.es6.js +5 -4
  39. package/index.js +7 -6
  40. package/package.json +1 -1
  41. package/plugins/main/api/api.d.ts +2 -0
  42. package/plugins/main/api/api.es6.js +44 -52
  43. package/plugins/main/api/api.js +43 -51
  44. package/plugins/main/endpoint/endpoint.es6.js +4 -1
  45. package/plugins/main/endpoint/endpoint.js +4 -1
  46. package/plugins/main/index.d.ts +1 -1
  47. package/plugins/main/index.es6.js +1 -1
  48. package/plugins/main/index.js +1 -1
  49. package/plugins/main/preset/index.d.ts +1 -0
  50. package/plugins/main/preset/index.es6.js +1 -0
  51. package/plugins/main/{fallback → preset}/index.js +2 -2
  52. package/plugins/main/preset/preset.d.ts +3 -0
  53. package/plugins/main/preset/preset.es6.js +13 -0
  54. package/plugins/main/preset/preset.js +21 -0
  55. package/plugins/main/request/request.es6.js +2 -13
  56. package/plugins/main/request/request.js +2 -13
  57. package/plugins/main/response/response.d.ts +1 -0
  58. package/plugins/main/response/response.es6.js +7 -7
  59. package/plugins/main/response/response.js +7 -7
  60. package/plugins/main/server/server.d.ts +3 -3
  61. package/plugins/main/server/server.es6.js +28 -6
  62. package/plugins/main/server/server.js +28 -6
  63. package/plugins/request/success/success.d.ts +1 -1
  64. package/plugins/request/success/success.es6.js +4 -4
  65. package/plugins/request/success/success.js +4 -4
  66. package/plugins/utils/blacklist/blacklist.es6.js +4 -3
  67. package/plugins/utils/blacklist/blacklist.js +4 -3
  68. package/plugins/utils/dts/dts.d.ts +2 -1
  69. package/plugins/utils/dts/dts.es6.js +2 -2
  70. package/plugins/utils/dts/dts.js +2 -2
  71. package/plugins/utils/protection/protection.es6.js +4 -2
  72. package/plugins/utils/protection/protection.js +4 -2
  73. package/plugins/utils/swagger/swagger.es6.js +5 -3
  74. package/plugins/utils/swagger/swagger.js +5 -3
  75. package/plugins/utils/whitelist/whitelist.es6.js +4 -2
  76. package/plugins/utils/whitelist/whitelist.js +4 -2
  77. package/types.d.ts +2 -9
  78. package/utils/action/Action.es6.js +12 -10
  79. package/utils/action/Action.js +12 -10
  80. package/utils/generateTypes/generateTypes.d.ts +2 -2
  81. package/utils/generateTypes/generateTypes.es6.js +40 -15
  82. package/utils/generateTypes/generateTypes.js +40 -15
  83. package/utils/getEndpoint/getEndpoint.es6.js +2 -2
  84. package/utils/getEndpoint/getEndpoint.js +2 -2
  85. package/hooks/useRequestPlugin/index.d.ts +0 -1
  86. package/hooks/useRequestPlugin/index.es6.js +0 -1
  87. package/hooks/useRequestPlugin/index.js +0 -9
  88. package/hooks/useRequestPlugin/useRequestPlugin.d.ts +0 -2
  89. package/hooks/useRequestPlugin/useRequestPlugin.es6.js +0 -13
  90. package/hooks/useRequestPlugin/useRequestPlugin.js +0 -17
  91. package/plugins/main/fallback/fallback.d.ts +0 -4
  92. package/plugins/main/fallback/fallback.es6.js +0 -19
  93. package/plugins/main/fallback/fallback.js +0 -23
  94. package/plugins/main/fallback/index.d.ts +0 -1
  95. 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)}\n`;
11
+ return `Schemas.${schema.$ref.slice(21)}${lastChar}`;
12
12
  }
13
13
  if (schema.type === 'integer') {
14
- return `${schema.format === 'int64' ? 'bigint' : 'number'}\n`;
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 'Date\n';
18
+ return `Date${lastChar}`;
19
19
  }
20
20
  if (schema.format === 'binary') {
21
- return 'Bin\n';
21
+ return `Bin${lastChar}`;
22
22
  }
23
- return 'string\n';
23
+ return `string${lastChar}`;
24
24
  }
25
25
  if (['boolean', 'number', 'null'].includes(schema.type)) {
26
- return `${schema.type}\n`;
26
+ return `${schema.type}${lastChar}`;
27
27
  }
28
28
  if (schema.type === 'array') {
29
29
  if (!schema.items)
30
- return 'any[]\n';
31
- return `(${generateSchemaTypes(schema.items, spaces + 2).slice(0, -1)})[]\n`;
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 'any\n';
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)}}\n`;
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 = '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';
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 === null || responses === void 0 ? void 0 : responses.default) {
98
- result += ` Response: ${generateSchemaTypes(responses.default.content['application/json'].schema, 8)}`;
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,9 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var useRequestPlugin = require('./useRequestPlugin.js');
6
-
7
-
8
-
9
- exports.useRequestPlugin = useRequestPlugin.useRequestPlugin;
@@ -1,2 +0,0 @@
1
- import { type RequestPlugin } from '../../types';
2
- export declare function useRequestPlugin(listener: RequestPlugin): void;
@@ -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,4 +0,0 @@
1
- import { type HandlerPlugin } from 'innet';
2
- export interface FallbackProps {
3
- }
4
- export declare const fallback: HandlerPlugin;
@@ -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';