@innet/server 2.0.0-alpha.13 → 2.0.0-alpha.15

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 (82) hide show
  1. package/README.md +356 -363
  2. package/handler/handler.d.ts +1 -3
  3. package/handler/handler.es6.js +0 -2
  4. package/handler/handler.js +0 -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/useServer/useServer.d.ts +1 -0
  14. package/hooks/useServerPlugin/index.d.ts +1 -0
  15. package/hooks/useServerPlugin/index.es6.js +1 -0
  16. package/hooks/useServerPlugin/index.js +9 -0
  17. package/hooks/useServerPlugin/useServerPlugin.d.ts +2 -0
  18. package/hooks/useServerPlugin/useServerPlugin.es6.js +13 -0
  19. package/hooks/useServerPlugin/useServerPlugin.js +17 -0
  20. package/hooks/useServerPlugins/index.d.ts +1 -0
  21. package/hooks/useServerPlugins/index.es6.js +1 -0
  22. package/hooks/useServerPlugins/index.js +10 -0
  23. package/hooks/useServerPlugins/useServerPlugins.d.ts +4 -0
  24. package/hooks/useServerPlugins/useServerPlugins.es6.js +14 -0
  25. package/hooks/useServerPlugins/useServerPlugins.js +19 -0
  26. package/index.es6.js +3 -3
  27. package/index.js +5 -5
  28. package/package.json +1 -1
  29. package/plugins/main/api/api.es6.js +34 -48
  30. package/plugins/main/api/api.js +33 -47
  31. package/plugins/main/endpoint/endpoint.es6.js +4 -1
  32. package/plugins/main/endpoint/endpoint.js +4 -1
  33. package/plugins/main/index.d.ts +0 -1
  34. package/plugins/main/index.es6.js +0 -1
  35. package/plugins/main/index.js +0 -1
  36. package/plugins/main/preset/index.es6.js +1 -1
  37. package/plugins/main/preset/index.js +0 -1
  38. package/plugins/main/preset/preset.d.ts +0 -4
  39. package/plugins/main/preset/preset.es6.js +6 -19
  40. package/plugins/main/preset/preset.js +4 -18
  41. package/plugins/main/request/request.es6.js +2 -13
  42. package/plugins/main/request/request.js +2 -13
  43. package/plugins/main/response/response.d.ts +1 -0
  44. package/plugins/main/response/response.es6.js +7 -7
  45. package/plugins/main/response/response.js +7 -7
  46. package/plugins/main/server/server.d.ts +3 -3
  47. package/plugins/main/server/server.es6.js +28 -6
  48. package/plugins/main/server/server.js +28 -6
  49. package/plugins/request/proxy/proxy.d.ts +3 -0
  50. package/plugins/request/proxy/proxy.es6.js +4 -1
  51. package/plugins/request/proxy/proxy.js +4 -1
  52. package/plugins/request/success/success.d.ts +1 -1
  53. package/plugins/request/success/success.es6.js +4 -4
  54. package/plugins/request/success/success.js +4 -4
  55. package/plugins/utils/blacklist/blacklist.es6.js +4 -3
  56. package/plugins/utils/blacklist/blacklist.js +4 -3
  57. package/plugins/utils/protection/protection.es6.js +4 -2
  58. package/plugins/utils/protection/protection.js +4 -2
  59. package/plugins/utils/swagger/swagger.es6.js +5 -3
  60. package/plugins/utils/swagger/swagger.js +5 -3
  61. package/plugins/utils/whitelist/whitelist.es6.js +4 -2
  62. package/plugins/utils/whitelist/whitelist.js +4 -2
  63. package/types.d.ts +2 -9
  64. package/utils/action/Action.es6.js +12 -10
  65. package/utils/action/Action.js +12 -10
  66. package/utils/generateTypes/generateTypes.d.ts +1 -1
  67. package/utils/generateTypes/generateTypes.es6.js +27 -13
  68. package/utils/generateTypes/generateTypes.js +27 -13
  69. package/utils/getEndpoint/getEndpoint.es6.js +2 -2
  70. package/utils/getEndpoint/getEndpoint.js +2 -2
  71. package/hooks/useRequestPlugin/index.d.ts +0 -1
  72. package/hooks/useRequestPlugin/index.es6.js +0 -1
  73. package/hooks/useRequestPlugin/index.js +0 -9
  74. package/hooks/useRequestPlugin/useRequestPlugin.d.ts +0 -2
  75. package/hooks/useRequestPlugin/useRequestPlugin.es6.js +0 -13
  76. package/hooks/useRequestPlugin/useRequestPlugin.js +0 -17
  77. package/plugins/main/fallback/fallback.d.ts +0 -4
  78. package/plugins/main/fallback/fallback.es6.js +0 -19
  79. package/plugins/main/fallback/fallback.js +0 -23
  80. package/plugins/main/fallback/index.d.ts +0 -1
  81. package/plugins/main/fallback/index.es6.js +0 -1
  82. package/plugins/main/fallback/index.js +0 -9
