vovk 3.0.0-draft.86 → 3.0.0-draft.90
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/dist/StreamJSONResponse.js +1 -1
- package/dist/VovkApp.js +53 -53
- package/dist/client/createRPC.d.ts +3 -3
- package/dist/client/createRPC.js +20 -11
- package/dist/client/defaultFetcher.js +1 -1
- package/dist/client/types.d.ts +3 -1
- package/dist/createDecorator.d.ts +1 -2
- package/dist/createDecorator.js +0 -2
- package/dist/createVovkApp.js +31 -31
- package/dist/index.d.ts +2 -2
- package/dist/types.d.ts +64 -3
- package/dist/types.js +1 -0
- package/dist/utils/getSchema.d.ts +2 -2
- package/package.json +5 -1
|
@@ -4,7 +4,7 @@ exports.StreamJSONResponse = void 0;
|
|
|
4
4
|
require("./utils/shim");
|
|
5
5
|
class StreamJSONResponse extends Response {
|
|
6
6
|
static defaultHeaders = {
|
|
7
|
-
'content-type': 'text/plain; format=jsonlines',
|
|
7
|
+
'content-type': 'text/plain; x-format=jsonlines',
|
|
8
8
|
};
|
|
9
9
|
isClosed = false;
|
|
10
10
|
controller;
|
package/dist/VovkApp.js
CHANGED
|
@@ -16,9 +16,9 @@ class VovkApp {
|
|
|
16
16
|
if (!options)
|
|
17
17
|
return {};
|
|
18
18
|
const corsHeaders = {
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
19
|
+
'access-control-allow-origin': '*',
|
|
20
|
+
'access-control-allow-methods': 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
|
|
21
|
+
'access-control-allow-headers': 'content-type, authorization',
|
|
22
22
|
};
|
|
23
23
|
const headers = {
|
|
24
24
|
...(options.cors ? corsHeaders : {}),
|
|
@@ -46,7 +46,7 @@ class VovkApp {
|
|
|
46
46
|
return new Response(JSON.stringify(body), {
|
|
47
47
|
status,
|
|
48
48
|
headers: {
|
|
49
|
-
'
|
|
49
|
+
'content-type': 'application/json',
|
|
50
50
|
..._a.getHeadersFromOptions(options),
|
|
51
51
|
},
|
|
52
52
|
});
|
|
@@ -59,10 +59,57 @@ class VovkApp {
|
|
|
59
59
|
isError: true,
|
|
60
60
|
}, options);
|
|
61
61
|
};
|
|
62
|
+
#getHandler = ({ handlers, path, params, }) => {
|
|
63
|
+
const methodParams = {};
|
|
64
|
+
if (Object.keys(params).length === 0) {
|
|
65
|
+
return { handler: handlers[''], methodParams };
|
|
66
|
+
}
|
|
67
|
+
const allMethodKeys = Object.keys(handlers);
|
|
68
|
+
let methodKeys = [];
|
|
69
|
+
const pathStr = path.join('/');
|
|
70
|
+
methodKeys = allMethodKeys
|
|
71
|
+
// First, try to match literal routes exactly.
|
|
72
|
+
.filter((p) => {
|
|
73
|
+
if (p.includes(':'))
|
|
74
|
+
return false; // Skip parameterized paths
|
|
75
|
+
return p === pathStr;
|
|
76
|
+
});
|
|
77
|
+
if (!methodKeys.length) {
|
|
78
|
+
methodKeys = allMethodKeys.filter((p) => {
|
|
79
|
+
const routeSegments = p.split('/');
|
|
80
|
+
if (routeSegments.length !== path.length)
|
|
81
|
+
return false;
|
|
82
|
+
for (let i = 0; i < routeSegments.length; i++) {
|
|
83
|
+
const routeSegment = routeSegments[i];
|
|
84
|
+
const pathSegment = path[i];
|
|
85
|
+
if (routeSegment.startsWith(':')) {
|
|
86
|
+
const parameter = routeSegment.slice(1);
|
|
87
|
+
if (parameter in methodParams) {
|
|
88
|
+
throw new HttpException_1.HttpException(types_1.HttpStatus.INTERNAL_SERVER_ERROR, `Duplicate parameter "${parameter}" at ${p}`);
|
|
89
|
+
}
|
|
90
|
+
// If it's a parameterized segment, capture the parameter value.
|
|
91
|
+
methodParams[parameter] = pathSegment;
|
|
92
|
+
}
|
|
93
|
+
else if (routeSegment !== pathSegment) {
|
|
94
|
+
// If it's a literal segment and it does not match the corresponding path segment, return false.
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (methodKeys.length > 1) {
|
|
102
|
+
throw new HttpException_1.HttpException(types_1.HttpStatus.INTERNAL_SERVER_ERROR, `Conflicting routes found: ${methodKeys.join(', ')}`);
|
|
103
|
+
}
|
|
104
|
+
const [methodKey] = methodKeys;
|
|
105
|
+
if (methodKey) {
|
|
106
|
+
return { handler: handlers[methodKey], methodParams };
|
|
107
|
+
}
|
|
108
|
+
return { handler: null, methodParams };
|
|
109
|
+
};
|
|
62
110
|
#callMethod = async (httpMethod, nextReq, params) => {
|
|
63
111
|
const req = nextReq;
|
|
64
112
|
const controllers = this.routes[httpMethod];
|
|
65
|
-
const methodParams = {};
|
|
66
113
|
const path = params[Object.keys(params)[0]];
|
|
67
114
|
const handlers = {};
|
|
68
115
|
controllers.forEach((staticMethods, controller) => {
|
|
@@ -75,54 +122,7 @@ class VovkApp {
|
|
|
75
122
|
handlers[fullPath] = { staticMethod, controller };
|
|
76
123
|
});
|
|
77
124
|
});
|
|
78
|
-
const
|
|
79
|
-
if (Object.keys(params).length === 0) {
|
|
80
|
-
return handlers[''];
|
|
81
|
-
}
|
|
82
|
-
const allMethodKeys = Object.keys(handlers);
|
|
83
|
-
let methodKeys = [];
|
|
84
|
-
const pathStr = path.join('/');
|
|
85
|
-
methodKeys = allMethodKeys
|
|
86
|
-
// First, try to match literal routes exactly.
|
|
87
|
-
.filter((p) => {
|
|
88
|
-
if (p.includes(':'))
|
|
89
|
-
return false; // Skip parameterized paths
|
|
90
|
-
return p === pathStr;
|
|
91
|
-
});
|
|
92
|
-
if (!methodKeys.length) {
|
|
93
|
-
methodKeys = allMethodKeys.filter((p) => {
|
|
94
|
-
const routeSegments = p.split('/');
|
|
95
|
-
if (routeSegments.length !== path.length)
|
|
96
|
-
return false;
|
|
97
|
-
for (let i = 0; i < routeSegments.length; i++) {
|
|
98
|
-
const routeSegment = routeSegments[i];
|
|
99
|
-
const pathSegment = path[i];
|
|
100
|
-
if (routeSegment.startsWith(':')) {
|
|
101
|
-
const parameter = routeSegment.slice(1);
|
|
102
|
-
if (parameter in methodParams) {
|
|
103
|
-
throw new HttpException_1.HttpException(types_1.HttpStatus.INTERNAL_SERVER_ERROR, `Duplicate parameter "${parameter}"`);
|
|
104
|
-
}
|
|
105
|
-
// If it's a parameterized segment, capture the parameter value.
|
|
106
|
-
methodParams[parameter] = pathSegment;
|
|
107
|
-
}
|
|
108
|
-
else if (routeSegment !== pathSegment) {
|
|
109
|
-
// If it's a literal segment and it does not match the corresponding path segment, return false.
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return true;
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
if (methodKeys.length > 1) {
|
|
117
|
-
throw new HttpException_1.HttpException(types_1.HttpStatus.INTERNAL_SERVER_ERROR, `Conflicting routes found: ${methodKeys.join(', ')}`);
|
|
118
|
-
}
|
|
119
|
-
const [methodKey] = methodKeys;
|
|
120
|
-
if (methodKey) {
|
|
121
|
-
return handlers[methodKey];
|
|
122
|
-
}
|
|
123
|
-
return null;
|
|
124
|
-
};
|
|
125
|
-
const handler = getHandler();
|
|
125
|
+
const { handler, methodParams } = this.#getHandler({ handlers, path, params });
|
|
126
126
|
if (!handler) {
|
|
127
127
|
return this.#respondWithError(types_1.HttpStatus.NOT_FOUND, `Route ${path.join('/')} is not found`);
|
|
128
128
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
declare const createRPC: <T, OPTS extends Record<string, KnownAny> = VovkDefaultFetcherOptions>(
|
|
1
|
+
import type { KnownAny, VovkFullSchema } from '../types';
|
|
2
|
+
import type { VovkClientOptions, VovkClient, VovkDefaultFetcherOptions } from './types';
|
|
3
|
+
declare const createRPC: <T, OPTS extends Record<string, KnownAny> = VovkDefaultFetcherOptions>(fullSchema: VovkFullSchema, segmentName: string, controllerName: string, options?: VovkClientOptions<OPTS>) => VovkClient<T, OPTS>;
|
|
4
4
|
export default createRPC;
|
package/dist/client/createRPC.js
CHANGED
|
@@ -10,22 +10,23 @@ const serializeQuery_1 = __importDefault(require("../utils/serializeQuery"));
|
|
|
10
10
|
const trimPath = (path) => path.trim().replace(/^\/|\/$/g, '');
|
|
11
11
|
const getHandlerPath = (endpoint, params, query) => {
|
|
12
12
|
let result = endpoint;
|
|
13
|
+
const queryStr = query ? (0, serializeQuery_1.default)(query) : null;
|
|
13
14
|
for (const [key, value] of Object.entries(params ?? {})) {
|
|
14
15
|
result = result.replace(`:${key}`, value);
|
|
15
16
|
}
|
|
16
|
-
const queryStr = query ? (0, serializeQuery_1.default)(query) : null;
|
|
17
17
|
return `${result}${queryStr ? '?' : ''}${queryStr}`;
|
|
18
18
|
};
|
|
19
|
-
const createRPC = (
|
|
20
|
-
const
|
|
19
|
+
const createRPC = (fullSchema, segmentName, controllerName, options) => {
|
|
20
|
+
const segmentSchema = fullSchema.segments[segmentName];
|
|
21
|
+
if (!segmentSchema)
|
|
22
|
+
throw new Error(`Unable to create RPC object. Segment schema is missing. Check client template.`);
|
|
23
|
+
const controllerSchema = fullSchema.segments[segmentName]?.controllers[controllerName];
|
|
21
24
|
const client = {};
|
|
22
|
-
if (!
|
|
23
|
-
throw new Error(`Unable to
|
|
24
|
-
|
|
25
|
-
throw new Error(`Unable to clientize. No schema for controller ${String(schema?.controllerName)} provided`);
|
|
26
|
-
const controllerPrefix = trimPath(schema.prefix ?? '');
|
|
25
|
+
if (!controllerSchema)
|
|
26
|
+
throw new Error(`Unable to create RPC object. Controller schema is missing. Check client template.`);
|
|
27
|
+
const controllerPrefix = trimPath(controllerSchema.prefix ?? '');
|
|
27
28
|
const { fetcher: settingsFetcher = defaultFetcher_1.default } = options ?? {};
|
|
28
|
-
for (const [staticMethodName, handlerSchema] of Object.entries(
|
|
29
|
+
for (const [staticMethodName, handlerSchema] of Object.entries(controllerSchema.handlers)) {
|
|
29
30
|
const { path, httpMethod, validation } = handlerSchema;
|
|
30
31
|
const getEndpoint = ({ apiRoot, params, query, }) => {
|
|
31
32
|
const mainPrefix = (apiRoot.startsWith('http://') || apiRoot.startsWith('https://') || apiRoot.startsWith('/') ? '' : '/') +
|
|
@@ -36,7 +37,13 @@ const createRPC = (controllerSchema, segmentName, options) => {
|
|
|
36
37
|
const handler = (input = {}) => {
|
|
37
38
|
const fetcher = input.fetcher ?? settingsFetcher;
|
|
38
39
|
const validate = async ({ body, query, params, endpoint, }) => {
|
|
39
|
-
|
|
40
|
+
const validateOnClient = input.validateOnClient ?? options?.validateOnClient;
|
|
41
|
+
if (validateOnClient) {
|
|
42
|
+
if (typeof validateOnClient !== 'function') {
|
|
43
|
+
throw new Error('validateOnClient must be a function');
|
|
44
|
+
}
|
|
45
|
+
await validateOnClient({ body, query, params, endpoint }, validation ?? {});
|
|
46
|
+
}
|
|
40
47
|
};
|
|
41
48
|
const internalOptions = {
|
|
42
49
|
name: staticMethodName,
|
|
@@ -66,7 +73,9 @@ const createRPC = (controllerSchema, segmentName, options) => {
|
|
|
66
73
|
return input.transform ? fetcherPromise.then(input.transform) : fetcherPromise;
|
|
67
74
|
};
|
|
68
75
|
handler.schema = handlerSchema;
|
|
69
|
-
handler.controllerSchema =
|
|
76
|
+
handler.controllerSchema = controllerSchema;
|
|
77
|
+
handler.segmentSchema = segmentSchema;
|
|
78
|
+
handler.fullSchema = fullSchema;
|
|
70
79
|
// @ts-expect-error TODO
|
|
71
80
|
client[staticMethodName] = handler;
|
|
72
81
|
}
|
|
@@ -52,7 +52,7 @@ const defaultFetcher = async ({ httpMethod, getEndpoint, validate, defaultHandle
|
|
|
52
52
|
if (contentType?.startsWith('application/json')) {
|
|
53
53
|
return defaultHandler(response);
|
|
54
54
|
}
|
|
55
|
-
if (contentType
|
|
55
|
+
if (contentType?.startsWith('text/plain') && contentType.includes('x-format=jsonlines')) {
|
|
56
56
|
return defaultStreamHandler(response);
|
|
57
57
|
}
|
|
58
58
|
return response;
|
package/dist/client/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { KnownAny, HttpMethod, ControllerStaticMethod, VovkControllerBody, VovkControllerQuery, VovkControllerParams, VovkHandlerSchema, VovkControllerSchema } from '../types';
|
|
1
|
+
import type { KnownAny, HttpMethod, ControllerStaticMethod, VovkControllerBody, VovkControllerQuery, VovkControllerParams, VovkHandlerSchema, VovkControllerSchema, VovkSegmentSchema, VovkFullSchema } from '../types';
|
|
2
2
|
import type { StreamJSONResponse } from '../StreamJSONResponse';
|
|
3
3
|
import type { NextResponse } from 'next/server';
|
|
4
4
|
export type StaticMethodInput<T extends ControllerStaticMethod> = (VovkControllerBody<T> extends undefined | void ? {
|
|
@@ -37,6 +37,8 @@ type ClientMethod<T extends (...args: KnownAny[]) => void | object | StreamJSONR
|
|
|
37
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
38
|
schema: VovkHandlerSchema;
|
|
39
39
|
controllerSchema: VovkControllerSchema;
|
|
40
|
+
segmentSchema: VovkSegmentSchema;
|
|
41
|
+
fullSchema: VovkFullSchema;
|
|
40
42
|
};
|
|
41
43
|
type OmitNever<T> = {
|
|
42
44
|
[K in keyof T as T[K] extends never ? never : K]: T[K];
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { VovkHandlerSchema, KnownAny, VovkController, VovkRequest
|
|
1
|
+
import type { VovkHandlerSchema, KnownAny, VovkController, VovkRequest } from './types';
|
|
2
2
|
type Next = () => Promise<unknown>;
|
|
3
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
4
|
handlerName: string;
|
|
5
|
-
controllerSchema: VovkControllerSchema;
|
|
6
5
|
}) => Omit<Partial<VovkHandlerSchema>, 'path' | 'httpMethod'>) | null | undefined): (...args: ARGS) => (target: KnownAny, propertyKey: string) => void;
|
|
7
6
|
export {};
|
package/dist/createDecorator.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createDecorator = createDecorator;
|
|
4
|
-
const getSchema_1 = require("./utils/getSchema");
|
|
5
4
|
function createDecorator(handler, initHandler) {
|
|
6
5
|
return function decoratorCreator(...args) {
|
|
7
6
|
return function decorator(target, propertyKey) {
|
|
@@ -27,7 +26,6 @@ function createDecorator(handler, initHandler) {
|
|
|
27
26
|
const initResult = typeof initResultReturn === 'function'
|
|
28
27
|
? initResultReturn(handlerSchema, {
|
|
29
28
|
handlerName: propertyKey,
|
|
30
|
-
controllerSchema: (0, getSchema_1.getControllerSchema)(controller, controller._controllerName ?? 'ERROR', true),
|
|
31
29
|
})
|
|
32
30
|
: initResultReturn;
|
|
33
31
|
controller._handlers = {
|
package/dist/createVovkApp.js
CHANGED
|
@@ -13,42 +13,42 @@ const toKebabCase = (str) => str
|
|
|
13
13
|
.replace(/([A-Z])/g, '-$1')
|
|
14
14
|
.toLowerCase()
|
|
15
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 validation = originalMethod._sourceMethod._getValidation?.(controller);
|
|
32
|
+
controller._handlers = {
|
|
33
|
+
...controller._handlers,
|
|
34
|
+
[propertyKey]: {
|
|
35
|
+
...(validation ? { validation } : {}),
|
|
36
|
+
...(controller._handlers ?? {})[propertyKey],
|
|
37
|
+
path,
|
|
38
|
+
httpMethod,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
methods[path] = controller[propertyKey];
|
|
42
|
+
methods[path]._options = options;
|
|
43
|
+
};
|
|
16
44
|
function createVovkApp() {
|
|
17
45
|
const vovkApp = new VovkApp_1.VovkApp();
|
|
18
46
|
const createHTTPDecorator = (httpMethod) => {
|
|
19
|
-
const assignSchema = (controller, propertyKey, path, options) => {
|
|
20
|
-
if (typeof window !== 'undefined') {
|
|
21
|
-
throw new Error('Decorators are intended for server-side use only. You have probably imported a controller on the client-side.');
|
|
22
|
-
}
|
|
23
|
-
if (!isClass(controller)) {
|
|
24
|
-
let decoratorName = httpMethod.toLowerCase();
|
|
25
|
-
if (decoratorName === 'delete')
|
|
26
|
-
decoratorName = 'del';
|
|
27
|
-
throw new Error(`Decorator must be used on a static class method. Check the controller method named "${propertyKey}" used with @${decoratorName}.`);
|
|
28
|
-
}
|
|
29
|
-
const methods = vovkApp.routes[httpMethod].get(controller) ?? {};
|
|
30
|
-
vovkApp.routes[httpMethod].set(controller, methods);
|
|
31
|
-
const originalMethod = controller[propertyKey];
|
|
32
|
-
originalMethod._controller = controller;
|
|
33
|
-
originalMethod._sourceMethod = originalMethod._sourceMethod ?? originalMethod;
|
|
34
|
-
const validation = originalMethod._sourceMethod._getValidation?.(controller);
|
|
35
|
-
controller._handlers = {
|
|
36
|
-
...controller._handlers,
|
|
37
|
-
[propertyKey]: {
|
|
38
|
-
...(validation ? { validation } : {}),
|
|
39
|
-
...(controller._handlers ?? {})[propertyKey],
|
|
40
|
-
path,
|
|
41
|
-
httpMethod,
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
methods[path] = controller[propertyKey];
|
|
45
|
-
methods[path]._options = options;
|
|
46
|
-
};
|
|
47
47
|
function decoratorCreator(givenPath = '', options) {
|
|
48
48
|
const path = trimPath(givenPath);
|
|
49
49
|
function decorator(givenTarget, propertyKey) {
|
|
50
|
-
const
|
|
51
|
-
assignSchema(
|
|
50
|
+
const controller = givenTarget;
|
|
51
|
+
assignSchema({ controller, propertyKey, path, options, httpMethod, vovkApp });
|
|
52
52
|
}
|
|
53
53
|
return decorator;
|
|
54
54
|
}
|
|
@@ -64,7 +64,7 @@ function createVovkApp() {
|
|
|
64
64
|
httpMethod,
|
|
65
65
|
},
|
|
66
66
|
};
|
|
67
|
-
assignSchema(controller, propertyKey, toKebabCase(propertyKey), options);
|
|
67
|
+
assignSchema({ controller, propertyKey, path: toKebabCase(propertyKey), options, httpMethod, vovkApp });
|
|
68
68
|
}
|
|
69
69
|
return decorator;
|
|
70
70
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createVovkApp } from './createVovkApp';
|
|
2
|
-
import { HttpStatus as HttpStatus, HttpMethod as HttpMethod, type KnownAny, type VovkErrorResponse, type VovkRequest, type VovkBody, type VovkQuery, type VovkParams, type VovkReturnType, type VovkYieldType, type VovkControllerBody, type VovkControllerQuery, type VovkControllerParams, type VovkControllerYieldType, type
|
|
2
|
+
import { HttpStatus as HttpStatus, HttpMethod as HttpMethod, type KnownAny, type VovkErrorResponse, type VovkRequest, type VovkBody, type VovkQuery, type VovkParams, type VovkReturnType, type VovkYieldType, type VovkControllerBody, type VovkControllerQuery, type VovkControllerParams, type VovkControllerYieldType, type VovkControllerOutput, type VovkSegmentSchema, type VovkControllerSchema, type VovkHandlerSchema, type VovkFullSchema, type VovkConfig, type VovkStrictConfig, type VovkEnv } from './types';
|
|
3
3
|
import { type VovkClient, type VovkClientOptions, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, type VovkStreamAsyncIterable, createRPC } from './client';
|
|
4
4
|
import { HttpException } from './HttpException';
|
|
5
5
|
import { createDecorator } from './createDecorator';
|
|
6
6
|
import { StreamJSONResponse } from './StreamJSONResponse';
|
|
7
7
|
import { generateStaticAPI } from './utils/generateStaticAPI';
|
|
8
8
|
import { setHandlerValidation } from './utils/setHandlerValidation';
|
|
9
|
-
export { type KnownAny, type VovkClient, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkStreamAsyncIterable, type VovkValidateOnClient, type
|
|
9
|
+
export { type KnownAny, type VovkClient, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkStreamAsyncIterable, type VovkValidateOnClient, type VovkSegmentSchema, type VovkErrorResponse, type VovkRequest, type VovkControllerBody, type VovkControllerQuery, type VovkControllerParams, type VovkControllerYieldType, type VovkControllerOutput, type VovkBody, type VovkQuery, type VovkParams, type VovkYieldType, type VovkReturnType, type VovkClientOptions, type VovkControllerSchema, type VovkHandlerSchema, type VovkFullSchema, type VovkConfig, type VovkStrictConfig, type VovkEnv, StreamJSONResponse, HttpException, HttpStatus, HttpMethod, createVovkApp, createDecorator, createRPC, generateStaticAPI, setHandlerValidation, };
|
|
10
10
|
export declare const get: {
|
|
11
11
|
(givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
|
|
12
12
|
auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
|
package/dist/types.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export type VovkControllerSchema = {
|
|
|
22
22
|
prefix?: string;
|
|
23
23
|
handlers: Record<string, VovkHandlerSchema>;
|
|
24
24
|
};
|
|
25
|
-
export type
|
|
25
|
+
export type VovkSegmentSchema = {
|
|
26
26
|
emitSchema: boolean;
|
|
27
27
|
segmentName: string;
|
|
28
28
|
controllers: Record<string, VovkControllerSchema>;
|
|
@@ -50,7 +50,7 @@ export type DecoratorOptions = {
|
|
|
50
50
|
export type RouteHandler = ((req: VovkRequest, params: Record<string, string>) => Response | Promise<Response> | Iterable<unknown> | AsyncIterable<unknown>) & {
|
|
51
51
|
_options?: DecoratorOptions;
|
|
52
52
|
};
|
|
53
|
-
export interface VovkRequest<BODY extends KnownAny = null, QUERY extends KnownAny = undefined, PARAMS extends
|
|
53
|
+
export interface VovkRequest<BODY extends KnownAny = null, QUERY extends KnownAny = undefined, PARAMS extends KnownAny = undefined> extends Omit<NextRequest, 'json' | 'nextUrl'> {
|
|
54
54
|
json: () => Promise<BODY>;
|
|
55
55
|
nextUrl: Omit<NextRequest['nextUrl'], 'searchParams'> & {
|
|
56
56
|
searchParams: Omit<NextRequest['nextUrl']['searchParams'], 'get' | 'getAll' | 'entries' | 'forEach' | 'keys' | 'values'> & {
|
|
@@ -77,8 +77,11 @@ export type ControllerStaticMethod<REQ extends VovkRequest<KnownAny, KnownAny> =
|
|
|
77
77
|
};
|
|
78
78
|
export type VovkControllerBody<T extends (...args: KnownAny) => KnownAny> = Awaited<ReturnType<Parameters<T>[0]['vovk']['body']>>;
|
|
79
79
|
export type VovkControllerQuery<T extends (...args: KnownAny) => KnownAny> = ReturnType<Parameters<T>[0]['vovk']['query']>;
|
|
80
|
-
export type VovkControllerParams<T extends (...args: KnownAny) => KnownAny> = Parameters<T>[1]
|
|
80
|
+
export type VovkControllerParams<T extends (...args: KnownAny) => KnownAny> = Parameters<T>[1] extends object ? Parameters<T>[1] : ReturnType<Parameters<T>[0]['vovk']['params']>;
|
|
81
81
|
export type VovkControllerYieldType<T extends (req: VovkRequest<KnownAny, KnownAny>) => KnownAny> = T extends (...args: KnownAny[]) => AsyncGenerator<infer Y, KnownAny, KnownAny> ? Y : T extends (...args: KnownAny[]) => Generator<infer Y, KnownAny, KnownAny> ? Y : T extends (...args: KnownAny[]) => Promise<StreamJSONResponse<infer Y>> | StreamJSONResponse<infer Y> ? Y : never;
|
|
82
|
+
export type VovkControllerOutput<T extends ((...args: KnownAny) => KnownAny) & {
|
|
83
|
+
__output?: KnownAny;
|
|
84
|
+
}> = T['__output'];
|
|
82
85
|
export type VovkBody<T extends (...args: KnownAny[]) => unknown> = Parameters<T>[0]['body'];
|
|
83
86
|
export type VovkQuery<T extends (...args: KnownAny[]) => unknown> = Parameters<T>[0]['query'];
|
|
84
87
|
export type VovkParams<T extends (...args: KnownAny[]) => unknown> = Parameters<T>[0]['params'];
|
|
@@ -88,6 +91,63 @@ export type StreamAbortMessage = {
|
|
|
88
91
|
isError: true;
|
|
89
92
|
reason: KnownAny;
|
|
90
93
|
};
|
|
94
|
+
type LogLevelNames = 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
95
|
+
export type VovkEnv = {
|
|
96
|
+
PORT?: string;
|
|
97
|
+
VOVK_CLIENT_OUT_DIR?: string;
|
|
98
|
+
VOVK_SCHEMA_OUT_DIR?: string;
|
|
99
|
+
VOVK_FETCHER_PATH?: string;
|
|
100
|
+
VOVK_VALIDATE_ON_CLIENT_PATH?: string;
|
|
101
|
+
VOVK_CREATE_RPC_PATH?: string;
|
|
102
|
+
VOVK_MODULES_DIR?: string;
|
|
103
|
+
VOVK_ORIGIN?: string;
|
|
104
|
+
VOVK_ROOT_ENTRY?: string;
|
|
105
|
+
VOVK_API_ENTRY_POINT?: string;
|
|
106
|
+
VOVK_ROOT_SEGMENT_MODULES_DIR_NAME?: string;
|
|
107
|
+
VOVK_LOG_LEVEL?: LogLevelNames;
|
|
108
|
+
VOVK_PRETTIFY_CLIENT?: string;
|
|
109
|
+
VOVK_DEV_HTTPS?: string;
|
|
110
|
+
__VOVK_START_WATCHER_IN_STANDALONE_MODE__?: 'true';
|
|
111
|
+
__VOVK_EXIT__?: 'true' | 'false';
|
|
112
|
+
};
|
|
113
|
+
type GenerateFrom = (string | {
|
|
114
|
+
templatePath: string;
|
|
115
|
+
outDir?: string;
|
|
116
|
+
templateName?: string;
|
|
117
|
+
fullSchema?: string | boolean;
|
|
118
|
+
})[];
|
|
119
|
+
export type VovkConfig = {
|
|
120
|
+
emitConfig?: boolean | string[];
|
|
121
|
+
clientOutDir?: string;
|
|
122
|
+
schemaOutDir?: string;
|
|
123
|
+
fetcherImport?: string | string[];
|
|
124
|
+
validateOnClientImport?: string | string[] | null;
|
|
125
|
+
createRPCImport?: string | string[];
|
|
126
|
+
modulesDir?: string;
|
|
127
|
+
rootEntry?: string;
|
|
128
|
+
origin?: string;
|
|
129
|
+
rootSegmentModulesDirName?: string;
|
|
130
|
+
logLevel?: LogLevelNames;
|
|
131
|
+
prettifyClient?: boolean;
|
|
132
|
+
devHttps?: boolean;
|
|
133
|
+
generateFrom?: GenerateFrom | ((value: GenerateFrom) => GenerateFrom);
|
|
134
|
+
templates?: {
|
|
135
|
+
service?: string;
|
|
136
|
+
controller?: string;
|
|
137
|
+
[key: string]: string | undefined;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
export type VovkStrictConfig = Required<Omit<VovkConfig, 'emitConfig' | 'validateOnClientImport' | 'fetcherImport' | 'createRPCImport' | 'generateFrom'>> & {
|
|
141
|
+
emitConfig: string[];
|
|
142
|
+
validateOnClientImport: string[] | null;
|
|
143
|
+
fetcherImport: string[];
|
|
144
|
+
createRPCImport: string[];
|
|
145
|
+
generateFrom: GenerateFrom;
|
|
146
|
+
};
|
|
147
|
+
export type VovkFullSchema = {
|
|
148
|
+
config: Partial<VovkStrictConfig>;
|
|
149
|
+
segments: Record<string, VovkSegmentSchema>;
|
|
150
|
+
};
|
|
91
151
|
export declare enum HttpMethod {
|
|
92
152
|
GET = "GET",
|
|
93
153
|
POST = "POST",
|
|
@@ -148,3 +208,4 @@ export declare enum HttpStatus {
|
|
|
148
208
|
GATEWAY_TIMEOUT = 504,
|
|
149
209
|
HTTP_VERSION_NOT_SUPPORTED = 505
|
|
150
210
|
}
|
|
211
|
+
export {};
|
package/dist/types.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { VovkSegmentSchema, VovkController, StaticClass } from '../types';
|
|
2
2
|
export declare function getControllerSchema(controller: VovkController, controllerName: string, exposeValidation: boolean): {
|
|
3
3
|
controllerName: string;
|
|
4
4
|
originalControllerName: string;
|
|
@@ -17,4 +17,4 @@ export default function getSchema(options: {
|
|
|
17
17
|
segmentName?: string;
|
|
18
18
|
controllers: Record<string, StaticClass>;
|
|
19
19
|
exposeValidation?: boolean;
|
|
20
|
-
}):
|
|
20
|
+
}): VovkSegmentSchema;
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vovk",
|
|
3
|
-
"version": "3.0.0-draft.
|
|
3
|
+
"version": "3.0.0-draft.90",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
|
+
"module": "dist/index.js",
|
|
5
6
|
"description": "RESTful RPC for Next.js - Transforms Next.js into a powerful REST API platform with RPC capabilities.",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
@@ -27,5 +28,8 @@
|
|
|
27
28
|
"homepage": "https://vovk.dev",
|
|
28
29
|
"peerDependencies": {
|
|
29
30
|
"next": "*"
|
|
31
|
+
},
|
|
32
|
+
"optionalDependencies": {
|
|
33
|
+
"openapi3-ts": "*"
|
|
30
34
|
}
|
|
31
35
|
}
|