vovk 3.0.0-draft.195 → 3.0.0-draft.196
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/cjs/VovkApp.js +1 -1
- package/cjs/client/createRPC.js +1 -1
- package/cjs/createVovkApp.js +1 -1
- package/cjs/openapi/openAPIToVovkSchema.js +1 -1
- package/cjs/openapi/vovkSchemaToOpenAPI.js +5 -5
- package/cjs/utils/createLLMFunctions.js +2 -2
- package/cjs/utils/generateStaticAPI.js +2 -2
- package/cjs/utils/getSchema.js +1 -1
- package/mjs/VovkApp.js +1 -1
- package/mjs/client/createRPC.js +1 -1
- package/mjs/createVovkApp.js +1 -1
- package/mjs/openapi/openAPIToVovkSchema.js +1 -1
- package/mjs/openapi/vovkSchemaToOpenAPI.js +5 -5
- package/mjs/utils/createLLMFunctions.js +2 -2
- package/mjs/utils/generateStaticAPI.js +2 -2
- package/mjs/utils/getSchema.js +1 -1
- package/package.json +1 -1
package/cjs/VovkApp.js
CHANGED
|
@@ -118,7 +118,7 @@ class VovkApp {
|
|
|
118
118
|
if (!controller._activated) {
|
|
119
119
|
throw new HttpException_js_1.HttpException(types_js_1.HttpStatus.INTERNAL_SERVER_ERROR, `Controller "${controller.name}" found but not activated`);
|
|
120
120
|
}
|
|
121
|
-
Object.entries(staticMethods).forEach(([path, staticMethod]) => {
|
|
121
|
+
Object.entries(staticMethods ?? {}).forEach(([path, staticMethod]) => {
|
|
122
122
|
const fullPath = [prefix, path].filter(Boolean).join('/');
|
|
123
123
|
handlers[fullPath] = { staticMethod, controller };
|
|
124
124
|
});
|
package/cjs/client/createRPC.js
CHANGED
|
@@ -28,7 +28,7 @@ const createRPC = (schema, segmentName, rpcModuleName, options) => {
|
|
|
28
28
|
throw new Error(`Unable to create RPC object. Controller schema is missing. Check client template.`);
|
|
29
29
|
const controllerPrefix = trimPath(controllerSchema.prefix ?? '');
|
|
30
30
|
const { fetcher: settingsFetcher = fetcher_js_1.fetcher } = options ?? {};
|
|
31
|
-
for (const [staticMethodName, handlerSchema] of Object.entries(controllerSchema.handlers)) {
|
|
31
|
+
for (const [staticMethodName, handlerSchema] of Object.entries(controllerSchema.handlers ?? {})) {
|
|
32
32
|
const { path, httpMethod, validation } = handlerSchema;
|
|
33
33
|
const getEndpoint = ({ apiRoot, params, query, }) => {
|
|
34
34
|
const endpoint = [
|
package/cjs/createVovkApp.js
CHANGED
|
@@ -95,7 +95,7 @@ function createVovkApp() {
|
|
|
95
95
|
};
|
|
96
96
|
const initVovk = (options) => {
|
|
97
97
|
options.segmentName = trimPath(options.segmentName ?? '');
|
|
98
|
-
for (const [rpcModuleName, controller] of Object.entries(options.controllers)) {
|
|
98
|
+
for (const [rpcModuleName, controller] of Object.entries(options.controllers ?? {})) {
|
|
99
99
|
controller._rpcModuleName = rpcModuleName;
|
|
100
100
|
controller._activated = true;
|
|
101
101
|
controller._onError = options?.onError;
|
|
@@ -87,7 +87,7 @@ function openAPIToVovkSchema({ openAPIObject, getHandlerInfo = defaultGetHandler
|
|
|
87
87
|
};
|
|
88
88
|
const segment = schema.segments[''];
|
|
89
89
|
return Object.entries(openAPIObject.paths ?? {}).reduce((acc, [path, operations]) => {
|
|
90
|
-
Object.entries(operations).forEach(([method, operation]) => {
|
|
90
|
+
Object.entries(operations ?? {}).forEach(([method, operation]) => {
|
|
91
91
|
const [rpcModuleName, handlerName] = getHandlerInfo({
|
|
92
92
|
method: method.toUpperCase(),
|
|
93
93
|
path,
|
|
@@ -22,7 +22,7 @@ function extractComponents(schema) {
|
|
|
22
22
|
components[key] = process(value, [...path, key]);
|
|
23
23
|
});
|
|
24
24
|
// Process all properties
|
|
25
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
25
|
+
for (const [key, value] of Object.entries(obj ?? {})) {
|
|
26
26
|
// Skip already processed special properties
|
|
27
27
|
if (key === '$defs' || key === 'definitions')
|
|
28
28
|
continue;
|
|
@@ -46,9 +46,9 @@ function extractComponents(schema) {
|
|
|
46
46
|
function vovkSchemaToOpenAPI({ rootEntry, schema: fullSchema, openAPIObject = {}, package: packageJson = { name: 'vovk-client' }, }) {
|
|
47
47
|
const paths = {};
|
|
48
48
|
const components = {};
|
|
49
|
-
for (const [segmentName, segmentSchema] of Object.entries(fullSchema.segments)) {
|
|
49
|
+
for (const [segmentName, segmentSchema] of Object.entries(fullSchema.segments ?? {})) {
|
|
50
50
|
for (const c of Object.values(segmentSchema.controllers)) {
|
|
51
|
-
for (const [handlerName, h] of Object.entries(c.handlers)) {
|
|
51
|
+
for (const [handlerName, h] of Object.entries(c.handlers ?? {})) {
|
|
52
52
|
if (h.openapi) {
|
|
53
53
|
const [queryValidation, queryComponents] = extractComponents(h?.validation?.query);
|
|
54
54
|
const [bodyValidation, bodyComponents] = extractComponents(h?.validation?.body);
|
|
@@ -64,7 +64,7 @@ function vovkSchemaToOpenAPI({ rootEntry, schema: fullSchema, openAPIObject = {}
|
|
|
64
64
|
controllerSchema: c,
|
|
65
65
|
});
|
|
66
66
|
const queryParameters = queryValidation && 'type' in queryValidation && 'properties' in queryValidation
|
|
67
|
-
? Object.entries(queryValidation.properties).map(([propName, propSchema]) => ({
|
|
67
|
+
? Object.entries(queryValidation.properties ?? {}).map(([propName, propSchema]) => ({
|
|
68
68
|
name: propName,
|
|
69
69
|
in: 'query',
|
|
70
70
|
required: queryValidation.required ? queryValidation.required.includes(propName) : false,
|
|
@@ -72,7 +72,7 @@ function vovkSchemaToOpenAPI({ rootEntry, schema: fullSchema, openAPIObject = {}
|
|
|
72
72
|
}))
|
|
73
73
|
: null;
|
|
74
74
|
const pathParameters = paramsValidation && 'type' in paramsValidation && 'properties' in paramsValidation
|
|
75
|
-
? Object.entries(paramsValidation.properties).map(([propName, propSchema]) => ({
|
|
75
|
+
? Object.entries(paramsValidation.properties ?? {}).map(([propName, propSchema]) => ({
|
|
76
76
|
name: propName,
|
|
77
77
|
in: 'path',
|
|
78
78
|
required: paramsValidation.required ? paramsValidation.required.includes(propName) : false,
|
|
@@ -80,9 +80,9 @@ _options) {
|
|
|
80
80
|
throw new Error('Handler is not a valid RPC or controller method');
|
|
81
81
|
}
|
|
82
82
|
function createLLMFunctions({ modules, caller = defaultCaller, onSuccess = (result) => result, onError = () => { }, }) {
|
|
83
|
-
const functions = Object.entries(modules)
|
|
83
|
+
const functions = Object.entries(modules ?? {})
|
|
84
84
|
.map(([rpcModuleName, module]) => {
|
|
85
|
-
return Object.entries(module)
|
|
85
|
+
return Object.entries(module ?? {})
|
|
86
86
|
.filter(([, handler]) => handler.schema?.openapi)
|
|
87
87
|
.map(([handlerName]) => createLLMFunction({
|
|
88
88
|
rpcModuleName,
|
|
@@ -9,13 +9,13 @@ function generateStaticAPI(c, slug = 'vovk') {
|
|
|
9
9
|
.map((controller) => {
|
|
10
10
|
const handlers = controller._handlers;
|
|
11
11
|
const splitPrefix = controller._prefix?.split('/') ?? [];
|
|
12
|
-
return Object.entries(handlers)
|
|
12
|
+
return Object.entries(handlers ?? {})
|
|
13
13
|
.map(([name, handler]) => {
|
|
14
14
|
const staticParams = controller._handlersMetadata?.[name]?.staticParams;
|
|
15
15
|
if (staticParams?.length) {
|
|
16
16
|
return staticParams.map((paramsItem) => {
|
|
17
17
|
let path = handler.path;
|
|
18
|
-
for (const [key, value] of Object.entries(paramsItem)) {
|
|
18
|
+
for (const [key, value] of Object.entries(paramsItem ?? {})) {
|
|
19
19
|
path = path.replace(`:${key}`, value);
|
|
20
20
|
}
|
|
21
21
|
return { [slug]: [...splitPrefix, ...path.split('/')].filter(Boolean) };
|
package/cjs/utils/getSchema.js
CHANGED
|
@@ -33,7 +33,7 @@ async function getSchema(options) {
|
|
|
33
33
|
};
|
|
34
34
|
if (!emitSchema)
|
|
35
35
|
return schema;
|
|
36
|
-
for (const [rpcModuleName, controller] of Object.entries(options.controllers)) {
|
|
36
|
+
for (const [rpcModuleName, controller] of Object.entries(options.controllers ?? {})) {
|
|
37
37
|
schema.controllers[rpcModuleName] = await getControllerSchema(controller, rpcModuleName, exposeValidation);
|
|
38
38
|
}
|
|
39
39
|
return schema;
|
package/mjs/VovkApp.js
CHANGED
|
@@ -118,7 +118,7 @@ class VovkApp {
|
|
|
118
118
|
if (!controller._activated) {
|
|
119
119
|
throw new HttpException_js_1.HttpException(types_js_1.HttpStatus.INTERNAL_SERVER_ERROR, `Controller "${controller.name}" found but not activated`);
|
|
120
120
|
}
|
|
121
|
-
Object.entries(staticMethods).forEach(([path, staticMethod]) => {
|
|
121
|
+
Object.entries(staticMethods ?? {}).forEach(([path, staticMethod]) => {
|
|
122
122
|
const fullPath = [prefix, path].filter(Boolean).join('/');
|
|
123
123
|
handlers[fullPath] = { staticMethod, controller };
|
|
124
124
|
});
|
package/mjs/client/createRPC.js
CHANGED
|
@@ -28,7 +28,7 @@ const createRPC = (schema, segmentName, rpcModuleName, options) => {
|
|
|
28
28
|
throw new Error(`Unable to create RPC object. Controller schema is missing. Check client template.`);
|
|
29
29
|
const controllerPrefix = trimPath(controllerSchema.prefix ?? '');
|
|
30
30
|
const { fetcher: settingsFetcher = fetcher_js_1.fetcher } = options ?? {};
|
|
31
|
-
for (const [staticMethodName, handlerSchema] of Object.entries(controllerSchema.handlers)) {
|
|
31
|
+
for (const [staticMethodName, handlerSchema] of Object.entries(controllerSchema.handlers ?? {})) {
|
|
32
32
|
const { path, httpMethod, validation } = handlerSchema;
|
|
33
33
|
const getEndpoint = ({ apiRoot, params, query, }) => {
|
|
34
34
|
const endpoint = [
|
package/mjs/createVovkApp.js
CHANGED
|
@@ -95,7 +95,7 @@ function createVovkApp() {
|
|
|
95
95
|
};
|
|
96
96
|
const initVovk = (options) => {
|
|
97
97
|
options.segmentName = trimPath(options.segmentName ?? '');
|
|
98
|
-
for (const [rpcModuleName, controller] of Object.entries(options.controllers)) {
|
|
98
|
+
for (const [rpcModuleName, controller] of Object.entries(options.controllers ?? {})) {
|
|
99
99
|
controller._rpcModuleName = rpcModuleName;
|
|
100
100
|
controller._activated = true;
|
|
101
101
|
controller._onError = options?.onError;
|
|
@@ -87,7 +87,7 @@ function openAPIToVovkSchema({ openAPIObject, getHandlerInfo = defaultGetHandler
|
|
|
87
87
|
};
|
|
88
88
|
const segment = schema.segments[''];
|
|
89
89
|
return Object.entries(openAPIObject.paths ?? {}).reduce((acc, [path, operations]) => {
|
|
90
|
-
Object.entries(operations).forEach(([method, operation]) => {
|
|
90
|
+
Object.entries(operations ?? {}).forEach(([method, operation]) => {
|
|
91
91
|
const [rpcModuleName, handlerName] = getHandlerInfo({
|
|
92
92
|
method: method.toUpperCase(),
|
|
93
93
|
path,
|
|
@@ -22,7 +22,7 @@ function extractComponents(schema) {
|
|
|
22
22
|
components[key] = process(value, [...path, key]);
|
|
23
23
|
});
|
|
24
24
|
// Process all properties
|
|
25
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
25
|
+
for (const [key, value] of Object.entries(obj ?? {})) {
|
|
26
26
|
// Skip already processed special properties
|
|
27
27
|
if (key === '$defs' || key === 'definitions')
|
|
28
28
|
continue;
|
|
@@ -46,9 +46,9 @@ function extractComponents(schema) {
|
|
|
46
46
|
function vovkSchemaToOpenAPI({ rootEntry, schema: fullSchema, openAPIObject = {}, package: packageJson = { name: 'vovk-client' }, }) {
|
|
47
47
|
const paths = {};
|
|
48
48
|
const components = {};
|
|
49
|
-
for (const [segmentName, segmentSchema] of Object.entries(fullSchema.segments)) {
|
|
49
|
+
for (const [segmentName, segmentSchema] of Object.entries(fullSchema.segments ?? {})) {
|
|
50
50
|
for (const c of Object.values(segmentSchema.controllers)) {
|
|
51
|
-
for (const [handlerName, h] of Object.entries(c.handlers)) {
|
|
51
|
+
for (const [handlerName, h] of Object.entries(c.handlers ?? {})) {
|
|
52
52
|
if (h.openapi) {
|
|
53
53
|
const [queryValidation, queryComponents] = extractComponents(h?.validation?.query);
|
|
54
54
|
const [bodyValidation, bodyComponents] = extractComponents(h?.validation?.body);
|
|
@@ -64,7 +64,7 @@ function vovkSchemaToOpenAPI({ rootEntry, schema: fullSchema, openAPIObject = {}
|
|
|
64
64
|
controllerSchema: c,
|
|
65
65
|
});
|
|
66
66
|
const queryParameters = queryValidation && 'type' in queryValidation && 'properties' in queryValidation
|
|
67
|
-
? Object.entries(queryValidation.properties).map(([propName, propSchema]) => ({
|
|
67
|
+
? Object.entries(queryValidation.properties ?? {}).map(([propName, propSchema]) => ({
|
|
68
68
|
name: propName,
|
|
69
69
|
in: 'query',
|
|
70
70
|
required: queryValidation.required ? queryValidation.required.includes(propName) : false,
|
|
@@ -72,7 +72,7 @@ function vovkSchemaToOpenAPI({ rootEntry, schema: fullSchema, openAPIObject = {}
|
|
|
72
72
|
}))
|
|
73
73
|
: null;
|
|
74
74
|
const pathParameters = paramsValidation && 'type' in paramsValidation && 'properties' in paramsValidation
|
|
75
|
-
? Object.entries(paramsValidation.properties).map(([propName, propSchema]) => ({
|
|
75
|
+
? Object.entries(paramsValidation.properties ?? {}).map(([propName, propSchema]) => ({
|
|
76
76
|
name: propName,
|
|
77
77
|
in: 'path',
|
|
78
78
|
required: paramsValidation.required ? paramsValidation.required.includes(propName) : false,
|
|
@@ -80,9 +80,9 @@ _options) {
|
|
|
80
80
|
throw new Error('Handler is not a valid RPC or controller method');
|
|
81
81
|
}
|
|
82
82
|
function createLLMFunctions({ modules, caller = defaultCaller, onSuccess = (result) => result, onError = () => { }, }) {
|
|
83
|
-
const functions = Object.entries(modules)
|
|
83
|
+
const functions = Object.entries(modules ?? {})
|
|
84
84
|
.map(([rpcModuleName, module]) => {
|
|
85
|
-
return Object.entries(module)
|
|
85
|
+
return Object.entries(module ?? {})
|
|
86
86
|
.filter(([, handler]) => handler.schema?.openapi)
|
|
87
87
|
.map(([handlerName]) => createLLMFunction({
|
|
88
88
|
rpcModuleName,
|
|
@@ -9,13 +9,13 @@ function generateStaticAPI(c, slug = 'vovk') {
|
|
|
9
9
|
.map((controller) => {
|
|
10
10
|
const handlers = controller._handlers;
|
|
11
11
|
const splitPrefix = controller._prefix?.split('/') ?? [];
|
|
12
|
-
return Object.entries(handlers)
|
|
12
|
+
return Object.entries(handlers ?? {})
|
|
13
13
|
.map(([name, handler]) => {
|
|
14
14
|
const staticParams = controller._handlersMetadata?.[name]?.staticParams;
|
|
15
15
|
if (staticParams?.length) {
|
|
16
16
|
return staticParams.map((paramsItem) => {
|
|
17
17
|
let path = handler.path;
|
|
18
|
-
for (const [key, value] of Object.entries(paramsItem)) {
|
|
18
|
+
for (const [key, value] of Object.entries(paramsItem ?? {})) {
|
|
19
19
|
path = path.replace(`:${key}`, value);
|
|
20
20
|
}
|
|
21
21
|
return { [slug]: [...splitPrefix, ...path.split('/')].filter(Boolean) };
|
package/mjs/utils/getSchema.js
CHANGED
|
@@ -33,7 +33,7 @@ async function getSchema(options) {
|
|
|
33
33
|
};
|
|
34
34
|
if (!emitSchema)
|
|
35
35
|
return schema;
|
|
36
|
-
for (const [rpcModuleName, controller] of Object.entries(options.controllers)) {
|
|
36
|
+
for (const [rpcModuleName, controller] of Object.entries(options.controllers ?? {})) {
|
|
37
37
|
schema.controllers[rpcModuleName] = await getControllerSchema(controller, rpcModuleName, exposeValidation);
|
|
38
38
|
}
|
|
39
39
|
return schema;
|