vovk 3.0.0-draft.113 → 3.0.0-draft.115
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 +1 -0
- package/dist/client/types.d.ts +1 -2
- package/dist/types.d.ts +5 -4
- package/dist/utils/reqForm.js +20 -1
- package/dist/utils/withValidation.d.ts +5 -5
- package/dist/utils/withValidation.js +19 -3
- package/package.json +1 -1
package/dist/VovkApp.js
CHANGED
|
@@ -136,6 +136,7 @@ class VovkApp {
|
|
|
136
136
|
params: () => methodParams,
|
|
137
137
|
};
|
|
138
138
|
try {
|
|
139
|
+
await staticMethod._options?.before?.call(controller, req);
|
|
139
140
|
const result = await staticMethod.call(controller, req, methodParams);
|
|
140
141
|
const isIterator = typeof result === 'object' &&
|
|
141
142
|
!!result &&
|
package/dist/client/types.d.ts
CHANGED
|
@@ -82,7 +82,6 @@ export type VovkClientFetcher<OPTS extends Record<string, KnownAny> = Record<str
|
|
|
82
82
|
} & OPTS) => KnownAny;
|
|
83
83
|
export interface VovkDefaultFetcherOptions {
|
|
84
84
|
apiRoot?: string;
|
|
85
|
-
segmentName?: string;
|
|
86
85
|
disableClientValidation?: boolean;
|
|
87
86
|
validateOnClient?: VovkValidateOnClient;
|
|
88
87
|
fetcher?: VovkClientFetcher;
|
|
@@ -98,7 +97,7 @@ export type VovkValidateOnClient = (input: {
|
|
|
98
97
|
query?: unknown;
|
|
99
98
|
params?: unknown;
|
|
100
99
|
endpoint: string;
|
|
101
|
-
}, validation: Exclude<VovkHandlerSchema['validation'], undefined>, fullSchema: VovkFullSchema) => void | Promise<void>;
|
|
100
|
+
}, validation: Omit<Exclude<VovkHandlerSchema['validation'], undefined>, 'output' | 'iteration'>, fullSchema: VovkFullSchema) => void | Promise<void>;
|
|
102
101
|
export type VovkClientOptions<OPTS extends Record<string, KnownAny> = Record<string, never>> = {
|
|
103
102
|
fetcher?: VovkClientFetcher<OPTS>;
|
|
104
103
|
validateOnClient?: VovkValidateOnClient;
|
package/dist/types.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ export type VovkController = StaticClass & VovkControllerInternal & {
|
|
|
47
47
|
export type DecoratorOptions = {
|
|
48
48
|
cors?: boolean;
|
|
49
49
|
headers?: Record<string, string>;
|
|
50
|
+
before?: (this: VovkController, req: VovkRequest) => unknown;
|
|
50
51
|
};
|
|
51
52
|
export type RouteHandler = ((req: VovkRequest, params: Record<string, string>) => Response | Promise<Response> | Iterable<unknown> | AsyncIterable<unknown>) & {
|
|
52
53
|
_options?: DecoratorOptions;
|
|
@@ -98,8 +99,8 @@ export type StreamAbortMessage = {
|
|
|
98
99
|
type LogLevelNames = 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
99
100
|
export type VovkEnv = {
|
|
100
101
|
PORT?: string;
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
VOVK_GENERATE_FULL_CLIENT?: string;
|
|
103
|
+
VOVK_GENERATE_SEGMENT_CLIENT?: string;
|
|
103
104
|
VOVK_CLIENT_OUT_DIR?: string;
|
|
104
105
|
VOVK_SCHEMA_OUT_DIR?: string;
|
|
105
106
|
VOVK_IMPORTS_FETCHER?: string;
|
|
@@ -128,8 +129,8 @@ export type VovkConfig = {
|
|
|
128
129
|
emitConfig?: boolean | (keyof VovkStrictConfig)[];
|
|
129
130
|
clientOutDir?: string;
|
|
130
131
|
schemaOutDir?: string;
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
generateFullClient?: boolean;
|
|
133
|
+
generateSegmentClient?: boolean;
|
|
133
134
|
imports?: {
|
|
134
135
|
fetcher?: string | [string, string] | [string];
|
|
135
136
|
validateOnClient?: string | [string, string] | [string];
|
package/dist/utils/reqForm.js
CHANGED
|
@@ -7,7 +7,26 @@ async function reqForm(req) {
|
|
|
7
7
|
return formMap.get(req);
|
|
8
8
|
}
|
|
9
9
|
const body = await req.formData();
|
|
10
|
-
const formData =
|
|
10
|
+
const formData = {};
|
|
11
|
+
for (const [key, value] of body.entries()) {
|
|
12
|
+
if (value instanceof File) {
|
|
13
|
+
// If this key already exists, convert to array or append to existing array
|
|
14
|
+
if (formData[key]) {
|
|
15
|
+
if (Array.isArray(formData[key])) {
|
|
16
|
+
formData[key].push(value);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
formData[key] = [formData[key], value];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
formData[key] = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
formData[key] = value.toString();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
11
30
|
formMap.set(req, formData);
|
|
12
31
|
return formData;
|
|
13
32
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function withValidation<T extends (req: KnownAny, params: KnownAny) => KnownAny, BODY_MODEL, QUERY_MODEL, PARAMS_MODEL, OUTPUT_MODEL, ITERATION_MODEL>({ disableServerSideValidation, skipSchemaEmission, validateEveryIteration, body, query, params, output, iteration, handle,
|
|
1
|
+
import { VovkValidationType, type KnownAny, type VovkRequest } from '../types';
|
|
2
|
+
export declare function withValidation<T extends (req: KnownAny, params: KnownAny) => KnownAny, BODY_MODEL, QUERY_MODEL, PARAMS_MODEL, OUTPUT_MODEL, ITERATION_MODEL>({ disableServerSideValidation, skipSchemaEmission, validateEveryIteration, body, query, params, output, iteration, handle, getJSONSchemaFromModel, validate, }: {
|
|
3
3
|
disableServerSideValidation?: boolean | VovkValidationType[];
|
|
4
4
|
skipSchemaEmission?: boolean | VovkValidationType[];
|
|
5
5
|
validateEveryIteration?: boolean;
|
|
@@ -9,9 +9,9 @@ export declare function withValidation<T extends (req: KnownAny, params: KnownAn
|
|
|
9
9
|
output?: OUTPUT_MODEL;
|
|
10
10
|
iteration?: ITERATION_MODEL;
|
|
11
11
|
handle: T;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}) =>
|
|
12
|
+
getJSONSchemaFromModel?: (model: NonNullable<BODY_MODEL | QUERY_MODEL | PARAMS_MODEL | OUTPUT_MODEL | ITERATION_MODEL>, meta: {
|
|
13
|
+
type: VovkValidationType;
|
|
14
|
+
}) => KnownAny;
|
|
15
15
|
validate: (data: KnownAny, model: NonNullable<BODY_MODEL | QUERY_MODEL | PARAMS_MODEL | OUTPUT_MODEL | ITERATION_MODEL>, meta: {
|
|
16
16
|
type: VovkValidationType;
|
|
17
17
|
req: VovkRequest<KnownAny, KnownAny>;
|
|
@@ -5,7 +5,7 @@ const HttpException_1 = require("../HttpException");
|
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
const setHandlerSchema_1 = require("./setHandlerSchema");
|
|
7
7
|
const validationTypes = ['body', 'query', 'params', 'output', 'iteration'];
|
|
8
|
-
function withValidation({ disableServerSideValidation, skipSchemaEmission, validateEveryIteration, body, query, params, output, iteration, handle,
|
|
8
|
+
function withValidation({ disableServerSideValidation, skipSchemaEmission, validateEveryIteration, body, query, params, output, iteration, handle, getJSONSchemaFromModel, validate, }) {
|
|
9
9
|
const disableServerSideValidationKeys = disableServerSideValidation === false
|
|
10
10
|
? []
|
|
11
11
|
: disableServerSideValidation === true
|
|
@@ -65,8 +65,24 @@ function withValidation({ disableServerSideValidation, skipSchemaEmission, valid
|
|
|
65
65
|
}
|
|
66
66
|
return outputHandler(req, handlerParams);
|
|
67
67
|
};
|
|
68
|
-
if (
|
|
69
|
-
|
|
68
|
+
if (getJSONSchemaFromModel) {
|
|
69
|
+
const validation = {};
|
|
70
|
+
if (body && !skipSchemaEmissionKeys.includes('body')) {
|
|
71
|
+
validation.body = getJSONSchemaFromModel(body, { type: 'body' });
|
|
72
|
+
}
|
|
73
|
+
if (query && !skipSchemaEmissionKeys.includes('query')) {
|
|
74
|
+
validation.query = getJSONSchemaFromModel(query, { type: 'query' });
|
|
75
|
+
}
|
|
76
|
+
if (params && !skipSchemaEmissionKeys.includes('params')) {
|
|
77
|
+
validation.params = getJSONSchemaFromModel(params, { type: 'params' });
|
|
78
|
+
}
|
|
79
|
+
if (output && !skipSchemaEmissionKeys.includes('output')) {
|
|
80
|
+
validation.output = getJSONSchemaFromModel(output, { type: 'output' });
|
|
81
|
+
}
|
|
82
|
+
if (iteration && !skipSchemaEmissionKeys.includes('iteration')) {
|
|
83
|
+
validation.iteration = getJSONSchemaFromModel(iteration, { type: 'iteration' });
|
|
84
|
+
}
|
|
85
|
+
(0, setHandlerSchema_1.setHandlerSchema)(resultHandler, { validation });
|
|
70
86
|
}
|
|
71
87
|
return resultHandler;
|
|
72
88
|
}
|
package/package.json
CHANGED