vovk 3.0.0-draft.82 → 3.0.0-draft.84
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/VovkApp.js
CHANGED
|
@@ -131,6 +131,7 @@ class VovkApp {
|
|
|
131
131
|
query: () => (0, reqQuery_1.default)(req),
|
|
132
132
|
meta: (meta) => (0, reqMeta_1.default)(req, meta),
|
|
133
133
|
form: () => (0, reqForm_1.default)(req),
|
|
134
|
+
params: () => methodParams,
|
|
134
135
|
};
|
|
135
136
|
try {
|
|
136
137
|
const result = await staticMethod.call(controller, req, methodParams);
|
package/dist/client/createRPC.js
CHANGED
|
@@ -35,8 +35,8 @@ const createRPC = (controllerSchema, segmentName, options) => {
|
|
|
35
35
|
};
|
|
36
36
|
const handler = (input = {}) => {
|
|
37
37
|
const fetcher = input.fetcher ?? settingsFetcher;
|
|
38
|
-
const validate = async ({ body, query, endpoint }) => {
|
|
39
|
-
await (input.validateOnClient ?? options?.validateOnClient)?.({ body, query, endpoint }, validation ?? {});
|
|
38
|
+
const validate = async ({ body, query, params, endpoint, }) => {
|
|
39
|
+
await (input.validateOnClient ?? options?.validateOnClient)?.({ body, query, params, endpoint }, validation ?? {});
|
|
40
40
|
};
|
|
41
41
|
const internalOptions = {
|
|
42
42
|
name: staticMethodName,
|
|
@@ -10,7 +10,7 @@ const defaultFetcher = async ({ httpMethod, getEndpoint, validate, defaultHandle
|
|
|
10
10
|
const endpoint = getEndpoint({ apiRoot, params, query });
|
|
11
11
|
if (!options.disableClientValidation) {
|
|
12
12
|
try {
|
|
13
|
-
await validate({ body, query, endpoint });
|
|
13
|
+
await validate({ body, query, params, endpoint });
|
|
14
14
|
}
|
|
15
15
|
catch (e) {
|
|
16
16
|
// if HttpException is thrown, rethrow it
|
package/dist/client/types.d.ts
CHANGED
|
@@ -64,6 +64,7 @@ export type VovkClientFetcher<OPTS extends Record<string, KnownAny> = Record<str
|
|
|
64
64
|
validate: (input: {
|
|
65
65
|
body?: unknown;
|
|
66
66
|
query?: unknown;
|
|
67
|
+
params?: unknown;
|
|
67
68
|
endpoint: string;
|
|
68
69
|
}) => void | Promise<void>;
|
|
69
70
|
defaultStreamHandler: (response: Response) => Promise<VovkStreamAsyncIterable<unknown>>;
|
|
@@ -90,6 +91,7 @@ export interface VovkDefaultFetcherOptions extends Omit<RequestInit, 'body' | 'm
|
|
|
90
91
|
export type VovkValidateOnClient = (input: {
|
|
91
92
|
body?: unknown;
|
|
92
93
|
query?: unknown;
|
|
94
|
+
params?: unknown;
|
|
93
95
|
endpoint: string;
|
|
94
96
|
}, validation: Exclude<VovkHandlerSchema['validation'], undefined>) => void | Promise<void>;
|
|
95
97
|
export type VovkClientOptions<OPTS extends Record<string, KnownAny> = Record<string, never>> = {
|
|
@@ -7,7 +7,11 @@ function fromSchema(apiRoot, vovkSchema, extendWith) {
|
|
|
7
7
|
for (const c of Object.values(schema.controllers)) {
|
|
8
8
|
for (const h of Object.values(c.handlers)) {
|
|
9
9
|
if (h.openapi) {
|
|
10
|
-
const path = '/' +
|
|
10
|
+
const path = '/' +
|
|
11
|
+
[apiRoot.replace(/^\/+|\/+$/g, ''), segmentName, c.prefix, h.path]
|
|
12
|
+
.filter(Boolean)
|
|
13
|
+
.join('/')
|
|
14
|
+
.replace(/:([a-zA-Z0-9_]+)/g, '{$1}');
|
|
11
15
|
paths[path] = paths[path] ?? {};
|
|
12
16
|
paths[path][h.httpMethod.toLowerCase()] = { ...h.openapi };
|
|
13
17
|
}
|
package/dist/openapi/openapi.js
CHANGED
|
@@ -4,64 +4,83 @@ exports.openapi = void 0;
|
|
|
4
4
|
const createDecorator_1 = require("../createDecorator");
|
|
5
5
|
const fromSchema_1 = require("./fromSchema");
|
|
6
6
|
const openapiDecorator = (0, createDecorator_1.createDecorator)(null, (openAPIOperationObject = {}) => {
|
|
7
|
-
return (handlerSchema) =>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
'
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
return (handlerSchema) => {
|
|
8
|
+
const queryParameters = handlerSchema?.validation?.query &&
|
|
9
|
+
'type' in handlerSchema.validation.query &&
|
|
10
|
+
'properties' in handlerSchema.validation.query
|
|
11
|
+
? Object.entries(handlerSchema.validation.query.properties).map(([propName, propSchema]) => ({
|
|
12
|
+
name: propName,
|
|
13
|
+
in: 'query',
|
|
14
|
+
description: propSchema.description || '',
|
|
15
|
+
required: handlerSchema.validation?.query.required
|
|
16
|
+
? handlerSchema.validation.query.required.includes(propName)
|
|
17
|
+
: false,
|
|
18
|
+
schema: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
},
|
|
21
|
+
}))
|
|
22
|
+
: null;
|
|
23
|
+
const pathParameters = handlerSchema?.validation?.params &&
|
|
24
|
+
'type' in handlerSchema.validation.params &&
|
|
25
|
+
'properties' in handlerSchema.validation.params
|
|
26
|
+
? Object.entries(handlerSchema.validation.params.properties).map(([propName, propSchema]) => ({
|
|
27
|
+
name: propName,
|
|
28
|
+
in: 'path',
|
|
29
|
+
description: propSchema.description || '',
|
|
30
|
+
required: handlerSchema.validation?.params.required
|
|
31
|
+
? handlerSchema.validation.params.required.includes(propName)
|
|
32
|
+
: false,
|
|
33
|
+
schema: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
},
|
|
36
|
+
}))
|
|
37
|
+
: null;
|
|
38
|
+
return {
|
|
39
|
+
...handlerSchema,
|
|
40
|
+
openapi: {
|
|
41
|
+
...handlerSchema?.openapi,
|
|
42
|
+
...(handlerSchema?.validation?.output &&
|
|
43
|
+
'type' in handlerSchema.validation.output &&
|
|
44
|
+
'properties' in handlerSchema.validation.output
|
|
45
|
+
? {
|
|
46
|
+
responses: {
|
|
47
|
+
200: {
|
|
48
|
+
description: 'description' in handlerSchema.validation.output
|
|
49
|
+
? handlerSchema.validation.output.description
|
|
50
|
+
: 'Success',
|
|
51
|
+
content: {
|
|
52
|
+
'application/json': {
|
|
53
|
+
schema: handlerSchema.validation.output,
|
|
54
|
+
},
|
|
23
55
|
},
|
|
24
56
|
},
|
|
25
57
|
},
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
58
|
+
}
|
|
59
|
+
: {}),
|
|
60
|
+
...(handlerSchema?.validation?.body &&
|
|
61
|
+
'type' in handlerSchema.validation.body &&
|
|
62
|
+
'properties' in handlerSchema.validation.body
|
|
63
|
+
? {
|
|
64
|
+
requestBody: {
|
|
65
|
+
description: 'description' in handlerSchema.validation.body
|
|
66
|
+
? handlerSchema.validation.body.description
|
|
67
|
+
: 'Request body',
|
|
68
|
+
required: true,
|
|
69
|
+
content: {
|
|
70
|
+
'application/json': {
|
|
71
|
+
schema: handlerSchema.validation.body,
|
|
72
|
+
},
|
|
41
73
|
},
|
|
42
74
|
},
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
.map(([propName, propSchema]) => ({
|
|
53
|
-
name: propName,
|
|
54
|
-
in: 'query',
|
|
55
|
-
description: propSchema.description || '',
|
|
56
|
-
required: handlerSchema.validation?.query.required
|
|
57
|
-
? handlerSchema.validation.query.required.includes(propName)
|
|
58
|
-
: false,
|
|
59
|
-
})),
|
|
60
|
-
}
|
|
61
|
-
: {}),
|
|
62
|
-
...openAPIOperationObject,
|
|
63
|
-
},
|
|
64
|
-
});
|
|
75
|
+
}
|
|
76
|
+
: {}),
|
|
77
|
+
...(queryParameters || pathParameters
|
|
78
|
+
? { parameters: [...(queryParameters || []), ...(pathParameters || [])] }
|
|
79
|
+
: {}),
|
|
80
|
+
...openAPIOperationObject,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
};
|
|
65
84
|
});
|
|
66
85
|
exports.openapi = openapiDecorator;
|
|
67
86
|
exports.openapi.fromSchema = fromSchema_1.fromSchema;
|
package/dist/types.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export type VovkHandlerSchema = {
|
|
|
11
11
|
query?: KnownAny;
|
|
12
12
|
body?: KnownAny;
|
|
13
13
|
output?: KnownAny;
|
|
14
|
+
params?: KnownAny;
|
|
14
15
|
};
|
|
15
16
|
openapi?: OperationObject;
|
|
16
17
|
custom?: Record<string, KnownAny>;
|
|
@@ -66,6 +67,7 @@ export interface VovkRequest<BODY = undefined, QUERY extends object | undefined
|
|
|
66
67
|
query: () => QUERY;
|
|
67
68
|
meta: <T = Record<KnownAny, KnownAny>>(meta?: T | null) => T;
|
|
68
69
|
form: <T = KnownAny>() => Promise<T>;
|
|
70
|
+
params: <T extends Record<string, string> = Record<string, string>>() => T;
|
|
69
71
|
};
|
|
70
72
|
}
|
|
71
73
|
export type ControllerStaticMethod<REQ extends VovkRequest<KnownAny, KnownAny> = VovkRequest<undefined, Record<string, KnownAny>>, PARAMS extends {
|
package/package.json
CHANGED