vovk 3.0.0-draft.99 → 3.0.0
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.
- package/README.md +22 -13
- package/bin/index.mjs +10 -0
- package/dist/client/createRPC.d.ts +13 -3
- package/dist/client/createRPC.js +112 -50
- package/dist/client/defaultHandler.d.ts +5 -1
- package/dist/client/defaultHandler.js +12 -9
- package/dist/client/defaultStreamHandler.d.ts +16 -4
- package/dist/client/defaultStreamHandler.js +259 -62
- package/dist/client/fetcher.d.ts +41 -3
- package/dist/client/fetcher.js +125 -60
- package/dist/client/progressive.d.ts +15 -0
- package/dist/client/progressive.js +56 -0
- package/dist/{utils → client}/serializeQuery.d.ts +2 -2
- package/dist/{utils → client}/serializeQuery.js +1 -4
- package/dist/core/HttpException.d.ts +16 -0
- package/dist/core/HttpException.js +26 -0
- package/dist/core/JSONLinesResponder.d.ts +42 -0
- package/dist/core/JSONLinesResponder.js +92 -0
- package/dist/core/controllersToStaticParams.d.ts +13 -0
- package/dist/core/controllersToStaticParams.js +36 -0
- package/dist/core/createDecorator.d.ts +12 -0
- package/dist/{createDecorator.js → core/createDecorator.js} +18 -12
- package/dist/core/decorators.d.ts +59 -0
- package/dist/core/decorators.js +132 -0
- package/dist/core/getSchema.d.ts +21 -0
- package/dist/core/getSchema.js +31 -0
- package/dist/core/initSegment.d.ts +33 -0
- package/dist/core/initSegment.js +35 -0
- package/dist/core/multitenant.d.ts +33 -0
- package/dist/core/multitenant.js +132 -0
- package/dist/core/resolveGeneratorConfigValues.d.ts +19 -0
- package/dist/core/resolveGeneratorConfigValues.js +59 -0
- package/dist/{utils → core}/setHandlerSchema.d.ts +2 -2
- package/dist/{utils → core}/setHandlerSchema.js +1 -4
- package/dist/core/toDownloadResponse.d.ts +11 -0
- package/dist/core/toDownloadResponse.js +25 -0
- package/dist/core/vovkApp.d.ts +36 -0
- package/dist/core/vovkApp.js +316 -0
- package/dist/index.d.ts +25 -59
- package/dist/index.js +23 -23
- package/dist/internal.d.ts +17 -0
- package/dist/internal.js +10 -0
- package/dist/openapi/error.d.ts +2 -0
- package/dist/openapi/error.js +97 -0
- package/dist/openapi/openAPIToVovkSchema/applyComponentsSchemas.d.ts +3 -0
- package/dist/openapi/openAPIToVovkSchema/applyComponentsSchemas.js +65 -0
- package/dist/openapi/openAPIToVovkSchema/index.d.ts +5 -0
- package/dist/openapi/openAPIToVovkSchema/index.js +153 -0
- package/dist/openapi/openAPIToVovkSchema/inlineRefs.d.ts +9 -0
- package/dist/openapi/openAPIToVovkSchema/inlineRefs.js +99 -0
- package/dist/openapi/operation.d.ts +10 -0
- package/dist/openapi/operation.js +19 -0
- package/dist/openapi/tool.d.ts +2 -0
- package/dist/openapi/tool.js +12 -0
- package/dist/openapi/vovkSchemaToOpenAPI.d.ts +21 -0
- package/dist/openapi/vovkSchemaToOpenAPI.js +250 -0
- package/dist/req/bufferBody.d.ts +1 -0
- package/dist/req/bufferBody.js +30 -0
- package/dist/req/parseBody.d.ts +4 -0
- package/dist/req/parseBody.js +49 -0
- package/dist/req/parseForm.d.ts +1 -0
- package/dist/req/parseForm.js +24 -0
- package/dist/{utils → req}/parseQuery.d.ts +1 -2
- package/dist/{utils → req}/parseQuery.js +2 -5
- package/dist/req/reqMeta.d.ts +2 -0
- package/dist/{utils → req}/reqMeta.js +1 -4
- package/dist/req/reqQuery.d.ts +2 -0
- package/dist/req/reqQuery.js +4 -0
- package/dist/req/validateContentType.d.ts +1 -0
- package/dist/req/validateContentType.js +32 -0
- package/dist/samples/createCodeSamples.d.ts +20 -0
- package/dist/samples/createCodeSamples.js +293 -0
- package/dist/samples/objectToCode.d.ts +8 -0
- package/dist/samples/objectToCode.js +38 -0
- package/dist/samples/schemaToCode.d.ts +11 -0
- package/dist/samples/schemaToCode.js +264 -0
- package/dist/samples/schemaToObject.d.ts +2 -0
- package/dist/samples/schemaToObject.js +164 -0
- package/dist/samples/schemaToTsType.d.ts +2 -0
- package/dist/samples/schemaToTsType.js +114 -0
- package/dist/tools/ToModelOutput.d.ts +8 -0
- package/dist/tools/ToModelOutput.js +10 -0
- package/dist/tools/createTool.d.ts +126 -0
- package/dist/tools/createTool.js +6 -0
- package/dist/tools/createToolFactory.d.ts +135 -0
- package/dist/tools/createToolFactory.js +61 -0
- package/dist/tools/deriveTools.d.ts +46 -0
- package/dist/tools/deriveTools.js +134 -0
- package/dist/tools/toModelOutputDefault.d.ts +7 -0
- package/dist/tools/toModelOutputDefault.js +7 -0
- package/dist/tools/toModelOutputMCP.d.ts +30 -0
- package/dist/tools/toModelOutputMCP.js +54 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/client.d.ts +140 -0
- package/dist/types/client.js +1 -0
- package/dist/types/config.d.ts +151 -0
- package/dist/types/config.js +1 -0
- package/dist/types/core.d.ts +115 -0
- package/dist/types/core.js +1 -0
- package/dist/types/enums.d.ts +75 -0
- package/dist/{types.js → types/enums.js} +21 -9
- package/dist/types/inference.d.ts +117 -0
- package/dist/types/inference.js +1 -0
- package/dist/types/json-schema.d.ts +51 -0
- package/dist/types/json-schema.js +1 -0
- package/dist/types/operation.d.ts +5 -0
- package/dist/types/operation.js +1 -0
- package/dist/types/package.d.ts +544 -0
- package/dist/types/package.js +5 -0
- package/dist/types/request.d.ts +48 -0
- package/dist/types/request.js +1 -0
- package/dist/types/standard-schema.d.ts +117 -0
- package/dist/types/standard-schema.js +6 -0
- package/dist/types/tools.d.ts +43 -0
- package/dist/types/tools.js +1 -0
- package/dist/types/utils.d.ts +9 -0
- package/dist/types/utils.js +1 -0
- package/dist/types/validation.d.ts +48 -0
- package/dist/types/validation.js +1 -0
- package/dist/utils/camelCase.d.ts +6 -0
- package/dist/utils/camelCase.js +34 -0
- package/dist/utils/deepExtend.d.ts +53 -0
- package/dist/utils/deepExtend.js +128 -0
- package/dist/utils/fileNameToDisposition.d.ts +1 -0
- package/dist/utils/fileNameToDisposition.js +3 -0
- package/dist/utils/shim.d.ts +1 -0
- package/dist/utils/shim.js +1 -1
- package/dist/utils/toKebabCase.d.ts +1 -0
- package/dist/utils/toKebabCase.js +5 -0
- package/dist/utils/trimPath.d.ts +1 -0
- package/dist/utils/trimPath.js +1 -0
- package/dist/utils/upperFirst.d.ts +1 -0
- package/dist/utils/upperFirst.js +3 -0
- package/dist/validation/createStandardValidation.d.ts +268 -0
- package/dist/validation/createStandardValidation.js +45 -0
- package/dist/validation/createValidateOnClient.d.ts +14 -0
- package/dist/validation/createValidateOnClient.js +23 -0
- package/dist/validation/procedure.d.ts +261 -0
- package/dist/validation/procedure.js +8 -0
- package/dist/validation/withValidationLibrary.d.ts +119 -0
- package/dist/validation/withValidationLibrary.js +174 -0
- package/package.json +44 -10
- package/dist/HttpException.d.ts +0 -7
- package/dist/HttpException.js +0 -15
- package/dist/StreamJSONResponse.d.ts +0 -14
- package/dist/StreamJSONResponse.js +0 -57
- package/dist/VovkApp.d.ts +0 -29
- package/dist/VovkApp.js +0 -188
- package/dist/client/index.d.ts +0 -3
- package/dist/client/index.js +0 -7
- package/dist/client/types.d.ts +0 -104
- package/dist/client/types.js +0 -2
- package/dist/createDecorator.d.ts +0 -6
- package/dist/createVovkApp.d.ts +0 -62
- package/dist/createVovkApp.js +0 -118
- package/dist/types.d.ts +0 -220
- package/dist/utils/generateStaticAPI.d.ts +0 -4
- package/dist/utils/generateStaticAPI.js +0 -18
- package/dist/utils/getSchema.d.ts +0 -20
- package/dist/utils/getSchema.js +0 -33
- package/dist/utils/reqForm.d.ts +0 -2
- package/dist/utils/reqForm.js +0 -13
- package/dist/utils/reqMeta.d.ts +0 -2
- package/dist/utils/reqQuery.d.ts +0 -2
- package/dist/utils/reqQuery.js +0 -10
- package/dist/utils/withValidation.d.ts +0 -20
- package/dist/utils/withValidation.js +0 -72
package/dist/index.d.ts
CHANGED
|
@@ -1,59 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
(givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
|
|
27
|
-
auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
|
|
28
|
-
}, options: {
|
|
29
|
-
(givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
|
|
30
|
-
auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
|
|
31
|
-
}, prefix: (givenPath?: string) => (givenTarget: KnownAny) => any, initVovk: (options: {
|
|
32
|
-
segmentName?: string;
|
|
33
|
-
controllers: Record<string, import("./types").StaticClass>;
|
|
34
|
-
exposeValidation?: boolean;
|
|
35
|
-
emitSchema?: boolean;
|
|
36
|
-
onError?: (err: Error, req: VovkRequest) => void | Promise<void>;
|
|
37
|
-
}) => {
|
|
38
|
-
GET: (req: import("next/server").NextRequest, data: {
|
|
39
|
-
params: Promise<Record<string, string[]>>;
|
|
40
|
-
}) => Promise<Response>;
|
|
41
|
-
POST: (req: import("next/server").NextRequest, data: {
|
|
42
|
-
params: Promise<Record<string, string[]>>;
|
|
43
|
-
}) => Promise<Response>;
|
|
44
|
-
PUT: (req: import("next/server").NextRequest, data: {
|
|
45
|
-
params: Promise<Record<string, string[]>>;
|
|
46
|
-
}) => Promise<Response>;
|
|
47
|
-
PATCH: (req: import("next/server").NextRequest, data: {
|
|
48
|
-
params: Promise<Record<string, string[]>>;
|
|
49
|
-
}) => Promise<Response>;
|
|
50
|
-
DELETE: (req: import("next/server").NextRequest, data: {
|
|
51
|
-
params: Promise<Record<string, string[]>>;
|
|
52
|
-
}) => Promise<Response>;
|
|
53
|
-
HEAD: (req: import("next/server").NextRequest, data: {
|
|
54
|
-
params: Promise<Record<string, string[]>>;
|
|
55
|
-
}) => Promise<Response>;
|
|
56
|
-
OPTIONS: (req: import("next/server").NextRequest, data: {
|
|
57
|
-
params: Promise<Record<string, string[]>>;
|
|
58
|
-
}) => Promise<Response>;
|
|
59
|
-
};
|
|
1
|
+
export { HttpException } from './core/HttpException.js';
|
|
2
|
+
export { createDecorator } from './core/createDecorator.js';
|
|
3
|
+
export { controllersToStaticParams } from './core/controllersToStaticParams.js';
|
|
4
|
+
export { multitenant } from './core/multitenant.js';
|
|
5
|
+
export { JSONLinesResponder } from './core/JSONLinesResponder.js';
|
|
6
|
+
export { toDownloadResponse } from './core/toDownloadResponse.js';
|
|
7
|
+
export { get, post, put, patch, del, head, options, prefix, cloneControllerMetadata } from './core/decorators.js';
|
|
8
|
+
export { progressive } from './client/progressive.js';
|
|
9
|
+
export { fetcher, createFetcher } from './client/fetcher.js';
|
|
10
|
+
export { initSegment } from './core/initSegment.js';
|
|
11
|
+
export { operation } from './openapi/operation.js';
|
|
12
|
+
export { createValidateOnClient } from './validation/createValidateOnClient.js';
|
|
13
|
+
export { procedure } from './validation/procedure.js';
|
|
14
|
+
export { ToModelOutput } from './tools/ToModelOutput.js';
|
|
15
|
+
export { createTool } from './tools/createTool.js';
|
|
16
|
+
export { deriveTools } from './tools/deriveTools.js';
|
|
17
|
+
export { HttpStatus, HttpMethod } from './types/enums.js';
|
|
18
|
+
export type { VovkBody, VovkQuery, VovkParams, VovkReturnType, VovkYieldType, VovkOutput, VovkIteration, } from './types/inference.js';
|
|
19
|
+
export type { VovkRequest } from './types/request.js';
|
|
20
|
+
export type { VovkJSONSchemaBase } from './types/json-schema.js';
|
|
21
|
+
export type { VovkConfig } from './types/config.js';
|
|
22
|
+
export type { VovkSchema } from './types/core.js';
|
|
23
|
+
export type { VovkFetcher } from './types/client.js';
|
|
24
|
+
export type { VovkValidateOnClient } from './types/validation.js';
|
|
25
|
+
export type { VovkTool } from './types/tools.js';
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
// core
|
|
2
|
+
export { HttpException } from './core/HttpException.js';
|
|
3
|
+
export { createDecorator } from './core/createDecorator.js';
|
|
4
|
+
export { controllersToStaticParams } from './core/controllersToStaticParams.js';
|
|
5
|
+
export { multitenant } from './core/multitenant.js';
|
|
6
|
+
export { JSONLinesResponder } from './core/JSONLinesResponder.js';
|
|
7
|
+
export { toDownloadResponse } from './core/toDownloadResponse.js';
|
|
8
|
+
export { get, post, put, patch, del, head, options, prefix, cloneControllerMetadata } from './core/decorators.js';
|
|
9
|
+
// client
|
|
10
|
+
export { progressive } from './client/progressive.js';
|
|
11
|
+
export { fetcher, createFetcher } from './client/fetcher.js';
|
|
12
|
+
export { initSegment } from './core/initSegment.js';
|
|
13
|
+
// openapi
|
|
14
|
+
export { operation } from './openapi/operation.js';
|
|
15
|
+
// validation
|
|
16
|
+
export { createValidateOnClient } from './validation/createValidateOnClient.js';
|
|
17
|
+
export { procedure } from './validation/procedure.js';
|
|
18
|
+
// tools
|
|
19
|
+
export { ToModelOutput } from './tools/ToModelOutput.js';
|
|
20
|
+
export { createTool } from './tools/createTool.js';
|
|
21
|
+
export { deriveTools } from './tools/deriveTools.js';
|
|
22
|
+
// types
|
|
23
|
+
export { HttpStatus, HttpMethod } from './types/enums.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { deepExtend } from './utils/deepExtend.js';
|
|
2
|
+
export { resolveGeneratorConfigValues } from './core/resolveGeneratorConfigValues.js';
|
|
3
|
+
export { createCodeSamples } from './samples/createCodeSamples.js';
|
|
4
|
+
export { withValidationLibrary } from './validation/withValidationLibrary.js';
|
|
5
|
+
export { operation } from './openapi/operation.js';
|
|
6
|
+
export { openAPIToVovkSchema } from './openapi/openAPIToVovkSchema/index.js';
|
|
7
|
+
export { vovkSchemaToOpenAPI } from './openapi/vovkSchemaToOpenAPI.js';
|
|
8
|
+
export { readableStreamToAsyncIterable } from './client/defaultStreamHandler.js';
|
|
9
|
+
export { VovkSchemaIdEnum } from './types/enums.js';
|
|
10
|
+
export type { VovkToolDerived, VovkToolNonDerived } from './types/tools.js';
|
|
11
|
+
export type { MCPModelOutput } from './tools/toModelOutputMCP.js';
|
|
12
|
+
export type { VovkErrorResponse, VovkMetaSchema, VovkSegmentSchema, VovkControllerSchema, VovkHandlerSchema, VovkValidationType, } from './types/core.js';
|
|
13
|
+
export type { VovkTypedProcedure } from './types/validation.js';
|
|
14
|
+
export type { VovkOutputConfig, VovkReadmeConfig, VovkSamplesConfig, VovkPackageJson, VovkOpenAPIMixin, VovkOpenAPIMixinNormalized, VovkStrictConfig, VovkBundleConfig, VovkSegmentConfig, } from './types/config.js';
|
|
15
|
+
export type { VovkOperationObject } from './types/operation.js';
|
|
16
|
+
export type { VovkRPCModule, VovkFetcherOptions, VovkStreamAsyncIterable } from './types/client.js';
|
|
17
|
+
export type { IsAny, IsNotAny } from './types/utils.js';
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// internal exports for other packages and tests
|
|
2
|
+
export { deepExtend } from './utils/deepExtend.js';
|
|
3
|
+
export { resolveGeneratorConfigValues } from './core/resolveGeneratorConfigValues.js';
|
|
4
|
+
export { createCodeSamples } from './samples/createCodeSamples.js';
|
|
5
|
+
export { withValidationLibrary } from './validation/withValidationLibrary.js';
|
|
6
|
+
export { operation } from './openapi/operation.js';
|
|
7
|
+
export { openAPIToVovkSchema } from './openapi/openAPIToVovkSchema/index.js';
|
|
8
|
+
export { vovkSchemaToOpenAPI } from './openapi/vovkSchemaToOpenAPI.js';
|
|
9
|
+
export { readableStreamToAsyncIterable } from './client/defaultStreamHandler.js';
|
|
10
|
+
export { VovkSchemaIdEnum } from './types/enums.js';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { HttpStatus } from '../types/enums.js';
|
|
2
|
+
import { createDecorator } from '../core/createDecorator.js';
|
|
3
|
+
const statusDisplayText = {
|
|
4
|
+
[HttpStatus.NULL]: 'Error',
|
|
5
|
+
[HttpStatus.CONTINUE]: 'Continue',
|
|
6
|
+
[HttpStatus.SWITCHING_PROTOCOLS]: 'Switching Protocols',
|
|
7
|
+
[HttpStatus.PROCESSING]: 'Processing',
|
|
8
|
+
[HttpStatus.EARLYHINTS]: 'Early Hints',
|
|
9
|
+
[HttpStatus.OK]: 'OK',
|
|
10
|
+
[HttpStatus.CREATED]: 'Created',
|
|
11
|
+
[HttpStatus.ACCEPTED]: 'Accepted',
|
|
12
|
+
[HttpStatus.NON_AUTHORITATIVE_INFORMATION]: 'Non Authoritative Information',
|
|
13
|
+
[HttpStatus.NO_CONTENT]: 'No Content',
|
|
14
|
+
[HttpStatus.RESET_CONTENT]: 'Reset Content',
|
|
15
|
+
[HttpStatus.PARTIAL_CONTENT]: 'Partial Content',
|
|
16
|
+
[HttpStatus.AMBIGUOUS]: 'Ambiguous',
|
|
17
|
+
[HttpStatus.MOVED_PERMANENTLY]: 'Moved Permanently',
|
|
18
|
+
[HttpStatus.FOUND]: 'Found',
|
|
19
|
+
[HttpStatus.SEE_OTHER]: 'See Other',
|
|
20
|
+
[HttpStatus.NOT_MODIFIED]: 'Not Modified',
|
|
21
|
+
[HttpStatus.TEMPORARY_REDIRECT]: 'Temporary Redirect',
|
|
22
|
+
[HttpStatus.PERMANENT_REDIRECT]: 'Permanent Redirect',
|
|
23
|
+
[HttpStatus.BAD_REQUEST]: 'Bad Request',
|
|
24
|
+
[HttpStatus.UNAUTHORIZED]: 'Unauthorized',
|
|
25
|
+
[HttpStatus.PAYMENT_REQUIRED]: 'Payment Required',
|
|
26
|
+
[HttpStatus.FORBIDDEN]: 'Forbidden',
|
|
27
|
+
[HttpStatus.NOT_FOUND]: 'Not Found',
|
|
28
|
+
[HttpStatus.METHOD_NOT_ALLOWED]: 'Method Not Allowed',
|
|
29
|
+
[HttpStatus.NOT_ACCEPTABLE]: 'Not Acceptable',
|
|
30
|
+
[HttpStatus.PROXY_AUTHENTICATION_REQUIRED]: 'Proxy Authentication Required',
|
|
31
|
+
[HttpStatus.REQUEST_TIMEOUT]: 'Request Timeout',
|
|
32
|
+
[HttpStatus.CONFLICT]: 'Conflict',
|
|
33
|
+
[HttpStatus.GONE]: 'Gone',
|
|
34
|
+
[HttpStatus.LENGTH_REQUIRED]: 'Length Required',
|
|
35
|
+
[HttpStatus.PRECONDITION_FAILED]: 'Precondition Failed',
|
|
36
|
+
[HttpStatus.PAYLOAD_TOO_LARGE]: 'Payload Too Large',
|
|
37
|
+
[HttpStatus.URI_TOO_LONG]: 'URI Too Long',
|
|
38
|
+
[HttpStatus.UNSUPPORTED_MEDIA_TYPE]: 'Unsupported Media Type',
|
|
39
|
+
[HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE]: 'Requested Range Not Satisfiable',
|
|
40
|
+
[HttpStatus.EXPECTATION_FAILED]: 'Expectation Failed',
|
|
41
|
+
[HttpStatus.I_AM_A_TEAPOT]: 'I am a teapot',
|
|
42
|
+
[HttpStatus.MISDIRECTED]: 'Misdirected',
|
|
43
|
+
[HttpStatus.UNPROCESSABLE_ENTITY]: 'Unprocessable Entity',
|
|
44
|
+
[HttpStatus.FAILED_DEPENDENCY]: 'Failed Dependency',
|
|
45
|
+
[HttpStatus.PRECONDITION_REQUIRED]: 'Precondition Required',
|
|
46
|
+
[HttpStatus.TOO_MANY_TRequestS]: 'Too Many Requests',
|
|
47
|
+
[HttpStatus.INTERNAL_SERVER_ERROR]: 'Internal Server Error',
|
|
48
|
+
[HttpStatus.NOT_IMPLEMENTED]: 'Not Implemented',
|
|
49
|
+
[HttpStatus.BAD_GATEWAY]: 'Bad Gateway',
|
|
50
|
+
[HttpStatus.SERVICE_UNAVAILABLE]: 'Service Unavailable',
|
|
51
|
+
[HttpStatus.GATEWAY_TIMEOUT]: 'Gateway Timeout',
|
|
52
|
+
[HttpStatus.HTTP_VERSION_NOT_SUPPORTED]: 'HTTP Version Not Supported',
|
|
53
|
+
};
|
|
54
|
+
export const error = createDecorator(null, (status, message) => {
|
|
55
|
+
return (handlerSchema) => {
|
|
56
|
+
return {
|
|
57
|
+
...handlerSchema,
|
|
58
|
+
operationObject: {
|
|
59
|
+
...handlerSchema?.operationObject,
|
|
60
|
+
responses: {
|
|
61
|
+
...handlerSchema?.operationObject?.responses,
|
|
62
|
+
[status]: {
|
|
63
|
+
description: `${status} ${statusDisplayText[status]}`,
|
|
64
|
+
content: {
|
|
65
|
+
'application/json': {
|
|
66
|
+
schema: {
|
|
67
|
+
allOf: [
|
|
68
|
+
{
|
|
69
|
+
$ref: '#/components/schemas/VovkErrorResponse',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
type: 'object',
|
|
73
|
+
properties: {
|
|
74
|
+
message: {
|
|
75
|
+
type: 'string',
|
|
76
|
+
enum: [
|
|
77
|
+
message,
|
|
78
|
+
...(handlerSchema?.operationObject?.responses?.[status]?.content?.['application/json']
|
|
79
|
+
?.schema?.allOf?.[1]?.properties?.message?.enum ?? []),
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
statusCode: {
|
|
83
|
+
type: 'integer',
|
|
84
|
+
enum: [status],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ComponentsObject } from 'openapi3-ts/oas31';
|
|
2
|
+
import type { VovkJSONSchemaBase } from '../../types/json-schema.js';
|
|
3
|
+
export declare function applyComponentsSchemas(schema: VovkJSONSchemaBase, components: ComponentsObject['schemas'], mixinName: string): VovkJSONSchemaBase | VovkJSONSchemaBase[];
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { camelCase } from '../../utils/camelCase.js';
|
|
2
|
+
import { upperFirst } from '../../utils/upperFirst.js';
|
|
3
|
+
// fast clone JSON object while ignoring Date, RegExp, and Function types
|
|
4
|
+
function cloneJSON(obj) {
|
|
5
|
+
if (obj === null || typeof obj !== 'object')
|
|
6
|
+
return obj;
|
|
7
|
+
if (Array.isArray(obj))
|
|
8
|
+
return obj.map(cloneJSON);
|
|
9
|
+
const result = {};
|
|
10
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
11
|
+
if (value instanceof Date || value instanceof RegExp || typeof value === 'function')
|
|
12
|
+
continue;
|
|
13
|
+
result[key] = cloneJSON(value);
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
export function applyComponentsSchemas(schema, components, mixinName) {
|
|
18
|
+
const key = 'components/schemas';
|
|
19
|
+
if (!components || !Object.keys(components).length)
|
|
20
|
+
return schema;
|
|
21
|
+
// Create a deep copy of the schema
|
|
22
|
+
const result = cloneJSON(schema);
|
|
23
|
+
// Initialize $defs if it doesn't exist
|
|
24
|
+
result.$defs = result.$defs || {};
|
|
25
|
+
// Set to track components we've added to $defs
|
|
26
|
+
const addedComponents = new Set();
|
|
27
|
+
// Process a schema object and replace $refs
|
|
28
|
+
function processSchema(obj) {
|
|
29
|
+
if (!obj || typeof obj !== 'object')
|
|
30
|
+
return obj;
|
|
31
|
+
// Handle arrays first - they don't have $ref
|
|
32
|
+
if (Array.isArray(obj)) {
|
|
33
|
+
return obj.map((item) => processSchema(item));
|
|
34
|
+
}
|
|
35
|
+
// Now we know it's an object, so we can safely access $ref
|
|
36
|
+
const newObj = { ...obj };
|
|
37
|
+
const $ref = newObj.$ref;
|
|
38
|
+
if ($ref && typeof $ref === 'string' && $ref.startsWith(`#/${key}/`)) {
|
|
39
|
+
const componentName = $ref.replace(`#/${key}/`, '');
|
|
40
|
+
if (components[componentName]) {
|
|
41
|
+
newObj.$ref = `#/$defs/${componentName}`;
|
|
42
|
+
newObj['x-tsType'] ??= `Mixins.${upperFirst(camelCase(mixinName))}.${upperFirst(camelCase(componentName))}`;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
delete newObj.$ref; // Remove $ref if component not found (Telegram API has Type $refs that is not defined in components)
|
|
46
|
+
}
|
|
47
|
+
// Add the component to $defs if not already added
|
|
48
|
+
if (!addedComponents.has(componentName) && components[componentName]) {
|
|
49
|
+
addedComponents.add(componentName);
|
|
50
|
+
if (result.$defs) {
|
|
51
|
+
result.$defs[componentName] = processSchema(cloneJSON(components[componentName]));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Process properties recursively
|
|
56
|
+
for (const key in newObj) {
|
|
57
|
+
if (Object.prototype.hasOwnProperty.call(newObj, key)) {
|
|
58
|
+
newObj[key] = processSchema(newObj[key]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return newObj;
|
|
62
|
+
}
|
|
63
|
+
// Process the main schema
|
|
64
|
+
return processSchema(result);
|
|
65
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { VovkSchema } from '../../types/core.js';
|
|
2
|
+
import type { VovkOpenAPIMixinNormalized } from '../../types/config.js';
|
|
3
|
+
export declare function openAPIToVovkSchema({ apiRoot, source: { object: openAPIObject }, getModuleName, getMethodName, errorMessageKey, segmentName, }: VovkOpenAPIMixinNormalized & {
|
|
4
|
+
segmentName?: string;
|
|
5
|
+
}): VovkSchema;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { applyComponentsSchemas } from './applyComponentsSchemas.js';
|
|
2
|
+
import { inlineRefs } from './inlineRefs.js';
|
|
3
|
+
import { VovkSchemaIdEnum } from '../../types/enums.js';
|
|
4
|
+
import { schemaToTsType } from '../../samples/schemaToTsType.js';
|
|
5
|
+
function getTsTypeString(contentType, schema) {
|
|
6
|
+
const tsTypes = new Set(contentType.flatMap((ct) => {
|
|
7
|
+
switch (ct) {
|
|
8
|
+
case 'application/json':
|
|
9
|
+
return [schemaToTsType(schema)];
|
|
10
|
+
case 'multipart/form-data':
|
|
11
|
+
return ['FormData', schemaToTsType(schema)];
|
|
12
|
+
case 'application/x-www-form-urlencoded':
|
|
13
|
+
return ['FormData', 'URLSearchParams', schemaToTsType(schema)];
|
|
14
|
+
case 'text/plain':
|
|
15
|
+
return ['string'];
|
|
16
|
+
default:
|
|
17
|
+
return ['Blob', 'ArrayBuffer', 'Uint8Array'];
|
|
18
|
+
}
|
|
19
|
+
}));
|
|
20
|
+
return [...tsTypes].join(' | ') || schemaToTsType(schema);
|
|
21
|
+
}
|
|
22
|
+
export function openAPIToVovkSchema({ apiRoot, source: { object: openAPIObject }, getModuleName, getMethodName, errorMessageKey, segmentName, }) {
|
|
23
|
+
segmentName = segmentName ?? '';
|
|
24
|
+
const forceApiRoot = apiRoot ||
|
|
25
|
+
(openAPIObject.servers?.[0]?.url ??
|
|
26
|
+
('host' in openAPIObject
|
|
27
|
+
? `https://${openAPIObject.host}${'basePath' in openAPIObject ? openAPIObject.basePath : ''}`
|
|
28
|
+
: null));
|
|
29
|
+
if (!forceApiRoot) {
|
|
30
|
+
throw new Error('API root URL is required in OpenAPI configuration');
|
|
31
|
+
}
|
|
32
|
+
const { paths, ...noPathsOpenAPIObject } = openAPIObject;
|
|
33
|
+
const schema = {
|
|
34
|
+
$schema: VovkSchemaIdEnum.SCHEMA,
|
|
35
|
+
segments: {
|
|
36
|
+
[segmentName]: {
|
|
37
|
+
$schema: VovkSchemaIdEnum.SEGMENT,
|
|
38
|
+
emitSchema: true,
|
|
39
|
+
segmentName,
|
|
40
|
+
segmentType: 'mixin',
|
|
41
|
+
controllers: {},
|
|
42
|
+
forceApiRoot,
|
|
43
|
+
meta: {
|
|
44
|
+
openAPIObject: noPathsOpenAPIObject,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const segment = schema.segments[segmentName];
|
|
50
|
+
return Object.entries(paths ?? {}).reduce((acc, [path, operations]) => {
|
|
51
|
+
Object.entries(operations ?? {})
|
|
52
|
+
.filter(([, operation]) => operation && typeof operation === 'object')
|
|
53
|
+
.forEach(([method, operation]) => {
|
|
54
|
+
const rpcModuleName = getModuleName({
|
|
55
|
+
method: method.toUpperCase(),
|
|
56
|
+
path,
|
|
57
|
+
openAPIObject,
|
|
58
|
+
operationObject: operation,
|
|
59
|
+
});
|
|
60
|
+
const handlerName = getMethodName({
|
|
61
|
+
method: method.toUpperCase(),
|
|
62
|
+
path,
|
|
63
|
+
openAPIObject,
|
|
64
|
+
operationObject: operation,
|
|
65
|
+
});
|
|
66
|
+
segment.controllers[rpcModuleName] ??= {
|
|
67
|
+
rpcModuleName,
|
|
68
|
+
handlers: {},
|
|
69
|
+
};
|
|
70
|
+
const parameters = inlineRefs(operation.parameters ?? [], openAPIObject);
|
|
71
|
+
const queryProperties = parameters?.filter((p) => p.in === 'query') ?? null;
|
|
72
|
+
const pathProperties = parameters?.filter((p) => p.in === 'path') ?? null;
|
|
73
|
+
const query = queryProperties?.length
|
|
74
|
+
? {
|
|
75
|
+
type: 'object',
|
|
76
|
+
properties: Object.fromEntries(queryProperties.map((p) => [p.name, p.schema])),
|
|
77
|
+
required: queryProperties.filter((p) => p.required).map((p) => p.name),
|
|
78
|
+
}
|
|
79
|
+
: null;
|
|
80
|
+
const params = pathProperties?.length
|
|
81
|
+
? {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: Object.fromEntries(pathProperties.map((p) => [p.name, p.schema])),
|
|
84
|
+
required: pathProperties.filter((p) => p.required).map((p) => p.name),
|
|
85
|
+
}
|
|
86
|
+
: null;
|
|
87
|
+
const requestBodyContent = inlineRefs(operation.requestBody, openAPIObject)?.content ?? {};
|
|
88
|
+
const contentTypes = [
|
|
89
|
+
'application/json',
|
|
90
|
+
'multipart/form-data',
|
|
91
|
+
'application/x-www-form-urlencoded',
|
|
92
|
+
'text/plain',
|
|
93
|
+
'application/octet-stream',
|
|
94
|
+
];
|
|
95
|
+
const bodySchemas = contentTypes
|
|
96
|
+
.map((contentType) => requestBodyContent[contentType]?.schema
|
|
97
|
+
? { ...requestBodyContent[contentType].schema, 'x-contentType': [contentType] }
|
|
98
|
+
: null)
|
|
99
|
+
.filter(Boolean);
|
|
100
|
+
const body = !bodySchemas.length
|
|
101
|
+
? null
|
|
102
|
+
: bodySchemas.length === 1
|
|
103
|
+
? {
|
|
104
|
+
...bodySchemas[0],
|
|
105
|
+
'x-tsType': getTsTypeString(bodySchemas[0]['x-contentType'] ?? [], bodySchemas[0]),
|
|
106
|
+
}
|
|
107
|
+
: {
|
|
108
|
+
anyOf: bodySchemas,
|
|
109
|
+
'x-tsType': getTsTypeString(bodySchemas.flatMap((s) => s['x-contentType'] ?? []), { anyOf: bodySchemas }),
|
|
110
|
+
};
|
|
111
|
+
const output = operation.responses?.['200']?.content?.['application/json']?.schema ??
|
|
112
|
+
operation.responses?.['201']?.content?.['application/json']?.schema ??
|
|
113
|
+
null;
|
|
114
|
+
const iteration = operation.responses?.['200']?.content?.['application/jsonl']?.schema ??
|
|
115
|
+
operation.responses?.['201']?.content?.['application/jsonl']?.schema ??
|
|
116
|
+
operation.responses?.['200']?.content?.['application/jsonlines']?.schema ??
|
|
117
|
+
operation.responses?.['201']?.content?.['application/jsonlines']?.schema ??
|
|
118
|
+
null;
|
|
119
|
+
if (errorMessageKey) {
|
|
120
|
+
operation['x-errorMessageKey'] = errorMessageKey;
|
|
121
|
+
}
|
|
122
|
+
const componentsSchemas = openAPIObject.components?.schemas ??
|
|
123
|
+
('definitions' in openAPIObject ? openAPIObject.definitions : {});
|
|
124
|
+
segment.controllers[rpcModuleName].handlers[handlerName] = {
|
|
125
|
+
httpMethod: method.toUpperCase(),
|
|
126
|
+
path,
|
|
127
|
+
operationObject: operation,
|
|
128
|
+
misc: {
|
|
129
|
+
isOpenAPIMixin: true,
|
|
130
|
+
originalPath: path,
|
|
131
|
+
},
|
|
132
|
+
validation: {
|
|
133
|
+
...(query && {
|
|
134
|
+
query: applyComponentsSchemas(query, componentsSchemas, segmentName),
|
|
135
|
+
}),
|
|
136
|
+
...(params && {
|
|
137
|
+
params: applyComponentsSchemas(params, componentsSchemas, segmentName),
|
|
138
|
+
}),
|
|
139
|
+
...(body && {
|
|
140
|
+
body: applyComponentsSchemas(body, componentsSchemas, segmentName),
|
|
141
|
+
}),
|
|
142
|
+
...(output && {
|
|
143
|
+
output: applyComponentsSchemas(output, componentsSchemas, segmentName),
|
|
144
|
+
}),
|
|
145
|
+
...(iteration && {
|
|
146
|
+
iteration: applyComponentsSchemas(iteration, componentsSchemas, segmentName),
|
|
147
|
+
}),
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
return acc;
|
|
152
|
+
}, schema);
|
|
153
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OpenAPIObject } from 'openapi3-ts/oas31';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves $ref references at the first level only (except for components/schemas references)
|
|
4
|
+
* For arrays, checks each item at the first level
|
|
5
|
+
* @param obj - The object to process (may contain $ref properties)
|
|
6
|
+
* @param openAPIObject - The complete OpenAPI document containing definitions
|
|
7
|
+
* @returns The object with resolved references (except components/schemas)
|
|
8
|
+
*/
|
|
9
|
+
export declare function inlineRefs<T extends object>(obj: unknown, openAPIObject: OpenAPIObject): T | null;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves $ref references at the first level only (except for components/schemas references)
|
|
3
|
+
* For arrays, checks each item at the first level
|
|
4
|
+
* @param obj - The object to process (may contain $ref properties)
|
|
5
|
+
* @param openAPIObject - The complete OpenAPI document containing definitions
|
|
6
|
+
* @returns The object with resolved references (except components/schemas)
|
|
7
|
+
*/
|
|
8
|
+
export function inlineRefs(obj, openAPIObject) {
|
|
9
|
+
// Handle null or undefined
|
|
10
|
+
if (obj === null || obj === undefined) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
// Handle arrays - check each item for $ref at first level only
|
|
14
|
+
if (Array.isArray(obj)) {
|
|
15
|
+
return obj.map((item) => {
|
|
16
|
+
// Only resolve if item is an object with $ref
|
|
17
|
+
if (item && typeof item === 'object' && '$ref' in item && typeof item.$ref === 'string') {
|
|
18
|
+
// Skip components/schemas references
|
|
19
|
+
if (item.$ref.startsWith('#/components/schemas/')) {
|
|
20
|
+
return item;
|
|
21
|
+
}
|
|
22
|
+
// Resolve the reference
|
|
23
|
+
const resolved = resolveRef(item.$ref, openAPIObject);
|
|
24
|
+
// If resolution successful, return resolved value (with any additional properties merged)
|
|
25
|
+
if (resolved !== undefined) {
|
|
26
|
+
// If there are additional properties besides $ref, merge them
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
28
|
+
const { $ref: _$ref, ...additionalProps } = item;
|
|
29
|
+
if (Object.keys(additionalProps).length > 0) {
|
|
30
|
+
return { ...resolved, ...additionalProps };
|
|
31
|
+
}
|
|
32
|
+
return resolved;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Return item as-is if not a resolvable $ref
|
|
36
|
+
return item;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
// Handle non-objects (primitives)
|
|
40
|
+
if (typeof obj !== 'object') {
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
// Check if object has a $ref property at the first level
|
|
44
|
+
if ('$ref' in obj && typeof obj.$ref === 'string') {
|
|
45
|
+
// Check if the reference points to components/schemas
|
|
46
|
+
if (obj.$ref.startsWith('#/components/schemas/')) {
|
|
47
|
+
// Return as-is for schema references
|
|
48
|
+
return obj;
|
|
49
|
+
}
|
|
50
|
+
// Resolve the reference
|
|
51
|
+
const resolved = resolveRef(obj.$ref, openAPIObject);
|
|
52
|
+
// If resolution successful, return resolved value (with any additional properties merged)
|
|
53
|
+
if (resolved !== undefined) {
|
|
54
|
+
// If there are additional properties besides $ref, merge them
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
56
|
+
const { $ref: _$ref, ...additionalProps } = obj;
|
|
57
|
+
if (Object.keys(additionalProps).length > 0) {
|
|
58
|
+
return { ...resolved, ...additionalProps };
|
|
59
|
+
}
|
|
60
|
+
return resolved;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// For regular objects without $ref, return as-is (no recursion)
|
|
64
|
+
return obj;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Resolves a JSON Reference ($ref) to its target value
|
|
68
|
+
* @param ref - The reference string (e.g., "#/components/parameters/id")
|
|
69
|
+
* @param openAPIObject - The complete OpenAPI document
|
|
70
|
+
* @returns The resolved value or undefined if not found
|
|
71
|
+
*/
|
|
72
|
+
function resolveRef(ref, openAPIObject) {
|
|
73
|
+
// Handle only local references (starting with #)
|
|
74
|
+
if (!ref.startsWith('#/')) {
|
|
75
|
+
// eslint-disable-next-line no-console
|
|
76
|
+
console.warn(`External references are not supported: ${ref}`);
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
// Remove the leading # and split the path
|
|
80
|
+
const path = ref
|
|
81
|
+
.substring(1)
|
|
82
|
+
.split('/')
|
|
83
|
+
.filter((p) => p !== '');
|
|
84
|
+
// Navigate through the object following the path
|
|
85
|
+
let current = openAPIObject;
|
|
86
|
+
for (const segment of path) {
|
|
87
|
+
// Decode the segment (handles encoded characters like ~0 for ~ and ~1 for /)
|
|
88
|
+
const decodedSegment = segment.replace(/~1/g, '/').replace(/~0/g, '~');
|
|
89
|
+
if (current && typeof current === 'object' && decodedSegment in current) {
|
|
90
|
+
current = current[decodedSegment];
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// eslint-disable-next-line no-console
|
|
94
|
+
console.warn(`Could not resolve reference: ${ref}`);
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return current;
|
|
99
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { VovkOperationObject } from '../types/operation.js';
|
|
2
|
+
export declare const operationDecorator: (openAPIOperationObject?: VovkOperationObject | undefined) => (target: import("../types/utils.js").KnownAny, propertyKey: string) => void;
|
|
3
|
+
/**
|
|
4
|
+
* OpenAPI operation decorator to add metadata to API operations. Also includes `error` and `tool` utilities.
|
|
5
|
+
* @see https://vovk.dev/openapi
|
|
6
|
+
*/
|
|
7
|
+
export declare const operation: ((openAPIOperationObject?: VovkOperationObject | undefined) => (target: import("../types/utils.js").KnownAny, propertyKey: string) => void) & {
|
|
8
|
+
error: (status: import("../index.js").HttpStatus, message: string) => (target: import("../types/utils.js").KnownAny, propertyKey: string) => void;
|
|
9
|
+
tool: (toolOptions: import("../types/tools.js").VovkToolOptions) => (target: import("../types/utils.js").KnownAny, propertyKey: string) => void;
|
|
10
|
+
};
|