vovk 3.0.0-draft.46 → 3.0.0-draft.460

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 +82 -0
  48. package/cjs/utils/createStandardValidation.js +34 -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 +77 -0
  81. package/cjs/utils/withValidationLibrary.js +124 -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 +82 -0
  128. package/mjs/utils/createStandardValidation.js +34 -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 +77 -0
  164. package/mjs/utils/withValidationLibrary.js +124 -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
@@ -1,61 +1,64 @@
1
+ import type { NextRequest } from 'next/server';
1
2
  import { type KnownAny, type DecoratorOptions, type VovkRequest, type StaticClass } from './types';
2
3
  export declare function createVovkApp(): {
3
4
  get: {
4
- (givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
5
+ (givenPath?: string | undefined, options?: DecoratorOptions | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
5
6
  auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
6
7
  };
7
8
  post: {
8
- (givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
9
+ (givenPath?: string | undefined, options?: Omit<DecoratorOptions, "staticParams"> | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
9
10
  auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
10
11
  };
11
12
  put: {
12
- (givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
13
+ (givenPath?: string | undefined, options?: Omit<DecoratorOptions, "staticParams"> | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
13
14
  auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
14
15
  };
15
16
  patch: {
16
- (givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
17
+ (givenPath?: string | undefined, options?: Omit<DecoratorOptions, "staticParams"> | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
17
18
  auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
18
19
  };
19
20
  del: {
20
- (givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
21
+ (givenPath?: string | undefined, options?: Omit<DecoratorOptions, "staticParams"> | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
21
22
  auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
22
23
  };
23
24
  head: {
24
- (givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
25
+ (givenPath?: string | undefined, options?: Omit<DecoratorOptions, "staticParams"> | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
25
26
  auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
26
27
  };
27
28
  options: {
28
- (givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
29
+ (givenPath?: string | undefined, options?: Omit<DecoratorOptions, "staticParams"> | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
29
30
  auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
30
31
  };
31
32
  prefix: (givenPath?: string) => (givenTarget: KnownAny) => any;
32
- initVovk: (options: {
33
+ initSegment: (options: {
33
34
  segmentName?: string;
34
35
  controllers: Record<string, StaticClass>;
35
- workers?: Record<string, StaticClass>;
36
36
  exposeValidation?: boolean;
37
37
  emitSchema?: boolean;
38
+ forceApiRoot?: string;
38
39
  onError?: (err: Error, req: VovkRequest) => void | Promise<void>;
40
+ onSuccess?: (resp: unknown, req: VovkRequest) => void | Promise<void>;
41
+ onBefore?: (req: VovkRequest) => void | Promise<void>;
39
42
  }) => {
40
- GET: (req: VovkRequest, data: {
43
+ GET: (req: NextRequest, data: {
41
44
  params: Promise<Record<string, string[]>>;
42
45
  }) => Promise<Response>;
43
- POST: (req: VovkRequest, data: {
46
+ POST: (req: NextRequest, data: {
44
47
  params: Promise<Record<string, string[]>>;
45
48
  }) => Promise<Response>;
46
- PUT: (req: VovkRequest, data: {
49
+ PUT: (req: NextRequest, data: {
47
50
  params: Promise<Record<string, string[]>>;
48
51
  }) => Promise<Response>;
49
- PATCH: (req: VovkRequest, data: {
52
+ PATCH: (req: NextRequest, data: {
50
53
  params: Promise<Record<string, string[]>>;
51
54
  }) => Promise<Response>;
52
- DELETE: (req: VovkRequest, data: {
55
+ DELETE: (req: NextRequest, data: {
53
56
  params: Promise<Record<string, string[]>>;
54
57
  }) => Promise<Response>;
55
- HEAD: (req: VovkRequest, data: {
58
+ HEAD: (req: NextRequest, data: {
56
59
  params: Promise<Record<string, string[]>>;
57
60
  }) => Promise<Response>;
58
- OPTIONS: (req: VovkRequest, data: {
61
+ OPTIONS: (req: NextRequest, data: {
59
62
  params: Promise<Record<string, string[]>>;
60
63
  }) => Promise<Response>;
61
64
  };
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createVovkApp = createVovkApp;
7
+ const VovkApp_1 = require("./VovkApp");
8
+ const types_1 = require("./types");
9
+ const getSchema_1 = __importDefault(require("./utils/getSchema"));
10
+ const trimPath = (path) => path.trim().replace(/^\/|\/$/g, '');
11
+ const isClass = (func) => typeof func === 'function' && /class/.test(func.toString());
12
+ const toKebabCase = (str) => str
13
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2') // Add hyphen between lowercase/digit and uppercase
14
+ .replace(/([A-Z])([A-Z])(?=[a-z])/g, '$1-$2') // Add hyphen between uppercase letters if the second one is followed by a lowercase
15
+ .toLowerCase()
16
+ .replace(/^-/, ''); // Remove leading hyphen
17
+ const assignSchema = ({ controller, propertyKey, path, options, httpMethod, vovkApp, }) => {
18
+ if (typeof window !== 'undefined') {
19
+ throw new Error('HTTP decorators can be used on server-side only. You have probably imported a controller on the client-side.');
20
+ }
21
+ if (!isClass(controller)) {
22
+ let decoratorName = httpMethod.toLowerCase();
23
+ if (decoratorName === 'delete')
24
+ decoratorName = 'del';
25
+ throw new Error(`Decorator must be used on a static class method. Check the controller method named "${propertyKey}" used with @${decoratorName}().`);
26
+ }
27
+ const methods = vovkApp.routes[httpMethod].get(controller) ?? {};
28
+ vovkApp.routes[httpMethod].set(controller, methods);
29
+ if (options?.cors) {
30
+ const optionsMethods = vovkApp.routes.OPTIONS.get(controller) ?? {};
31
+ optionsMethods[path] = (() => { });
32
+ optionsMethods[path]._options = options;
33
+ vovkApp.routes.OPTIONS.set(controller, optionsMethods);
34
+ }
35
+ const originalMethod = controller[propertyKey];
36
+ originalMethod._controller = controller;
37
+ originalMethod._sourceMethod = originalMethod._sourceMethod ?? originalMethod;
38
+ const schema = originalMethod._sourceMethod._getSchema?.(controller);
39
+ // TODO: Some of these assignments probably not needed anymore
40
+ originalMethod.schema = schema;
41
+ originalMethod.fn = originalMethod._sourceMethod?.fn;
42
+ originalMethod.models = originalMethod._sourceMethod?.models;
43
+ originalMethod._sourceMethod.wrapper = originalMethod;
44
+ controller._handlers = {
45
+ ...controller._handlers,
46
+ [propertyKey]: {
47
+ ...schema,
48
+ ...(controller._handlers ?? {})[propertyKey],
49
+ path,
50
+ httpMethod,
51
+ },
52
+ };
53
+ methods[path] = originalMethod;
54
+ methods[path]._options = options;
55
+ controller._handlersMetadata = {
56
+ ...controller._handlersMetadata,
57
+ [propertyKey]: {
58
+ ...(controller._handlersMetadata ?? {})[propertyKey],
59
+ staticParams: options?.staticParams,
60
+ },
61
+ };
62
+ };
63
+ function createVovkApp() {
64
+ const vovkApp = new VovkApp_1.VovkApp();
65
+ function createHTTPDecorator(httpMethod) {
66
+ function decoratorCreator(givenPath = '', options) {
67
+ const path = trimPath(givenPath);
68
+ function decorator(givenTarget, propertyKey) {
69
+ const controller = givenTarget;
70
+ assignSchema({ controller, propertyKey, path, options, httpMethod, vovkApp });
71
+ }
72
+ return decorator;
73
+ }
74
+ const auto = (options) => {
75
+ function decorator(givenTarget, propertyKey) {
76
+ const controller = givenTarget;
77
+ const methods = vovkApp.routes[httpMethod].get(controller) ?? {};
78
+ vovkApp.routes[httpMethod].set(controller, methods);
79
+ controller._handlers = {
80
+ ...controller._handlers,
81
+ [propertyKey]: {
82
+ ...(controller._handlers ?? {})[propertyKey],
83
+ httpMethod,
84
+ },
85
+ };
86
+ const properties = Object.keys(controller._handlers[propertyKey]?.validation?.params?.properties ?? {});
87
+ const kebab = toKebabCase(propertyKey); // 🥙
88
+ const path = properties.length ? `${kebab}/${properties.map((prop) => `{${prop}}`).join('/')}` : kebab;
89
+ assignSchema({ controller, propertyKey, path, options, httpMethod, vovkApp });
90
+ }
91
+ return decorator;
92
+ };
93
+ const enhancedDecoratorCreator = decoratorCreator;
94
+ enhancedDecoratorCreator.auto = auto;
95
+ return enhancedDecoratorCreator;
96
+ }
97
+ const prefix = (givenPath = '') => {
98
+ const path = trimPath(givenPath);
99
+ return (givenTarget) => {
100
+ const controller = givenTarget;
101
+ controller._prefix = path;
102
+ return givenTarget;
103
+ };
104
+ };
105
+ const initSegment = (options) => {
106
+ options.segmentName = trimPath(options.segmentName ?? '');
107
+ for (const [rpcModuleName, controller] of Object.entries(options.controllers ?? {})) {
108
+ controller._rpcModuleName = rpcModuleName;
109
+ controller._onError = options?.onError;
110
+ controller._onSuccess = options?.onSuccess;
111
+ controller._onBefore = options?.onBefore;
112
+ }
113
+ async function GET_DEV(req, data) {
114
+ const params = await data.params;
115
+ if (params[Object.keys(params)[0]]?.[0] === '_schema_') {
116
+ const schema = await (0, getSchema_1.default)(options);
117
+ return vovkApp.respond({
118
+ req: req,
119
+ statusCode: 200,
120
+ responseBody: { schema },
121
+ });
122
+ }
123
+ return vovkApp.GET(req, data);
124
+ }
125
+ return {
126
+ GET: process.env.NODE_ENV === 'development' ? GET_DEV : vovkApp.GET,
127
+ POST: vovkApp.POST,
128
+ PUT: vovkApp.PUT,
129
+ PATCH: vovkApp.PATCH,
130
+ DELETE: vovkApp.DELETE,
131
+ HEAD: vovkApp.HEAD,
132
+ OPTIONS: vovkApp.OPTIONS,
133
+ };
134
+ };
135
+ return {
136
+ get: createHTTPDecorator(types_1.HttpMethod.GET),
137
+ post: createHTTPDecorator(types_1.HttpMethod.POST),
138
+ put: createHTTPDecorator(types_1.HttpMethod.PUT),
139
+ patch: createHTTPDecorator(types_1.HttpMethod.PATCH),
140
+ del: createHTTPDecorator(types_1.HttpMethod.DELETE),
141
+ head: createHTTPDecorator(types_1.HttpMethod.HEAD),
142
+ options: createHTTPDecorator(types_1.HttpMethod.OPTIONS),
143
+ prefix,
144
+ initSegment,
145
+ };
146
+ }
package/cjs/index.d.ts ADDED
@@ -0,0 +1,69 @@
1
+ import { createVovkApp } from './createVovkApp';
2
+ import { HttpStatus, HttpMethod, VovkSchemaIdEnum, type KnownAny, type VovkErrorResponse, type VovkRequest, type VovkBody, type VovkQuery, type VovkParams, type VovkReturnType, type VovkYieldType, type VovkOutput, type VovkIteration, type VovkMetaSchema, type VovkSegmentSchema, type VovkControllerSchema, type VovkHandlerSchema, type VovkSchema, type VovkConfig, type VovkGeneratorConfig, type VovkReadmeConfig, type VovkSamplesConfig, type VovkPackageJson, type VovkOpenAPIMixin, type VovkOpenAPIMixinNormalized, type VovkStrictConfig, type VovkValidationType, type VovkLLMTool, type VovkTypedMethod, type VovkBasicJSONSchema, type VovkOperationObject } from './types';
3
+ import { type VovkRPCModule, type VovkFetcher, type VovkFetcherOptions, type VovkValidateOnClient, type VovkStreamAsyncIterable, createRPC, fetcher, createFetcher, progressive } from './client';
4
+ import { operation, openAPIToVovkSchema, vovkSchemaToOpenAPI } from './openapi';
5
+ import { HttpException } from './HttpException';
6
+ import { createDecorator } from './utils/createDecorator';
7
+ import { JSONLinesResponse } from './JSONLinesResponse';
8
+ import { generateStaticAPI } from './utils/generateStaticAPI';
9
+ import { withValidationLibrary } from './utils/withValidationLibrary';
10
+ import { createStandardValidation } from './utils/createStandardValidation';
11
+ import { multitenant } from './utils/multitenant';
12
+ import { createLLMTools } from './utils/createLLMTools';
13
+ import { createCodeSamples } from './utils/createCodeSamples';
14
+ import { createValidateOnClient } from './utils/createValidateOnClient';
15
+ import { resolveGeneratorConfigValues } from './utils/resolveGeneratorConfigValues';
16
+ export { type KnownAny, type VovkRPCModule, type VovkFetcher, type VovkFetcherOptions, type VovkStreamAsyncIterable, type VovkValidateOnClient, type VovkSegmentSchema, type VovkErrorResponse, type VovkRequest, type VovkOutput, type VovkIteration, type VovkBody, type VovkQuery, type VovkParams, type VovkYieldType, type VovkReturnType, type VovkMetaSchema, type VovkControllerSchema, type VovkHandlerSchema, type VovkSchema, type VovkConfig, type VovkStrictConfig, type VovkGeneratorConfig, type VovkPackageJson, type VovkReadmeConfig, type VovkSamplesConfig, type VovkOpenAPIMixin, type VovkOpenAPIMixinNormalized, type VovkValidationType, type VovkLLMTool, type VovkTypedMethod, type VovkBasicJSONSchema, type VovkOperationObject, VovkSchemaIdEnum, JSONLinesResponse, HttpException, HttpStatus, HttpMethod, createVovkApp, createDecorator, createRPC, fetcher, createFetcher, generateStaticAPI, withValidationLibrary, createStandardValidation, multitenant, createLLMTools, createCodeSamples, createValidateOnClient, progressive, operation, openAPIToVovkSchema, vovkSchemaToOpenAPI, resolveGeneratorConfigValues, };
17
+ export declare const get: {
18
+ (givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
19
+ auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
20
+ }, post: {
21
+ (givenPath?: string | undefined, options?: Omit<import("./types").DecoratorOptions, "staticParams"> | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
22
+ auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
23
+ }, put: {
24
+ (givenPath?: string | undefined, options?: Omit<import("./types").DecoratorOptions, "staticParams"> | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
25
+ auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
26
+ }, patch: {
27
+ (givenPath?: string | undefined, options?: Omit<import("./types").DecoratorOptions, "staticParams"> | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
28
+ auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
29
+ }, del: {
30
+ (givenPath?: string | undefined, options?: Omit<import("./types").DecoratorOptions, "staticParams"> | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
31
+ auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
32
+ }, head: {
33
+ (givenPath?: string | undefined, options?: Omit<import("./types").DecoratorOptions, "staticParams"> | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
34
+ auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
35
+ }, options: {
36
+ (givenPath?: string | undefined, options?: Omit<import("./types").DecoratorOptions, "staticParams"> | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
37
+ auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
38
+ }, prefix: (givenPath?: string) => (givenTarget: KnownAny) => any, initSegment: (options: {
39
+ segmentName?: string;
40
+ controllers: Record<string, import("./types").StaticClass>;
41
+ exposeValidation?: boolean;
42
+ emitSchema?: boolean;
43
+ forceApiRoot?: string;
44
+ onError?: (err: Error, req: VovkRequest) => void | Promise<void>;
45
+ onSuccess?: (resp: unknown, req: VovkRequest) => void | Promise<void>;
46
+ onBefore?: (req: VovkRequest) => void | Promise<void>;
47
+ }) => {
48
+ GET: (req: import("next/server").NextRequest, data: {
49
+ params: Promise<Record<string, string[]>>;
50
+ }) => Promise<Response>;
51
+ POST: (req: import("next/server").NextRequest, data: {
52
+ params: Promise<Record<string, string[]>>;
53
+ }) => Promise<Response>;
54
+ PUT: (req: import("next/server").NextRequest, data: {
55
+ params: Promise<Record<string, string[]>>;
56
+ }) => Promise<Response>;
57
+ PATCH: (req: import("next/server").NextRequest, data: {
58
+ params: Promise<Record<string, string[]>>;
59
+ }) => Promise<Response>;
60
+ DELETE: (req: import("next/server").NextRequest, data: {
61
+ params: Promise<Record<string, string[]>>;
62
+ }) => Promise<Response>;
63
+ HEAD: (req: import("next/server").NextRequest, data: {
64
+ params: Promise<Record<string, string[]>>;
65
+ }) => Promise<Response>;
66
+ OPTIONS: (req: import("next/server").NextRequest, data: {
67
+ params: Promise<Record<string, string[]>>;
68
+ }) => Promise<Response>;
69
+ };
package/cjs/index.js ADDED
@@ -0,0 +1,42 @@
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.resolveGeneratorConfigValues = exports.vovkSchemaToOpenAPI = exports.openAPIToVovkSchema = exports.operation = exports.progressive = exports.createValidateOnClient = exports.createCodeSamples = 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 client_1 = require("./client");
12
+ Object.defineProperty(exports, "createRPC", { enumerable: true, get: function () { return client_1.createRPC; } });
13
+ Object.defineProperty(exports, "fetcher", { enumerable: true, get: function () { return client_1.fetcher; } });
14
+ Object.defineProperty(exports, "createFetcher", { enumerable: true, get: function () { return client_1.createFetcher; } });
15
+ Object.defineProperty(exports, "progressive", { enumerable: true, get: function () { return client_1.progressive; } });
16
+ const openapi_1 = require("./openapi");
17
+ Object.defineProperty(exports, "operation", { enumerable: true, get: function () { return openapi_1.operation; } });
18
+ Object.defineProperty(exports, "openAPIToVovkSchema", { enumerable: true, get: function () { return openapi_1.openAPIToVovkSchema; } });
19
+ Object.defineProperty(exports, "vovkSchemaToOpenAPI", { enumerable: true, get: function () { return openapi_1.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 createCodeSamples_1 = require("./utils/createCodeSamples");
37
+ Object.defineProperty(exports, "createCodeSamples", { enumerable: true, get: function () { return createCodeSamples_1.createCodeSamples; } });
38
+ const createValidateOnClient_1 = require("./utils/createValidateOnClient");
39
+ Object.defineProperty(exports, "createValidateOnClient", { enumerable: true, get: function () { return createValidateOnClient_1.createValidateOnClient; } });
40
+ const resolveGeneratorConfigValues_1 = require("./utils/resolveGeneratorConfigValues");
41
+ Object.defineProperty(exports, "resolveGeneratorConfigValues", { enumerable: true, get: function () { return resolveGeneratorConfigValues_1.resolveGeneratorConfigValues; } });
42
+ _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_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;