vovk 3.0.0-draft.99 → 3.0.2
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 +23 -12
- 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 +262 -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 +2 -5
- 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 +94 -0
- package/dist/core/controllersToStaticParams.d.ts +13 -0
- package/dist/core/controllersToStaticParams.js +32 -0
- package/dist/core/createDecorator.d.ts +18 -0
- package/dist/core/createDecorator.js +60 -0
- package/dist/core/decorators.d.ts +66 -0
- package/dist/core/decorators.js +155 -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 +318 -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 +6 -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 +26 -0
- package/dist/openapi/operation.js +19 -0
- package/dist/openapi/tool.d.ts +6 -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 +12 -12
- 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 +62 -0
- package/dist/tools/deriveTools.d.ts +46 -0
- package/dist/tools/deriveTools.js +132 -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 +139 -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 +54 -0
- package/dist/utils/deepExtend.js +127 -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 +45 -11
- 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/createDecorator.js +0 -43
- 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/HttpException.d.ts
DELETED
package/dist/HttpException.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpException = void 0;
|
|
4
|
-
class HttpException extends Error {
|
|
5
|
-
statusCode;
|
|
6
|
-
message;
|
|
7
|
-
cause;
|
|
8
|
-
constructor(statusCode, message, cause) {
|
|
9
|
-
super(message);
|
|
10
|
-
this.statusCode = statusCode;
|
|
11
|
-
this.message = message;
|
|
12
|
-
this.cause = cause;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.HttpException = HttpException;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { headers } from 'next/headers';
|
|
2
|
-
import type { KnownAny, StreamAbortMessage } from './types';
|
|
3
|
-
import './utils/shim';
|
|
4
|
-
export declare class StreamJSONResponse<T> extends Response {
|
|
5
|
-
isClosed: boolean;
|
|
6
|
-
controller?: ReadableStreamDefaultController;
|
|
7
|
-
readonly encoder: TextEncoder;
|
|
8
|
-
readonly readableStream: ReadableStream;
|
|
9
|
-
constructor(requestHeaders: Awaited<ReturnType<typeof headers>>, init?: ResponseInit);
|
|
10
|
-
send(data: T | StreamAbortMessage): void;
|
|
11
|
-
close(): void;
|
|
12
|
-
throw(e: KnownAny): void;
|
|
13
|
-
[Symbol.dispose](): void;
|
|
14
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StreamJSONResponse = void 0;
|
|
4
|
-
require("./utils/shim");
|
|
5
|
-
class StreamJSONResponse extends Response {
|
|
6
|
-
isClosed = false;
|
|
7
|
-
controller;
|
|
8
|
-
encoder;
|
|
9
|
-
readableStream;
|
|
10
|
-
constructor(requestHeaders, init) {
|
|
11
|
-
const encoder = new TextEncoder();
|
|
12
|
-
let readableController;
|
|
13
|
-
const readableStream = new ReadableStream({
|
|
14
|
-
cancel: () => {
|
|
15
|
-
this.isClosed = true;
|
|
16
|
-
},
|
|
17
|
-
start: (controller) => {
|
|
18
|
-
readableController = controller;
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
if (!requestHeaders) {
|
|
22
|
-
throw new Error('Request headers are required');
|
|
23
|
-
}
|
|
24
|
-
const accept = requestHeaders.get('accept');
|
|
25
|
-
super(readableStream, {
|
|
26
|
-
...init,
|
|
27
|
-
headers: {
|
|
28
|
-
...init?.headers,
|
|
29
|
-
'Content-Type': accept?.includes('application/jsonl') ? 'application/jsonl' : 'text/plain',
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
this.readableStream = readableStream;
|
|
33
|
-
this.encoder = encoder;
|
|
34
|
-
this.controller = readableController;
|
|
35
|
-
}
|
|
36
|
-
send(data) {
|
|
37
|
-
const { controller, encoder } = this;
|
|
38
|
-
if (this.isClosed)
|
|
39
|
-
return;
|
|
40
|
-
return controller?.enqueue(encoder.encode(JSON.stringify(data) + '\n'));
|
|
41
|
-
}
|
|
42
|
-
close() {
|
|
43
|
-
const { controller } = this;
|
|
44
|
-
if (this.isClosed)
|
|
45
|
-
return;
|
|
46
|
-
this.isClosed = true;
|
|
47
|
-
controller?.close();
|
|
48
|
-
}
|
|
49
|
-
throw(e) {
|
|
50
|
-
this.send({ isError: true, reason: e instanceof Error ? e.message : e });
|
|
51
|
-
return this.close();
|
|
52
|
-
}
|
|
53
|
-
[Symbol.dispose]() {
|
|
54
|
-
this.close();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.StreamJSONResponse = StreamJSONResponse;
|
package/dist/VovkApp.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { NextRequest } from 'next/server';
|
|
2
|
-
import { HttpMethod, HttpStatus, type RouteHandler, type VovkController, type DecoratorOptions } from './types';
|
|
3
|
-
export declare class VovkApp {
|
|
4
|
-
#private;
|
|
5
|
-
private static getHeadersFromOptions;
|
|
6
|
-
routes: Record<HttpMethod, Map<VovkController, Record<string, RouteHandler>>>;
|
|
7
|
-
GET: (req: NextRequest, data: {
|
|
8
|
-
params: Promise<Record<string, string[]>>;
|
|
9
|
-
}) => Promise<Response>;
|
|
10
|
-
POST: (req: NextRequest, data: {
|
|
11
|
-
params: Promise<Record<string, string[]>>;
|
|
12
|
-
}) => Promise<Response>;
|
|
13
|
-
PUT: (req: NextRequest, data: {
|
|
14
|
-
params: Promise<Record<string, string[]>>;
|
|
15
|
-
}) => Promise<Response>;
|
|
16
|
-
PATCH: (req: NextRequest, data: {
|
|
17
|
-
params: Promise<Record<string, string[]>>;
|
|
18
|
-
}) => Promise<Response>;
|
|
19
|
-
DELETE: (req: NextRequest, data: {
|
|
20
|
-
params: Promise<Record<string, string[]>>;
|
|
21
|
-
}) => Promise<Response>;
|
|
22
|
-
HEAD: (req: NextRequest, data: {
|
|
23
|
-
params: Promise<Record<string, string[]>>;
|
|
24
|
-
}) => Promise<Response>;
|
|
25
|
-
OPTIONS: (req: NextRequest, data: {
|
|
26
|
-
params: Promise<Record<string, string[]>>;
|
|
27
|
-
}) => Promise<Response>;
|
|
28
|
-
respond: (status: HttpStatus, body: unknown, options?: DecoratorOptions) => Response;
|
|
29
|
-
}
|
package/dist/VovkApp.js
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
var _a;
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.VovkApp = void 0;
|
|
8
|
-
const types_1 = require("./types");
|
|
9
|
-
const HttpException_1 = require("./HttpException");
|
|
10
|
-
const StreamJSONResponse_1 = require("./StreamJSONResponse");
|
|
11
|
-
const reqQuery_1 = __importDefault(require("./utils/reqQuery"));
|
|
12
|
-
const reqMeta_1 = __importDefault(require("./utils/reqMeta"));
|
|
13
|
-
const reqForm_1 = __importDefault(require("./utils/reqForm"));
|
|
14
|
-
const headers_1 = require("next/headers");
|
|
15
|
-
class VovkApp {
|
|
16
|
-
static getHeadersFromOptions(options) {
|
|
17
|
-
if (!options)
|
|
18
|
-
return {};
|
|
19
|
-
const corsHeaders = {
|
|
20
|
-
'access-control-allow-origin': '*',
|
|
21
|
-
'access-control-allow-methods': 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
|
|
22
|
-
'access-control-allow-headers': 'content-type, authorization',
|
|
23
|
-
};
|
|
24
|
-
const headers = {
|
|
25
|
-
...(options.cors ? corsHeaders : {}),
|
|
26
|
-
...(options.headers ?? {}),
|
|
27
|
-
};
|
|
28
|
-
return headers;
|
|
29
|
-
}
|
|
30
|
-
routes = {
|
|
31
|
-
GET: new Map(),
|
|
32
|
-
POST: new Map(),
|
|
33
|
-
PUT: new Map(),
|
|
34
|
-
PATCH: new Map(),
|
|
35
|
-
DELETE: new Map(),
|
|
36
|
-
HEAD: new Map(),
|
|
37
|
-
OPTIONS: new Map(),
|
|
38
|
-
};
|
|
39
|
-
GET = async (req, data) => this.#callMethod(types_1.HttpMethod.GET, req, await data.params);
|
|
40
|
-
POST = async (req, data) => this.#callMethod(types_1.HttpMethod.POST, req, await data.params);
|
|
41
|
-
PUT = async (req, data) => this.#callMethod(types_1.HttpMethod.PUT, req, await data.params);
|
|
42
|
-
PATCH = async (req, data) => this.#callMethod(types_1.HttpMethod.PATCH, req, await data.params);
|
|
43
|
-
DELETE = async (req, data) => this.#callMethod(types_1.HttpMethod.DELETE, req, await data.params);
|
|
44
|
-
HEAD = async (req, data) => this.#callMethod(types_1.HttpMethod.HEAD, req, await data.params);
|
|
45
|
-
OPTIONS = async (req, data) => this.#callMethod(types_1.HttpMethod.OPTIONS, req, await data.params);
|
|
46
|
-
respond = (status, body, options) => {
|
|
47
|
-
return new Response(JSON.stringify(body), {
|
|
48
|
-
status,
|
|
49
|
-
headers: {
|
|
50
|
-
'content-type': 'application/json',
|
|
51
|
-
..._a.getHeadersFromOptions(options),
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
#respondWithError = (statusCode, message, options, cause) => {
|
|
56
|
-
return this.respond(statusCode, {
|
|
57
|
-
cause,
|
|
58
|
-
statusCode,
|
|
59
|
-
message,
|
|
60
|
-
isError: true,
|
|
61
|
-
}, options);
|
|
62
|
-
};
|
|
63
|
-
#getHandler = ({ handlers, path, params, }) => {
|
|
64
|
-
const methodParams = {};
|
|
65
|
-
if (Object.keys(params).length === 0) {
|
|
66
|
-
return { handler: handlers[''], methodParams };
|
|
67
|
-
}
|
|
68
|
-
const allMethodKeys = Object.keys(handlers);
|
|
69
|
-
let methodKeys = [];
|
|
70
|
-
const pathStr = path.join('/');
|
|
71
|
-
methodKeys = allMethodKeys
|
|
72
|
-
// First, try to match literal routes exactly.
|
|
73
|
-
.filter((p) => {
|
|
74
|
-
if (p.includes(':'))
|
|
75
|
-
return false; // Skip parameterized paths
|
|
76
|
-
return p === pathStr;
|
|
77
|
-
});
|
|
78
|
-
if (!methodKeys.length) {
|
|
79
|
-
methodKeys = allMethodKeys.filter((p) => {
|
|
80
|
-
const routeSegments = p.split('/');
|
|
81
|
-
if (routeSegments.length !== path.length)
|
|
82
|
-
return false;
|
|
83
|
-
for (let i = 0; i < routeSegments.length; i++) {
|
|
84
|
-
const routeSegment = routeSegments[i];
|
|
85
|
-
const pathSegment = path[i];
|
|
86
|
-
if (routeSegment.startsWith(':')) {
|
|
87
|
-
const parameter = routeSegment.slice(1);
|
|
88
|
-
if (parameter in methodParams) {
|
|
89
|
-
throw new HttpException_1.HttpException(types_1.HttpStatus.INTERNAL_SERVER_ERROR, `Duplicate parameter "${parameter}" at ${p}`);
|
|
90
|
-
}
|
|
91
|
-
// If it's a parameterized segment, capture the parameter value.
|
|
92
|
-
methodParams[parameter] = pathSegment;
|
|
93
|
-
}
|
|
94
|
-
else if (routeSegment !== pathSegment) {
|
|
95
|
-
// If it's a literal segment and it does not match the corresponding path segment, return false.
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return true;
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
if (methodKeys.length > 1) {
|
|
103
|
-
throw new HttpException_1.HttpException(types_1.HttpStatus.INTERNAL_SERVER_ERROR, `Conflicting routes found: ${methodKeys.join(', ')}`);
|
|
104
|
-
}
|
|
105
|
-
const [methodKey] = methodKeys;
|
|
106
|
-
if (methodKey) {
|
|
107
|
-
return { handler: handlers[methodKey], methodParams };
|
|
108
|
-
}
|
|
109
|
-
return { handler: null, methodParams };
|
|
110
|
-
};
|
|
111
|
-
#callMethod = async (httpMethod, nextReq, params) => {
|
|
112
|
-
const req = nextReq;
|
|
113
|
-
const controllers = this.routes[httpMethod];
|
|
114
|
-
const path = params[Object.keys(params)[0]];
|
|
115
|
-
const handlers = {};
|
|
116
|
-
controllers.forEach((staticMethods, controller) => {
|
|
117
|
-
const prefix = controller._prefix ?? '';
|
|
118
|
-
if (!controller._activated) {
|
|
119
|
-
throw new HttpException_1.HttpException(types_1.HttpStatus.INTERNAL_SERVER_ERROR, `Controller "${controller.name}" found but not activated`);
|
|
120
|
-
}
|
|
121
|
-
Object.entries(staticMethods).forEach(([path, staticMethod]) => {
|
|
122
|
-
const fullPath = [prefix, path].filter(Boolean).join('/');
|
|
123
|
-
handlers[fullPath] = { staticMethod, controller };
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
const { handler, methodParams } = this.#getHandler({ handlers, path, params });
|
|
127
|
-
if (!handler) {
|
|
128
|
-
return this.#respondWithError(types_1.HttpStatus.NOT_FOUND, `Route ${path.join('/')} is not found`);
|
|
129
|
-
}
|
|
130
|
-
const { staticMethod, controller } = handler;
|
|
131
|
-
req.vovk = {
|
|
132
|
-
body: () => req.json(),
|
|
133
|
-
query: () => (0, reqQuery_1.default)(req),
|
|
134
|
-
meta: (meta) => (0, reqMeta_1.default)(req, meta),
|
|
135
|
-
form: () => (0, reqForm_1.default)(req),
|
|
136
|
-
params: () => methodParams,
|
|
137
|
-
};
|
|
138
|
-
try {
|
|
139
|
-
const result = await staticMethod.call(controller, req, methodParams);
|
|
140
|
-
const isIterator = typeof result === 'object' &&
|
|
141
|
-
!!result &&
|
|
142
|
-
((Reflect.has(result, Symbol.iterator) &&
|
|
143
|
-
typeof result[Symbol.iterator] === 'function') ||
|
|
144
|
-
(Reflect.has(result, Symbol.asyncIterator) &&
|
|
145
|
-
typeof result[Symbol.asyncIterator] === 'function'));
|
|
146
|
-
if (isIterator && !(result instanceof Array)) {
|
|
147
|
-
const streamResponse = new StreamJSONResponse_1.StreamJSONResponse(await (0, headers_1.headers)(), {
|
|
148
|
-
headers: {
|
|
149
|
-
..._a.getHeadersFromOptions(staticMethod._options),
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
void (async () => {
|
|
153
|
-
try {
|
|
154
|
-
for await (const chunk of result) {
|
|
155
|
-
streamResponse.send(chunk);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
catch (e) {
|
|
159
|
-
return streamResponse.throw(e);
|
|
160
|
-
}
|
|
161
|
-
return streamResponse.close();
|
|
162
|
-
})();
|
|
163
|
-
return streamResponse;
|
|
164
|
-
}
|
|
165
|
-
if (result instanceof Response) {
|
|
166
|
-
return result;
|
|
167
|
-
}
|
|
168
|
-
return this.respond(200, result ?? null, staticMethod._options);
|
|
169
|
-
}
|
|
170
|
-
catch (e) {
|
|
171
|
-
const err = e;
|
|
172
|
-
try {
|
|
173
|
-
await controller._onError?.(err, req);
|
|
174
|
-
}
|
|
175
|
-
catch (onErrorError) {
|
|
176
|
-
// eslint-disable-next-line no-console
|
|
177
|
-
console.error(onErrorError);
|
|
178
|
-
}
|
|
179
|
-
if (err.message !== 'NEXT_REDIRECT' && err.message !== 'NEXT_NOT_FOUND') {
|
|
180
|
-
const statusCode = err.statusCode || types_1.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
181
|
-
return this.#respondWithError(statusCode, err.message, staticMethod._options, err.cause);
|
|
182
|
-
}
|
|
183
|
-
throw e; // if NEXT_REDIRECT or NEXT_NOT_FOUND, rethrow it
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
exports.VovkApp = VovkApp;
|
|
188
|
-
_a = VovkApp;
|
package/dist/client/index.d.ts
DELETED
package/dist/client/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetcher = exports.createRPC = void 0;
|
|
4
|
-
var createRPC_1 = require("./createRPC");
|
|
5
|
-
Object.defineProperty(exports, "createRPC", { enumerable: true, get: function () { return createRPC_1.createRPC; } });
|
|
6
|
-
var fetcher_1 = require("./fetcher");
|
|
7
|
-
Object.defineProperty(exports, "fetcher", { enumerable: true, get: function () { return fetcher_1.fetcher; } });
|
package/dist/client/types.d.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import type { KnownAny, HttpMethod, ControllerStaticMethod, VovkControllerBody, VovkControllerQuery, VovkControllerParams, VovkHandlerSchema, VovkControllerSchema, VovkSegmentSchema, VovkFullSchema } from '../types';
|
|
2
|
-
import type { StreamJSONResponse } from '../StreamJSONResponse';
|
|
3
|
-
import type { NextResponse } from 'next/server';
|
|
4
|
-
export type StaticMethodInput<T extends ControllerStaticMethod> = (VovkControllerBody<T> extends undefined | void ? {
|
|
5
|
-
body?: undefined;
|
|
6
|
-
} : VovkControllerBody<T> extends null ? {
|
|
7
|
-
body?: null;
|
|
8
|
-
} : {
|
|
9
|
-
body: VovkControllerBody<T>;
|
|
10
|
-
}) & (VovkControllerQuery<T> extends undefined | void ? {
|
|
11
|
-
query?: undefined;
|
|
12
|
-
} : {
|
|
13
|
-
query: VovkControllerQuery<T>;
|
|
14
|
-
}) & (VovkControllerParams<T> extends undefined | void ? {
|
|
15
|
-
params?: undefined;
|
|
16
|
-
} : {
|
|
17
|
-
params: VovkControllerParams<T>;
|
|
18
|
-
});
|
|
19
|
-
type ToPromise<T> = T extends PromiseLike<unknown> ? T : Promise<T>;
|
|
20
|
-
export type VovkStreamAsyncIterable<T> = {
|
|
21
|
-
status: number;
|
|
22
|
-
[Symbol.dispose](): Promise<void> | void;
|
|
23
|
-
[Symbol.asyncDispose](): Promise<void> | void;
|
|
24
|
-
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
25
|
-
cancel: () => Promise<void> | void;
|
|
26
|
-
};
|
|
27
|
-
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>;
|
|
28
|
-
type StaticMethodReturnPromise<T extends ControllerStaticMethod> = ToPromise<StaticMethodReturn<T>>;
|
|
29
|
-
type ClientMethod<T extends (...args: KnownAny[]) => void | object | StreamJSONResponse<STREAM> | Promise<StreamJSONResponse<STREAM>>, OPTS extends Record<string, KnownAny>, STREAM extends KnownAny = unknown> = (<R>(options: (StaticMethodInput<T> extends {
|
|
30
|
-
body?: undefined | null;
|
|
31
|
-
query?: undefined;
|
|
32
|
-
params?: undefined;
|
|
33
|
-
} ? unknown : Parameters<T>[0] extends void ? StaticMethodInput<T>['params'] extends object ? {
|
|
34
|
-
params: StaticMethodInput<T>['params'];
|
|
35
|
-
} : unknown : StaticMethodInput<T>) & (Partial<OPTS & {
|
|
36
|
-
transform: (staticMethodReturn: Awaited<StaticMethodReturn<T>>) => R;
|
|
37
|
-
}> | void)) => ReturnType<T> extends Promise<StreamJSONResponse<infer U>> | StreamJSONResponse<infer U> | Iterator<infer U> | AsyncIterator<infer U> ? Promise<VovkStreamAsyncIterable<U>> : R extends object ? Promise<R> : StaticMethodReturnPromise<T>) & {
|
|
38
|
-
schema: VovkHandlerSchema;
|
|
39
|
-
controllerSchema: VovkControllerSchema;
|
|
40
|
-
segmentSchema: VovkSegmentSchema;
|
|
41
|
-
fullSchema: VovkFullSchema;
|
|
42
|
-
};
|
|
43
|
-
type OmitNever<T> = {
|
|
44
|
-
[K in keyof T as T[K] extends never ? never : K]: T[K];
|
|
45
|
-
};
|
|
46
|
-
type VovkClientWithNever<T, OPTS extends {
|
|
47
|
-
[key: string]: KnownAny;
|
|
48
|
-
}> = {
|
|
49
|
-
[K in keyof T]: T[K] extends (...args: KnownAny) => KnownAny ? ClientMethod<T[K], OPTS> : never;
|
|
50
|
-
};
|
|
51
|
-
export type VovkClient<T, OPTS extends {
|
|
52
|
-
[key: string]: KnownAny;
|
|
53
|
-
}> = OmitNever<VovkClientWithNever<T, OPTS>>;
|
|
54
|
-
export type VovkClientFetcher<OPTS extends Record<string, KnownAny> = Record<string, never>, T = KnownAny> = (options: {
|
|
55
|
-
name: keyof T;
|
|
56
|
-
httpMethod: HttpMethod;
|
|
57
|
-
getEndpoint: (data: {
|
|
58
|
-
apiRoot: string;
|
|
59
|
-
params: {
|
|
60
|
-
[key: string]: string;
|
|
61
|
-
};
|
|
62
|
-
query: {
|
|
63
|
-
[key: string]: string;
|
|
64
|
-
};
|
|
65
|
-
}) => string;
|
|
66
|
-
validate: (input: {
|
|
67
|
-
body?: unknown;
|
|
68
|
-
query?: unknown;
|
|
69
|
-
params?: unknown;
|
|
70
|
-
endpoint: string;
|
|
71
|
-
}) => void | Promise<void>;
|
|
72
|
-
defaultStreamHandler: (response: Response) => Promise<VovkStreamAsyncIterable<unknown>>;
|
|
73
|
-
defaultHandler: (response: Response) => Promise<unknown>;
|
|
74
|
-
}, input: {
|
|
75
|
-
body: unknown;
|
|
76
|
-
query: {
|
|
77
|
-
[key: string]: string;
|
|
78
|
-
};
|
|
79
|
-
params: {
|
|
80
|
-
[key: string]: string;
|
|
81
|
-
};
|
|
82
|
-
} & OPTS) => KnownAny;
|
|
83
|
-
export interface VovkDefaultFetcherOptions extends Omit<RequestInit, 'body' | 'method'> {
|
|
84
|
-
reactNative?: {
|
|
85
|
-
textStreaming: boolean;
|
|
86
|
-
};
|
|
87
|
-
apiRoot?: string;
|
|
88
|
-
segmentName?: string;
|
|
89
|
-
disableClientValidation?: boolean;
|
|
90
|
-
validateOnClient?: VovkValidateOnClient;
|
|
91
|
-
fetcher?: VovkClientFetcher;
|
|
92
|
-
}
|
|
93
|
-
export type VovkValidateOnClient = (input: {
|
|
94
|
-
body?: unknown;
|
|
95
|
-
query?: unknown;
|
|
96
|
-
params?: unknown;
|
|
97
|
-
endpoint: string;
|
|
98
|
-
}, validation: Exclude<VovkHandlerSchema['validation'], undefined>, fullSchema: VovkFullSchema) => void | Promise<void>;
|
|
99
|
-
export type VovkClientOptions<OPTS extends Record<string, KnownAny> = Record<string, never>> = {
|
|
100
|
-
fetcher?: VovkClientFetcher<OPTS>;
|
|
101
|
-
validateOnClient?: VovkValidateOnClient;
|
|
102
|
-
defaultOptions?: Partial<OPTS>;
|
|
103
|
-
};
|
|
104
|
-
export {};
|
package/dist/client/types.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { VovkHandlerSchema, KnownAny, VovkController, VovkRequest } from './types';
|
|
2
|
-
type Next = () => Promise<unknown>;
|
|
3
|
-
export declare function createDecorator<ARGS extends unknown[], REQUEST = VovkRequest>(handler: null | ((this: VovkController, req: REQUEST, next: Next, ...args: ARGS) => unknown), initHandler?: (this: VovkController, ...args: ARGS) => Omit<VovkHandlerSchema, 'path' | 'httpMethod'> | ((handlerSchema: VovkHandlerSchema | null, options: {
|
|
4
|
-
handlerName: string;
|
|
5
|
-
}) => Omit<Partial<VovkHandlerSchema>, 'path' | 'httpMethod'>) | null | undefined): (...args: ARGS) => (target: KnownAny, propertyKey: string) => void;
|
|
6
|
-
export {};
|
package/dist/createDecorator.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDecorator = createDecorator;
|
|
4
|
-
function createDecorator(handler, initHandler) {
|
|
5
|
-
return function decoratorCreator(...args) {
|
|
6
|
-
return function decorator(target, propertyKey) {
|
|
7
|
-
const controller = target;
|
|
8
|
-
const originalMethod = controller[propertyKey];
|
|
9
|
-
if (typeof originalMethod !== 'function') {
|
|
10
|
-
throw new Error(`Unable to decorate: ${propertyKey} is not a function`);
|
|
11
|
-
}
|
|
12
|
-
const sourceMethod = originalMethod._sourceMethod ?? originalMethod;
|
|
13
|
-
const method = function method(req, params) {
|
|
14
|
-
const next = async () => {
|
|
15
|
-
return (await originalMethod.call(controller, req, params));
|
|
16
|
-
};
|
|
17
|
-
return handler ? handler.call(controller, req, next, ...args) : next();
|
|
18
|
-
};
|
|
19
|
-
controller[propertyKey] = method;
|
|
20
|
-
method._controller = controller;
|
|
21
|
-
method._sourceMethod = sourceMethod;
|
|
22
|
-
// TODO define internal method type
|
|
23
|
-
originalMethod._controller = controller;
|
|
24
|
-
const handlerSchema = controller._handlers?.[propertyKey] ?? null;
|
|
25
|
-
const initResultReturn = initHandler?.call(controller, ...args);
|
|
26
|
-
const initResult = typeof initResultReturn === 'function'
|
|
27
|
-
? initResultReturn(handlerSchema, {
|
|
28
|
-
handlerName: propertyKey,
|
|
29
|
-
})
|
|
30
|
-
: initResultReturn;
|
|
31
|
-
controller._handlers = {
|
|
32
|
-
...controller._handlers,
|
|
33
|
-
[propertyKey]: {
|
|
34
|
-
...handlerSchema,
|
|
35
|
-
// avoid override of path and httpMethod
|
|
36
|
-
...(initResult?.validation ? { validation: initResult.validation } : {}),
|
|
37
|
-
...(initResult?.openapi ? { openapi: initResult.openapi } : {}),
|
|
38
|
-
...(initResult?.custom ? { custom: initResult.custom } : {}),
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
}
|
package/dist/createVovkApp.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { NextRequest } from 'next/server';
|
|
2
|
-
import { type KnownAny, type DecoratorOptions, type VovkRequest, type StaticClass } from './types';
|
|
3
|
-
export declare function createVovkApp(): {
|
|
4
|
-
get: {
|
|
5
|
-
(givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
|
|
6
|
-
auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
|
|
7
|
-
};
|
|
8
|
-
post: {
|
|
9
|
-
(givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
|
|
10
|
-
auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
|
|
11
|
-
};
|
|
12
|
-
put: {
|
|
13
|
-
(givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
|
|
14
|
-
auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
|
|
15
|
-
};
|
|
16
|
-
patch: {
|
|
17
|
-
(givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
|
|
18
|
-
auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
|
|
19
|
-
};
|
|
20
|
-
del: {
|
|
21
|
-
(givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
|
|
22
|
-
auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
|
|
23
|
-
};
|
|
24
|
-
head: {
|
|
25
|
-
(givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
|
|
26
|
-
auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
|
|
27
|
-
};
|
|
28
|
-
options: {
|
|
29
|
-
(givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
|
|
30
|
-
auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
|
|
31
|
-
};
|
|
32
|
-
prefix: (givenPath?: string) => (givenTarget: KnownAny) => any;
|
|
33
|
-
initVovk: (options: {
|
|
34
|
-
segmentName?: string;
|
|
35
|
-
controllers: Record<string, StaticClass>;
|
|
36
|
-
exposeValidation?: boolean;
|
|
37
|
-
emitSchema?: boolean;
|
|
38
|
-
onError?: (err: Error, req: VovkRequest) => void | Promise<void>;
|
|
39
|
-
}) => {
|
|
40
|
-
GET: (req: NextRequest, data: {
|
|
41
|
-
params: Promise<Record<string, string[]>>;
|
|
42
|
-
}) => Promise<Response>;
|
|
43
|
-
POST: (req: NextRequest, data: {
|
|
44
|
-
params: Promise<Record<string, string[]>>;
|
|
45
|
-
}) => Promise<Response>;
|
|
46
|
-
PUT: (req: NextRequest, data: {
|
|
47
|
-
params: Promise<Record<string, string[]>>;
|
|
48
|
-
}) => Promise<Response>;
|
|
49
|
-
PATCH: (req: NextRequest, data: {
|
|
50
|
-
params: Promise<Record<string, string[]>>;
|
|
51
|
-
}) => Promise<Response>;
|
|
52
|
-
DELETE: (req: NextRequest, data: {
|
|
53
|
-
params: Promise<Record<string, string[]>>;
|
|
54
|
-
}) => Promise<Response>;
|
|
55
|
-
HEAD: (req: NextRequest, data: {
|
|
56
|
-
params: Promise<Record<string, string[]>>;
|
|
57
|
-
}) => Promise<Response>;
|
|
58
|
-
OPTIONS: (req: NextRequest, data: {
|
|
59
|
-
params: Promise<Record<string, string[]>>;
|
|
60
|
-
}) => Promise<Response>;
|
|
61
|
-
};
|
|
62
|
-
};
|
package/dist/createVovkApp.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
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-Z])/g, '-$1')
|
|
14
|
-
.toLowerCase()
|
|
15
|
-
.replace(/^-/, '');
|
|
16
|
-
const assignSchema = ({ controller, propertyKey, path, options, httpMethod, vovkApp, }) => {
|
|
17
|
-
if (typeof window !== 'undefined') {
|
|
18
|
-
throw new Error('Decorators are intended for server-side use only. You have probably imported a controller on the client-side.');
|
|
19
|
-
}
|
|
20
|
-
if (!isClass(controller)) {
|
|
21
|
-
let decoratorName = httpMethod.toLowerCase();
|
|
22
|
-
if (decoratorName === 'delete')
|
|
23
|
-
decoratorName = 'del';
|
|
24
|
-
throw new Error(`Decorator must be used on a static class method. Check the controller method named "${propertyKey}" used with @${decoratorName}().`);
|
|
25
|
-
}
|
|
26
|
-
const methods = vovkApp.routes[httpMethod].get(controller) ?? {};
|
|
27
|
-
vovkApp.routes[httpMethod].set(controller, methods);
|
|
28
|
-
const originalMethod = controller[propertyKey];
|
|
29
|
-
originalMethod._controller = controller;
|
|
30
|
-
originalMethod._sourceMethod = originalMethod._sourceMethod ?? originalMethod;
|
|
31
|
-
const schema = originalMethod._sourceMethod._getSchema?.(controller);
|
|
32
|
-
controller._handlers = {
|
|
33
|
-
...controller._handlers,
|
|
34
|
-
[propertyKey]: {
|
|
35
|
-
...schema,
|
|
36
|
-
...(controller._handlers ?? {})[propertyKey],
|
|
37
|
-
path,
|
|
38
|
-
httpMethod,
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
methods[path] = controller[propertyKey];
|
|
42
|
-
methods[path]._options = options;
|
|
43
|
-
};
|
|
44
|
-
function createVovkApp() {
|
|
45
|
-
const vovkApp = new VovkApp_1.VovkApp();
|
|
46
|
-
const createHTTPDecorator = (httpMethod) => {
|
|
47
|
-
function decoratorCreator(givenPath = '', options) {
|
|
48
|
-
const path = trimPath(givenPath);
|
|
49
|
-
function decorator(givenTarget, propertyKey) {
|
|
50
|
-
const controller = givenTarget;
|
|
51
|
-
assignSchema({ controller, propertyKey, path, options, httpMethod, vovkApp });
|
|
52
|
-
}
|
|
53
|
-
return decorator;
|
|
54
|
-
}
|
|
55
|
-
const auto = (options) => {
|
|
56
|
-
function decorator(givenTarget, propertyKey) {
|
|
57
|
-
const controller = givenTarget;
|
|
58
|
-
const methods = vovkApp.routes[httpMethod].get(controller) ?? {};
|
|
59
|
-
vovkApp.routes[httpMethod].set(controller, methods);
|
|
60
|
-
controller._handlers = {
|
|
61
|
-
...controller._handlers,
|
|
62
|
-
[propertyKey]: {
|
|
63
|
-
...(controller._handlers ?? {})[propertyKey],
|
|
64
|
-
httpMethod,
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
assignSchema({ controller, propertyKey, path: toKebabCase(propertyKey), options, httpMethod, vovkApp });
|
|
68
|
-
}
|
|
69
|
-
return decorator;
|
|
70
|
-
};
|
|
71
|
-
const enhancedDecoratorCreator = decoratorCreator;
|
|
72
|
-
enhancedDecoratorCreator.auto = auto;
|
|
73
|
-
return enhancedDecoratorCreator;
|
|
74
|
-
};
|
|
75
|
-
const prefix = (givenPath = '') => {
|
|
76
|
-
const path = trimPath(givenPath);
|
|
77
|
-
return (givenTarget) => {
|
|
78
|
-
const controller = givenTarget;
|
|
79
|
-
controller._prefix = path;
|
|
80
|
-
return givenTarget;
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
const initVovk = (options) => {
|
|
84
|
-
for (const [controllerName, controller] of Object.entries(options.controllers)) {
|
|
85
|
-
controller._controllerName = controllerName;
|
|
86
|
-
controller._activated = true;
|
|
87
|
-
controller._onError = options?.onError;
|
|
88
|
-
}
|
|
89
|
-
async function GET_DEV(req, data) {
|
|
90
|
-
const params = await data.params;
|
|
91
|
-
if (params[Object.keys(params)[0]]?.[0] === '_schema_') {
|
|
92
|
-
const schema = (0, getSchema_1.default)(options);
|
|
93
|
-
return vovkApp.respond(200, { schema });
|
|
94
|
-
}
|
|
95
|
-
return vovkApp.GET(req, data);
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
GET: process.env.NODE_ENV === 'development' ? GET_DEV : vovkApp.GET,
|
|
99
|
-
POST: vovkApp.POST,
|
|
100
|
-
PUT: vovkApp.PUT,
|
|
101
|
-
PATCH: vovkApp.PATCH,
|
|
102
|
-
DELETE: vovkApp.DELETE,
|
|
103
|
-
HEAD: vovkApp.HEAD,
|
|
104
|
-
OPTIONS: vovkApp.OPTIONS,
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
return {
|
|
108
|
-
get: createHTTPDecorator(types_1.HttpMethod.GET),
|
|
109
|
-
post: createHTTPDecorator(types_1.HttpMethod.POST),
|
|
110
|
-
put: createHTTPDecorator(types_1.HttpMethod.PUT),
|
|
111
|
-
patch: createHTTPDecorator(types_1.HttpMethod.PATCH),
|
|
112
|
-
del: createHTTPDecorator(types_1.HttpMethod.DELETE),
|
|
113
|
-
head: createHTTPDecorator(types_1.HttpMethod.HEAD),
|
|
114
|
-
options: createHTTPDecorator(types_1.HttpMethod.OPTIONS),
|
|
115
|
-
prefix,
|
|
116
|
-
initVovk,
|
|
117
|
-
};
|
|
118
|
-
}
|