vovk 3.0.0-draft.33 → 3.0.0-draft.331

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 (196) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +8 -96
  3. package/bin/index.mjs +8 -0
  4. package/{HttpException.d.ts → cjs/HttpException.d.ts} +2 -2
  5. package/{HttpException.js → cjs/HttpException.js} +3 -3
  6. package/cjs/JSONLinesResponse.d.ts +19 -0
  7. package/cjs/JSONLinesResponse.js +93 -0
  8. package/{VovkApp.d.ts → cjs/VovkApp.d.ts} +10 -9
  9. package/cjs/VovkApp.js +202 -0
  10. package/cjs/client/createRPC.d.ts +3 -0
  11. package/cjs/client/createRPC.js +90 -0
  12. package/cjs/client/defaultHandler.d.ts +6 -0
  13. package/cjs/client/defaultHandler.js +29 -0
  14. package/cjs/client/defaultStreamHandler.d.ts +9 -0
  15. package/{client → cjs/client}/defaultStreamHandler.js +25 -13
  16. package/cjs/client/fetcher.d.ts +14 -0
  17. package/cjs/client/fetcher.js +93 -0
  18. package/cjs/client/index.d.ts +4 -0
  19. package/cjs/client/index.js +10 -0
  20. package/cjs/client/progressive.d.ts +9 -0
  21. package/cjs/client/progressive.js +45 -0
  22. package/cjs/client/types.d.ts +123 -0
  23. package/{createVovkApp.d.ts → cjs/createVovkApp.d.ts} +12 -11
  24. package/cjs/createVovkApp.js +133 -0
  25. package/cjs/index.d.ts +65 -0
  26. package/cjs/index.js +38 -0
  27. package/cjs/openapi/error.d.ts +2 -0
  28. package/cjs/openapi/error.js +100 -0
  29. package/cjs/openapi/generateFnName.d.ts +23 -0
  30. package/cjs/openapi/generateFnName.js +81 -0
  31. package/cjs/openapi/index.d.ts +12 -0
  32. package/cjs/openapi/index.js +21 -0
  33. package/cjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.d.ts +3 -0
  34. package/cjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.js +67 -0
  35. package/cjs/openapi/openAPIToVovkSchema/index.d.ts +4 -0
  36. package/cjs/openapi/openAPIToVovkSchema/index.js +192 -0
  37. package/cjs/openapi/openAPIToVovkSchema/inlineRefs.d.ts +10 -0
  38. package/cjs/openapi/openAPIToVovkSchema/inlineRefs.js +102 -0
  39. package/cjs/openapi/vovkSchemaToOpenAPI.d.ts +9 -0
  40. package/cjs/openapi/vovkSchemaToOpenAPI.js +233 -0
  41. package/cjs/types.d.ts +400 -0
  42. package/cjs/types.js +74 -0
  43. package/cjs/utils/camelCase.d.ts +6 -0
  44. package/cjs/utils/camelCase.js +37 -0
  45. package/cjs/utils/createCodeExamples.d.ts +19 -0
  46. package/cjs/utils/createCodeExamples.js +110 -0
  47. package/cjs/utils/createDecorator.d.ts +6 -0
  48. package/{createDecorator.js → cjs/utils/createDecorator.js} +26 -16
  49. package/cjs/utils/createLLMTools.d.ts +44 -0
  50. package/cjs/utils/createLLMTools.js +118 -0
  51. package/cjs/utils/createStandardValidation.d.ts +81 -0
  52. package/cjs/utils/createStandardValidation.js +33 -0
  53. package/cjs/utils/generateStaticAPI.d.ts +4 -0
  54. package/cjs/utils/generateStaticAPI.js +30 -0
  55. package/cjs/utils/getJSONSchemaExample.d.ts +8 -0
  56. package/cjs/utils/getJSONSchemaExample.js +234 -0
  57. package/cjs/utils/getJSONSchemaSample.d.ts +2 -0
  58. package/cjs/utils/getJSONSchemaSample.js +167 -0
  59. package/cjs/utils/getSchema.d.ts +21 -0
  60. package/cjs/utils/getSchema.js +38 -0
  61. package/cjs/utils/multitenant.d.ts +24 -0
  62. package/cjs/utils/multitenant.js +170 -0
  63. package/cjs/utils/parseQuery.d.ts +25 -0
  64. package/cjs/utils/parseQuery.js +156 -0
  65. package/{utils → cjs/utils}/reqForm.d.ts +1 -2
  66. package/cjs/utils/reqForm.js +33 -0
  67. package/{utils → cjs/utils}/reqMeta.d.ts +1 -2
  68. package/cjs/utils/reqQuery.d.ts +2 -0
  69. package/cjs/utils/reqQuery.js +10 -0
  70. package/cjs/utils/serializeQuery.d.ts +13 -0
  71. package/cjs/utils/serializeQuery.js +65 -0
  72. package/cjs/utils/setHandlerSchema.d.ts +4 -0
  73. package/cjs/utils/setHandlerSchema.js +15 -0
  74. package/cjs/utils/upperFirst.d.ts +1 -0
  75. package/cjs/utils/upperFirst.js +6 -0
  76. package/cjs/utils/withValidationLibrary.d.ts +76 -0
  77. package/cjs/utils/withValidationLibrary.js +123 -0
  78. package/mjs/HttpException.d.ts +7 -0
  79. package/mjs/HttpException.js +15 -0
  80. package/mjs/JSONLinesResponse.d.ts +19 -0
  81. package/mjs/JSONLinesResponse.js +93 -0
  82. package/mjs/VovkApp.d.ts +29 -0
  83. package/mjs/VovkApp.js +202 -0
  84. package/mjs/client/createRPC.d.ts +3 -0
  85. package/mjs/client/createRPC.js +90 -0
  86. package/mjs/client/defaultHandler.d.ts +6 -0
  87. package/mjs/client/defaultHandler.js +29 -0
  88. package/mjs/client/defaultStreamHandler.d.ts +9 -0
  89. package/mjs/client/defaultStreamHandler.js +94 -0
  90. package/mjs/client/fetcher.d.ts +14 -0
  91. package/mjs/client/fetcher.js +93 -0
  92. package/mjs/client/index.d.ts +4 -0
  93. package/mjs/client/index.js +10 -0
  94. package/mjs/client/progressive.d.ts +9 -0
  95. package/mjs/client/progressive.js +45 -0
  96. package/mjs/client/types.d.ts +123 -0
  97. package/mjs/createVovkApp.d.ts +63 -0
  98. package/mjs/createVovkApp.js +133 -0
  99. package/mjs/index.d.ts +65 -0
  100. package/mjs/index.js +38 -0
  101. package/mjs/openapi/error.d.ts +2 -0
  102. package/mjs/openapi/error.js +100 -0
  103. package/mjs/openapi/generateFnName.d.ts +23 -0
  104. package/mjs/openapi/generateFnName.js +81 -0
  105. package/mjs/openapi/index.d.ts +12 -0
  106. package/mjs/openapi/index.js +21 -0
  107. package/mjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.d.ts +3 -0
  108. package/mjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.js +67 -0
  109. package/mjs/openapi/openAPIToVovkSchema/index.d.ts +4 -0
  110. package/mjs/openapi/openAPIToVovkSchema/index.js +192 -0
  111. package/mjs/openapi/openAPIToVovkSchema/inlineRefs.d.ts +10 -0
  112. package/mjs/openapi/openAPIToVovkSchema/inlineRefs.js +102 -0
  113. package/mjs/openapi/vovkSchemaToOpenAPI.d.ts +9 -0
  114. package/mjs/openapi/vovkSchemaToOpenAPI.js +233 -0
  115. package/mjs/types.d.ts +400 -0
  116. package/mjs/types.js +74 -0
  117. package/mjs/utils/camelCase.d.ts +6 -0
  118. package/mjs/utils/camelCase.js +37 -0
  119. package/mjs/utils/createCodeExamples.d.ts +19 -0
  120. package/mjs/utils/createCodeExamples.js +110 -0
  121. package/mjs/utils/createDecorator.d.ts +6 -0
  122. package/mjs/utils/createDecorator.js +48 -0
  123. package/mjs/utils/createLLMTools.d.ts +44 -0
  124. package/mjs/utils/createLLMTools.js +118 -0
  125. package/mjs/utils/createStandardValidation.d.ts +81 -0
  126. package/mjs/utils/createStandardValidation.js +33 -0
  127. package/mjs/utils/generateStaticAPI.d.ts +4 -0
  128. package/mjs/utils/generateStaticAPI.js +30 -0
  129. package/mjs/utils/getJSONSchemaExample.d.ts +8 -0
  130. package/mjs/utils/getJSONSchemaExample.js +234 -0
  131. package/mjs/utils/getJSONSchemaSample.d.ts +2 -0
  132. package/mjs/utils/getJSONSchemaSample.js +167 -0
  133. package/mjs/utils/getSchema.d.ts +21 -0
  134. package/mjs/utils/getSchema.js +38 -0
  135. package/mjs/utils/multitenant.d.ts +24 -0
  136. package/mjs/utils/multitenant.js +170 -0
  137. package/mjs/utils/parseQuery.d.ts +25 -0
  138. package/mjs/utils/parseQuery.js +156 -0
  139. package/mjs/utils/reqForm.d.ts +2 -0
  140. package/mjs/utils/reqForm.js +33 -0
  141. package/mjs/utils/reqMeta.d.ts +2 -0
  142. package/mjs/utils/reqMeta.js +13 -0
  143. package/mjs/utils/reqQuery.d.ts +2 -0
  144. package/mjs/utils/reqQuery.js +10 -0
  145. package/mjs/utils/serializeQuery.d.ts +13 -0
  146. package/mjs/utils/serializeQuery.js +65 -0
  147. package/mjs/utils/setHandlerSchema.d.ts +4 -0
  148. package/mjs/utils/setHandlerSchema.js +15 -0
  149. package/mjs/utils/shim.d.ts +1 -0
  150. package/mjs/utils/shim.js +18 -0
  151. package/mjs/utils/upperFirst.d.ts +1 -0
  152. package/mjs/utils/upperFirst.js +6 -0
  153. package/mjs/utils/withValidationLibrary.d.ts +76 -0
  154. package/mjs/utils/withValidationLibrary.js +123 -0
  155. package/package.json +29 -6
  156. package/.npmignore +0 -2
  157. package/StreamJSONResponse.d.ts +0 -17
  158. package/StreamJSONResponse.js +0 -54
  159. package/VovkApp.js +0 -185
  160. package/client/clientizeController.d.ts +0 -4
  161. package/client/clientizeController.js +0 -92
  162. package/client/defaultFetcher.d.ts +0 -4
  163. package/client/defaultFetcher.js +0 -49
  164. package/client/defaultHandler.d.ts +0 -2
  165. package/client/defaultHandler.js +0 -22
  166. package/client/defaultStreamHandler.d.ts +0 -4
  167. package/client/index.d.ts +0 -4
  168. package/client/index.js +0 -5
  169. package/client/types.d.ts +0 -100
  170. package/createDecorator.d.ts +0 -4
  171. package/createVovkApp.js +0 -118
  172. package/index.d.ts +0 -60
  173. package/index.js +0 -20
  174. package/types.d.ts +0 -157
  175. package/types.js +0 -65
  176. package/utils/generateStaticAPI.d.ts +0 -4
  177. package/utils/generateStaticAPI.js +0 -18
  178. package/utils/getSchema.d.ts +0 -8
  179. package/utils/getSchema.js +0 -38
  180. package/utils/reqForm.js +0 -13
  181. package/utils/reqQuery.d.ts +0 -3
  182. package/utils/reqQuery.js +0 -25
  183. package/utils/setClientValidatorsForHandler.d.ts +0 -5
  184. package/utils/setClientValidatorsForHandler.js +0 -25
  185. package/worker/index.d.ts +0 -3
  186. package/worker/index.js +0 -7
  187. package/worker/promisifyWorker.d.ts +0 -2
  188. package/worker/promisifyWorker.js +0 -141
  189. package/worker/types.d.ts +0 -31
  190. package/worker/worker.d.ts +0 -1
  191. package/worker/worker.js +0 -43
  192. /package/{client → cjs/client}/types.js +0 -0
  193. /package/{utils → cjs/utils}/reqMeta.js +0 -0
  194. /package/{utils → cjs/utils}/shim.d.ts +0 -0
  195. /package/{utils → cjs/utils}/shim.js +0 -0
  196. /package/{worker → mjs/client}/types.js +0 -0
