vovk 3.0.0-draft.77 → 3.0.0-draft.79
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/client/types.d.ts +1 -4
- package/dist/createDecorator.js +0 -1
- package/dist/createVovkApp.js +5 -5
- package/dist/openapi/openapi.d.ts +3 -2
- package/dist/openapi/openapi.js +1 -1
- package/dist/utils/getSchema.js +3 -1
- package/dist/utils/setHandlerValidation.d.ts +2 -2
- package/dist/utils/setHandlerValidation.js +2 -8
- package/package.json +1 -1
package/dist/client/types.d.ts
CHANGED
|
@@ -91,10 +91,7 @@ export type VovkValidateOnClient = (input: {
|
|
|
91
91
|
body?: unknown;
|
|
92
92
|
query?: unknown;
|
|
93
93
|
endpoint: string;
|
|
94
|
-
},
|
|
95
|
-
body?: unknown;
|
|
96
|
-
query?: unknown;
|
|
97
|
-
}) => void | Promise<void>;
|
|
94
|
+
}, validation: Exclude<VovkHandlerSchema['validation'], undefined>) => void | Promise<void>;
|
|
98
95
|
export type VovkClientOptions<OPTS extends Record<string, KnownAny> = Record<string, never>> = {
|
|
99
96
|
fetcher?: VovkClientFetcher<OPTS>;
|
|
100
97
|
validateOnClient?: VovkValidateOnClient;
|
package/dist/createDecorator.js
CHANGED
|
@@ -21,7 +21,6 @@ function createDecorator(handler, initHandler) {
|
|
|
21
21
|
method._sourceMethod = sourceMethod;
|
|
22
22
|
// TODO define internal method type
|
|
23
23
|
originalMethod._controller = controller;
|
|
24
|
-
originalMethod?._onSettled?.(controller);
|
|
25
24
|
const handlerSchema = controller._handlers?.[propertyKey] ?? null;
|
|
26
25
|
const initResultReturn = initHandler?.call(controller, ...args);
|
|
27
26
|
const initResult = typeof initResultReturn === 'function' ? initResultReturn(handlerSchema) : initResultReturn;
|
package/dist/createVovkApp.js
CHANGED
|
@@ -28,17 +28,19 @@ function createVovkApp() {
|
|
|
28
28
|
}
|
|
29
29
|
const methods = vovkApp.routes[httpMethod].get(controller) ?? {};
|
|
30
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);
|
|
31
35
|
controller._handlers = {
|
|
32
36
|
...controller._handlers,
|
|
33
37
|
[propertyKey]: {
|
|
38
|
+
...(validation ? { validation } : {}),
|
|
34
39
|
...(controller._handlers ?? {})[propertyKey],
|
|
35
40
|
path,
|
|
36
41
|
httpMethod,
|
|
37
42
|
},
|
|
38
43
|
};
|
|
39
|
-
const originalMethod = controller[propertyKey];
|
|
40
|
-
originalMethod._controller = controller;
|
|
41
|
-
originalMethod._sourceMethod = originalMethod._sourceMethod ?? originalMethod;
|
|
42
44
|
methods[path] = controller[propertyKey];
|
|
43
45
|
methods[path]._options = options;
|
|
44
46
|
};
|
|
@@ -87,8 +89,6 @@ function createVovkApp() {
|
|
|
87
89
|
async function GET_DEV(req, data) {
|
|
88
90
|
const params = await data.params;
|
|
89
91
|
if (params[Object.keys(params)[0]]?.[0] === '_schema_') {
|
|
90
|
-
// Wait for schema to be set (it can be set after decorators are called with another setTimeout)
|
|
91
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
92
92
|
const schema = (0, getSchema_1.default)(options);
|
|
93
93
|
return vovkApp.respond(200, { schema });
|
|
94
94
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { OperationObject } from 'openapi3-ts/oas31';
|
|
2
2
|
import { fromSchema } from './fromSchema';
|
|
3
|
+
import type { KnownAny } from '../types';
|
|
3
4
|
type OperationObjectWithCustomProperties = OperationObject & {
|
|
4
|
-
[key in `${'x' | 'X'}-${string}`]:
|
|
5
|
+
[key in `${'x' | 'X'}-${string}`]: KnownAny;
|
|
5
6
|
};
|
|
6
|
-
declare const openapiDecorator: (openAPIOperationObject?: OperationObjectWithCustomProperties | undefined) => (target:
|
|
7
|
+
declare const openapiDecorator: (openAPIOperationObject?: OperationObjectWithCustomProperties | undefined) => (target: KnownAny, propertyKey: string) => void;
|
|
7
8
|
export declare const openapi: typeof openapiDecorator & {
|
|
8
9
|
fromSchema: typeof fromSchema;
|
|
9
10
|
};
|
package/dist/openapi/openapi.js
CHANGED
|
@@ -48,7 +48,7 @@ const openapiDecorator = (0, createDecorator_1.createDecorator)(null, (openAPIOp
|
|
|
48
48
|
'properties' in handlerSchema.validation.query
|
|
49
49
|
? {
|
|
50
50
|
parameters: Object.entries(handlerSchema.validation.query.properties)
|
|
51
|
-
.filter(([, propSchema]) => propSchema.type
|
|
51
|
+
.filter(([, propSchema]) => propSchema.type !== 'object')
|
|
52
52
|
.map(([propName, propSchema]) => ({
|
|
53
53
|
name: propName,
|
|
54
54
|
in: 'query',
|
package/dist/utils/getSchema.js
CHANGED
|
@@ -19,7 +19,9 @@ function getSchema(options) {
|
|
|
19
19
|
handlers: {
|
|
20
20
|
...(exposeValidation
|
|
21
21
|
? controller._handlers
|
|
22
|
-
: Object.fromEntries(
|
|
22
|
+
: Object.fromEntries(
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
24
|
+
Object.entries(controller._handlers ?? {}).map(([key, { validation: _v, ...value }]) => [key, value]))),
|
|
23
25
|
},
|
|
24
26
|
};
|
|
25
27
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { KnownAny, VovkController, VovkHandlerSchema } from '../types';
|
|
2
2
|
export declare function setHandlerValidation(h: ((...args: KnownAny[]) => KnownAny) & {
|
|
3
|
-
|
|
4
|
-
}, validation:
|
|
3
|
+
_getValidation?: (controller: VovkController) => void;
|
|
4
|
+
}, validation: Exclude<VovkHandlerSchema['validation'], undefined>): Promise<void>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setHandlerValidation = setHandlerValidation;
|
|
4
4
|
async function setHandlerValidation(h, validation) {
|
|
5
|
-
h.
|
|
5
|
+
h._getValidation = (controller) => {
|
|
6
6
|
if (!controller) {
|
|
7
7
|
throw new Error('Error setting client validators. Controller not found. Did you forget to use an HTTP decorator?');
|
|
8
8
|
}
|
|
@@ -10,12 +10,6 @@ async function setHandlerValidation(h, validation) {
|
|
|
10
10
|
if (!handlerName) {
|
|
11
11
|
throw new Error('Error setting client validators. Handler not found.');
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
...controller._handlers,
|
|
15
|
-
[handlerName]: {
|
|
16
|
-
...controller._handlers?.[handlerName],
|
|
17
|
-
validation,
|
|
18
|
-
},
|
|
19
|
-
};
|
|
13
|
+
return validation;
|
|
20
14
|
};
|
|
21
15
|
}
|
package/package.json
CHANGED