vovk 3.4.0 → 3.4.1
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/core/compose.d.ts +38 -0
- package/dist/core/compose.js +31 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +1 -0
- package/dist/openapi/openAPIToVovkSchema/applyComponentsSchemas.d.ts +21 -1
- package/dist/openapi/openAPIToVovkSchema/applyComponentsSchemas.js +37 -12
- package/dist/openapi/openAPIToVovkSchema/index.js +3 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/HttpException.d.ts +0 -7
- package/dist/HttpException.js +0 -15
- package/dist/JSONLinesResponse.d.ts +0 -14
- package/dist/JSONLinesResponse.js +0 -59
- package/dist/VovkApp.d.ts +0 -29
- package/dist/VovkApp.js +0 -189
- package/dist/client/index.d.ts +0 -3
- package/dist/client/index.js +0 -7
- package/dist/client/types.d.ts +0 -102
- 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 -129
- package/dist/types.d.ts +0 -239
- package/dist/types.js +0 -66
- package/dist/utils/generateStaticAPI.d.ts +0 -4
- package/dist/utils/generateStaticAPI.js +0 -30
- package/dist/utils/getSchema.d.ts +0 -20
- package/dist/utils/getSchema.js +0 -33
- package/dist/utils/parseQuery.d.ts +0 -25
- package/dist/utils/parseQuery.js +0 -156
- package/dist/utils/reqForm.d.ts +0 -2
- package/dist/utils/reqForm.js +0 -32
- package/dist/utils/reqMeta.d.ts +0 -2
- package/dist/utils/reqMeta.js +0 -13
- package/dist/utils/reqQuery.d.ts +0 -2
- package/dist/utils/reqQuery.js +0 -10
- package/dist/utils/serializeQuery.d.ts +0 -13
- package/dist/utils/serializeQuery.js +0 -65
- package/dist/utils/setHandlerSchema.d.ts +0 -4
- package/dist/utils/setHandlerSchema.js +0 -15
- package/dist/utils/withValidation.d.ts +0 -21
- package/dist/utils/withValidation.js +0 -88
package/dist/createVovkApp.js
DELETED
|
@@ -1,129 +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-z0-9])([A-Z])/g, '$1-$2') // Add hyphen between lowercase/digit and uppercase
|
|
14
|
-
.replace(/([A-Z])([A-Z])(?=[a-z])/g, '$1-$2') // Add hyphen between uppercase letters if the second one is followed by a lowercase
|
|
15
|
-
.toLowerCase()
|
|
16
|
-
.replace(/^-/, ''); // Remove leading hyphen
|
|
17
|
-
const assignSchema = ({ controller, propertyKey, path, options, httpMethod, vovkApp, }) => {
|
|
18
|
-
if (typeof window !== 'undefined') {
|
|
19
|
-
throw new Error('Decorators are intended for server-side use only. You have probably imported a controller on the client-side.');
|
|
20
|
-
}
|
|
21
|
-
if (!isClass(controller)) {
|
|
22
|
-
let decoratorName = httpMethod.toLowerCase();
|
|
23
|
-
if (decoratorName === 'delete')
|
|
24
|
-
decoratorName = 'del';
|
|
25
|
-
throw new Error(`Decorator must be used on a static class method. Check the controller method named "${propertyKey}" used with @${decoratorName}().`);
|
|
26
|
-
}
|
|
27
|
-
const methods = vovkApp.routes[httpMethod].get(controller) ?? {};
|
|
28
|
-
vovkApp.routes[httpMethod].set(controller, methods);
|
|
29
|
-
const originalMethod = controller[propertyKey];
|
|
30
|
-
originalMethod._controller = controller;
|
|
31
|
-
originalMethod._sourceMethod = originalMethod._sourceMethod ?? originalMethod;
|
|
32
|
-
const schema = originalMethod._sourceMethod._getSchema?.(controller);
|
|
33
|
-
controller._handlers = {
|
|
34
|
-
...controller._handlers,
|
|
35
|
-
[propertyKey]: {
|
|
36
|
-
...schema,
|
|
37
|
-
...(controller._handlers ?? {})[propertyKey],
|
|
38
|
-
path,
|
|
39
|
-
httpMethod,
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
methods[path] = controller[propertyKey];
|
|
43
|
-
methods[path]._options = options;
|
|
44
|
-
controller._handlersMetadata = {
|
|
45
|
-
...controller._handlersMetadata,
|
|
46
|
-
[propertyKey]: {
|
|
47
|
-
...(controller._handlersMetadata ?? {})[propertyKey],
|
|
48
|
-
staticParams: options?.staticParams,
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
function createVovkApp() {
|
|
53
|
-
const vovkApp = new VovkApp_1.VovkApp();
|
|
54
|
-
const createHTTPDecorator = (httpMethod) => {
|
|
55
|
-
function decoratorCreator(givenPath = '', options) {
|
|
56
|
-
const path = trimPath(givenPath);
|
|
57
|
-
function decorator(givenTarget, propertyKey) {
|
|
58
|
-
const controller = givenTarget;
|
|
59
|
-
assignSchema({ controller, propertyKey, path, options, httpMethod, vovkApp });
|
|
60
|
-
}
|
|
61
|
-
return decorator;
|
|
62
|
-
}
|
|
63
|
-
const auto = (options) => {
|
|
64
|
-
function decorator(givenTarget, propertyKey) {
|
|
65
|
-
const controller = givenTarget;
|
|
66
|
-
const methods = vovkApp.routes[httpMethod].get(controller) ?? {};
|
|
67
|
-
vovkApp.routes[httpMethod].set(controller, methods);
|
|
68
|
-
controller._handlers = {
|
|
69
|
-
...controller._handlers,
|
|
70
|
-
[propertyKey]: {
|
|
71
|
-
...(controller._handlers ?? {})[propertyKey],
|
|
72
|
-
httpMethod,
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
const properties = Object.keys(controller._handlers[propertyKey]?.validation?.params?.properties ?? {});
|
|
76
|
-
const kebab = toKebabCase(propertyKey); // 🥙
|
|
77
|
-
const path = properties.length ? `${kebab}/${properties.map((prop) => `:${prop}`).join('/')}` : kebab;
|
|
78
|
-
assignSchema({ controller, propertyKey, path, options, httpMethod, vovkApp });
|
|
79
|
-
}
|
|
80
|
-
return decorator;
|
|
81
|
-
};
|
|
82
|
-
const enhancedDecoratorCreator = decoratorCreator;
|
|
83
|
-
enhancedDecoratorCreator.auto = auto;
|
|
84
|
-
return enhancedDecoratorCreator;
|
|
85
|
-
};
|
|
86
|
-
const prefix = (givenPath = '') => {
|
|
87
|
-
const path = trimPath(givenPath);
|
|
88
|
-
return (givenTarget) => {
|
|
89
|
-
const controller = givenTarget;
|
|
90
|
-
controller._prefix = path;
|
|
91
|
-
return givenTarget;
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
const initVovk = (options) => {
|
|
95
|
-
for (const [rpcModuleName, controller] of Object.entries(options.controllers)) {
|
|
96
|
-
controller._rpcModuleName = rpcModuleName;
|
|
97
|
-
controller._activated = true;
|
|
98
|
-
controller._onError = options?.onError;
|
|
99
|
-
}
|
|
100
|
-
async function GET_DEV(req, data) {
|
|
101
|
-
const params = await data.params;
|
|
102
|
-
if (params[Object.keys(params)[0]]?.[0] === '_schema_') {
|
|
103
|
-
const schema = (0, getSchema_1.default)(options);
|
|
104
|
-
return vovkApp.respond(200, { schema });
|
|
105
|
-
}
|
|
106
|
-
return vovkApp.GET(req, data);
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
GET: process.env.NODE_ENV === 'development' ? GET_DEV : vovkApp.GET,
|
|
110
|
-
POST: vovkApp.POST,
|
|
111
|
-
PUT: vovkApp.PUT,
|
|
112
|
-
PATCH: vovkApp.PATCH,
|
|
113
|
-
DELETE: vovkApp.DELETE,
|
|
114
|
-
HEAD: vovkApp.HEAD,
|
|
115
|
-
OPTIONS: vovkApp.OPTIONS,
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
return {
|
|
119
|
-
get: createHTTPDecorator(types_1.HttpMethod.GET),
|
|
120
|
-
post: createHTTPDecorator(types_1.HttpMethod.POST),
|
|
121
|
-
put: createHTTPDecorator(types_1.HttpMethod.PUT),
|
|
122
|
-
patch: createHTTPDecorator(types_1.HttpMethod.PATCH),
|
|
123
|
-
del: createHTTPDecorator(types_1.HttpMethod.DELETE),
|
|
124
|
-
head: createHTTPDecorator(types_1.HttpMethod.HEAD),
|
|
125
|
-
options: createHTTPDecorator(types_1.HttpMethod.OPTIONS),
|
|
126
|
-
prefix,
|
|
127
|
-
initVovk,
|
|
128
|
-
};
|
|
129
|
-
}
|
package/dist/types.d.ts
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import type { NextRequest } from 'next/server';
|
|
2
|
-
import type { OperationObject } from 'openapi3-ts/oas31';
|
|
3
|
-
import type { JSONLinesResponse } from './JSONLinesResponse';
|
|
4
|
-
import { VovkStreamAsyncIterable } from './client/types';
|
|
5
|
-
import type { PackageJson } from 'type-fest';
|
|
6
|
-
export type KnownAny = any;
|
|
7
|
-
export type StaticClass = Function;
|
|
8
|
-
export type VovkHandlerSchema = {
|
|
9
|
-
path: string;
|
|
10
|
-
httpMethod: string;
|
|
11
|
-
validation?: {
|
|
12
|
-
query?: KnownAny;
|
|
13
|
-
body?: KnownAny;
|
|
14
|
-
params?: KnownAny;
|
|
15
|
-
output?: KnownAny;
|
|
16
|
-
iteration?: KnownAny;
|
|
17
|
-
};
|
|
18
|
-
openapi?: OperationObject;
|
|
19
|
-
misc?: Record<string, KnownAny>;
|
|
20
|
-
};
|
|
21
|
-
export type VovkControllerSchema = {
|
|
22
|
-
rpcModuleName: string;
|
|
23
|
-
originalControllerName: string;
|
|
24
|
-
prefix?: string;
|
|
25
|
-
handlers: Record<string, VovkHandlerSchema>;
|
|
26
|
-
};
|
|
27
|
-
export type VovkSegmentSchema = {
|
|
28
|
-
emitSchema: boolean;
|
|
29
|
-
segmentName: string;
|
|
30
|
-
controllers: Record<string, VovkControllerSchema>;
|
|
31
|
-
};
|
|
32
|
-
export type VovkErrorResponse = {
|
|
33
|
-
cause?: unknown;
|
|
34
|
-
statusCode: HttpStatus;
|
|
35
|
-
message: string;
|
|
36
|
-
isError: true;
|
|
37
|
-
};
|
|
38
|
-
export type VovkControllerInternal = {
|
|
39
|
-
_rpcModuleName?: VovkControllerSchema['rpcModuleName'];
|
|
40
|
-
_prefix?: VovkControllerSchema['prefix'];
|
|
41
|
-
_handlers: VovkControllerSchema['handlers'];
|
|
42
|
-
_handlersMetadata?: Record<string, {
|
|
43
|
-
staticParams?: Record<string, string>[];
|
|
44
|
-
}>;
|
|
45
|
-
_activated?: true;
|
|
46
|
-
_onError?: (err: Error, req: VovkRequest) => void | Promise<void>;
|
|
47
|
-
};
|
|
48
|
-
export type VovkController = StaticClass & VovkControllerInternal & {
|
|
49
|
-
[key: string]: unknown;
|
|
50
|
-
};
|
|
51
|
-
export type DecoratorOptions = {
|
|
52
|
-
cors?: boolean;
|
|
53
|
-
headers?: Record<string, string>;
|
|
54
|
-
staticParams?: Record<string, string>[];
|
|
55
|
-
before?: (this: VovkController, req: VovkRequest) => unknown;
|
|
56
|
-
};
|
|
57
|
-
export type RouteHandler = ((req: VovkRequest, params: Record<string, string>) => Response | Promise<Response> | Iterable<unknown> | AsyncIterable<unknown>) & {
|
|
58
|
-
_options?: DecoratorOptions;
|
|
59
|
-
};
|
|
60
|
-
export interface VovkRequest<BODY extends KnownAny = null, QUERY extends KnownAny = undefined, PARAMS extends KnownAny = undefined> extends Omit<NextRequest, 'json' | 'nextUrl'> {
|
|
61
|
-
json: () => Promise<BODY>;
|
|
62
|
-
nextUrl: Omit<NextRequest['nextUrl'], 'searchParams'> & {
|
|
63
|
-
searchParams: Omit<NextRequest['nextUrl']['searchParams'], 'get' | 'getAll' | 'entries' | 'forEach' | 'keys' | 'values'> & {
|
|
64
|
-
get: <KEY extends keyof QUERY>(key: KEY) => QUERY[KEY] extends readonly (infer ITEM)[] ? ITEM : QUERY[KEY];
|
|
65
|
-
getAll: <KEY extends keyof QUERY>(key: KEY) => QUERY[KEY] extends KnownAny[] ? QUERY[KEY] : QUERY[KEY][];
|
|
66
|
-
entries: () => IterableIterator<[keyof QUERY, QUERY[keyof QUERY]]>;
|
|
67
|
-
forEach: (callbackfn: (value: QUERY[keyof QUERY], key: keyof QUERY, searchParams: NextRequest['nextUrl']['searchParams']) => void) => void;
|
|
68
|
-
keys: () => IterableIterator<keyof QUERY>;
|
|
69
|
-
values: () => IterableIterator<QUERY[keyof QUERY]>;
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
vovk: {
|
|
73
|
-
body: () => Promise<BODY>;
|
|
74
|
-
query: () => QUERY;
|
|
75
|
-
meta: <T = Record<KnownAny, KnownAny>>(meta?: T | null) => T;
|
|
76
|
-
form: <T = KnownAny>() => Promise<T>;
|
|
77
|
-
params: () => PARAMS;
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
export type ControllerStaticMethod<REQ extends VovkRequest<KnownAny, KnownAny> = VovkRequest<undefined, Record<string, KnownAny>>, PARAMS extends {
|
|
81
|
-
[key: string]: string;
|
|
82
|
-
} = KnownAny> = ((req: REQ, params: PARAMS) => unknown) & {
|
|
83
|
-
_controller?: VovkController;
|
|
84
|
-
};
|
|
85
|
-
export type VovkControllerBody<T extends (...args: KnownAny) => KnownAny> = Awaited<ReturnType<Parameters<T>[0]['vovk']['body']>>;
|
|
86
|
-
export type VovkControllerQuery<T extends (...args: KnownAny) => KnownAny> = ReturnType<Parameters<T>[0]['vovk']['query']>;
|
|
87
|
-
export type VovkControllerParams<T extends (...args: KnownAny) => KnownAny> = Parameters<T>[1] extends object ? Parameters<T>[1] : ReturnType<Parameters<T>[0]['vovk']['params']>;
|
|
88
|
-
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<JSONLinesResponse<infer Y>> | JSONLinesResponse<infer Y> ? Y : never;
|
|
89
|
-
export type VovkControllerOutput<T extends ((...args: KnownAny) => KnownAny) & {
|
|
90
|
-
__output?: KnownAny;
|
|
91
|
-
}> = T['__output'];
|
|
92
|
-
export type VovkControllerIteration<T extends ((...args: KnownAny) => KnownAny) & {
|
|
93
|
-
__iteration?: KnownAny;
|
|
94
|
-
}> = T['__iteration'];
|
|
95
|
-
export type VovkBody<T extends (...args: KnownAny[]) => unknown> = Parameters<T>[0]['body'];
|
|
96
|
-
export type VovkQuery<T extends (...args: KnownAny[]) => unknown> = Parameters<T>[0]['query'];
|
|
97
|
-
export type VovkParams<T extends (...args: KnownAny[]) => unknown> = Parameters<T>[0]['params'];
|
|
98
|
-
export type VovkYieldType<T extends (...args: KnownAny[]) => unknown> = T extends (...args: KnownAny[]) => Promise<VovkStreamAsyncIterable<infer Y>> ? Y : never;
|
|
99
|
-
export type VovkReturnType<T extends (...args: KnownAny) => unknown> = Awaited<ReturnType<T>>;
|
|
100
|
-
export type StreamAbortMessage = {
|
|
101
|
-
isError: true;
|
|
102
|
-
reason: KnownAny;
|
|
103
|
-
};
|
|
104
|
-
export type VovkValidationType = 'body' | 'query' | 'params' | 'output' | 'iteration';
|
|
105
|
-
export type VovkFullSchema = {
|
|
106
|
-
config: Partial<VovkStrictConfig>;
|
|
107
|
-
segments: Record<string, VovkSegmentSchema>;
|
|
108
|
-
};
|
|
109
|
-
export declare enum HttpMethod {
|
|
110
|
-
GET = "GET",
|
|
111
|
-
POST = "POST",
|
|
112
|
-
PUT = "PUT",
|
|
113
|
-
PATCH = "PATCH",
|
|
114
|
-
DELETE = "DELETE",
|
|
115
|
-
HEAD = "HEAD",
|
|
116
|
-
OPTIONS = "OPTIONS"
|
|
117
|
-
}
|
|
118
|
-
export declare enum HttpStatus {
|
|
119
|
-
NULL = 0,
|
|
120
|
-
CONTINUE = 100,
|
|
121
|
-
SWITCHING_PROTOCOLS = 101,
|
|
122
|
-
PROCESSING = 102,
|
|
123
|
-
EARLYHINTS = 103,
|
|
124
|
-
OK = 200,
|
|
125
|
-
CREATED = 201,
|
|
126
|
-
ACCEPTED = 202,
|
|
127
|
-
NON_AUTHORITATIVE_INFORMATION = 203,
|
|
128
|
-
NO_CONTENT = 204,
|
|
129
|
-
RESET_CONTENT = 205,
|
|
130
|
-
PARTIAL_CONTENT = 206,
|
|
131
|
-
AMBIGUOUS = 300,
|
|
132
|
-
MOVED_PERMANENTLY = 301,
|
|
133
|
-
FOUND = 302,
|
|
134
|
-
SEE_OTHER = 303,
|
|
135
|
-
NOT_MODIFIED = 304,
|
|
136
|
-
TEMPORARY_REDIRECT = 307,
|
|
137
|
-
PERMANENT_REDIRECT = 308,
|
|
138
|
-
BAD_REQUEST = 400,
|
|
139
|
-
UNAUTHORIZED = 401,
|
|
140
|
-
PAYMENT_REQUIRED = 402,
|
|
141
|
-
FORBIDDEN = 403,
|
|
142
|
-
NOT_FOUND = 404,
|
|
143
|
-
METHOD_NOT_ALLOWED = 405,
|
|
144
|
-
NOT_ACCEPTABLE = 406,
|
|
145
|
-
PROXY_AUTHENTICATION_REQUIRED = 407,
|
|
146
|
-
REQUEST_TIMEOUT = 408,
|
|
147
|
-
CONFLICT = 409,
|
|
148
|
-
GONE = 410,
|
|
149
|
-
LENGTH_REQUIRED = 411,
|
|
150
|
-
PRECONDITION_FAILED = 412,
|
|
151
|
-
PAYLOAD_TOO_LARGE = 413,
|
|
152
|
-
URI_TOO_LONG = 414,
|
|
153
|
-
UNSUPPORTED_MEDIA_TYPE = 415,
|
|
154
|
-
REQUESTED_RANGE_NOT_SATISFIABLE = 416,
|
|
155
|
-
EXPECTATION_FAILED = 417,
|
|
156
|
-
I_AM_A_TEAPOT = 418,
|
|
157
|
-
MISDIRECTED = 421,
|
|
158
|
-
UNPROCESSABLE_ENTITY = 422,
|
|
159
|
-
FAILED_DEPENDENCY = 424,
|
|
160
|
-
PRECONDITION_REQUIRED = 428,
|
|
161
|
-
TOO_MANY_REQUESTS = 429,
|
|
162
|
-
INTERNAL_SERVER_ERROR = 500,
|
|
163
|
-
NOT_IMPLEMENTED = 501,
|
|
164
|
-
BAD_GATEWAY = 502,
|
|
165
|
-
SERVICE_UNAVAILABLE = 503,
|
|
166
|
-
GATEWAY_TIMEOUT = 504,
|
|
167
|
-
HTTP_VERSION_NOT_SUPPORTED = 505
|
|
168
|
-
}
|
|
169
|
-
type ClientConfigCommon = {
|
|
170
|
-
enabled?: boolean;
|
|
171
|
-
outDir?: string;
|
|
172
|
-
fromTemplates?: string[];
|
|
173
|
-
} & ({
|
|
174
|
-
excludeSegments?: never;
|
|
175
|
-
includeSegments?: string[];
|
|
176
|
-
} | {
|
|
177
|
-
excludeSegments?: string[];
|
|
178
|
-
includeSegments?: never;
|
|
179
|
-
});
|
|
180
|
-
type ClientConfigFull = ClientConfigCommon & {
|
|
181
|
-
package?: PackageJson;
|
|
182
|
-
};
|
|
183
|
-
type ClientConfigSegmented = ClientConfigCommon & {
|
|
184
|
-
packages?: Record<string, PackageJson>;
|
|
185
|
-
};
|
|
186
|
-
export type ClientTemplateDef = {
|
|
187
|
-
extends?: string;
|
|
188
|
-
templatePath?: string | null;
|
|
189
|
-
origin?: string | null;
|
|
190
|
-
fullClient?: Omit<ClientConfigFull, 'fromTemplates' | 'enabled'>;
|
|
191
|
-
segmentedClient?: Omit<ClientConfigSegmented, 'fromTemplates' | 'enabled'>;
|
|
192
|
-
segmentConfig?: false | Record<string, {
|
|
193
|
-
origin?: string;
|
|
194
|
-
rootEntry?: boolean;
|
|
195
|
-
}>;
|
|
196
|
-
requires?: Record<string, string>;
|
|
197
|
-
};
|
|
198
|
-
export type VovkConfig = {
|
|
199
|
-
emitConfig?: boolean | (keyof VovkStrictConfig)[];
|
|
200
|
-
schemaOutDir?: string;
|
|
201
|
-
fullClient?: ClientConfigFull;
|
|
202
|
-
segmentedClient?: ClientConfigSegmented;
|
|
203
|
-
imports?: {
|
|
204
|
-
fetcher?: string | [string, string] | [string];
|
|
205
|
-
validateOnClient?: string | [string, string] | [string];
|
|
206
|
-
createRPC?: string | [string, string] | [string];
|
|
207
|
-
};
|
|
208
|
-
modulesDir?: string;
|
|
209
|
-
rootEntry?: string;
|
|
210
|
-
origin?: string;
|
|
211
|
-
rootSegmentModulesDirName?: string;
|
|
212
|
-
logLevel?: 'error' | 'trace' | 'debug' | 'info' | 'warn';
|
|
213
|
-
prettifyClient?: boolean;
|
|
214
|
-
devHttps?: boolean;
|
|
215
|
-
clientTemplateDefs?: Record<string, ClientTemplateDef>;
|
|
216
|
-
moduleTemplates?: {
|
|
217
|
-
service?: string;
|
|
218
|
-
controller?: string;
|
|
219
|
-
[key: string]: string | undefined;
|
|
220
|
-
};
|
|
221
|
-
libs?: Record<string, KnownAny>;
|
|
222
|
-
segmentConfig?: false | Record<string, {
|
|
223
|
-
origin?: string;
|
|
224
|
-
rootEntry?: boolean;
|
|
225
|
-
}>;
|
|
226
|
-
};
|
|
227
|
-
export type VovkStrictConfig = Required<Omit<VovkConfig, 'emitConfig' | 'libs' | 'imports' | 'fullClient' | 'segmentedClient'>> & {
|
|
228
|
-
emitConfig: (keyof VovkStrictConfig)[];
|
|
229
|
-
imports: {
|
|
230
|
-
fetcher: [string, string] | [string];
|
|
231
|
-
validateOnClient: [string, string] | [string] | null;
|
|
232
|
-
createRPC: [string, string] | [string];
|
|
233
|
-
};
|
|
234
|
-
libs: Record<string, KnownAny>;
|
|
235
|
-
fullClient: RequireFields<ClientConfigFull, 'enabled' | 'fromTemplates' | 'outDir'>;
|
|
236
|
-
segmentedClient: RequireFields<ClientConfigSegmented, 'enabled' | 'fromTemplates' | 'outDir'>;
|
|
237
|
-
};
|
|
238
|
-
type RequireFields<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
239
|
-
export {};
|
package/dist/types.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpStatus = exports.HttpMethod = void 0;
|
|
4
|
-
// Enums
|
|
5
|
-
var HttpMethod;
|
|
6
|
-
(function (HttpMethod) {
|
|
7
|
-
HttpMethod["GET"] = "GET";
|
|
8
|
-
HttpMethod["POST"] = "POST";
|
|
9
|
-
HttpMethod["PUT"] = "PUT";
|
|
10
|
-
HttpMethod["PATCH"] = "PATCH";
|
|
11
|
-
HttpMethod["DELETE"] = "DELETE";
|
|
12
|
-
HttpMethod["HEAD"] = "HEAD";
|
|
13
|
-
HttpMethod["OPTIONS"] = "OPTIONS";
|
|
14
|
-
})(HttpMethod || (exports.HttpMethod = HttpMethod = {}));
|
|
15
|
-
var HttpStatus;
|
|
16
|
-
(function (HttpStatus) {
|
|
17
|
-
HttpStatus[HttpStatus["NULL"] = 0] = "NULL";
|
|
18
|
-
HttpStatus[HttpStatus["CONTINUE"] = 100] = "CONTINUE";
|
|
19
|
-
HttpStatus[HttpStatus["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
|
|
20
|
-
HttpStatus[HttpStatus["PROCESSING"] = 102] = "PROCESSING";
|
|
21
|
-
HttpStatus[HttpStatus["EARLYHINTS"] = 103] = "EARLYHINTS";
|
|
22
|
-
HttpStatus[HttpStatus["OK"] = 200] = "OK";
|
|
23
|
-
HttpStatus[HttpStatus["CREATED"] = 201] = "CREATED";
|
|
24
|
-
HttpStatus[HttpStatus["ACCEPTED"] = 202] = "ACCEPTED";
|
|
25
|
-
HttpStatus[HttpStatus["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
|
|
26
|
-
HttpStatus[HttpStatus["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
27
|
-
HttpStatus[HttpStatus["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
28
|
-
HttpStatus[HttpStatus["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
29
|
-
HttpStatus[HttpStatus["AMBIGUOUS"] = 300] = "AMBIGUOUS";
|
|
30
|
-
HttpStatus[HttpStatus["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
31
|
-
HttpStatus[HttpStatus["FOUND"] = 302] = "FOUND";
|
|
32
|
-
HttpStatus[HttpStatus["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
33
|
-
HttpStatus[HttpStatus["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
34
|
-
HttpStatus[HttpStatus["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
35
|
-
HttpStatus[HttpStatus["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
36
|
-
HttpStatus[HttpStatus["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
37
|
-
HttpStatus[HttpStatus["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
38
|
-
HttpStatus[HttpStatus["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
39
|
-
HttpStatus[HttpStatus["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
40
|
-
HttpStatus[HttpStatus["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
41
|
-
HttpStatus[HttpStatus["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
42
|
-
HttpStatus[HttpStatus["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
43
|
-
HttpStatus[HttpStatus["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
44
|
-
HttpStatus[HttpStatus["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
45
|
-
HttpStatus[HttpStatus["CONFLICT"] = 409] = "CONFLICT";
|
|
46
|
-
HttpStatus[HttpStatus["GONE"] = 410] = "GONE";
|
|
47
|
-
HttpStatus[HttpStatus["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
48
|
-
HttpStatus[HttpStatus["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
49
|
-
HttpStatus[HttpStatus["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
|
|
50
|
-
HttpStatus[HttpStatus["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
|
|
51
|
-
HttpStatus[HttpStatus["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
52
|
-
HttpStatus[HttpStatus["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
|
|
53
|
-
HttpStatus[HttpStatus["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
54
|
-
HttpStatus[HttpStatus["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
|
|
55
|
-
HttpStatus[HttpStatus["MISDIRECTED"] = 421] = "MISDIRECTED";
|
|
56
|
-
HttpStatus[HttpStatus["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
57
|
-
HttpStatus[HttpStatus["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
58
|
-
HttpStatus[HttpStatus["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
59
|
-
HttpStatus[HttpStatus["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
60
|
-
HttpStatus[HttpStatus["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
61
|
-
HttpStatus[HttpStatus["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
62
|
-
HttpStatus[HttpStatus["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
63
|
-
HttpStatus[HttpStatus["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
64
|
-
HttpStatus[HttpStatus["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
65
|
-
HttpStatus[HttpStatus["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
66
|
-
})(HttpStatus || (exports.HttpStatus = HttpStatus = {}));
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateStaticAPI = generateStaticAPI;
|
|
4
|
-
function generateStaticAPI(c, slug = 'vovk') {
|
|
5
|
-
const controllers = c;
|
|
6
|
-
return [
|
|
7
|
-
{ [slug]: ['_schema_'] },
|
|
8
|
-
...Object.values(controllers)
|
|
9
|
-
.map((controller) => {
|
|
10
|
-
const handlers = controller._handlers;
|
|
11
|
-
const splitPrefix = controller._prefix?.split('/') ?? [];
|
|
12
|
-
return Object.entries(handlers)
|
|
13
|
-
.map(([name, handler]) => {
|
|
14
|
-
const staticParams = controller._handlersMetadata?.[name]?.staticParams;
|
|
15
|
-
if (staticParams?.length) {
|
|
16
|
-
return staticParams.map((paramsItem) => {
|
|
17
|
-
let path = handler.path;
|
|
18
|
-
for (const [key, value] of Object.entries(paramsItem)) {
|
|
19
|
-
path = path.replace(`:${key}`, value);
|
|
20
|
-
}
|
|
21
|
-
return { [slug]: [...splitPrefix, ...path.split('/')].filter(Boolean) };
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
return [{ [slug]: [...splitPrefix, ...handler.path.split('/')].filter(Boolean) }];
|
|
25
|
-
})
|
|
26
|
-
.flat();
|
|
27
|
-
})
|
|
28
|
-
.flat(),
|
|
29
|
-
];
|
|
30
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { VovkSegmentSchema, VovkController, StaticClass } from '../types';
|
|
2
|
-
export declare function getControllerSchema(controller: VovkController, rpcModuleName: string, exposeValidation: boolean): {
|
|
3
|
-
rpcModuleName: string;
|
|
4
|
-
originalControllerName: string;
|
|
5
|
-
prefix: string;
|
|
6
|
-
handlers: {
|
|
7
|
-
[k: string]: {
|
|
8
|
-
path: string;
|
|
9
|
-
httpMethod: string;
|
|
10
|
-
openapi?: import("openapi3-ts/oas31").OperationObject;
|
|
11
|
-
misc?: Record<string, import("../types").KnownAny>;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export default function getSchema(options: {
|
|
16
|
-
emitSchema?: boolean;
|
|
17
|
-
segmentName?: string;
|
|
18
|
-
controllers: Record<string, StaticClass>;
|
|
19
|
-
exposeValidation?: boolean;
|
|
20
|
-
}): VovkSegmentSchema;
|
package/dist/utils/getSchema.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getControllerSchema = getControllerSchema;
|
|
4
|
-
exports.default = getSchema;
|
|
5
|
-
function getControllerSchema(controller, rpcModuleName, exposeValidation) {
|
|
6
|
-
return {
|
|
7
|
-
rpcModuleName,
|
|
8
|
-
originalControllerName: controller.name,
|
|
9
|
-
prefix: controller._prefix ?? '',
|
|
10
|
-
handlers: {
|
|
11
|
-
...(exposeValidation
|
|
12
|
-
? controller._handlers
|
|
13
|
-
: Object.fromEntries(
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
15
|
-
Object.entries(controller._handlers ?? {}).map(([key, { validation: _v, ...value }]) => [key, value]))),
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function getSchema(options) {
|
|
20
|
-
const exposeValidation = options?.exposeValidation ?? true;
|
|
21
|
-
const emitSchema = options.emitSchema ?? true;
|
|
22
|
-
const schema = {
|
|
23
|
-
emitSchema,
|
|
24
|
-
segmentName: options.segmentName ?? '',
|
|
25
|
-
controllers: {},
|
|
26
|
-
};
|
|
27
|
-
if (!emitSchema)
|
|
28
|
-
return schema;
|
|
29
|
-
for (const [rpcModuleName, controller] of Object.entries(options.controllers)) {
|
|
30
|
-
schema.controllers[rpcModuleName] = getControllerSchema(controller, rpcModuleName, exposeValidation);
|
|
31
|
-
}
|
|
32
|
-
return schema;
|
|
33
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { KnownAny } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Deserialize a bracket-based query string into an object.
|
|
4
|
-
*
|
|
5
|
-
* Supports:
|
|
6
|
-
* - Key/value pairs with nested brackets (e.g. "a[b][0]=value")
|
|
7
|
-
* - Arrays with empty bracket (e.g. "arr[]=1&arr[]=2")
|
|
8
|
-
* - Mixed arrays of objects, etc.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* parseQuery("x=xx&y[0]=yy&y[1]=uu&z[f]=x&z[u][0]=uu&z[u][1]=xx&z[d][x]=ee")
|
|
12
|
-
* => {
|
|
13
|
-
* x: "xx",
|
|
14
|
-
* y: ["yy", "uu"],
|
|
15
|
-
* z: {
|
|
16
|
-
* f: "x",
|
|
17
|
-
* u: ["uu", "xx"],
|
|
18
|
-
* d: { x: "ee" }
|
|
19
|
-
* }
|
|
20
|
-
* }
|
|
21
|
-
*
|
|
22
|
-
* @param queryString - The raw query string (e.g. location.search.slice(1))
|
|
23
|
-
* @returns - A nested object representing the query params
|
|
24
|
-
*/
|
|
25
|
-
export default function parseQuery(queryString: string): Record<string, KnownAny>;
|