vovk 3.0.0-draft.21 → 3.0.0-draft.211

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 (169) 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 +14 -0
  7. package/{StreamJSONResponse.js → cjs/JSONLinesResponse.js} +15 -10
  8. package/{Segment.d.ts → cjs/VovkApp.d.ts} +11 -10
  9. package/cjs/VovkApp.js +189 -0
  10. package/cjs/client/createRPC.d.ts +3 -0
  11. package/cjs/client/createRPC.js +87 -0
  12. package/{client → cjs/client}/defaultHandler.d.ts +1 -1
  13. package/cjs/client/defaultHandler.js +22 -0
  14. package/cjs/client/defaultStreamHandler.d.ts +4 -0
  15. package/{client → cjs/client}/defaultStreamHandler.js +11 -12
  16. package/cjs/client/fetcher.d.ts +13 -0
  17. package/cjs/client/fetcher.js +90 -0
  18. package/cjs/client/index.d.ts +3 -0
  19. package/cjs/client/index.js +8 -0
  20. package/cjs/client/types.d.ts +111 -0
  21. package/{createSegment.d.ts → cjs/createVovkApp.d.ts} +11 -10
  22. package/cjs/createVovkApp.js +132 -0
  23. package/cjs/index.d.ts +65 -0
  24. package/cjs/index.js +37 -0
  25. package/cjs/openapi/error.d.ts +2 -0
  26. package/cjs/openapi/error.js +100 -0
  27. package/cjs/openapi/generateFnName.d.ts +23 -0
  28. package/cjs/openapi/generateFnName.js +81 -0
  29. package/cjs/openapi/index.d.ts +12 -0
  30. package/cjs/openapi/index.js +21 -0
  31. package/cjs/openapi/openAPIToVovkSchema.d.ts +2 -0
  32. package/cjs/openapi/openAPIToVovkSchema.js +197 -0
  33. package/cjs/openapi/vovkSchemaToOpenAPI.d.ts +9 -0
  34. package/cjs/openapi/vovkSchemaToOpenAPI.js +237 -0
  35. package/cjs/types.d.ts +364 -0
  36. package/cjs/types.js +74 -0
  37. package/cjs/utils/camelCase.d.ts +6 -0
  38. package/cjs/utils/camelCase.js +37 -0
  39. package/cjs/utils/createCodeExamples.d.ts +19 -0
  40. package/cjs/utils/createCodeExamples.js +114 -0
  41. package/cjs/utils/createDecorator.d.ts +6 -0
  42. package/{createDecorator.js → cjs/utils/createDecorator.js} +24 -16
  43. package/cjs/utils/createLLMFunctions.d.ts +20 -0
  44. package/cjs/utils/createLLMFunctions.js +100 -0
  45. package/cjs/utils/generateStaticAPI.d.ts +4 -0
  46. package/cjs/utils/generateStaticAPI.js +30 -0
  47. package/cjs/utils/getSchema.d.ts +21 -0
  48. package/cjs/utils/getSchema.js +43 -0
  49. package/cjs/utils/multitenant.d.ts +24 -0
  50. package/cjs/utils/multitenant.js +170 -0
  51. package/cjs/utils/parseQuery.d.ts +25 -0
  52. package/cjs/utils/parseQuery.js +156 -0
  53. package/cjs/utils/reqForm.d.ts +2 -0
  54. package/cjs/utils/reqForm.js +33 -0
  55. package/{utils → cjs/utils}/reqMeta.d.ts +1 -2
  56. package/cjs/utils/reqQuery.d.ts +2 -0
  57. package/cjs/utils/reqQuery.js +10 -0
  58. package/cjs/utils/serializeQuery.d.ts +13 -0
  59. package/cjs/utils/serializeQuery.js +65 -0
  60. package/cjs/utils/setHandlerSchema.d.ts +4 -0
  61. package/cjs/utils/setHandlerSchema.js +15 -0
  62. package/cjs/utils/withStandard.d.ts +51 -0
  63. package/cjs/utils/withStandard.js +30 -0
  64. package/cjs/utils/withValidationLibrary.d.ts +49 -0
  65. package/cjs/utils/withValidationLibrary.js +123 -0
  66. package/mjs/HttpException.d.ts +7 -0
  67. package/mjs/HttpException.js +15 -0
  68. package/mjs/JSONLinesResponse.d.ts +14 -0
  69. package/mjs/JSONLinesResponse.js +59 -0
  70. package/mjs/VovkApp.d.ts +29 -0
  71. package/mjs/VovkApp.js +189 -0
  72. package/mjs/client/createRPC.d.ts +3 -0
  73. package/mjs/client/createRPC.js +87 -0
  74. package/mjs/client/defaultHandler.d.ts +2 -0
  75. package/mjs/client/defaultHandler.js +22 -0
  76. package/mjs/client/defaultStreamHandler.d.ts +4 -0
  77. package/mjs/client/defaultStreamHandler.js +81 -0
  78. package/mjs/client/fetcher.d.ts +13 -0
  79. package/mjs/client/fetcher.js +90 -0
  80. package/mjs/client/index.d.ts +3 -0
  81. package/mjs/client/index.js +8 -0
  82. package/mjs/client/types.d.ts +111 -0
  83. package/mjs/createVovkApp.d.ts +63 -0
  84. package/mjs/createVovkApp.js +132 -0
  85. package/mjs/index.d.ts +65 -0
  86. package/mjs/index.js +37 -0
  87. package/mjs/openapi/error.d.ts +2 -0
  88. package/mjs/openapi/error.js +100 -0
  89. package/mjs/openapi/generateFnName.d.ts +23 -0
  90. package/mjs/openapi/generateFnName.js +81 -0
  91. package/mjs/openapi/index.d.ts +12 -0
  92. package/mjs/openapi/index.js +21 -0
  93. package/mjs/openapi/openAPIToVovkSchema.d.ts +2 -0
  94. package/mjs/openapi/openAPIToVovkSchema.js +197 -0
  95. package/mjs/openapi/vovkSchemaToOpenAPI.d.ts +9 -0
  96. package/mjs/openapi/vovkSchemaToOpenAPI.js +237 -0
  97. package/mjs/types.d.ts +364 -0
  98. package/mjs/types.js +74 -0
  99. package/mjs/utils/camelCase.d.ts +6 -0
  100. package/mjs/utils/camelCase.js +37 -0
  101. package/mjs/utils/createCodeExamples.d.ts +19 -0
  102. package/mjs/utils/createCodeExamples.js +114 -0
  103. package/mjs/utils/createDecorator.d.ts +6 -0
  104. package/mjs/utils/createDecorator.js +46 -0
  105. package/mjs/utils/createLLMFunctions.d.ts +20 -0
  106. package/mjs/utils/createLLMFunctions.js +100 -0
  107. package/mjs/utils/generateStaticAPI.d.ts +4 -0
  108. package/mjs/utils/generateStaticAPI.js +30 -0
  109. package/mjs/utils/getSchema.d.ts +21 -0
  110. package/mjs/utils/getSchema.js +43 -0
  111. package/mjs/utils/multitenant.d.ts +24 -0
  112. package/mjs/utils/multitenant.js +170 -0
  113. package/mjs/utils/parseQuery.d.ts +25 -0
  114. package/mjs/utils/parseQuery.js +156 -0
  115. package/mjs/utils/reqForm.d.ts +2 -0
  116. package/mjs/utils/reqForm.js +33 -0
  117. package/mjs/utils/reqMeta.d.ts +2 -0
  118. package/mjs/utils/reqMeta.js +13 -0
  119. package/mjs/utils/reqQuery.d.ts +2 -0
  120. package/mjs/utils/reqQuery.js +10 -0
  121. package/mjs/utils/serializeQuery.d.ts +13 -0
  122. package/mjs/utils/serializeQuery.js +65 -0
  123. package/mjs/utils/setHandlerSchema.d.ts +4 -0
  124. package/mjs/utils/setHandlerSchema.js +15 -0
  125. package/mjs/utils/shim.d.ts +1 -0
  126. package/mjs/utils/shim.js +18 -0
  127. package/mjs/utils/withStandard.d.ts +51 -0
  128. package/mjs/utils/withStandard.js +30 -0
  129. package/mjs/utils/withValidationLibrary.d.ts +49 -0
  130. package/mjs/utils/withValidationLibrary.js +123 -0
  131. package/package.json +30 -5
  132. package/.npmignore +0 -2
  133. package/Segment.js +0 -182
  134. package/StreamJSONResponse.d.ts +0 -17
  135. package/client/clientizeController.d.ts +0 -4
  136. package/client/clientizeController.js +0 -92
  137. package/client/defaultFetcher.d.ts +0 -4
  138. package/client/defaultFetcher.js +0 -49
  139. package/client/defaultHandler.js +0 -21
  140. package/client/defaultStreamHandler.d.ts +0 -4
  141. package/client/index.d.ts +0 -4
  142. package/client/index.js +0 -5
  143. package/client/types.d.ts +0 -100
  144. package/createDecorator.d.ts +0 -4
  145. package/createSegment.js +0 -118
  146. package/generateStaticAPI.d.ts +0 -4
  147. package/generateStaticAPI.js +0 -18
  148. package/index.d.ts +0 -60
  149. package/index.js +0 -20
  150. package/types.d.ts +0 -155
  151. package/types.js +0 -65
  152. package/utils/getSchema.d.ts +0 -8
  153. package/utils/getSchema.js +0 -38
  154. package/utils/reqQuery.d.ts +0 -3
  155. package/utils/reqQuery.js +0 -25
  156. package/utils/setClientValidatorsForHandler.d.ts +0 -5
  157. package/utils/setClientValidatorsForHandler.js +0 -28
  158. package/worker/index.d.ts +0 -3
  159. package/worker/index.js +0 -7
  160. package/worker/promisifyWorker.d.ts +0 -2
  161. package/worker/promisifyWorker.js +0 -141
  162. package/worker/types.d.ts +0 -31
  163. package/worker/worker.d.ts +0 -1
  164. package/worker/worker.js +0 -43
  165. /package/{client → cjs/client}/types.js +0 -0
  166. /package/{utils → cjs/utils}/reqMeta.js +0 -0
  167. /package/{utils → cjs/utils}/shim.d.ts +0 -0
  168. /package/{utils → cjs/utils}/shim.js +0 -0
  169. /package/{worker → mjs/client}/types.js +0 -0
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetcher = exports.DEFAULT_ERROR_MESSAGE = void 0;
4
+ exports.createFetcher = createFetcher;
5
+ const types_js_1 = require("../types.js");
6
+ const HttpException_js_1 = require("../HttpException.js");
7
+ exports.DEFAULT_ERROR_MESSAGE = 'Unknown error at default fetcher';
8
+ function createFetcher({ prepareRequestInit, transformResponse, } = {}) {
9
+ // fetcher uses HttpException class to throw errors of fake HTTP status 0 if client-side error occurs
10
+ // For normal HTTP errors, it uses message and status code from the response of VovkErrorResponse type
11
+ const newFetcher = async ({ httpMethod, getEndpoint, validate, defaultHandler, defaultStreamHandler }, options) => {
12
+ const { params, query, body, apiRoot, disableClientValidation, init, interpretAs } = options;
13
+ const endpoint = getEndpoint({ apiRoot, params, query });
14
+ const unusedParams = new URL(endpoint.startsWith('/') ? `http://localhost${endpoint}` : endpoint).pathname
15
+ .split('/')
16
+ .filter((segment) => segment.startsWith(':'));
17
+ if (unusedParams.length) {
18
+ throw new HttpException_js_1.HttpException(types_js_1.HttpStatus.NULL, `Unused params: ${unusedParams.join(', ')} in ${endpoint}`, {
19
+ body,
20
+ query,
21
+ params,
22
+ endpoint,
23
+ });
24
+ }
25
+ if (!disableClientValidation) {
26
+ try {
27
+ await validate({ body, query, params, endpoint });
28
+ }
29
+ catch (e) {
30
+ // if HttpException is thrown, rethrow it
31
+ if (e instanceof HttpException_js_1.HttpException)
32
+ throw e;
33
+ // otherwise, throw HttpException with status 0
34
+ throw new HttpException_js_1.HttpException(types_js_1.HttpStatus.NULL, e.message ?? exports.DEFAULT_ERROR_MESSAGE, {
35
+ body,
36
+ query,
37
+ params,
38
+ endpoint,
39
+ });
40
+ }
41
+ }
42
+ let requestInit = {
43
+ method: httpMethod,
44
+ ...init,
45
+ headers: {
46
+ accept: 'application/jsonl, application/json',
47
+ ...init?.headers,
48
+ },
49
+ };
50
+ if (body instanceof FormData) {
51
+ requestInit.body = body;
52
+ }
53
+ else if (body) {
54
+ requestInit.body = JSON.stringify(body);
55
+ }
56
+ requestInit = prepareRequestInit
57
+ ? ((await prepareRequestInit(requestInit, options)) ?? requestInit)
58
+ : requestInit;
59
+ let response;
60
+ try {
61
+ response = await fetch(endpoint, requestInit);
62
+ }
63
+ catch (e) {
64
+ // handle network errors
65
+ throw new HttpException_js_1.HttpException(types_js_1.HttpStatus.NULL, (e?.message ?? exports.DEFAULT_ERROR_MESSAGE) + ' ' + endpoint, {
66
+ body,
67
+ query,
68
+ params,
69
+ endpoint,
70
+ });
71
+ }
72
+ const contentType = interpretAs ?? response.headers.get('content-type');
73
+ let resp;
74
+ if (contentType?.startsWith('application/jsonl')) {
75
+ resp = defaultStreamHandler(response);
76
+ }
77
+ else if (contentType?.startsWith('application/json')) {
78
+ resp = defaultHandler(response);
79
+ }
80
+ else {
81
+ resp = response;
82
+ }
83
+ resp = await resp;
84
+ return transformResponse
85
+ ? ((await transformResponse(resp, options, requestInit)) ?? resp)
86
+ : resp;
87
+ };
88
+ return newFetcher;
89
+ }
90
+ exports.fetcher = createFetcher();
@@ -0,0 +1,3 @@
1
+ export { createRPC } from './createRPC.js';
2
+ export { fetcher, createFetcher } from './fetcher.js';
3
+ export type { VovkClient, VovkClientFetcher, VovkDefaultFetcherOptions, VovkValidateOnClient, VovkStreamAsyncIterable, } from './types.js';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFetcher = exports.fetcher = exports.createRPC = void 0;
4
+ var createRPC_js_1 = require("./createRPC.js");
5
+ Object.defineProperty(exports, "createRPC", { enumerable: true, get: function () { return createRPC_js_1.createRPC; } });
6
+ var fetcher_js_1 = require("./fetcher.js");
7
+ Object.defineProperty(exports, "fetcher", { enumerable: true, get: function () { return fetcher_js_1.fetcher; } });
8
+ Object.defineProperty(exports, "createFetcher", { enumerable: true, get: function () { return fetcher_js_1.createFetcher; } });
@@ -0,0 +1,111 @@
1
+ import type { KnownAny, HttpMethod, ControllerStaticMethod, VovkHandlerSchema, VovkControllerSchema, VovkSegmentSchema, VovkSchema, VovkRequest } from '../types.js';
2
+ import type { JSONLinesResponse } from '../JSONLinesResponse.js';
3
+ import type { NextResponse } from 'next/server';
4
+ type OmitNullable<T> = {
5
+ [K in keyof T as T[K] extends null | undefined ? never : K]: T[K];
6
+ };
7
+ type Empty = {};
8
+ export type StaticMethodInput<T extends ((req: VovkRequest<KnownAny, KnownAny, KnownAny>, params: KnownAny) => KnownAny) & {
9
+ __types?: {
10
+ isForm: boolean;
11
+ };
12
+ }> = OmitNullable<(Parameters<T>[0] extends VovkRequest<infer BODY, infer QUERY, infer PARAMS> ? (BODY extends Record<KnownAny, KnownAny> ? {
13
+ body: NonNullable<T['__types']>['isForm'] extends true ? FormData : BODY;
14
+ } : Empty) & (QUERY extends Record<KnownAny, KnownAny> ? {
15
+ query: QUERY;
16
+ } : Empty) & (PARAMS extends Record<KnownAny, KnownAny> ? {
17
+ params: PARAMS;
18
+ } : Empty) : Empty) & (Parameters<T>[1] extends Record<KnownAny, KnownAny> ? {
19
+ params: Parameters<T>[1];
20
+ } : Empty)>;
21
+ type ToPromise<T> = T extends PromiseLike<unknown> ? T : Promise<T>;
22
+ export type VovkStreamAsyncIterable<T> = {
23
+ status: number;
24
+ [Symbol.dispose](): Promise<void> | void;
25
+ [Symbol.asyncDispose](): Promise<void> | void;
26
+ [Symbol.asyncIterator](): AsyncIterator<T>;
27
+ cancel: () => Promise<void> | void;
28
+ };
29
+ type StaticMethodReturn<T extends ControllerStaticMethod> = ReturnType<T> extends NextResponse<infer U> | Promise<NextResponse<infer U>> ? U : ReturnType<T> extends Response | Promise<Response> ? Awaited<ReturnType<T>> : ReturnType<T>;
30
+ type StaticMethodReturnPromise<T extends ControllerStaticMethod> = ToPromise<StaticMethodReturn<T>>;
31
+ type StaticMethodOptions<T extends (req: VovkRequest<KnownAny, KnownAny, KnownAny>, params: KnownAny) => void | object | JSONLinesResponse<STREAM> | Promise<JSONLinesResponse<STREAM>>, OPTS extends Record<string, KnownAny>, STREAM, R, F extends VovkDefaultFetcherOptions<KnownAny>> = Partial<OPTS & {
32
+ transform: (staticMethodReturn: Awaited<StaticMethodReturn<T>>) => R;
33
+ fetcher: VovkClientFetcher<F>;
34
+ }>;
35
+ type ClientMethodReturn<T extends (req: VovkRequest<KnownAny, KnownAny, KnownAny>, params: KnownAny) => void | object | JSONLinesResponse<STREAM> | Promise<JSONLinesResponse<STREAM>>, STREAM, R> = ReturnType<T> extends Promise<JSONLinesResponse<infer U>> | JSONLinesResponse<infer U> | Iterator<infer U> | AsyncIterator<infer U> ? Promise<VovkStreamAsyncIterable<U>> : R extends object ? Promise<Awaited<R>> : StaticMethodReturnPromise<T>;
36
+ type ClientMethod<T extends ((req: VovkRequest<KnownAny, KnownAny, KnownAny>, params: KnownAny) => void | object | JSONLinesResponse<STREAM> | Promise<JSONLinesResponse<STREAM>>) & {
37
+ __types?: {
38
+ body: KnownAny;
39
+ query: KnownAny;
40
+ params: KnownAny;
41
+ output: KnownAny;
42
+ iteration: KnownAny;
43
+ isForm: boolean;
44
+ };
45
+ }, OPTS extends Record<string, KnownAny>, STREAM extends KnownAny = unknown> = (IsEmptyObject<StaticMethodInput<T>> extends true ? <R, F extends VovkDefaultFetcherOptions<KnownAny> = VovkDefaultFetcherOptions<OPTS>>(options?: Prettify<StaticMethodOptions<T, OPTS, STREAM, R, F>>) => ClientMethodReturn<T, STREAM, R> : <R, F extends VovkDefaultFetcherOptions<KnownAny> = VovkDefaultFetcherOptions<OPTS>>(options: Prettify<StaticMethodInput<T> & StaticMethodOptions<T, OPTS, STREAM, R, F>>) => ClientMethodReturn<T, STREAM, R>) & {
46
+ isRPC: true;
47
+ path: string;
48
+ schema: VovkHandlerSchema;
49
+ controllerSchema: VovkControllerSchema;
50
+ segmentSchema: VovkSegmentSchema;
51
+ fullSchema: VovkSchema;
52
+ __types: T['__types'];
53
+ };
54
+ type OmitNever<T> = {
55
+ [K in keyof T as T[K] extends never ? never : K]: T[K];
56
+ };
57
+ type VovkClientWithNever<T, OPTS extends {
58
+ [key: string]: KnownAny;
59
+ }> = {
60
+ [K in keyof T]: T[K] extends (...args: KnownAny) => KnownAny ? ClientMethod<T[K], OPTS> : never;
61
+ };
62
+ export type VovkClient<T, OPTS extends {
63
+ [key: string]: KnownAny;
64
+ }> = OmitNever<VovkClientWithNever<T, OPTS>>;
65
+ export type VovkClientFetcher<OPTS> = (options: {
66
+ name: string;
67
+ httpMethod: HttpMethod;
68
+ getEndpoint: (data: {
69
+ apiRoot: string | undefined;
70
+ params: {
71
+ [key: string]: string;
72
+ };
73
+ query: {
74
+ [key: string]: string;
75
+ };
76
+ }) => string;
77
+ validate: (input: {
78
+ body?: unknown;
79
+ query?: unknown;
80
+ params?: unknown;
81
+ endpoint: string;
82
+ }) => void | Promise<void>;
83
+ defaultStreamHandler: (response: Response) => Promise<VovkStreamAsyncIterable<unknown>>;
84
+ defaultHandler: (response: Response) => Promise<unknown>;
85
+ }, input: {
86
+ body: unknown;
87
+ query: {
88
+ [key: string]: string;
89
+ };
90
+ params: {
91
+ [key: string]: string;
92
+ };
93
+ } & OPTS) => KnownAny;
94
+ export type VovkDefaultFetcherOptions<T> = T & {
95
+ apiRoot?: string;
96
+ disableClientValidation?: boolean;
97
+ validateOnClient?: VovkValidateOnClient;
98
+ interpretAs?: string;
99
+ init?: RequestInit;
100
+ };
101
+ export type VovkValidateOnClient = (input: {
102
+ body?: unknown;
103
+ query?: unknown;
104
+ params?: unknown;
105
+ endpoint: string;
106
+ }, validation: Omit<Exclude<VovkHandlerSchema['validation'], undefined>, 'output' | 'iteration'>, fullSchema: VovkSchema) => void | Promise<void>;
107
+ type IsEmptyObject<T> = T extends object ? keyof T extends never ? true : false : false;
108
+ type Prettify<T> = {
109
+ [K in keyof T]: T[K];
110
+ } & {};
111
+ export {};
@@ -1,5 +1,6 @@
1
- import { type _KnownAny as KnownAny, type _DecoratorOptions as DecoratorOptions, type _VovkRequest as VovkRequest, type _StaticClass as StaticClass } from './types';
2
- export declare function _createSegment(): {
1
+ import type { NextRequest } from 'next/server';
2
+ import { type KnownAny, type DecoratorOptions, type VovkRequest, type StaticClass } from './types.js';
3
+ export declare function createVovkApp(): {
3
4
  get: {
4
5
  (givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
5
6
  auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
@@ -32,30 +33,30 @@ export declare function _createSegment(): {
32
33
  initVovk: (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>;
39
40
  }) => {
40
- GET: (req: VovkRequest, data: {
41
+ GET: (req: NextRequest, data: {
41
42
  params: Promise<Record<string, string[]>>;
42
43
  }) => Promise<Response>;
43
- POST: (req: VovkRequest, data: {
44
+ POST: (req: NextRequest, data: {
44
45
  params: Promise<Record<string, string[]>>;
45
46
  }) => Promise<Response>;
46
- PUT: (req: VovkRequest, data: {
47
+ PUT: (req: NextRequest, data: {
47
48
  params: Promise<Record<string, string[]>>;
48
49
  }) => Promise<Response>;
49
- PATCH: (req: VovkRequest, data: {
50
+ PATCH: (req: NextRequest, data: {
50
51
  params: Promise<Record<string, string[]>>;
51
52
  }) => Promise<Response>;
52
- DELETE: (req: VovkRequest, data: {
53
+ DELETE: (req: NextRequest, data: {
53
54
  params: Promise<Record<string, string[]>>;
54
55
  }) => Promise<Response>;
55
- HEAD: (req: VovkRequest, data: {
56
+ HEAD: (req: NextRequest, data: {
56
57
  params: Promise<Record<string, string[]>>;
57
58
  }) => Promise<Response>;
58
- OPTIONS: (req: VovkRequest, data: {
59
+ OPTIONS: (req: NextRequest, data: {
59
60
  params: Promise<Record<string, string[]>>;
60
61
  }) => Promise<Response>;
61
62
  };
@@ -0,0 +1,132 @@
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_js_1 = require("./VovkApp.js");
8
+ const types_js_1 = require("./types.js");
9
+ const getSchema_js_1 = __importDefault(require("./utils/getSchema.js"));
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('Decorators are intended for server-side use 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.func = originalMethod._sourceMethod?.func;
35
+ controller._handlers = {
36
+ ...controller._handlers,
37
+ [propertyKey]: {
38
+ ...schema,
39
+ ...(controller._handlers ?? {})[propertyKey],
40
+ path,
41
+ httpMethod,
42
+ },
43
+ };
44
+ methods[path] = originalMethod;
45
+ methods[path]._options = options;
46
+ controller._handlersMetadata = {
47
+ ...controller._handlersMetadata,
48
+ [propertyKey]: {
49
+ ...(controller._handlersMetadata ?? {})[propertyKey],
50
+ staticParams: options?.staticParams,
51
+ },
52
+ };
53
+ };
54
+ function createVovkApp() {
55
+ const vovkApp = new VovkApp_js_1.VovkApp();
56
+ const createHTTPDecorator = (httpMethod) => {
57
+ function decoratorCreator(givenPath = '', options) {
58
+ const path = trimPath(givenPath);
59
+ function decorator(givenTarget, propertyKey) {
60
+ const controller = givenTarget;
61
+ assignSchema({ controller, propertyKey, path, options, httpMethod, vovkApp });
62
+ }
63
+ return decorator;
64
+ }
65
+ const auto = (options) => {
66
+ function decorator(givenTarget, propertyKey) {
67
+ const controller = givenTarget;
68
+ const methods = vovkApp.routes[httpMethod].get(controller) ?? {};
69
+ vovkApp.routes[httpMethod].set(controller, methods);
70
+ controller._handlers = {
71
+ ...controller._handlers,
72
+ [propertyKey]: {
73
+ ...(controller._handlers ?? {})[propertyKey],
74
+ httpMethod,
75
+ },
76
+ };
77
+ const properties = Object.keys(controller._handlers[propertyKey]?.validation?.params?.properties ?? {});
78
+ const kebab = toKebabCase(propertyKey); // 🥙
79
+ const path = properties.length ? `${kebab}/${properties.map((prop) => `:${prop}`).join('/')}` : kebab;
80
+ assignSchema({ controller, propertyKey, path, options, httpMethod, vovkApp });
81
+ }
82
+ return decorator;
83
+ };
84
+ const enhancedDecoratorCreator = decoratorCreator;
85
+ enhancedDecoratorCreator.auto = auto;
86
+ return enhancedDecoratorCreator;
87
+ };
88
+ const prefix = (givenPath = '') => {
89
+ const path = trimPath(givenPath);
90
+ return (givenTarget) => {
91
+ const controller = givenTarget;
92
+ controller._prefix = path;
93
+ return givenTarget;
94
+ };
95
+ };
96
+ const initVovk = (options) => {
97
+ options.segmentName = trimPath(options.segmentName ?? '');
98
+ for (const [rpcModuleName, controller] of Object.entries(options.controllers ?? {})) {
99
+ controller._rpcModuleName = rpcModuleName;
100
+ controller._activated = true;
101
+ controller._onError = options?.onError;
102
+ }
103
+ async function GET_DEV(req, data) {
104
+ const params = await data.params;
105
+ if (params[Object.keys(params)[0]]?.[0] === '_schema_') {
106
+ const schema = await (0, getSchema_js_1.default)(options);
107
+ return vovkApp.respond(200, { schema });
108
+ }
109
+ return vovkApp.GET(req, data);
110
+ }
111
+ return {
112
+ GET: process.env.NODE_ENV === 'development' ? GET_DEV : vovkApp.GET,
113
+ POST: vovkApp.POST,
114
+ PUT: vovkApp.PUT,
115
+ PATCH: vovkApp.PATCH,
116
+ DELETE: vovkApp.DELETE,
117
+ HEAD: vovkApp.HEAD,
118
+ OPTIONS: vovkApp.OPTIONS,
119
+ };
120
+ };
121
+ return {
122
+ get: createHTTPDecorator(types_js_1.HttpMethod.GET),
123
+ post: createHTTPDecorator(types_js_1.HttpMethod.POST),
124
+ put: createHTTPDecorator(types_js_1.HttpMethod.PUT),
125
+ patch: createHTTPDecorator(types_js_1.HttpMethod.PATCH),
126
+ del: createHTTPDecorator(types_js_1.HttpMethod.DELETE),
127
+ head: createHTTPDecorator(types_js_1.HttpMethod.HEAD),
128
+ options: createHTTPDecorator(types_js_1.HttpMethod.OPTIONS),
129
+ prefix,
130
+ initVovk,
131
+ };
132
+ }
package/cjs/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 VovkSegmentSchema, type VovkControllerSchema, type VovkHandlerSchema, type VovkSchema, type VovkConfig, type VovkStrictConfig, type VovkValidationType, type VovkLLMFunction, type VovkTypedMethod } from './types';
3
+ import { type VovkClient, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, type VovkStreamAsyncIterable, createRPC, fetcher, createFetcher } 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 { withStandard } from './utils/withStandard';
11
+ import { multitenant } from './utils/multitenant';
12
+ import { createLLMFunctions } from './utils/createLLMFunctions';
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 VovkControllerSchema, type VovkHandlerSchema, type VovkSchema, type VovkConfig, type VovkStrictConfig, type VovkValidationType, type VovkLLMFunction, type VovkTypedMethod, VovkSchemaIdEnum, JSONLinesResponse, HttpException, HttpStatus, HttpMethod, createVovkApp, createDecorator, createRPC, fetcher, createFetcher, generateStaticAPI, withValidationLibrary, withStandard, multitenant, createLLMFunctions, createCodeExamples, 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, initVovk: (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/cjs/index.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.initVovk = exports.prefix = exports.options = exports.head = exports.del = exports.patch = exports.put = exports.post = exports.get = exports.vovkSchemaToOpenAPI = exports.openAPIToVovkSchema = exports.openapi = exports.createCodeExamples = exports.createLLMFunctions = exports.multitenant = exports.withStandard = 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
+ const index_2 = require("./openapi/index");
16
+ Object.defineProperty(exports, "openapi", { enumerable: true, get: function () { return index_2.openapi; } });
17
+ Object.defineProperty(exports, "openAPIToVovkSchema", { enumerable: true, get: function () { return index_2.openAPIToVovkSchema; } });
18
+ Object.defineProperty(exports, "vovkSchemaToOpenAPI", { enumerable: true, get: function () { return index_2.vovkSchemaToOpenAPI; } });
19
+ const HttpException_1 = require("./HttpException");
20
+ Object.defineProperty(exports, "HttpException", { enumerable: true, get: function () { return HttpException_1.HttpException; } });
21
+ const createDecorator_1 = require("./utils/createDecorator");
22
+ Object.defineProperty(exports, "createDecorator", { enumerable: true, get: function () { return createDecorator_1.createDecorator; } });
23
+ const JSONLinesResponse_1 = require("./JSONLinesResponse");
24
+ Object.defineProperty(exports, "JSONLinesResponse", { enumerable: true, get: function () { return JSONLinesResponse_1.JSONLinesResponse; } });
25
+ const generateStaticAPI_1 = require("./utils/generateStaticAPI");
26
+ Object.defineProperty(exports, "generateStaticAPI", { enumerable: true, get: function () { return generateStaticAPI_1.generateStaticAPI; } });
27
+ const withValidationLibrary_1 = require("./utils/withValidationLibrary");
28
+ Object.defineProperty(exports, "withValidationLibrary", { enumerable: true, get: function () { return withValidationLibrary_1.withValidationLibrary; } });
29
+ const withStandard_1 = require("./utils/withStandard");
30
+ Object.defineProperty(exports, "withStandard", { enumerable: true, get: function () { return withStandard_1.withStandard; } });
31
+ const multitenant_1 = require("./utils/multitenant");
32
+ Object.defineProperty(exports, "multitenant", { enumerable: true, get: function () { return multitenant_1.multitenant; } });
33
+ const createLLMFunctions_1 = require("./utils/createLLMFunctions");
34
+ Object.defineProperty(exports, "createLLMFunctions", { enumerable: true, get: function () { return createLLMFunctions_1.createLLMFunctions; } });
35
+ const createCodeExamples_1 = require("./utils/createCodeExamples");
36
+ Object.defineProperty(exports, "createCodeExamples", { enumerable: true, get: function () { return createCodeExamples_1.createCodeExamples; } });
37
+ _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.initVovk = _a.initVovk;
@@ -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 {};