package/cjs/index.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.initSegment = exports.prefix = exports.options = exports.head = exports.del = exports.patch = exports.put = exports.post = exports.get = exports.vovkSchemaToOpenAPI = exports.openAPIToVovkSchema = exports.openapi = exports.progressive = exports.createCodeExamples = exports.createLLMTools = exports.multitenant = exports.createStandardValidation = exports.withValidationLibrary = exports.generateStaticAPI = exports.createFetcher = exports.fetcher = exports.createRPC = exports.createDecorator = exports.createVovkApp = exports.HttpMethod = exports.HttpStatus = exports.HttpException = exports.JSONLinesResponse = exports.VovkSchemaIdEnum = void 0;
5
+ const createVovkApp_1 = require("./createVovkApp");
6
+ Object.defineProperty(exports, "createVovkApp", { enumerable: true, get: function () { return createVovkApp_1.createVovkApp; } });
7
+ const types_1 = require("./types");
8
+ Object.defineProperty(exports, "HttpStatus", { enumerable: true, get: function () { return types_1.HttpStatus; } });
9
+ Object.defineProperty(exports, "HttpMethod", { enumerable: true, get: function () { return types_1.HttpMethod; } });
10
+ Object.defineProperty(exports, "VovkSchemaIdEnum", { enumerable: true, get: function () { return types_1.VovkSchemaIdEnum; } });
11
+ const index_1 = require("./client/index");
12
+ Object.defineProperty(exports, "createRPC", { enumerable: true, get: function () { return index_1.createRPC; } });
13
+ Object.defineProperty(exports, "fetcher", { enumerable: true, get: function () { return index_1.fetcher; } });
14
+ Object.defineProperty(exports, "createFetcher", { enumerable: true, get: function () { return index_1.createFetcher; } });
15
+ Object.defineProperty(exports, "progressive", { enumerable: true, get: function () { return index_1.progressive; } });
16
+ const index_2 = require("./openapi/index");
17
+ Object.defineProperty(exports, "openapi", { enumerable: true, get: function () { return index_2.openapi; } });
18
+ Object.defineProperty(exports, "openAPIToVovkSchema", { enumerable: true, get: function () { return index_2.openAPIToVovkSchema; } });
19
+ Object.defineProperty(exports, "vovkSchemaToOpenAPI", { enumerable: true, get: function () { return index_2.vovkSchemaToOpenAPI; } });
20
+ const HttpException_1 = require("./HttpException");
21
+ Object.defineProperty(exports, "HttpException", { enumerable: true, get: function () { return HttpException_1.HttpException; } });
22
+ const createDecorator_1 = require("./utils/createDecorator");
23
+ Object.defineProperty(exports, "createDecorator", { enumerable: true, get: function () { return createDecorator_1.createDecorator; } });
24
+ const JSONLinesResponse_1 = require("./JSONLinesResponse");
25
+ Object.defineProperty(exports, "JSONLinesResponse", { enumerable: true, get: function () { return JSONLinesResponse_1.JSONLinesResponse; } });
26
+ const generateStaticAPI_1 = require("./utils/generateStaticAPI");
27
+ Object.defineProperty(exports, "generateStaticAPI", { enumerable: true, get: function () { return generateStaticAPI_1.generateStaticAPI; } });
28
+ const withValidationLibrary_1 = require("./utils/withValidationLibrary");
29
+ Object.defineProperty(exports, "withValidationLibrary", { enumerable: true, get: function () { return withValidationLibrary_1.withValidationLibrary; } });
30
+ const createStandardValidation_1 = require("./utils/createStandardValidation");
31
+ Object.defineProperty(exports, "createStandardValidation", { enumerable: true, get: function () { return createStandardValidation_1.createStandardValidation; } });
32
+ const multitenant_1 = require("./utils/multitenant");
33
+ Object.defineProperty(exports, "multitenant", { enumerable: true, get: function () { return multitenant_1.multitenant; } });
34
+ const createLLMTools_1 = require("./utils/createLLMTools");
35
+ Object.defineProperty(exports, "createLLMTools", { enumerable: true, get: function () { return createLLMTools_1.createLLMTools; } });
36
+ const createCodeExamples_1 = require("./utils/createCodeExamples");
37
+ Object.defineProperty(exports, "createCodeExamples", { enumerable: true, get: function () { return createCodeExamples_1.createCodeExamples; } });
38
+ _a = (0, createVovkApp_1.createVovkApp)(), exports.get = _a.get, exports.post = _a.post, exports.put = _a.put, exports.patch = _a.patch, exports.del = _a.del, exports.head = _a.head, exports.options = _a.options, exports.prefix = _a.prefix, exports.initSegment = _a.initSegment;
@@ -0,0 +1,2 @@
1
+ import { HttpStatus } from '../types';
2
+ export declare const error: (status: HttpStatus, message: string) => (target: import("../types").KnownAny, propertyKey: string) => void;
@@ -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_REQUESTS]: '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
+ openapi: {
62
+ ...handlerSchema?.openapi,
63
+ responses: {
64
+ ...handlerSchema?.openapi?.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?.openapi?.responses?.[status]?.content?.['application/json']?.schema
82
+ ?.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,23 @@
1
+ import { HttpMethod } from '../types';
2
+ export interface VerbMapEntry {
3
+ noParams?: string;
4
+ withParams?: string;
5
+ default?: string;
6
+ }
7
+ export declare const VERB_MAP: Record<HttpMethod, VerbMapEntry>;
8
+ export declare function capitalize(str: string): string;
9
+ interface GenerateFnNameOptions {
10
+ /** Segments to strip out (e.g. ['api','v1']) */
11
+ ignoreSegments?: string[];
12
+ }
13
+ /**
14
+ * Turn an HTTP method + OpenAPI path into a camelCased function name.
15
+ *
16
+ * Examples:
17
+ * generateFnName('GET', '/users') // "listUsers"
18
+ * generateFnName('GET', '/users/{id}') // "getUsersById"
19
+ * generateFnName('POST', '/v1/api/orders') // "createOrders"
20
+ * generateFnName('PATCH', '/users/{userId}/profile') // "patchUsersProfileByUserId"
21
+ */
22
+ export declare function generateFnName(method: HttpMethod, rawPath: string, opts?: GenerateFnNameOptions): string;
23
+ export {};
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERB_MAP = void 0;
4
+ exports.capitalize = capitalize;
5
+ exports.generateFnName = generateFnName;
6
+ exports.VERB_MAP = {
7
+ GET: { noParams: 'list', withParams: 'get' },
8
+ POST: { default: 'create' },
9
+ PUT: { default: 'update' },
10
+ PATCH: { default: 'patch' },
11
+ DELETE: { default: 'delete' },
12
+ HEAD: { default: 'head' },
13
+ OPTIONS: { default: 'options' },
14
+ };
15
+ function capitalize(str) {
16
+ if (str.length === 0)
17
+ return '';
18
+ return str[0].toUpperCase() + str.slice(1);
19
+ }
20
+ const DEFAULT_OPTIONS = {
21
+ ignoreSegments: ['api'],
22
+ };
23
+ /**
24
+ * Turn an HTTP method + OpenAPI path into a camelCased function name.
25
+ *
26
+ * Examples:
27
+ * generateFnName('GET', '/users') // "listUsers"
28
+ * generateFnName('GET', '/users/{id}') // "getUsersById"
29
+ * generateFnName('POST', '/v1/api/orders') // "createOrders"
30
+ * generateFnName('PATCH', '/users/{userId}/profile') // "patchUsersProfileByUserId"
31
+ */
32
+ function generateFnName(method, rawPath, opts = {}) {
33
+ const { ignoreSegments } = {
34
+ ...DEFAULT_OPTIONS,
35
+ ...opts,
36
+ };
37
+ // 1. Clean & split path
38
+ const parts = rawPath
39
+ .replace(/^\/|\/$/g, '') // strip leading/trailing slash
40
+ .split('/')
41
+ .filter((seg) => !ignoreSegments?.includes(seg.toLowerCase()))
42
+ .filter(Boolean);
43
+ // 2. Separate resource tokens from path-params
44
+ const resources = [];
45
+ const params = [];
46
+ parts.forEach((seg) => {
47
+ const match = seg.match(/^{?([^}]+)}?$/);
48
+ if (match) {
49
+ params.push(match[1]);
50
+ }
51
+ else {
52
+ resources.push(seg);
53
+ }
54
+ });
55
+ // 3. Pick base verb from VERB_MAP
56
+ let baseVerb;
57
+ if (method === 'GET') {
58
+ baseVerb = params.length ? exports.VERB_MAP.GET.withParams : exports.VERB_MAP.GET.noParams;
59
+ }
60
+ else {
61
+ baseVerb = exports.VERB_MAP[method].default;
62
+ }
63
+ // 4. Build the “resource” part
64
+ const resourcePart = resources.map(capitalize).join('');
65
+ // 5. Build the “ByParam” suffix
66
+ const byParams = params.length ? 'By' + params.map(capitalize).join('') : '';
67
+ // 6. Combine and ensure camelCase
68
+ const rawName = `${baseVerb}${resourcePart}${byParams}`;
69
+ return rawName[0].toLowerCase() + rawName.slice(1);
70
+ }
71
+ /*
72
+ // --- Example usage ---
73
+ console.log(generateFnName('GET', '/users')); // listUsers
74
+ console.log(generateFnName('GET', '/users/{id}')); // getUsersById
75
+ console.log(generateFnName('POST', '/users')); // createUsers
76
+ console.log(generateFnName('PATCH', '/users/{userId}/profile')); // patchUsersProfileByUserId
77
+ console.log(generateFnName('DELETE', '/v1/api/orders/{orderId}')); // deleteOrdersByOrderId
78
+
79
+ // You can also enable singularization:
80
+ console.log(generateFnName('GET', '/users/{userId}/orders', { singularizeResources: true })); // getUserOrderByUserId
81
+ */
@@ -0,0 +1,12 @@
1
+ import type { OperationObject } from 'openapi3-ts/oas31';
2
+ import { vovkSchemaToOpenAPI } from './vovkSchemaToOpenAPI';
3
+ import { openAPIToVovkSchema } from './openAPIToVovkSchema';
4
+ import type { KnownAny } from '../types';
5
+ type OperationObjectWithCustomProperties = OperationObject & {
6
+ [key in `${'x' | 'X'}-${string}`]: KnownAny;
7
+ };
8
+ export declare const openapiDecorator: (openAPIOperationObject?: OperationObjectWithCustomProperties | undefined) => (target: KnownAny, propertyKey: string) => void;
9
+ export declare const openapi: ((openAPIOperationObject?: OperationObjectWithCustomProperties | undefined) => (target: KnownAny, propertyKey: string) => void) & {
10
+ error: (status: import("../types").HttpStatus, message: string) => (target: KnownAny, propertyKey: string) => void;
11
+ };
12
+ export { vovkSchemaToOpenAPI, openAPIToVovkSchema };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openAPIToVovkSchema = exports.vovkSchemaToOpenAPI = exports.openapi = exports.openapiDecorator = void 0;
4
+ const vovkSchemaToOpenAPI_1 = require("./vovkSchemaToOpenAPI");
5
+ Object.defineProperty(exports, "vovkSchemaToOpenAPI", { enumerable: true, get: function () { return vovkSchemaToOpenAPI_1.vovkSchemaToOpenAPI; } });
6
+ const openAPIToVovkSchema_1 = require("./openAPIToVovkSchema");
7
+ Object.defineProperty(exports, "openAPIToVovkSchema", { enumerable: true, get: function () { return openAPIToVovkSchema_1.openAPIToVovkSchema; } });
8
+ const error_1 = require("./error");
9
+ const createDecorator_1 = require("../utils/createDecorator");
10
+ exports.openapiDecorator = (0, createDecorator_1.createDecorator)(null, (openAPIOperationObject = {}) => {
11
+ return (handlerSchema) => {
12
+ return {
13
+ ...handlerSchema,
14
+ openapi: {
15
+ ...handlerSchema?.openapi,
16
+ ...openAPIOperationObject,
17
+ },
18
+ };
19
+ };
20
+ });
21
+ exports.openapi = Object.assign(exports.openapiDecorator, { error: error_1.error });
@@ -0,0 +1,3 @@
1
+ import { ComponentsObject } from 'openapi3-ts/oas31';
2
+ import { SimpleJSONSchema } from '../../types';
3
+ export declare function applyComponentsSchemas(schema: SimpleJSONSchema, components: ComponentsObject['schemas'], mixinName: string): SimpleJSONSchema | SimpleJSONSchema[];
@@ -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 { type VovkSchema, VovkStrictConfig } from '../../types';
2
+ export declare function openAPIToVovkSchema({ apiRoot, source: { object: openAPIObject }, getModuleName, getMethodName, errorMessageKey, package: packageJson, mixinName, }: VovkStrictConfig['openApiMixins'][string] & {
3
+ mixinName: string;
4
+ }): VovkSchema;
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openAPIToVovkSchema = openAPIToVovkSchema;
4
+ const types_1 = require("../../types");
5
+ const generateFnName_1 = require("../generateFnName");
6
+ const camelCase_1 = require("../../utils/camelCase");
7
+ const applyComponentsSchemas_1 = require("./applyComponentsSchemas");
8
+ const inlineRefs_1 = require("./inlineRefs");
9
+ const getNamesNestJS = (operationObject) => {
10
+ const operationId = operationObject.operationId;
11
+ if (!operationId) {
12
+ throw new Error('Operation ID is required for NestJS module name generation');
13
+ }
14
+ const controllerHandlerMatch = operationId?.match(/^([A-Z][a-zA-Z0-9]*)_([a-zA-Z0-9_]+)/);
15
+ if (!controllerHandlerMatch) {
16
+ throw new Error(`Invalid operationId format for NestJS: ${operationId}`);
17
+ }
18
+ const [controllerName, handlerName] = controllerHandlerMatch.slice(1, 3);
19
+ return [controllerName.replace(/Controller$/, 'RPC'), handlerName];
20
+ };
21
+ const normalizeGetModuleName = (getModuleName) => {
22
+ if (getModuleName === 'nestjs-operation-id') {
23
+ getModuleName = ({ operationObject }) => getNamesNestJS(operationObject)[0];
24
+ }
25
+ else if (typeof getModuleName === 'string') {
26
+ const moduleName = getModuleName;
27
+ getModuleName = () => moduleName;
28
+ }
29
+ else if (typeof getModuleName !== 'function') {
30
+ throw new Error('getModuleName must be a function or one of the predefined strings');
31
+ }
32
+ return getModuleName;
33
+ };
34
+ const normalizeGetMethodName = (getMethodName) => {
35
+ if (getMethodName === 'nestjs-operation-id') {
36
+ getMethodName = ({ operationObject }) => getNamesNestJS(operationObject)[1];
37
+ }
38
+ else if (getMethodName === 'camel-case-operation-id') {
39
+ getMethodName = ({ operationObject }) => {
40
+ const operationId = operationObject.operationId;
41
+ if (!operationId) {
42
+ throw new Error('Operation ID is required for camel-case method name generation');
43
+ }
44
+ return (0, camelCase_1.camelCase)(operationId);
45
+ };
46
+ }
47
+ else if (getMethodName === 'auto') {
48
+ getMethodName = ({ operationObject, method, path }) => {
49
+ const operationId = operationObject.operationId;
50
+ const isCamelCase = operationId && /^[a-z][a-zA-Z0-9]*$/.test(operationId);
51
+ const isSnakeCase = operationId && /^[a-z][a-z0-9_]+$/.test(operationId);
52
+ return isCamelCase ? operationId : isSnakeCase ? (0, camelCase_1.camelCase)(operationId) : (0, generateFnName_1.generateFnName)(method, path);
53
+ };
54
+ }
55
+ else if (typeof getMethodName !== 'function') {
56
+ throw new Error('getMethodName must be a function or one of the predefined strings');
57
+ }
58
+ return getMethodName;
59
+ };
60
+ function openAPIToVovkSchema({ apiRoot, source: { object: openAPIObject }, getModuleName = 'api', getMethodName = 'auto', errorMessageKey, package: packageJson, mixinName, }) {
61
+ const forceApiRoot = apiRoot ??
62
+ openAPIObject.servers?.[0]?.url ??
63
+ ('host' in openAPIObject
64
+ ? `https://${openAPIObject.host}${'basePath' in openAPIObject ? openAPIObject.basePath : ''}`
65
+ : null);
66
+ if (!forceApiRoot) {
67
+ throw new Error('API root URL is required in OpenAPI configuration');
68
+ }
69
+ const schema = {
70
+ $schema: types_1.VovkSchemaIdEnum.SCHEMA,
71
+ segments: {
72
+ [mixinName]: {
73
+ $schema: types_1.VovkSchemaIdEnum.SEGMENT,
74
+ emitSchema: true,
75
+ segmentName: mixinName,
76
+ segmentType: 'mixin',
77
+ controllers: {},
78
+ meta: {
79
+ components: openAPIObject.components,
80
+ package: packageJson,
81
+ },
82
+ },
83
+ },
84
+ };
85
+ const segment = schema.segments[mixinName];
86
+ getModuleName = normalizeGetModuleName(getModuleName);
87
+ getMethodName = normalizeGetMethodName(getMethodName);
88
+ return Object.entries(openAPIObject.paths ?? {}).reduce((acc, [path, operations]) => {
89
+ Object.entries(operations ?? {})
90
+ .filter(([, operation]) => operation && typeof operation === 'object')
91
+ .forEach(([method, operation]) => {
92
+ const rpcModuleName = getModuleName({
93
+ method: method.toUpperCase(),
94
+ path,
95
+ openAPIObject,
96
+ operationObject: operation,
97
+ });
98
+ const handlerName = getMethodName({
99
+ method: method.toUpperCase(),
100
+ path,
101
+ openAPIObject,
102
+ operationObject: operation,
103
+ });
104
+ segment.controllers[rpcModuleName] ??= {
105
+ forceApiRoot,
106
+ rpcModuleName,
107
+ handlers: {},
108
+ };
109
+ const parameters = (0, inlineRefs_1.inlineRefs)(operation.parameters ?? [], openAPIObject);
110
+ const queryProperties = parameters.filter((p) => p.in === 'query') ?? null;
111
+ const pathProperties = parameters.filter((p) => p.in === 'path') ?? null;
112
+ const query = queryProperties?.length
113
+ ? {
114
+ type: 'object',
115
+ properties: Object.fromEntries(queryProperties.map((p) => [p.name, p.schema])),
116
+ required: queryProperties.filter((p) => p.required).map((p) => p.name),
117
+ }
118
+ : null;
119
+ const params = pathProperties?.length
120
+ ? {
121
+ type: 'object',
122
+ properties: Object.fromEntries(pathProperties.map((p) => [p.name, p.schema])),
123
+ required: pathProperties.filter((p) => p.required).map((p) => p.name),
124
+ }
125
+ : null;
126
+ // TODO: how to utilize ReferenceObject?
127
+ const requestBodyContent = (0, inlineRefs_1.inlineRefs)(operation.requestBody, openAPIObject)?.content ?? {};
128
+ const jsonBody = requestBodyContent['application/json']?.schema ?? null;
129
+ const formDataBody = requestBodyContent['multipart/form-data']?.schema ?? null;
130
+ let urlEncodedBody = requestBodyContent['application/x-www-form-urlencoded']?.schema ?? null;
131
+ if (formDataBody && urlEncodedBody && JSON.stringify(formDataBody) === JSON.stringify(urlEncodedBody)) {
132
+ urlEncodedBody = null; // Avoid duplication if both form-data and url-encoded bodies are the same
133
+ }
134
+ if (formDataBody) {
135
+ Object.assign(formDataBody, {
136
+ 'x-formData': true,
137
+ 'x-tsType': 'FormData',
138
+ });
139
+ }
140
+ if (urlEncodedBody) {
141
+ Object.assign(urlEncodedBody, {
142
+ 'x-formData': true,
143
+ 'x-tsType': 'FormData',
144
+ });
145
+ }
146
+ const bodySchemas = [jsonBody, formDataBody, urlEncodedBody].filter(Boolean);
147
+ const body = !bodySchemas.length
148
+ ? null
149
+ : bodySchemas.length === 1
150
+ ? bodySchemas[0]
151
+ : {
152
+ anyOf: bodySchemas,
153
+ };
154
+ const output = operation.responses?.['200']?.content?.['application/json']?.schema ??
155
+ operation.responses?.['201']?.content?.['application/json']?.schema ??
156
+ null;
157
+ const iteration = operation.responses?.['200']?.content?.['application/jsonl']?.schema ??
158
+ operation.responses?.['201']?.content?.['application/jsonl']?.schema ??
159
+ operation.responses?.['200']?.content?.['application/jsonlines']?.schema ??
160
+ operation.responses?.['201']?.content?.['application/jsonlines']?.schema ??
161
+ null;
162
+ if (errorMessageKey) {
163
+ operation['x-errorMessageKey'] = errorMessageKey;
164
+ }
165
+ const componentsSchemas = openAPIObject.components?.schemas ??
166
+ ('definitions' in openAPIObject ? openAPIObject.definitions : {});
167
+ segment.controllers[rpcModuleName].handlers[handlerName] = {
168
+ httpMethod: method.toUpperCase(),
169
+ path,
170
+ openapi: operation,
171
+ validation: {
172
+ ...(query && {
173
+ query: (0, applyComponentsSchemas_1.applyComponentsSchemas)(query, componentsSchemas, mixinName),
174
+ }),
175
+ ...(params && {
176
+ params: (0, applyComponentsSchemas_1.applyComponentsSchemas)(params, componentsSchemas, mixinName),
177
+ }),
178
+ ...(body && {
179
+ body: (0, applyComponentsSchemas_1.applyComponentsSchemas)(body, componentsSchemas, mixinName),
180
+ }),
181
+ ...(output && {
182
+ output: (0, applyComponentsSchemas_1.applyComponentsSchemas)(output, componentsSchemas, mixinName),
183
+ }),
184
+ ...(iteration && {
185
+ iteration: (0, applyComponentsSchemas_1.applyComponentsSchemas)(iteration, componentsSchemas, mixinName),
186
+ }),
187
+ },
188
+ };
189
+ });
190
+ return acc;
191
+ }, schema);
192
+ }
@@ -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;