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
@@ -0,0 +1,133 @@
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
+ const originalMethod = controller[propertyKey];
30
+ originalMethod._controller = controller;
31
+ originalMethod._sourceMethod = originalMethod._sourceMethod ?? originalMethod;
32
+ const schema = originalMethod._sourceMethod._getSchema?.(controller);
33
+ originalMethod.schema = schema;
34
+ originalMethod.fn = originalMethod._sourceMethod?.fn;
35
+ originalMethod.models = originalMethod._sourceMethod?.models;
36
+ originalMethod._sourceMethod.wrapper = originalMethod;
37
+ controller._handlers = {
38
+ ...controller._handlers,
39
+ [propertyKey]: {
40
+ ...schema,
41
+ ...(controller._handlers ?? {})[propertyKey],
42
+ path,
43
+ httpMethod,
44
+ },
45
+ };
46
+ methods[path] = originalMethod;
47
+ methods[path]._options = options;
48
+ controller._handlersMetadata = {
49
+ ...controller._handlersMetadata,
50
+ [propertyKey]: {
51
+ ...(controller._handlersMetadata ?? {})[propertyKey],
52
+ staticParams: options?.staticParams,
53
+ },
54
+ };
55
+ };
56
+ function createVovkApp() {
57
+ const vovkApp = new VovkApp_1.VovkApp();
58
+ const createHTTPDecorator = (httpMethod) => {
59
+ function decoratorCreator(givenPath = '', options) {
60
+ const path = trimPath(givenPath);
61
+ function decorator(givenTarget, propertyKey) {
62
+ const controller = givenTarget;
63
+ assignSchema({ controller, propertyKey, path, options, httpMethod, vovkApp });
64
+ }
65
+ return decorator;
66
+ }
67
+ const auto = (options) => {
68
+ function decorator(givenTarget, propertyKey) {
69
+ const controller = givenTarget;
70
+ const methods = vovkApp.routes[httpMethod].get(controller) ?? {};
71
+ vovkApp.routes[httpMethod].set(controller, methods);
72
+ controller._handlers = {
73
+ ...controller._handlers,
74
+ [propertyKey]: {
75
+ ...(controller._handlers ?? {})[propertyKey],
76
+ httpMethod,
77
+ },
78
+ };
79
+ const properties = Object.keys(controller._handlers[propertyKey]?.validation?.params?.properties ?? {});
80
+ const kebab = toKebabCase(propertyKey); // 🥙
81
+ const path = properties.length ? `${kebab}/${properties.map((prop) => `:${prop}`).join('/')}` : kebab;
82
+ assignSchema({ controller, propertyKey, path, options, httpMethod, vovkApp });
83
+ }
84
+ return decorator;
85
+ };
86
+ const enhancedDecoratorCreator = decoratorCreator;
87
+ enhancedDecoratorCreator.auto = auto;
88
+ return enhancedDecoratorCreator;
89
+ };
90
+ const prefix = (givenPath = '') => {
91
+ const path = trimPath(givenPath);
92
+ return (givenTarget) => {
93
+ const controller = givenTarget;
94
+ controller._prefix = path;
95
+ return givenTarget;
96
+ };
97
+ };
98
+ const initSegment = (options) => {
99
+ options.segmentName = trimPath(options.segmentName ?? '');
100
+ for (const [rpcModuleName, controller] of Object.entries(options.controllers ?? {})) {
101
+ controller._rpcModuleName = rpcModuleName;
102
+ controller._onError = options?.onError;
103
+ }
104
+ async function GET_DEV(req, data) {
105
+ const params = await data.params;
106
+ if (params[Object.keys(params)[0]]?.[0] === '_schema_') {
107
+ const schema = await (0, getSchema_1.default)(options);
108
+ return vovkApp.respond(200, { schema });
109
+ }
110
+ return vovkApp.GET(req, data);
111
+ }
112
+ return {
113
+ GET: process.env.NODE_ENV === 'development' ? GET_DEV : vovkApp.GET,
114
+ POST: vovkApp.POST,
115
+ PUT: vovkApp.PUT,
116
+ PATCH: vovkApp.PATCH,
117
+ DELETE: vovkApp.DELETE,
118
+ HEAD: vovkApp.HEAD,
119
+ OPTIONS: vovkApp.OPTIONS,
120
+ };
121
+ };
122
+ return {
123
+ get: createHTTPDecorator(types_1.HttpMethod.GET),
124
+ post: createHTTPDecorator(types_1.HttpMethod.POST),
125
+ put: createHTTPDecorator(types_1.HttpMethod.PUT),
126
+ patch: createHTTPDecorator(types_1.HttpMethod.PATCH),
127
+ del: createHTTPDecorator(types_1.HttpMethod.DELETE),
128
+ head: createHTTPDecorator(types_1.HttpMethod.HEAD),
129
+ options: createHTTPDecorator(types_1.HttpMethod.OPTIONS),
130
+ prefix,
131
+ initSegment,
132
+ };
133
+ }
package/mjs/index.d.ts ADDED
@@ -0,0 +1,65 @@
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 VovkStrictConfig, type VovkValidationType, type VovkLLMTool, type VovkTypedMethod } from './types';
3
+ import { type VovkClient, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, type VovkStreamAsyncIterable, createRPC, fetcher, createFetcher, progressive } from './client/index';
4
+ import { openapi, openAPIToVovkSchema, vovkSchemaToOpenAPI } from './openapi/index';
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 { createCodeExamples } from './utils/createCodeExamples';
14
+ export { type KnownAny, type VovkClient, type VovkClientFetcher, type VovkDefaultFetcherOptions, 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 VovkValidationType, type VovkLLMTool, type VovkTypedMethod, VovkSchemaIdEnum, JSONLinesResponse, HttpException, HttpStatus, HttpMethod, createVovkApp, createDecorator, createRPC, fetcher, createFetcher, generateStaticAPI, withValidationLibrary, createStandardValidation, multitenant, createLLMTools, createCodeExamples, progressive, openapi, openAPIToVovkSchema, vovkSchemaToOpenAPI, };
15
+ export declare const get: {
16
+ (givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
17
+ auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
18
+ }, post: {
19
+ (givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
20
+ auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
21
+ }, put: {
22
+ (givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
23
+ auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
24
+ }, patch: {
25
+ (givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
26
+ auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
27
+ }, del: {
28
+ (givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
29
+ auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
30
+ }, head: {
31
+ (givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
32
+ auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
33
+ }, options: {
34
+ (givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
35
+ auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
36
+ }, prefix: (givenPath?: string) => (givenTarget: KnownAny) => any, initSegment: (options: {
37
+ segmentName?: string;
38
+ controllers: Record<string, import("./types").StaticClass>;
39
+ exposeValidation?: boolean;
40
+ emitSchema?: boolean;
41
+ forceApiRoot?: string;
42
+ onError?: (err: Error, req: VovkRequest) => void | Promise<void>;
43
+ }) => {
44
+ GET: (req: import("next/server").NextRequest, data: {
45
+ params: Promise<Record<string, string[]>>;
46
+ }) => Promise<Response>;
47
+ POST: (req: import("next/server").NextRequest, data: {
48
+ params: Promise<Record<string, string[]>>;
49
+ }) => Promise<Response>;
50
+ PUT: (req: import("next/server").NextRequest, data: {
51
+ params: Promise<Record<string, string[]>>;
52
+ }) => Promise<Response>;
53
+ PATCH: (req: import("next/server").NextRequest, data: {
54
+ params: Promise<Record<string, string[]>>;
55
+ }) => Promise<Response>;
56
+ DELETE: (req: import("next/server").NextRequest, data: {
57
+ params: Promise<Record<string, string[]>>;
58
+ }) => Promise<Response>;
59
+ HEAD: (req: import("next/server").NextRequest, data: {
60
+ params: Promise<Record<string, string[]>>;
61
+ }) => Promise<Response>;
62
+ OPTIONS: (req: import("next/server").NextRequest, data: {
63
+ params: Promise<Record<string, string[]>>;
64
+ }) => Promise<Response>;
65
+ };
package/mjs/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;