@@ -6,14 +6,16 @@ var jsx = require('@innet/jsx');
6
6
  require('../../../hooks/index.js');
7
7
  var swagger$1 = require('./swagger.html.js');
8
8
  var useApi = require('../../../hooks/useApi/useApi.js');
9
- var useRequestPlugin = require('../../../hooks/useRequestPlugin/useRequestPlugin.js');
9
+ var useServerPlugin = require('../../../hooks/useServerPlugin/useServerPlugin.js');
10
+ var useAction = require('../../../hooks/useAction/useAction.js');
10
11
 
11
12
  const swagger = () => {
12
13
  const { path = '/swagger-ui' } = jsx.useProps() || {};
13
14
  const { docs, prefix } = useApi.useApi();
14
15
  let swaggerResponse;
15
- useRequestPlugin.useRequestPlugin(action => {
16
- if (action.req.url === prefix + path) {
16
+ useServerPlugin.useServerPlugin(() => {
17
+ const action = useAction.useAction();
18
+ if (action.path === prefix + path) {
17
19
  if (!swaggerResponse) {
18
20
  swaggerResponse = swagger$1["default"].replace('spec: {},', `spec: ${JSON.stringify(docs)},`);
19
21
  }
@@ -1,6 +1,7 @@
1
1
  import { useProps, useChildren } from '@innet/jsx';
2
2
  import '../../../hooks/index.es6.js';
3
- import { useRequestPlugin } from '../../../hooks/useRequestPlugin/useRequestPlugin.es6.js';
3
+ import { useServerPlugin } from '../../../hooks/useServerPlugin/useServerPlugin.es6.js';
4
+ import { useAction } from '../../../hooks/useAction/useAction.es6.js';
4
5
 
5
6
  function whitelist() {
6
7
  const { ip = process.env.WHITELIST_IP, } = useProps() || {};
@@ -8,7 +9,8 @@ function whitelist() {
8
9
  const ips = typeof ip === 'string' ? ip.split(',') : ip;
9
10
  if (!ips)
10
11
  return;
11
- useRequestPlugin(action => {
12
+ useServerPlugin(() => {
13
+ const action = useAction();
12
14
  if (!action.clientIp || !ips.includes(action.clientIp)) {
13
15
  return children;
14
16
  }
@@ -4,7 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var jsx = require('@innet/jsx');
6
6
  require('../../../hooks/index.js');
7
- var useRequestPlugin = require('../../../hooks/useRequestPlugin/useRequestPlugin.js');
7
+ var useServerPlugin = require('../../../hooks/useServerPlugin/useServerPlugin.js');
8
+ var useAction = require('../../../hooks/useAction/useAction.js');
8
9
 
9
10
  function whitelist() {
10
11
  const { ip = process.env.WHITELIST_IP, } = jsx.useProps() || {};
@@ -12,7 +13,8 @@ function whitelist() {
12
13
  const ips = typeof ip === 'string' ? ip.split(',') : ip;
13
14
  if (!ips)
14
15
  return;
15
- useRequestPlugin.useRequestPlugin(action => {
16
+ useServerPlugin.useServerPlugin(() => {
17
+ const action = useAction.useAction();
16
18
  if (!action.clientIp || !ips.includes(action.clientIp)) {
17
19
  return children;
18
20
  }
package/types.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import type { Handler } from 'innet';
2
1
  import type { OpenAPIV3_1 as API } from 'openapi-types';
3
2
  import type { ApiErrorValue } from './constants';
4
- import { type Action } from './utils';
3
+ import { type ServerPlugin } from './hooks';
5
4
  import { type Rule, type RulesErrors } from './utils/rules';
6
5
  export type TagObject = API.TagObject;
7
6
  export type Document = API.Document;
@@ -37,10 +36,9 @@ export interface EndpointRulesMaps {
37
36
  }
38
37
  export interface Endpoint<I = unknown, O = unknown, E extends ApiErrorValue = ApiErrorValue, P extends InValidationErrorParam = InValidationErrorParam, D extends ValidationErrorData = ValidationErrorData> {
39
38
  key: string;
40
- content?: any;
39
+ plugins: Set<ServerPlugin>;
41
40
  rules?: EndpointRules;
42
41
  rulesMaps?: EndpointRulesMaps;
43
- handler?: Handler;
44
42
  static?: Record<string, Endpoint<I, O, E, P, D>>;
45
43
  dynamic?: Endpoint<I, O, E, P, D>[];
46
44
  }
@@ -68,8 +66,3 @@ export interface BaseSchemaProps<T> {
68
66
  export interface ValuesSchemaProps<T> extends BaseSchemaProps<T> {
69
67
  values?: T[];
70
68
  }
71
- export interface Fallback {
72
- children: any;
73
- handler: Handler;
74
- }
75
- export type RequestPlugin = (action: Action) => any;
@@ -30,8 +30,8 @@ let Action = (() => {
30
30
  _Action_cookie.set(this, {});
31
31
  }
32
32
  get parsedUrl() {
33
- var _a;
34
- const match = (_a = this.req.url) === null || _a === void 0 ? void 0 : _a.match(URL_PARSER);
33
+ var _b;
34
+ const match = (_b = this.req.url) === null || _b === void 0 ? void 0 : _b.match(URL_PARSER);
35
35
  if (!match)
36
36
  throw Error('cannot parse url');
37
37
  const result = match.groups;
@@ -68,8 +68,8 @@ let Action = (() => {
68
68
  __classPrivateFieldSet(this, _Action_headers, value, "f");
69
69
  }
70
70
  get originCookies() {
71
- var _a;
72
- return cookieLib.parse((_a = this.req.headers.cookie) !== null && _a !== void 0 ? _a : '');
71
+ var _b;
72
+ return cookieLib.parse((_b = this.req.headers.cookie) !== null && _b !== void 0 ? _b : '');
73
73
  }
74
74
  get cookies() {
75
75
  if (__classPrivateFieldGet(this, _Action_cookie, "f"))
@@ -128,18 +128,20 @@ let Action = (() => {
128
128
  _Action_headers = new WeakMap(),
129
129
  _Action_cookie = new WeakMap(),
130
130
  (() => {
131
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
131
132
  _get_parsedUrl_decorators = [once];
132
133
  _get_originSearch_decorators = [once];
133
134
  _get_originCookies_decorators = [once];
134
135
  _get_bodyType_decorators = [once];
135
136
  _parseBody_decorators = [once];
136
137
  _get_clientIp_decorators = [once];
137
- __esDecorate(_a, null, _get_parsedUrl_decorators, { kind: "getter", name: "parsedUrl", static: false, private: false, access: { has: obj => "parsedUrl" in obj, get: obj => obj.parsedUrl } }, null, _instanceExtraInitializers);
138
- __esDecorate(_a, null, _get_originSearch_decorators, { kind: "getter", name: "originSearch", static: false, private: false, access: { has: obj => "originSearch" in obj, get: obj => obj.originSearch } }, null, _instanceExtraInitializers);
139
- __esDecorate(_a, null, _get_originCookies_decorators, { kind: "getter", name: "originCookies", static: false, private: false, access: { has: obj => "originCookies" in obj, get: obj => obj.originCookies } }, null, _instanceExtraInitializers);
140
- __esDecorate(_a, null, _get_bodyType_decorators, { kind: "getter", name: "bodyType", static: false, private: false, access: { has: obj => "bodyType" in obj, get: obj => obj.bodyType } }, null, _instanceExtraInitializers);
141
- __esDecorate(_a, null, _parseBody_decorators, { kind: "method", name: "parseBody", static: false, private: false, access: { has: obj => "parseBody" in obj, get: obj => obj.parseBody } }, null, _instanceExtraInitializers);
142
- __esDecorate(_a, null, _get_clientIp_decorators, { kind: "getter", name: "clientIp", static: false, private: false, access: { has: obj => "clientIp" in obj, get: obj => obj.clientIp } }, null, _instanceExtraInitializers);
138
+ __esDecorate(_a, null, _get_parsedUrl_decorators, { kind: "getter", name: "parsedUrl", static: false, private: false, access: { has: obj => "parsedUrl" in obj, get: obj => obj.parsedUrl }, metadata: _metadata }, null, _instanceExtraInitializers);
139
+ __esDecorate(_a, null, _get_originSearch_decorators, { kind: "getter", name: "originSearch", static: false, private: false, access: { has: obj => "originSearch" in obj, get: obj => obj.originSearch }, metadata: _metadata }, null, _instanceExtraInitializers);
140
+ __esDecorate(_a, null, _get_originCookies_decorators, { kind: "getter", name: "originCookies", static: false, private: false, access: { has: obj => "originCookies" in obj, get: obj => obj.originCookies }, metadata: _metadata }, null, _instanceExtraInitializers);
141
+ __esDecorate(_a, null, _get_bodyType_decorators, { kind: "getter", name: "bodyType", static: false, private: false, access: { has: obj => "bodyType" in obj, get: obj => obj.bodyType }, metadata: _metadata }, null, _instanceExtraInitializers);
142
+ __esDecorate(_a, null, _parseBody_decorators, { kind: "method", name: "parseBody", static: false, private: false, access: { has: obj => "parseBody" in obj, get: obj => obj.parseBody }, metadata: _metadata }, null, _instanceExtraInitializers);
143
+ __esDecorate(_a, null, _get_clientIp_decorators, { kind: "getter", name: "clientIp", static: false, private: false, access: { has: obj => "clientIp" in obj, get: obj => obj.clientIp }, metadata: _metadata }, null, _instanceExtraInitializers);
144
+ if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
143
145
  })(),
144
146
  _a;
145
147
  })();
@@ -38,8 +38,8 @@ let Action = (() => {
38
38
  _Action_cookie.set(this, {});
39
39
  }
40
40
  get parsedUrl() {
41
- var _a;
42
- const match = (_a = this.req.url) === null || _a === void 0 ? void 0 : _a.match(URL_PARSER);
41
+ var _b;
42
+ const match = (_b = this.req.url) === null || _b === void 0 ? void 0 : _b.match(URL_PARSER);
43
43
  if (!match)
44
44
  throw Error('cannot parse url');
45
45
  const result = match.groups;
@@ -76,8 +76,8 @@ let Action = (() => {
76
76
  tslib.__classPrivateFieldSet(this, _Action_headers, value, "f");
77
77
  }
78
78
  get originCookies() {
79
- var _a;
80
- return cookieLib__default["default"].parse((_a = this.req.headers.cookie) !== null && _a !== void 0 ? _a : '');
79
+ var _b;
80
+ return cookieLib__default["default"].parse((_b = this.req.headers.cookie) !== null && _b !== void 0 ? _b : '');
81
81
  }
82
82
  get cookies() {
83
83
  if (tslib.__classPrivateFieldGet(this, _Action_cookie, "f"))
@@ -136,18 +136,20 @@ let Action = (() => {
136
136
  _Action_headers = new WeakMap(),
137
137
  _Action_cookie = new WeakMap(),
138
138
  (() => {
139
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
139
140
  _get_parsedUrl_decorators = [once.once];
140
141
  _get_originSearch_decorators = [once.once];
141
142
  _get_originCookies_decorators = [once.once];
142
143
  _get_bodyType_decorators = [once.once];
143
144
  _parseBody_decorators = [once.once];
144
145
  _get_clientIp_decorators = [once.once];
145
- tslib.__esDecorate(_a, null, _get_parsedUrl_decorators, { kind: "getter", name: "parsedUrl", static: false, private: false, access: { has: obj => "parsedUrl" in obj, get: obj => obj.parsedUrl } }, null, _instanceExtraInitializers);
146
- tslib.__esDecorate(_a, null, _get_originSearch_decorators, { kind: "getter", name: "originSearch", static: false, private: false, access: { has: obj => "originSearch" in obj, get: obj => obj.originSearch } }, null, _instanceExtraInitializers);
147
- tslib.__esDecorate(_a, null, _get_originCookies_decorators, { kind: "getter", name: "originCookies", static: false, private: false, access: { has: obj => "originCookies" in obj, get: obj => obj.originCookies } }, null, _instanceExtraInitializers);
148
- tslib.__esDecorate(_a, null, _get_bodyType_decorators, { kind: "getter", name: "bodyType", static: false, private: false, access: { has: obj => "bodyType" in obj, get: obj => obj.bodyType } }, null, _instanceExtraInitializers);
149
- tslib.__esDecorate(_a, null, _parseBody_decorators, { kind: "method", name: "parseBody", static: false, private: false, access: { has: obj => "parseBody" in obj, get: obj => obj.parseBody } }, null, _instanceExtraInitializers);
150
- tslib.__esDecorate(_a, null, _get_clientIp_decorators, { kind: "getter", name: "clientIp", static: false, private: false, access: { has: obj => "clientIp" in obj, get: obj => obj.clientIp } }, null, _instanceExtraInitializers);
146
+ tslib.__esDecorate(_a, null, _get_parsedUrl_decorators, { kind: "getter", name: "parsedUrl", static: false, private: false, access: { has: obj => "parsedUrl" in obj, get: obj => obj.parsedUrl }, metadata: _metadata }, null, _instanceExtraInitializers);
147
+ tslib.__esDecorate(_a, null, _get_originSearch_decorators, { kind: "getter", name: "originSearch", static: false, private: false, access: { has: obj => "originSearch" in obj, get: obj => obj.originSearch }, metadata: _metadata }, null, _instanceExtraInitializers);
148
+ tslib.__esDecorate(_a, null, _get_originCookies_decorators, { kind: "getter", name: "originCookies", static: false, private: false, access: { has: obj => "originCookies" in obj, get: obj => obj.originCookies }, metadata: _metadata }, null, _instanceExtraInitializers);
149
+ tslib.__esDecorate(_a, null, _get_bodyType_decorators, { kind: "getter", name: "bodyType", static: false, private: false, access: { has: obj => "bodyType" in obj, get: obj => obj.bodyType }, metadata: _metadata }, null, _instanceExtraInitializers);
150
+ tslib.__esDecorate(_a, null, _parseBody_decorators, { kind: "method", name: "parseBody", static: false, private: false, access: { has: obj => "parseBody" in obj, get: obj => obj.parseBody }, metadata: _metadata }, null, _instanceExtraInitializers);
151
+ tslib.__esDecorate(_a, null, _get_clientIp_decorators, { kind: "getter", name: "clientIp", static: false, private: false, access: { has: obj => "clientIp" in obj, get: obj => obj.clientIp }, metadata: _metadata }, null, _instanceExtraInitializers);
152
+ if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
151
153
  })(),
152
154
  _a;
153
155
  })();
@@ -1,3 +1,3 @@
1
1
  import { type Document, type SchemaObject } from '../../types';
2
- export declare function generateSchemaTypes(schema: SchemaObject, spaces?: number): string;
2
+ export declare function generateSchemaTypes(schema: SchemaObject, spaces?: number, lastChar?: string): string;
3
3
  export declare function generateTypes(docs: Document, namespace?: string): string;
@@ -1,34 +1,34 @@
1
1
  function hasDefault(target) {
2
2
  return Boolean(target && ('default' in target || 'x-default' in target));
3
3
  }
4
- function generateSchemaTypes(schema, spaces = 2) {
4
+ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
5
5
  const space = [...new Array(spaces)].map(() => ' ').join('');
6
6
  if ('$ref' in schema) {
7
- return `Schemas.${schema.$ref.slice(21)}\n`;
7
+ return `Schemas.${schema.$ref.slice(21)}${lastChar}`;
8
8
  }
9
9
  if (schema.type === 'integer') {
10
- return `${schema.format === 'int64' ? 'bigint' : 'number'}\n`;
10
+ return `${schema.format === 'int64' ? 'bigint' : 'number'}${lastChar}`;
11
11
  }
12
12
  if (schema.type === 'string') {
13
13
  if (schema.format === 'date-time') {
14
- return 'Date\n';
14
+ return `Date${lastChar}`;
15
15
  }
16
16
  if (schema.format === 'binary') {
17
- return 'Bin\n';
17
+ return `Bin${lastChar}`;
18
18
  }
19
- return 'string\n';
19
+ return `string${lastChar}`;
20
20
  }
21
21
  if (['boolean', 'number', 'null'].includes(schema.type)) {
22
- return `${schema.type}\n`;
22
+ return `${schema.type}${lastChar}`;
23
23
  }
24
24
  if (schema.type === 'array') {
25
25
  if (!schema.items)
26
- return 'any[]\n';
27
- return `(${generateSchemaTypes(schema.items, spaces + 2).slice(0, -1)})[]\n`;
26
+ return `any[]${lastChar}`;
27
+ return `Array<${generateSchemaTypes(schema.items, spaces + 2, '')}>${lastChar}`;
28
28
  }
29
29
  if (schema.type !== 'object') {
30
30
  console.error('unknown type', schema);
31
- return 'any\n';
31
+ return `any${lastChar}`;
32
32
  }
33
33
  let result = '{\n';
34
34
  const required = schema.required || [];
@@ -39,7 +39,7 @@ function generateSchemaTypes(schema, spaces = 2) {
39
39
  : '?:';
40
40
  result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
41
41
  }
42
- return `${result}${space.slice(0, -2)}}\n`;
42
+ return `${result}${space.slice(0, -2)}}${lastChar}`;
43
43
  }
44
44
  function generateTypes(docs, namespace = 'Api') {
45
45
  var _a;
@@ -101,8 +101,22 @@ function generateTypes(docs, namespace = 'Api') {
101
101
  if (requestBody) {
102
102
  result += ` Body: ${generateSchemaTypes(requestBody.content['multipart/form-data'].schema, 8)}`;
103
103
  }
104
- if (responses === null || responses === void 0 ? void 0 : responses.default) {
105
- result += ` Response: ${generateSchemaTypes(responses.default.content['application/json'].schema, 8)}`;
104
+ if (responses) {
105
+ result += ' Response: {\n';
106
+ for (const key in responses) {
107
+ let multiple = false;
108
+ const response = responses[key];
109
+ result += ` ['${key}']: `;
110
+ for (const type in response.content) {
111
+ if (multiple) {
112
+ result += ' | ';
113
+ }
114
+ result += generateSchemaTypes(response.content[type].schema, 10, '');
115
+ multiple = true;
116
+ }
117
+ result += '\n';
118
+ }
119
+ result += ' }\n';
106
120
  }
107
121
  result += ' }\n';
108
122
  }
@@ -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,7 +43,7 @@ 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
48
  function generateTypes(docs, namespace = 'Api') {
49
49
  var _a;
@@ -105,8 +105,22 @@ function generateTypes(docs, namespace = 'Api') {
105
105
  if (requestBody) {
106
106
  result += ` Body: ${generateSchemaTypes(requestBody.content['multipart/form-data'].schema, 8)}`;
107
107
  }
108
- if (responses === null || responses === void 0 ? void 0 : responses.default) {
109
- 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';
110
124
  }
111
125
  result += ' }\n';
112
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';
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var fallback = require('./fallback.js');
6
-
7
-
8
-
9
- exports.fallback = fallback.fallback;