vovk 3.0.0-draft.46 → 3.0.0-draft.461

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 (207) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +8 -96
  3. package/bin/index.mjs +8 -0
  4. package/cjs/JSONLinesResponse.d.ts +19 -0
  5. package/cjs/JSONLinesResponse.js +95 -0
  6. package/{VovkApp.d.ts → cjs/VovkApp.d.ts} +14 -8
  7. package/cjs/VovkApp.js +304 -0
  8. package/cjs/client/createRPC.d.ts +5 -0
  9. package/cjs/client/createRPC.js +116 -0
  10. package/cjs/client/defaultHandler.d.ts +6 -0
  11. package/{client → cjs/client}/defaultHandler.js +9 -2
  12. package/cjs/client/defaultStreamHandler.d.ts +9 -0
  13. package/{client → cjs/client}/defaultStreamHandler.js +49 -26
  14. package/cjs/client/fetcher.d.ts +18 -0
  15. package/cjs/client/fetcher.js +97 -0
  16. package/cjs/client/index.d.ts +4 -0
  17. package/cjs/client/index.js +10 -0
  18. package/cjs/client/progressive.d.ts +9 -0
  19. package/cjs/client/progressive.js +54 -0
  20. package/cjs/client/types.d.ts +120 -0
  21. package/{createVovkApp.d.ts → cjs/createVovkApp.d.ts} +19 -16
  22. package/cjs/createVovkApp.js +146 -0
  23. package/cjs/index.d.ts +69 -0
  24. package/cjs/index.js +42 -0
  25. package/cjs/openapi/error.d.ts +2 -0
  26. package/cjs/openapi/error.js +100 -0
  27. package/cjs/openapi/index.d.ts +8 -0
  28. package/cjs/openapi/index.js +21 -0
  29. package/cjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.d.ts +3 -0
  30. package/cjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.js +67 -0
  31. package/cjs/openapi/openAPIToVovkSchema/index.d.ts +4 -0
  32. package/cjs/openapi/openAPIToVovkSchema/index.js +141 -0
  33. package/cjs/openapi/openAPIToVovkSchema/inlineRefs.d.ts +10 -0
  34. package/cjs/openapi/openAPIToVovkSchema/inlineRefs.js +102 -0
  35. package/cjs/openapi/vovkSchemaToOpenAPI.d.ts +8 -0
  36. package/cjs/openapi/vovkSchemaToOpenAPI.js +238 -0
  37. package/cjs/types.d.ts +466 -0
  38. package/{types.js → cjs/types.js} +14 -2
  39. package/cjs/utils/camelCase.d.ts +6 -0
  40. package/cjs/utils/camelCase.js +37 -0
  41. package/cjs/utils/createCodeSamples.d.ts +20 -0
  42. package/cjs/utils/createCodeSamples.js +279 -0
  43. package/cjs/utils/createDecorator.d.ts +6 -0
  44. package/{createDecorator.js → cjs/utils/createDecorator.js} +24 -14
  45. package/cjs/utils/createLLMTools.d.ts +50 -0
  46. package/cjs/utils/createLLMTools.js +168 -0
  47. package/cjs/utils/createStandardValidation.d.ts +83 -0
  48. package/cjs/utils/createStandardValidation.js +35 -0
  49. package/cjs/utils/createValidateOnClient.d.ts +7 -0
  50. package/cjs/utils/createValidateOnClient.js +19 -0
  51. package/cjs/utils/deepExtend.d.ts +54 -0
  52. package/cjs/utils/deepExtend.js +134 -0
  53. package/{utils → cjs/utils}/generateStaticAPI.d.ts +2 -2
  54. package/cjs/utils/generateStaticAPI.js +30 -0
  55. package/cjs/utils/getJSONSchemaExample.d.ts +11 -0
  56. package/cjs/utils/getJSONSchemaExample.js +264 -0
  57. package/cjs/utils/getJSONSchemaSample.d.ts +2 -0
  58. package/cjs/utils/getJSONSchemaSample.js +167 -0
  59. package/cjs/utils/getSampleFromObject.d.ts +9 -0
  60. package/cjs/utils/getSampleFromObject.js +41 -0
  61. package/cjs/utils/getSchema.d.ts +21 -0
  62. package/cjs/utils/getSchema.js +38 -0
  63. package/cjs/utils/multitenant.d.ts +24 -0
  64. package/cjs/utils/multitenant.js +131 -0
  65. package/cjs/utils/parseQuery.d.ts +25 -0
  66. package/cjs/utils/parseQuery.js +156 -0
  67. package/cjs/utils/reqForm.d.ts +2 -0
  68. package/cjs/utils/reqForm.js +33 -0
  69. package/cjs/utils/reqMeta.d.ts +2 -0
  70. package/cjs/utils/reqQuery.d.ts +2 -0
  71. package/cjs/utils/reqQuery.js +10 -0
  72. package/cjs/utils/resolveGeneratorConfigValues.d.ts +18 -0
  73. package/cjs/utils/resolveGeneratorConfigValues.js +82 -0
  74. package/cjs/utils/serializeQuery.d.ts +13 -0
  75. package/cjs/utils/serializeQuery.js +65 -0
  76. package/cjs/utils/setHandlerSchema.d.ts +4 -0
  77. package/cjs/utils/setHandlerSchema.js +15 -0
  78. package/cjs/utils/upperFirst.d.ts +1 -0
  79. package/cjs/utils/upperFirst.js +6 -0
  80. package/cjs/utils/withValidationLibrary.d.ts +78 -0
  81. package/cjs/utils/withValidationLibrary.js +133 -0
  82. package/mjs/HttpException.d.ts +7 -0
  83. package/mjs/HttpException.js +15 -0
  84. package/mjs/JSONLinesResponse.d.ts +19 -0
  85. package/mjs/JSONLinesResponse.js +95 -0
  86. package/mjs/VovkApp.d.ts +34 -0
  87. package/mjs/VovkApp.js +304 -0
  88. package/mjs/client/createRPC.d.ts +5 -0
  89. package/mjs/client/createRPC.js +116 -0
  90. package/mjs/client/defaultHandler.d.ts +6 -0
  91. package/mjs/client/defaultHandler.js +29 -0
  92. package/mjs/client/defaultStreamHandler.d.ts +9 -0
  93. package/mjs/client/defaultStreamHandler.js +105 -0
  94. package/mjs/client/fetcher.d.ts +18 -0
  95. package/mjs/client/fetcher.js +97 -0
  96. package/mjs/client/index.d.ts +4 -0
  97. package/mjs/client/index.js +10 -0
  98. package/mjs/client/progressive.d.ts +9 -0
  99. package/mjs/client/progressive.js +54 -0
  100. package/mjs/client/types.d.ts +120 -0
  101. package/mjs/createVovkApp.d.ts +65 -0
  102. package/mjs/createVovkApp.js +146 -0
  103. package/mjs/index.d.ts +69 -0
  104. package/mjs/index.js +42 -0
  105. package/mjs/openapi/error.d.ts +2 -0
  106. package/mjs/openapi/error.js +100 -0
  107. package/mjs/openapi/index.d.ts +8 -0
  108. package/mjs/openapi/index.js +21 -0
  109. package/mjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.d.ts +3 -0
  110. package/mjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.js +67 -0
  111. package/mjs/openapi/openAPIToVovkSchema/index.d.ts +4 -0
  112. package/mjs/openapi/openAPIToVovkSchema/index.js +141 -0
  113. package/mjs/openapi/openAPIToVovkSchema/inlineRefs.d.ts +10 -0
  114. package/mjs/openapi/openAPIToVovkSchema/inlineRefs.js +102 -0
  115. package/mjs/openapi/vovkSchemaToOpenAPI.d.ts +8 -0
  116. package/mjs/openapi/vovkSchemaToOpenAPI.js +238 -0
  117. package/mjs/types.d.ts +466 -0
  118. package/mjs/types.js +77 -0
  119. package/mjs/utils/camelCase.d.ts +6 -0
  120. package/mjs/utils/camelCase.js +37 -0
  121. package/mjs/utils/createCodeSamples.d.ts +20 -0
  122. package/mjs/utils/createCodeSamples.js +279 -0
  123. package/mjs/utils/createDecorator.d.ts +6 -0
  124. package/mjs/utils/createDecorator.js +48 -0
  125. package/mjs/utils/createLLMTools.d.ts +50 -0
  126. package/mjs/utils/createLLMTools.js +168 -0
  127. package/mjs/utils/createStandardValidation.d.ts +83 -0
  128. package/mjs/utils/createStandardValidation.js +35 -0
  129. package/mjs/utils/createValidateOnClient.d.ts +7 -0
  130. package/mjs/utils/createValidateOnClient.js +19 -0
  131. package/mjs/utils/deepExtend.d.ts +54 -0
  132. package/mjs/utils/deepExtend.js +134 -0
  133. package/mjs/utils/generateStaticAPI.d.ts +4 -0
  134. package/mjs/utils/generateStaticAPI.js +30 -0
  135. package/mjs/utils/getJSONSchemaExample.d.ts +11 -0
  136. package/mjs/utils/getJSONSchemaExample.js +264 -0
  137. package/mjs/utils/getJSONSchemaSample.d.ts +2 -0
  138. package/mjs/utils/getJSONSchemaSample.js +167 -0
  139. package/mjs/utils/getSampleFromObject.d.ts +9 -0
  140. package/mjs/utils/getSampleFromObject.js +41 -0
  141. package/mjs/utils/getSchema.d.ts +21 -0
  142. package/mjs/utils/getSchema.js +38 -0
  143. package/mjs/utils/multitenant.d.ts +24 -0
  144. package/mjs/utils/multitenant.js +131 -0
  145. package/mjs/utils/parseQuery.d.ts +25 -0
  146. package/mjs/utils/parseQuery.js +156 -0
  147. package/mjs/utils/reqForm.d.ts +2 -0
  148. package/mjs/utils/reqForm.js +33 -0
  149. package/mjs/utils/reqMeta.d.ts +2 -0
  150. package/mjs/utils/reqMeta.js +13 -0
  151. package/mjs/utils/reqQuery.d.ts +2 -0
  152. package/mjs/utils/reqQuery.js +10 -0
  153. package/mjs/utils/resolveGeneratorConfigValues.d.ts +18 -0
  154. package/mjs/utils/resolveGeneratorConfigValues.js +82 -0
  155. package/mjs/utils/serializeQuery.d.ts +13 -0
  156. package/mjs/utils/serializeQuery.js +65 -0
  157. package/mjs/utils/setHandlerSchema.d.ts +4 -0
  158. package/mjs/utils/setHandlerSchema.js +15 -0
  159. package/mjs/utils/shim.d.ts +1 -0
  160. package/mjs/utils/shim.js +18 -0
  161. package/mjs/utils/upperFirst.d.ts +1 -0
  162. package/mjs/utils/upperFirst.js +6 -0
  163. package/mjs/utils/withValidationLibrary.d.ts +78 -0
  164. package/mjs/utils/withValidationLibrary.js +133 -0
  165. package/package.json +28 -6
  166. package/.npmignore +0 -2
  167. package/StreamJSONResponse.d.ts +0 -17
  168. package/StreamJSONResponse.js +0 -54
  169. package/VovkApp.js +0 -185
  170. package/client/clientizeController.d.ts +0 -4
  171. package/client/clientizeController.js +0 -93
  172. package/client/defaultFetcher.d.ts +0 -4
  173. package/client/defaultFetcher.js +0 -49
  174. package/client/defaultHandler.d.ts +0 -2
  175. package/client/defaultStreamHandler.d.ts +0 -4
  176. package/client/index.d.ts +0 -4
  177. package/client/index.js +0 -5
  178. package/client/types.d.ts +0 -100
  179. package/createDecorator.d.ts +0 -4
  180. package/createVovkApp.js +0 -118
  181. package/index.d.ts +0 -60
  182. package/index.js +0 -20
  183. package/types.d.ts +0 -157
  184. package/utils/generateStaticAPI.js +0 -18
  185. package/utils/getSchema.d.ts +0 -8
  186. package/utils/getSchema.js +0 -38
  187. package/utils/reqForm.d.ts +0 -3
  188. package/utils/reqForm.js +0 -13
  189. package/utils/reqMeta.d.ts +0 -3
  190. package/utils/reqQuery.d.ts +0 -3
  191. package/utils/reqQuery.js +0 -25
  192. package/utils/setClientValidatorsForHandler.d.ts +0 -5
  193. package/utils/setClientValidatorsForHandler.js +0 -25
  194. package/worker/index.d.ts +0 -3
  195. package/worker/index.js +0 -7
  196. package/worker/promisifyWorker.d.ts +0 -2
  197. package/worker/promisifyWorker.js +0 -141
  198. package/worker/types.d.ts +0 -31
  199. package/worker/worker.d.ts +0 -1
  200. package/worker/worker.js +0 -43
  201. /package/{HttpException.d.ts → cjs/HttpException.d.ts} +0 -0
  202. /package/{HttpException.js → cjs/HttpException.js} +0 -0
  203. /package/{client → cjs/client}/types.js +0 -0
  204. /package/{utils → cjs/utils}/reqMeta.js +0 -0
  205. /package/{utils → cjs/utils}/shim.d.ts +0 -0
  206. /package/{utils → cjs/utils}/shim.js +0 -0
  207. /package/{worker → mjs/client}/types.js +0 -0
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.error = void 0;
4
+ const types_1 = require("../types");
5
+ const createDecorator_1 = require("../utils/createDecorator");
6
+ const statusDisplayText = {
7
+ [types_1.HttpStatus.NULL]: 'Error',
8
+ [types_1.HttpStatus.CONTINUE]: 'Continue',
9
+ [types_1.HttpStatus.SWITCHING_PROTOCOLS]: 'Switching Protocols',
10
+ [types_1.HttpStatus.PROCESSING]: 'Processing',
11
+ [types_1.HttpStatus.EARLYHINTS]: 'Early Hints',
12
+ [types_1.HttpStatus.OK]: 'OK',
13
+ [types_1.HttpStatus.CREATED]: 'Created',
14
+ [types_1.HttpStatus.ACCEPTED]: 'Accepted',
15
+ [types_1.HttpStatus.NON_AUTHORITATIVE_INFORMATION]: 'Non Authoritative Information',
16
+ [types_1.HttpStatus.NO_CONTENT]: 'No Content',
17
+ [types_1.HttpStatus.RESET_CONTENT]: 'Reset Content',
18
+ [types_1.HttpStatus.PARTIAL_CONTENT]: 'Partial Content',
19
+ [types_1.HttpStatus.AMBIGUOUS]: 'Ambiguous',
20
+ [types_1.HttpStatus.MOVED_PERMANENTLY]: 'Moved Permanently',
21
+ [types_1.HttpStatus.FOUND]: 'Found',
22
+ [types_1.HttpStatus.SEE_OTHER]: 'See Other',
23
+ [types_1.HttpStatus.NOT_MODIFIED]: 'Not Modified',
24
+ [types_1.HttpStatus.TEMPORARY_REDIRECT]: 'Temporary Redirect',
25
+ [types_1.HttpStatus.PERMANENT_REDIRECT]: 'Permanent Redirect',
26
+ [types_1.HttpStatus.BAD_REQUEST]: 'Bad Request',
27
+ [types_1.HttpStatus.UNAUTHORIZED]: 'Unauthorized',
28
+ [types_1.HttpStatus.PAYMENT_REQUIRED]: 'Payment Required',
29
+ [types_1.HttpStatus.FORBIDDEN]: 'Forbidden',
30
+ [types_1.HttpStatus.NOT_FOUND]: 'Not Found',
31
+ [types_1.HttpStatus.METHOD_NOT_ALLOWED]: 'Method Not Allowed',
32
+ [types_1.HttpStatus.NOT_ACCEPTABLE]: 'Not Acceptable',
33
+ [types_1.HttpStatus.PROXY_AUTHENTICATION_REQUIRED]: 'Proxy Authentication Required',
34
+ [types_1.HttpStatus.REQUEST_TIMEOUT]: 'Request Timeout',
35
+ [types_1.HttpStatus.CONFLICT]: 'Conflict',
36
+ [types_1.HttpStatus.GONE]: 'Gone',
37
+ [types_1.HttpStatus.LENGTH_REQUIRED]: 'Length Required',
38
+ [types_1.HttpStatus.PRECONDITION_FAILED]: 'Precondition Failed',
39
+ [types_1.HttpStatus.PAYLOAD_TOO_LARGE]: 'Payload Too Large',
40
+ [types_1.HttpStatus.URI_TOO_LONG]: 'URI Too Long',
41
+ [types_1.HttpStatus.UNSUPPORTED_MEDIA_TYPE]: 'Unsupported Media Type',
42
+ [types_1.HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE]: 'Requested Range Not Satisfiable',
43
+ [types_1.HttpStatus.EXPECTATION_FAILED]: 'Expectation Failed',
44
+ [types_1.HttpStatus.I_AM_A_TEAPOT]: 'I am a teapot',
45
+ [types_1.HttpStatus.MISDIRECTED]: 'Misdirected',
46
+ [types_1.HttpStatus.UNPROCESSABLE_ENTITY]: 'Unprocessable Entity',
47
+ [types_1.HttpStatus.FAILED_DEPENDENCY]: 'Failed Dependency',
48
+ [types_1.HttpStatus.PRECONDITION_REQUIRED]: 'Precondition Required',
49
+ [types_1.HttpStatus.TOO_MANY_TRequestS]: 'Too Many Requests',
50
+ [types_1.HttpStatus.INTERNAL_SERVER_ERROR]: 'Internal Server Error',
51
+ [types_1.HttpStatus.NOT_IMPLEMENTED]: 'Not Implemented',
52
+ [types_1.HttpStatus.BAD_GATEWAY]: 'Bad Gateway',
53
+ [types_1.HttpStatus.SERVICE_UNAVAILABLE]: 'Service Unavailable',
54
+ [types_1.HttpStatus.GATEWAY_TIMEOUT]: 'Gateway Timeout',
55
+ [types_1.HttpStatus.HTTP_VERSION_NOT_SUPPORTED]: 'HTTP Version Not Supported',
56
+ };
57
+ exports.error = (0, createDecorator_1.createDecorator)(null, (status, message) => {
58
+ return (handlerSchema) => {
59
+ return {
60
+ ...handlerSchema,
61
+ operationObject: {
62
+ ...handlerSchema?.operationObject,
63
+ responses: {
64
+ ...handlerSchema?.operationObject?.responses,
65
+ [status]: {
66
+ description: `${status} ${statusDisplayText[status]}`,
67
+ content: {
68
+ 'application/json': {
69
+ schema: {
70
+ allOf: [
71
+ {
72
+ $ref: '#/components/schemas/VovkErrorResponse',
73
+ },
74
+ {
75
+ type: 'object',
76
+ properties: {
77
+ message: {
78
+ type: 'string',
79
+ enum: [
80
+ message,
81
+ ...(handlerSchema?.operationObject?.responses?.[status]?.content?.['application/json']
82
+ ?.schema?.allOf?.[1]?.properties?.message?.enum ?? []),
83
+ ],
84
+ },
85
+ statusCode: {
86
+ type: 'integer',
87
+ enum: [status],
88
+ },
89
+ },
90
+ },
91
+ ],
92
+ },
93
+ },
94
+ },
95
+ },
96
+ },
97
+ },
98
+ };
99
+ };
100
+ });
@@ -0,0 +1,8 @@
1
+ import { vovkSchemaToOpenAPI } from './vovkSchemaToOpenAPI';
2
+ import { openAPIToVovkSchema } from './openAPIToVovkSchema/index';
3
+ import type { VovkOperationObject } from '../types';
4
+ export declare const operationDecorator: (openAPIOperationObject?: VovkOperationObject | undefined) => (target: import("../types").KnownAny, propertyKey: string) => void;
5
+ export declare const operation: ((openAPIOperationObject?: VovkOperationObject | undefined) => (target: import("../types").KnownAny, propertyKey: string) => void) & {
6
+ error: (status: import("../types").HttpStatus, message: string) => (target: import("../types").KnownAny, propertyKey: string) => void;
7
+ };
8
+ export { vovkSchemaToOpenAPI, openAPIToVovkSchema };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openAPIToVovkSchema = exports.vovkSchemaToOpenAPI = exports.operation = exports.operationDecorator = void 0;
4
+ const vovkSchemaToOpenAPI_1 = require("./vovkSchemaToOpenAPI");
5
+ Object.defineProperty(exports, "vovkSchemaToOpenAPI", { enumerable: true, get: function () { return vovkSchemaToOpenAPI_1.vovkSchemaToOpenAPI; } });
6
+ const index_1 = require("./openAPIToVovkSchema/index");
7
+ Object.defineProperty(exports, "openAPIToVovkSchema", { enumerable: true, get: function () { return index_1.openAPIToVovkSchema; } });
8
+ const error_1 = require("./error");
9
+ const createDecorator_1 = require("../utils/createDecorator");
10
+ exports.operationDecorator = (0, createDecorator_1.createDecorator)(null, (openAPIOperationObject = {}) => {
11
+ return (handlerSchema) => {
12
+ return {
13
+ ...handlerSchema,
14
+ operationObject: {
15
+ ...handlerSchema?.operationObject,
16
+ ...openAPIOperationObject,
17
+ },
18
+ };
19
+ };
20
+ });
21
+ exports.operation = Object.assign(exports.operationDecorator, { error: error_1.error });
@@ -0,0 +1,3 @@
1
+ import { ComponentsObject } from 'openapi3-ts/oas31';
2
+ import { VovkBasicJSONSchema } from '../../types';
3
+ export declare function applyComponentsSchemas(schema: VovkBasicJSONSchema, components: ComponentsObject['schemas'], mixinName: string): VovkBasicJSONSchema | VovkBasicJSONSchema[];
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyComponentsSchemas = applyComponentsSchemas;
4
+ const camelCase_1 = require("../../utils/camelCase");
5
+ const upperFirst_1 = require("../../utils/upperFirst");
6
+ // fast clone JSON object while ignoring Date, RegExp, and Function types
7
+ function cloneJSON(obj) {
8
+ if (obj === null || typeof obj !== 'object')
9
+ return obj;
10
+ if (Array.isArray(obj))
11
+ return obj.map(cloneJSON);
12
+ const result = {};
13
+ for (const [key, value] of Object.entries(obj)) {
14
+ if (value instanceof Date || value instanceof RegExp || typeof value === 'function')
15
+ continue;
16
+ result[key] = cloneJSON(value);
17
+ }
18
+ return result;
19
+ }
20
+ function applyComponentsSchemas(schema, components, mixinName) {
21
+ const key = 'components/schemas';
22
+ if (!components || !Object.keys(components).length)
23
+ return schema;
24
+ // Create a deep copy of the schema
25
+ const result = cloneJSON(schema);
26
+ // Initialize $defs if it doesn't exist
27
+ result.$defs = result.$defs || {};
28
+ // Set to track components we've added to $defs
29
+ const addedComponents = new Set();
30
+ // Process a schema object and replace $refs
31
+ function processSchema(obj) {
32
+ if (!obj || typeof obj !== 'object')
33
+ return obj;
34
+ // Handle arrays first - they don't have $ref
35
+ if (Array.isArray(obj)) {
36
+ return obj.map((item) => processSchema(item));
37
+ }
38
+ // Now we know it's an object, so we can safely access $ref
39
+ const newObj = { ...obj };
40
+ const $ref = newObj.$ref;
41
+ if ($ref && typeof $ref === 'string' && $ref.startsWith(`#/${key}/`)) {
42
+ const componentName = $ref.replace(`#/${key}/`, '');
43
+ if (components[componentName]) {
44
+ newObj.$ref = `#/$defs/${componentName}`;
45
+ newObj['x-tsType'] ??= `Mixins.${(0, upperFirst_1.upperFirst)((0, camelCase_1.camelCase)(mixinName))}.${(0, upperFirst_1.upperFirst)((0, camelCase_1.camelCase)(componentName))}`;
46
+ }
47
+ else {
48
+ delete newObj.$ref; // Remove $ref if component not found (Telegram API has Type $refs that is not defined in components)
49
+ }
50
+ // Add the component to $defs if not already added
51
+ if (!addedComponents.has(componentName) && components[componentName]) {
52
+ addedComponents.add(componentName);
53
+ // TODO: Optimize
54
+ result.$defs[componentName] = processSchema(cloneJSON(components[componentName]));
55
+ }
56
+ }
57
+ // Process properties recursively
58
+ for (const key in newObj) {
59
+ if (Object.prototype.hasOwnProperty.call(newObj, key)) {
60
+ newObj[key] = processSchema(newObj[key]);
61
+ }
62
+ }
63
+ return newObj;
64
+ }
65
+ // Process the main schema
66
+ return processSchema(result);
67
+ }
@@ -0,0 +1,4 @@
1
+ import { VovkOpenAPIMixinNormalized, type VovkSchema } from '../../types';
2
+ export declare function openAPIToVovkSchema({ apiRoot, source: { object: openAPIObject }, getModuleName, getMethodName, errorMessageKey, segmentName, }: VovkOpenAPIMixinNormalized & {
3
+ segmentName?: string;
4
+ }): VovkSchema;
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openAPIToVovkSchema = openAPIToVovkSchema;
4
+ const types_1 = require("../../types");
5
+ const applyComponentsSchemas_1 = require("./applyComponentsSchemas");
6
+ const inlineRefs_1 = require("./inlineRefs");
7
+ function openAPIToVovkSchema({ apiRoot, source: { object: openAPIObject }, getModuleName, getMethodName, errorMessageKey, segmentName, }) {
8
+ segmentName = segmentName ?? '';
9
+ const forceApiRoot = apiRoot ||
10
+ (openAPIObject.servers?.[0]?.url ??
11
+ ('host' in openAPIObject
12
+ ? `https://${openAPIObject.host}${'basePath' in openAPIObject ? openAPIObject.basePath : ''}`
13
+ : null));
14
+ if (!forceApiRoot) {
15
+ throw new Error('API root URL is required in OpenAPI configuration');
16
+ }
17
+ const { paths, ...noPathsOpenAPIObject } = openAPIObject;
18
+ const schema = {
19
+ $schema: types_1.VovkSchemaIdEnum.SCHEMA,
20
+ segments: {
21
+ [segmentName]: {
22
+ $schema: types_1.VovkSchemaIdEnum.SEGMENT,
23
+ emitSchema: true,
24
+ segmentName,
25
+ segmentType: 'mixin',
26
+ controllers: {},
27
+ forceApiRoot,
28
+ meta: {
29
+ openAPIObject: noPathsOpenAPIObject,
30
+ },
31
+ },
32
+ },
33
+ };
34
+ const segment = schema.segments[segmentName];
35
+ return Object.entries(paths ?? {}).reduce((acc, [path, operations]) => {
36
+ Object.entries(operations ?? {})
37
+ .filter(([, operation]) => operation && typeof operation === 'object')
38
+ .forEach(([method, operation]) => {
39
+ const rpcModuleName = getModuleName({
40
+ method: method.toUpperCase(),
41
+ path,
42
+ openAPIObject,
43
+ operationObject: operation,
44
+ });
45
+ const handlerName = getMethodName({
46
+ method: method.toUpperCase(),
47
+ path,
48
+ openAPIObject,
49
+ operationObject: operation,
50
+ });
51
+ segment.controllers[rpcModuleName] ??= {
52
+ rpcModuleName,
53
+ handlers: {},
54
+ };
55
+ const parameters = (0, inlineRefs_1.inlineRefs)(operation.parameters ?? [], openAPIObject);
56
+ const queryProperties = parameters.filter((p) => p.in === 'query') ?? null;
57
+ const pathProperties = parameters.filter((p) => p.in === 'path') ?? null;
58
+ const query = queryProperties?.length
59
+ ? {
60
+ type: 'object',
61
+ properties: Object.fromEntries(queryProperties.map((p) => [p.name, p.schema])),
62
+ required: queryProperties.filter((p) => p.required).map((p) => p.name),
63
+ }
64
+ : null;
65
+ const params = pathProperties?.length
66
+ ? {
67
+ type: 'object',
68
+ properties: Object.fromEntries(pathProperties.map((p) => [p.name, p.schema])),
69
+ required: pathProperties.filter((p) => p.required).map((p) => p.name),
70
+ }
71
+ : null;
72
+ // TODO: how to utilize ReferenceObject?
73
+ const requestBodyContent = (0, inlineRefs_1.inlineRefs)(operation.requestBody, openAPIObject)?.content ?? {};
74
+ const jsonBody = requestBodyContent['application/json']?.schema ?? null;
75
+ const formDataBody = requestBodyContent['multipart/form-data']?.schema ?? null;
76
+ let urlEncodedBody = requestBodyContent['application/x-www-form-urlencoded']?.schema ?? null;
77
+ if (formDataBody && urlEncodedBody && JSON.stringify(formDataBody) === JSON.stringify(urlEncodedBody)) {
78
+ urlEncodedBody = null; // Avoid duplication if both form-data and url-encoded bodies are the same
79
+ }
80
+ if (formDataBody) {
81
+ Object.assign(formDataBody, {
82
+ 'x-isForm': true,
83
+ 'x-tsType': 'FormData',
84
+ });
85
+ }
86
+ if (urlEncodedBody) {
87
+ Object.assign(urlEncodedBody, {
88
+ 'x-isForm': true,
89
+ 'x-tsType': 'FormData',
90
+ });
91
+ }
92
+ const bodySchemas = [jsonBody, formDataBody, urlEncodedBody].filter(Boolean);
93
+ const body = !bodySchemas.length
94
+ ? null
95
+ : bodySchemas.length === 1
96
+ ? bodySchemas[0]
97
+ : {
98
+ anyOf: bodySchemas,
99
+ };
100
+ const output = operation.responses?.['200']?.content?.['application/json']?.schema ??
101
+ operation.responses?.['201']?.content?.['application/json']?.schema ??
102
+ null;
103
+ const iteration = operation.responses?.['200']?.content?.['application/jsonl']?.schema ??
104
+ operation.responses?.['201']?.content?.['application/jsonl']?.schema ??
105
+ operation.responses?.['200']?.content?.['application/jsonlines']?.schema ??
106
+ operation.responses?.['201']?.content?.['application/jsonlines']?.schema ??
107
+ null;
108
+ if (errorMessageKey) {
109
+ operation['x-errorMessageKey'] = errorMessageKey;
110
+ }
111
+ const componentsSchemas = openAPIObject.components?.schemas ??
112
+ ('definitions' in openAPIObject ? openAPIObject.definitions : {});
113
+ segment.controllers[rpcModuleName].handlers[handlerName] = {
114
+ httpMethod: method.toUpperCase(),
115
+ path,
116
+ operationObject: operation,
117
+ misc: {
118
+ originalPath: path,
119
+ },
120
+ validation: {
121
+ ...(query && {
122
+ query: (0, applyComponentsSchemas_1.applyComponentsSchemas)(query, componentsSchemas, segmentName),
123
+ }),
124
+ ...(params && {
125
+ params: (0, applyComponentsSchemas_1.applyComponentsSchemas)(params, componentsSchemas, segmentName),
126
+ }),
127
+ ...(body && {
128
+ body: (0, applyComponentsSchemas_1.applyComponentsSchemas)(body, componentsSchemas, segmentName),
129
+ }),
130
+ ...(output && {
131
+ output: (0, applyComponentsSchemas_1.applyComponentsSchemas)(output, componentsSchemas, segmentName),
132
+ }),
133
+ ...(iteration && {
134
+ iteration: (0, applyComponentsSchemas_1.applyComponentsSchemas)(iteration, componentsSchemas, segmentName),
135
+ }),
136
+ },
137
+ };
138
+ });
139
+ return acc;
140
+ }, schema);
141
+ }
@@ -0,0 +1,10 @@
1
+ import { OpenAPIObject } from 'openapi3-ts/oas31';
2
+ import { KnownAny } from '../../types';
3
+ /**
4
+ * Resolves $ref references at the first level only (except for components/schemas references)
5
+ * For arrays, checks each item at the first level
6
+ * @param obj - The object to process (may contain $ref properties)
7
+ * @param openAPIObject - The complete OpenAPI document containing definitions
8
+ * @returns The object with resolved references (except components/schemas)
9
+ */
10
+ export declare function inlineRefs<T extends object>(obj: KnownAny, openAPIObject: OpenAPIObject): T;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inlineRefs = inlineRefs;
4
+ /**
5
+ * Resolves $ref references at the first level only (except for components/schemas references)
6
+ * For arrays, checks each item at the first level
7
+ * @param obj - The object to process (may contain $ref properties)
8
+ * @param openAPIObject - The complete OpenAPI document containing definitions
9
+ * @returns The object with resolved references (except components/schemas)
10
+ */
11
+ function inlineRefs(obj, openAPIObject) {
12
+ // Handle null or undefined
13
+ if (obj === null || obj === undefined) {
14
+ return obj;
15
+ }
16
+ // Handle arrays - check each item for $ref at first level only
17
+ if (Array.isArray(obj)) {
18
+ return obj.map((item) => {
19
+ // Only resolve if item is an object with $ref
20
+ if (item && typeof item === 'object' && '$ref' in item && typeof item.$ref === 'string') {
21
+ // Skip components/schemas references
22
+ if (item.$ref.startsWith('#/components/schemas/')) {
23
+ return item;
24
+ }
25
+ // Resolve the reference
26
+ const resolved = resolveRef(item.$ref, openAPIObject);
27
+ // If resolution successful, return resolved value (with any additional properties merged)
28
+ if (resolved !== undefined) {
29
+ // If there are additional properties besides $ref, merge them
30
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
+ const { $ref: _$ref, ...additionalProps } = item;
32
+ if (Object.keys(additionalProps).length > 0) {
33
+ return { ...resolved, ...additionalProps };
34
+ }
35
+ return resolved;
36
+ }
37
+ }
38
+ // Return item as-is if not a resolvable $ref
39
+ return item;
40
+ });
41
+ }
42
+ // Handle non-objects (primitives)
43
+ if (typeof obj !== 'object') {
44
+ return obj;
45
+ }
46
+ // Check if object has a $ref property at the first level
47
+ if ('$ref' in obj && typeof obj.$ref === 'string') {
48
+ // Check if the reference points to components/schemas
49
+ if (obj.$ref.startsWith('#/components/schemas/')) {
50
+ // Return as-is for schema references
51
+ return obj;
52
+ }
53
+ // Resolve the reference
54
+ const resolved = resolveRef(obj.$ref, openAPIObject);
55
+ // If resolution successful, return resolved value (with any additional properties merged)
56
+ if (resolved !== undefined) {
57
+ // If there are additional properties besides $ref, merge them
58
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
59
+ const { $ref: _$ref, ...additionalProps } = obj;
60
+ if (Object.keys(additionalProps).length > 0) {
61
+ return { ...resolved, ...additionalProps };
62
+ }
63
+ return resolved;
64
+ }
65
+ }
66
+ // For regular objects without $ref, return as-is (no recursion)
67
+ return obj;
68
+ }
69
+ /**
70
+ * Resolves a JSON Reference ($ref) to its target value
71
+ * @param ref - The reference string (e.g., "#/components/parameters/id")
72
+ * @param openAPIObject - The complete OpenAPI document
73
+ * @returns The resolved value or undefined if not found
74
+ */
75
+ function resolveRef(ref, openAPIObject) {
76
+ // Handle only local references (starting with #)
77
+ if (!ref.startsWith('#/')) {
78
+ // eslint-disable-next-line no-console
79
+ console.warn(`External references are not supported: ${ref}`);
80
+ return undefined;
81
+ }
82
+ // Remove the leading # and split the path
83
+ const path = ref
84
+ .substring(1)
85
+ .split('/')
86
+ .filter((p) => p !== '');
87
+ // Navigate through the object following the path
88
+ let current = openAPIObject;
89
+ for (const segment of path) {
90
+ // Decode the segment (handles encoded characters like ~0 for ~ and ~1 for /)
91
+ const decodedSegment = segment.replace(/~1/g, '/').replace(/~0/g, '~');
92
+ if (current && typeof current === 'object' && decodedSegment in current) {
93
+ current = current[decodedSegment];
94
+ }
95
+ else {
96
+ // eslint-disable-next-line no-console
97
+ console.warn(`Could not resolve reference: ${ref}`);
98
+ return undefined;
99
+ }
100
+ }
101
+ return current;
102
+ }
@@ -0,0 +1,8 @@
1
+ import type { OpenAPIObject } from 'openapi3-ts/oas31';
2
+ import { type VovkSchema, type VovkGeneratorConfig } from '../types';
3
+ export declare function vovkSchemaToOpenAPI({ rootEntry, schema: fullSchema, configs, segmentName: givenSegmentName, }: {
4
+ rootEntry?: string;
5
+ schema: VovkSchema;
6
+ configs?: VovkGeneratorConfig[];
7
+ segmentName?: string;
8
+ }): OpenAPIObject;