vovk-cli 0.0.1-draft.39 → 0.0.1-draft.390
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/LICENSE +1 -1
- package/README.md +31 -1
- package/client-templates/cjs/index.cjs.ejs +20 -0
- package/client-templates/cjs/index.d.cts.ejs +22 -0
- package/client-templates/mixins/mixins.d.ts.ejs +64 -0
- package/client-templates/mixins/mixins.json.ejs +1 -0
- package/client-templates/mjs/index.d.mts.ejs +22 -0
- package/client-templates/mjs/index.mjs.ejs +19 -0
- package/client-templates/openapiCjs/openapi.cjs.ejs +4 -0
- package/client-templates/openapiCjs/openapi.d.cts.ejs +4 -0
- package/client-templates/openapiJson/openapi.json.ejs +1 -0
- package/client-templates/openapiTs/openapi.ts.ejs +4 -0
- package/client-templates/packageJson/package.json.ejs +1 -0
- package/client-templates/readme/README.md.ejs +39 -0
- package/client-templates/schemaCjs/schema.cjs.ejs +24 -0
- package/client-templates/schemaCjs/schema.d.cts.ejs +10 -0
- package/client-templates/schemaJson/schema.json.ejs +1 -0
- package/client-templates/schemaTs/schema.ts.ejs +28 -0
- package/client-templates/ts/index.ts.ejs +33 -0
- package/dist/bundle/index.d.mts +8 -0
- package/dist/bundle/index.mjs +74 -0
- package/dist/dev/diffSegmentSchema.d.mts +36 -0
- package/dist/dev/{diffSchema.mjs → diffSegmentSchema.mjs} +3 -11
- package/dist/dev/ensureSchemaFiles.d.mts +4 -1
- package/dist/dev/ensureSchemaFiles.mjs +15 -31
- package/dist/dev/index.d.mts +5 -1
- package/dist/dev/index.mjs +141 -66
- package/dist/dev/logDiffResult.d.mts +1 -1
- package/dist/dev/logDiffResult.mjs +6 -43
- package/dist/dev/writeMetaJson.d.mts +2 -0
- package/dist/dev/writeMetaJson.mjs +20 -0
- package/dist/dev/writeOneSegmentSchemaFile.d.mts +12 -0
- package/dist/dev/{writeOneSchemaFile.mjs → writeOneSegmentSchemaFile.mjs} +10 -6
- package/dist/generate/ensureClient.d.mts +3 -0
- package/dist/generate/ensureClient.mjs +28 -0
- package/dist/generate/generate.d.mts +13 -0
- package/dist/generate/generate.mjs +307 -0
- package/dist/generate/getClientTemplateFiles.d.mts +20 -0
- package/dist/generate/getClientTemplateFiles.mjs +85 -0
- package/dist/generate/getProjectFullSchema.d.mts +8 -0
- package/dist/generate/getProjectFullSchema.mjs +66 -0
- package/dist/generate/getTemplateClientImports.d.mts +20 -0
- package/dist/generate/getTemplateClientImports.mjs +54 -0
- package/dist/generate/index.d.mts +33 -0
- package/dist/generate/index.mjs +186 -0
- package/dist/generate/writeOneClientFile.d.mts +42 -0
- package/dist/generate/writeOneClientFile.mjs +151 -0
- package/dist/getProjectInfo/getConfig/getConfigAbsolutePaths.d.mts +5 -0
- package/dist/getProjectInfo/{getConfigAbsolutePaths.mjs → getConfig/getConfigAbsolutePaths.mjs} +4 -1
- package/dist/getProjectInfo/{getRelativeSrcRoot.d.mts → getConfig/getRelativeSrcRoot.d.mts} +1 -1
- package/dist/getProjectInfo/{getRelativeSrcRoot.mjs → getConfig/getRelativeSrcRoot.mjs} +2 -2
- package/dist/getProjectInfo/getConfig/getTemplateDefs.d.mts +24 -0
- package/dist/getProjectInfo/getConfig/getTemplateDefs.mjs +165 -0
- package/dist/getProjectInfo/{getUserConfig.d.mts → getConfig/getUserConfig.d.mts} +3 -2
- package/dist/getProjectInfo/{getUserConfig.mjs → getConfig/getUserConfig.mjs} +3 -3
- package/dist/getProjectInfo/{importUncachedModule.mjs → getConfig/importUncachedModule.mjs} +1 -4
- package/dist/getProjectInfo/getConfig/index.d.mts +91 -0
- package/dist/getProjectInfo/getConfig/index.mjs +92 -0
- package/dist/getProjectInfo/getMetaSchema.d.mts +8 -0
- package/dist/getProjectInfo/getMetaSchema.mjs +27 -0
- package/dist/getProjectInfo/index.d.mts +14 -9
- package/dist/getProjectInfo/index.mjs +24 -22
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +116 -35
- package/dist/init/createConfig.d.mts +2 -2
- package/dist/init/createConfig.mjs +40 -13
- package/dist/init/createStandardSchemaValidatorFile.d.mts +4 -0
- package/dist/init/createStandardSchemaValidatorFile.mjs +52 -0
- package/dist/init/getTemplateFilesFromPackage.mjs +10 -5
- package/dist/init/index.d.mts +2 -2
- package/dist/init/index.mjs +121 -72
- package/dist/init/installDependencies.mjs +4 -2
- package/dist/init/logUpdateDependenciesError.d.mts +3 -1
- package/dist/init/logUpdateDependenciesError.mjs +7 -1
- package/dist/init/updateDependenciesWithoutInstalling.mjs +39 -9
- package/dist/init/updateNPMScripts.mjs +1 -1
- package/dist/init/updateTypeScriptConfig.d.mts +4 -1
- package/dist/init/updateTypeScriptConfig.mjs +11 -7
- package/dist/initProgram.d.mts +1 -1
- package/dist/initProgram.mjs +17 -17
- package/dist/locateSegments.d.mts +8 -1
- package/dist/locateSegments.mjs +13 -3
- package/dist/new/addClassToSegmentCode.d.mts +1 -2
- package/dist/new/addClassToSegmentCode.mjs +3 -3
- package/dist/new/index.d.mts +2 -1
- package/dist/new/index.mjs +5 -3
- package/dist/new/newModule.d.mts +5 -2
- package/dist/new/newModule.mjs +26 -24
- package/dist/new/newSegment.d.mts +4 -1
- package/dist/new/newSegment.mjs +20 -12
- package/dist/new/render.d.mts +7 -3
- package/dist/new/render.mjs +31 -10
- package/dist/types.d.mts +66 -44
- package/dist/utils/compileJSONSchemaToTypeScriptType.d.mts +5 -0
- package/dist/utils/compileJSONSchemaToTypeScriptType.mjs +9 -0
- package/dist/utils/compileTs.d.mts +12 -0
- package/dist/utils/compileTs.mjs +261 -0
- package/dist/utils/debounceWithArgs.d.mts +1 -1
- package/dist/utils/deepExtend.d.mts +54 -0
- package/dist/utils/deepExtend.mjs +129 -0
- package/dist/utils/formatLoggedSegmentName.d.mts +3 -1
- package/dist/utils/formatLoggedSegmentName.mjs +3 -2
- package/dist/utils/generateFnName.d.mts +23 -0
- package/dist/utils/generateFnName.mjs +76 -0
- package/dist/utils/getPackageJson.d.mts +3 -0
- package/dist/utils/getPackageJson.mjs +22 -0
- package/dist/utils/getPublicModuleNameFromPath.d.mts +4 -0
- package/dist/utils/getPublicModuleNameFromPath.mjs +9 -0
- package/dist/utils/normalizeOpenAPIMixin.d.mts +14 -0
- package/dist/utils/normalizeOpenAPIMixin.mjs +114 -0
- package/dist/utils/pickSegmentFullSchema.d.mts +3 -0
- package/dist/utils/pickSegmentFullSchema.mjs +15 -0
- package/dist/utils/removeUnlistedDirectories.d.mts +10 -0
- package/dist/utils/removeUnlistedDirectories.mjs +61 -0
- package/dist/utils/resolveAbsoluteModulePath.d.mts +2 -0
- package/dist/utils/resolveAbsoluteModulePath.mjs +32 -0
- package/module-templates/arktype/controller.ts.ejs +78 -0
- package/module-templates/type/controller.ts.ejs +64 -0
- package/module-templates/type/service.ts.ejs +37 -0
- package/module-templates/valibot/controller.ts.ejs +78 -0
- package/package.json +39 -22
- package/dist/dev/diffSchema.d.mts +0 -43
- package/dist/dev/ensureClient.d.mts +0 -5
- package/dist/dev/ensureClient.mjs +0 -31
- package/dist/dev/isMetadataEmpty.d.mts +0 -2
- package/dist/dev/isMetadataEmpty.mjs +0 -4
- package/dist/dev/writeOneSchemaFile.d.mts +0 -11
- package/dist/generateClient.d.mts +0 -7
- package/dist/generateClient.mjs +0 -97
- package/dist/getProjectInfo/getConfig.d.mts +0 -11
- package/dist/getProjectInfo/getConfig.mjs +0 -29
- package/dist/getProjectInfo/getConfigAbsolutePaths.d.mts +0 -4
- package/dist/postinstall.d.mts +0 -1
- package/dist/postinstall.mjs +0 -24
- package/templates/controller.ejs +0 -52
- package/templates/service.ejs +0 -27
- package/templates/worker.ejs +0 -24
- /package/dist/getProjectInfo/{importUncachedModule.d.mts → getConfig/importUncachedModule.d.mts} +0 -0
- /package/dist/getProjectInfo/{importUncachedModuleWorker.d.mts → getConfig/importUncachedModuleWorker.d.mts} +0 -0
- /package/dist/getProjectInfo/{importUncachedModuleWorker.mjs → getConfig/importUncachedModuleWorker.mjs} +0 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import * as YAML from 'yaml';
|
|
4
|
+
import chalkHighlightThing from './chalkHighlightThing.mjs';
|
|
5
|
+
import camelCase from 'lodash/camelCase.js';
|
|
6
|
+
import { generateFnName } from './generateFnName.mjs';
|
|
7
|
+
const getNamesNestJS = (operationObject) => {
|
|
8
|
+
const operationId = operationObject.operationId;
|
|
9
|
+
if (!operationId) {
|
|
10
|
+
throw new Error('Operation ID is required for NestJS module name generation');
|
|
11
|
+
}
|
|
12
|
+
const controllerHandlerMatch = operationId?.match(/^([A-Z][a-zA-Z0-9]*)_([a-zA-Z0-9_]+)/);
|
|
13
|
+
if (!controllerHandlerMatch) {
|
|
14
|
+
throw new Error(`Invalid operationId format for NestJS: ${operationId}`);
|
|
15
|
+
}
|
|
16
|
+
const [controllerName, handlerName] = controllerHandlerMatch.slice(1, 3);
|
|
17
|
+
return [controllerName.replace(/Controller$/, 'RPC'), handlerName];
|
|
18
|
+
};
|
|
19
|
+
const normalizeGetModuleName = (getModuleName) => {
|
|
20
|
+
if (getModuleName === 'nestjs-operation-id') {
|
|
21
|
+
getModuleName = ({ operationObject }) => getNamesNestJS(operationObject)[0];
|
|
22
|
+
}
|
|
23
|
+
else if (typeof getModuleName === 'string') {
|
|
24
|
+
const moduleName = getModuleName;
|
|
25
|
+
getModuleName = () => moduleName;
|
|
26
|
+
}
|
|
27
|
+
else if (typeof getModuleName !== 'function') {
|
|
28
|
+
throw new Error('getModuleName must be a function or one of the predefined strings');
|
|
29
|
+
}
|
|
30
|
+
return getModuleName;
|
|
31
|
+
};
|
|
32
|
+
const normalizeGetMethodName = (getMethodName) => {
|
|
33
|
+
if (getMethodName === 'nestjs-operation-id') {
|
|
34
|
+
getMethodName = ({ operationObject }) => getNamesNestJS(operationObject)[1];
|
|
35
|
+
}
|
|
36
|
+
else if (getMethodName === 'camel-case-operation-id') {
|
|
37
|
+
getMethodName = ({ operationObject }) => {
|
|
38
|
+
const operationId = operationObject.operationId;
|
|
39
|
+
if (!operationId) {
|
|
40
|
+
throw new Error('Operation ID is required for camel-case method name generation');
|
|
41
|
+
}
|
|
42
|
+
return camelCase(operationId);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
else if (getMethodName === 'auto') {
|
|
46
|
+
getMethodName = ({ operationObject, method, path }) => {
|
|
47
|
+
const operationId = operationObject.operationId;
|
|
48
|
+
const isCamelCase = operationId && /^[a-z][a-zA-Z0-9]*$/.test(operationId);
|
|
49
|
+
const isSnakeCase = operationId && /^[a-z][a-z0-9_]+$/.test(operationId);
|
|
50
|
+
return isCamelCase ? operationId : isSnakeCase ? camelCase(operationId) : generateFnName(method, path);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
else if (typeof getMethodName !== 'function') {
|
|
54
|
+
throw new Error('getMethodName must be a function or one of the predefined strings');
|
|
55
|
+
}
|
|
56
|
+
return getMethodName;
|
|
57
|
+
};
|
|
58
|
+
async function getOpenApiSpecLocal(openApiSpecFilePath, cwd) {
|
|
59
|
+
const openApiSpecAbsolutePath = path.resolve(cwd, openApiSpecFilePath);
|
|
60
|
+
const fileName = path.basename(openApiSpecAbsolutePath);
|
|
61
|
+
if (!fileName.endsWith('.json') && !fileName.endsWith('.yaml') && !fileName.endsWith('.yml')) {
|
|
62
|
+
throw new Error(`Invalid OpenAPI spec file format: ${fileName}. Please provide a JSON or YAML file.`);
|
|
63
|
+
}
|
|
64
|
+
const openApiSpecContent = await fs.readFile(openApiSpecAbsolutePath, 'utf8');
|
|
65
|
+
return (fileName.endsWith('.json') ? JSON.parse(openApiSpecContent) : YAML.parse(openApiSpecContent));
|
|
66
|
+
}
|
|
67
|
+
async function getOpenApiSpecRemote({ cwd, url, fallback, log, }) {
|
|
68
|
+
const resp = await fetch(url);
|
|
69
|
+
const text = await resp.text();
|
|
70
|
+
if (!resp.ok) {
|
|
71
|
+
if (fallback) {
|
|
72
|
+
log.warn(`Failed to fetch OpenAPI spec from ${chalkHighlightThing(url)}: ${resp.status} ${resp.statusText}. Falling back to ${chalkHighlightThing(fallback)}`);
|
|
73
|
+
return getOpenApiSpecLocal(fallback, cwd);
|
|
74
|
+
}
|
|
75
|
+
throw new Error(`Failed to fetch OpenAPI spec from ${chalkHighlightThing(url)}: ${resp.status} ${resp.statusText}`);
|
|
76
|
+
}
|
|
77
|
+
if (fallback) {
|
|
78
|
+
const fallbackAbsolutePath = path.resolve(cwd, fallback);
|
|
79
|
+
const existingFallback = await fs.readFile(fallbackAbsolutePath, 'utf8').catch(() => null);
|
|
80
|
+
if (existingFallback !== text) {
|
|
81
|
+
await fs.mkdir(path.dirname(fallbackAbsolutePath), { recursive: true });
|
|
82
|
+
await fs.writeFile(fallbackAbsolutePath, text);
|
|
83
|
+
log.info(`Saved OpenAPI spec to fallback file ${chalkHighlightThing(fallbackAbsolutePath)}`);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
log.debug(`OpenAPI spec at ${chalkHighlightThing(url)} is unchanged. Skipping write to fallback file ${chalkHighlightThing(fallbackAbsolutePath)}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return (text.trim().startsWith('{') || text.trim().startsWith('[') ? JSON.parse(text) : YAML.parse(text));
|
|
90
|
+
}
|
|
91
|
+
export async function normalizeOpenAPIMixin({
|
|
92
|
+
// mixinName,
|
|
93
|
+
mixinModule, log, cwd = process.cwd(), }) {
|
|
94
|
+
const { source, getModuleName, getMethodName } = mixinModule;
|
|
95
|
+
let openAPIObject;
|
|
96
|
+
if ('url' in source) {
|
|
97
|
+
openAPIObject = await getOpenApiSpecRemote({ url: source.url, fallback: source.fallback, log, cwd });
|
|
98
|
+
}
|
|
99
|
+
else if ('file' in source) {
|
|
100
|
+
openAPIObject = await getOpenApiSpecLocal(source.file, cwd);
|
|
101
|
+
}
|
|
102
|
+
else if ('object' in source) {
|
|
103
|
+
openAPIObject = source.object;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
throw new Error('Invalid source type for OpenAPI configuration');
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
...mixinModule,
|
|
110
|
+
source: { object: openAPIObject },
|
|
111
|
+
getModuleName: normalizeGetModuleName(getModuleName),
|
|
112
|
+
getMethodName: normalizeGetMethodName(getMethodName),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { VovkSchemaIdEnum } from 'vovk';
|
|
2
|
+
export default function pickSegmentFullSchema(schema, segmentNames) {
|
|
3
|
+
return {
|
|
4
|
+
$schema: VovkSchemaIdEnum.SCHEMA,
|
|
5
|
+
meta: schema.meta,
|
|
6
|
+
segments: Object.fromEntries(segmentNames.map((segmentName) => [segmentName, schema.segments[segmentName]])),
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function omitSegmentFullSchema(schema, segmentNames) {
|
|
10
|
+
return {
|
|
11
|
+
$schema: VovkSchemaIdEnum.SCHEMA,
|
|
12
|
+
meta: schema.meta,
|
|
13
|
+
segments: Object.fromEntries(Object.entries(schema.segments).filter(([segmentName]) => !segmentNames.includes(segmentName))),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes all directories in a folder that aren't in the provided allowlist
|
|
3
|
+
* Supports nested directory paths like 'foo/bar/baz'
|
|
4
|
+
*
|
|
5
|
+
* @param folderPath - The path to the folder to process
|
|
6
|
+
* @param allowedDirs - Array of relative directory paths to keep
|
|
7
|
+
* @returns Promise that resolves when all operations are complete
|
|
8
|
+
*/
|
|
9
|
+
declare function removeUnlistedDirectories(folderPath: string, allowedDirs: string[]): Promise<void>;
|
|
10
|
+
export default removeUnlistedDirectories;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import getFileSystemEntryType, { FileSystemEntryType } from './getFileSystemEntryType.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* Removes all directories in a folder that aren't in the provided allowlist
|
|
6
|
+
* Supports nested directory paths like 'foo/bar/baz'
|
|
7
|
+
*
|
|
8
|
+
* @param folderPath - The path to the folder to process
|
|
9
|
+
* @param allowedDirs - Array of relative directory paths to keep
|
|
10
|
+
* @returns Promise that resolves when all operations are complete
|
|
11
|
+
*/
|
|
12
|
+
async function removeUnlistedDirectories(folderPath, allowedDirs) {
|
|
13
|
+
// Normalize all allowed paths to use the system-specific separator
|
|
14
|
+
const normalizedAllowedDirs = allowedDirs.map((dir) => dir.split('/').join(path.sep));
|
|
15
|
+
// Process the directory tree recursively
|
|
16
|
+
await processDirectory(folderPath, '', normalizedAllowedDirs);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Recursively processes directories to determine which should be kept or removed
|
|
20
|
+
*
|
|
21
|
+
* @param basePath - The absolute base path being processed
|
|
22
|
+
* @param relativePath - The current relative path from the base
|
|
23
|
+
* @param allowedDirs - Normalized list of allowed directory paths
|
|
24
|
+
*/
|
|
25
|
+
async function processDirectory(basePath, relativePath, allowedDirs) {
|
|
26
|
+
const currentDirPath = path.join(basePath, relativePath);
|
|
27
|
+
// check if the current path is a directory
|
|
28
|
+
const type = await getFileSystemEntryType(currentDirPath);
|
|
29
|
+
if (type !== FileSystemEntryType.DIRECTORY) {
|
|
30
|
+
// If it's not a directory, return early
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// Read all entries in the current directory
|
|
34
|
+
const entries = await fs.readdir(currentDirPath, { withFileTypes: true });
|
|
35
|
+
// Process only directories
|
|
36
|
+
const dirEntries = entries.filter((entry) => entry.isDirectory());
|
|
37
|
+
// Check each directory
|
|
38
|
+
for (const dir of dirEntries) {
|
|
39
|
+
// Calculate the new relative path
|
|
40
|
+
const newRelativePath = relativePath ? path.join(relativePath, dir.name) : dir.name;
|
|
41
|
+
// Check if this directory or any of its subdirectories should be kept
|
|
42
|
+
const shouldKeep = allowedDirs.some((allowedDir) => {
|
|
43
|
+
// Direct match
|
|
44
|
+
if (allowedDir === newRelativePath)
|
|
45
|
+
return true;
|
|
46
|
+
// Check if it's a parent path of an allowed directory
|
|
47
|
+
// e.g. "foo" is a parent of "foo/bar/baz"
|
|
48
|
+
return allowedDir.startsWith(newRelativePath + path.sep);
|
|
49
|
+
});
|
|
50
|
+
if (shouldKeep) {
|
|
51
|
+
// Recursively process this directory's contents
|
|
52
|
+
await processDirectory(basePath, newRelativePath, allowedDirs);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// Remove this directory since it's not in the allowed list
|
|
56
|
+
const fullPath = path.join(basePath, newRelativePath);
|
|
57
|
+
await fs.rm(fullPath, { recursive: true, force: true });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export default removeUnlistedDirectories;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import getPublicModuleNameFromPath from './getPublicModuleNameFromPath.mjs';
|
|
4
|
+
// Returns the path up to and including the last occurrence of the given module name
|
|
5
|
+
export function getPathUpToModule(moduleName, fullPath) {
|
|
6
|
+
const idx = fullPath.lastIndexOf(moduleName);
|
|
7
|
+
if (idx === -1)
|
|
8
|
+
return moduleName;
|
|
9
|
+
return fullPath.slice(0, idx + moduleName.length);
|
|
10
|
+
}
|
|
11
|
+
export default function resolveAbsoluteModulePath(modulePath, cwd) {
|
|
12
|
+
// If it's an absolute path or starts with '.' (relative), resolve it directly
|
|
13
|
+
if (modulePath.startsWith('/') || modulePath.startsWith('.')) {
|
|
14
|
+
return path.resolve(cwd, modulePath);
|
|
15
|
+
}
|
|
16
|
+
// For npm package names, use Node's module resolution algorithm
|
|
17
|
+
try {
|
|
18
|
+
const { moduleName, restPath } = getPublicModuleNameFromPath(modulePath);
|
|
19
|
+
if (!moduleName) {
|
|
20
|
+
throw new Error(`Invalid module path: ${modulePath}`);
|
|
21
|
+
}
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
const resolved = require.resolve(moduleName);
|
|
24
|
+
return path.resolve(getPathUpToModule(moduleName, path.dirname(resolved)), restPath);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
// eslint-disable-next-line no-console
|
|
28
|
+
console.error(`Error resolving module path: ${modulePath}`, e);
|
|
29
|
+
// If resolution fails, fall back to the original behavior
|
|
30
|
+
return path.resolve(cwd, './node_modules', modulePath);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<% const vars = {
|
|
2
|
+
ModuleName: t.TheThing + 'Controller',
|
|
3
|
+
ServiceName: t.TheThing + 'Service',
|
|
4
|
+
}; %>
|
|
5
|
+
---
|
|
6
|
+
outDir: <%= t.defaultOutDir %>
|
|
7
|
+
fileName: <%= vars.ModuleName + '.ts' %>
|
|
8
|
+
sourceName: <%= vars.ModuleName %>
|
|
9
|
+
compiledName: <%= t.TheThing + 'RPC' %>
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
import { prefix, get, put, post, del, operation } from 'vovk';
|
|
13
|
+
import { type } from 'arktype';
|
|
14
|
+
import withArk from '@/lib/withArk<%= t.nodeNextResolutionExt.ts %>';
|
|
15
|
+
<% if(t.withService) { %>
|
|
16
|
+
import <%= vars.ServiceName %> from './<%= vars.ServiceName %><%= t.nodeNextResolutionExt.ts %>';
|
|
17
|
+
<% } %>
|
|
18
|
+
|
|
19
|
+
@prefix('<%= t['the-things'] %>')
|
|
20
|
+
export default class <%= vars.ModuleName %> {
|
|
21
|
+
@operation({
|
|
22
|
+
summary: 'Get <%= t.TheThings %>',
|
|
23
|
+
})
|
|
24
|
+
@get()
|
|
25
|
+
static get<%= t.TheThings %> = withArk({
|
|
26
|
+
handle() {
|
|
27
|
+
<% if(t.withService) { %>
|
|
28
|
+
return <%= vars.ServiceName %>.get<%= t.TheThings %>();
|
|
29
|
+
<% } else { %>
|
|
30
|
+
return { message: 'TODO: get <%= t.theThings %>' };
|
|
31
|
+
<% } %>
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
@operation({
|
|
36
|
+
summary: 'Update <%= t.TheThing %>',
|
|
37
|
+
})
|
|
38
|
+
@put('{id}')
|
|
39
|
+
static update<%= t.TheThing %> = withArk({
|
|
40
|
+
body: type({ todo: type('true') }),
|
|
41
|
+
params: type({ id: type('string') }),
|
|
42
|
+
async handle(req, params) {
|
|
43
|
+
const { id } = params;
|
|
44
|
+
const body = await req.json();
|
|
45
|
+
<% if(t.withService) { %>
|
|
46
|
+
return <%= vars.ServiceName %>.update<%= t.TheThing %>(id, body);
|
|
47
|
+
<% } else { %>
|
|
48
|
+
return { message: `TODO: update <%= t.theThing %>`, id, body };
|
|
49
|
+
<% } %>
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
@post()
|
|
54
|
+
static create<%= t.TheThing %> = withArk({
|
|
55
|
+
body: type({ todo: type('true') }),
|
|
56
|
+
async handle(req) {
|
|
57
|
+
const body = await req.json();
|
|
58
|
+
<% if(t.withService) { %>
|
|
59
|
+
return <%= vars.ServiceName %>.create<%= t.TheThing %>(body);
|
|
60
|
+
<% } else { %>
|
|
61
|
+
return { message: `TODO: create <%= t.theThing %>`, body };
|
|
62
|
+
<% } %>
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
@del('{id}')
|
|
67
|
+
static delete<%= t.TheThing %> = withArk({
|
|
68
|
+
params: type({ id: type('string') }),
|
|
69
|
+
handle(_req, params) {
|
|
70
|
+
const { id } = params;
|
|
71
|
+
<% if(t.withService) { %>
|
|
72
|
+
return <%= vars.ServiceName %>.delete<%= t.TheThing %>(id);
|
|
73
|
+
<% } else { %>
|
|
74
|
+
return { message: `TODO: delete <%= t.theThing %>`, id };
|
|
75
|
+
<% } %>
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<% const vars = {
|
|
2
|
+
ControllerName: t.TheThing + 'Controller',
|
|
3
|
+
ServiceName: t.TheThing + 'Service',
|
|
4
|
+
}; %>
|
|
5
|
+
---
|
|
6
|
+
outDir: <%= t.defaultOutDir %>
|
|
7
|
+
fileName: <%= vars.ControllerName + '.ts' %>
|
|
8
|
+
sourceName: <%= vars.ControllerName %>
|
|
9
|
+
compiledName: <%= t.TheThing + 'RPC' %>
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
import { prefix, get, put, post, del, operation, type VovkRequest } from 'vovk';
|
|
13
|
+
<% if(t.withService) { %>
|
|
14
|
+
import <%= vars.ServiceName %> from './<%= vars.ServiceName %><%= t.nodeNextResolutionExt.ts %>';
|
|
15
|
+
<% } %>
|
|
16
|
+
|
|
17
|
+
@prefix('<%= t['the-things'] %>')
|
|
18
|
+
export default class <%= vars.ControllerName %> {
|
|
19
|
+
@operation({
|
|
20
|
+
summary: 'Get <%= t.TheThings %>',
|
|
21
|
+
})
|
|
22
|
+
@get()
|
|
23
|
+
static get<%= t.TheThings %> = () => {
|
|
24
|
+
<% if(t.withService) { %>
|
|
25
|
+
return <%= vars.ServiceName %>.get<%= t.TheThings %>();
|
|
26
|
+
<% } else { %>
|
|
27
|
+
return { message: 'TODO: get <%= t.theThings %>' };
|
|
28
|
+
<% } %>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@operation({
|
|
32
|
+
summary: 'Update <%= t.TheThing %>',
|
|
33
|
+
})
|
|
34
|
+
@put('{id}')
|
|
35
|
+
static update<%= t.TheThing %> = async (req: VovkRequest<{ todo: true }>, params: { id: string }) => {
|
|
36
|
+
const { id } = params;
|
|
37
|
+
const body = await req.json();
|
|
38
|
+
<% if(t.withService) { %>
|
|
39
|
+
return <%= vars.ServiceName %>.update<%= t.TheThing %>(id, body);
|
|
40
|
+
<% } else { %>
|
|
41
|
+
return { message: `TODO: update <%= t.theThing %>`, id, body };
|
|
42
|
+
<% } %>
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
@post()
|
|
46
|
+
static create<%= t.TheThing %> = async (req: VovkRequest<{ todo: true }>) => {
|
|
47
|
+
const body = await req.json();
|
|
48
|
+
<% if(t.withService) { %>
|
|
49
|
+
return <%= vars.ServiceName %>.create<%= t.TheThing %>(body);
|
|
50
|
+
<% } else { %>
|
|
51
|
+
return { message: `TODO: create <%= t.theThing %>`, body };
|
|
52
|
+
<% } %>
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
@del('{id}')
|
|
56
|
+
static delete<%= t.TheThing %> = (_req: VovkRequest<unknown>, params: { id: string }) => {
|
|
57
|
+
const { id } = params;
|
|
58
|
+
<% if(t.withService) { %>
|
|
59
|
+
return <%= vars.ServiceName %>.delete<%= t.TheThing %>(id);
|
|
60
|
+
<% } else { %>
|
|
61
|
+
return { message: `TODO: delete <%= t.theThing %>`, id };
|
|
62
|
+
<% } %>
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<% const vars = {
|
|
2
|
+
ControllerName: t.TheThing + 'Controller',
|
|
3
|
+
ServiceName: t.TheThing + 'Service',
|
|
4
|
+
}; %>
|
|
5
|
+
---
|
|
6
|
+
outDir: <%= t.defaultOutDir %>
|
|
7
|
+
fileName: <%= vars.ServiceName + '.ts' %>
|
|
8
|
+
sourceName: <%= vars.ServiceName %>
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
import type { VovkBody, VovkParams } from 'vovk';
|
|
12
|
+
import type <%= vars.ControllerName %> from './<%= vars.ControllerName %><%= t.nodeNextResolutionExt.ts %>';
|
|
13
|
+
|
|
14
|
+
export default class <%= vars.ServiceName %> {
|
|
15
|
+
static get<%= t.TheThings %> = () => {
|
|
16
|
+
return { message: 'TODO: get <%= t.theThings %>' };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
static update<%= t.TheThing %> = (
|
|
20
|
+
id: VovkParams<typeof <%= vars.ControllerName %>.update<%= t.TheThing %>>['id'],
|
|
21
|
+
body: VovkBody<typeof <%= vars.ControllerName %>.update<%= t.TheThing %>>
|
|
22
|
+
) => {
|
|
23
|
+
return { message: `TODO: update <%= t.theThing %>`, id, body };
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
static create<%= t.TheThing %> = (
|
|
27
|
+
body: VovkBody<typeof <%= vars.ControllerName %>.create<%= t.TheThing %>>
|
|
28
|
+
) => {
|
|
29
|
+
return { message: `TODO: create <%= t.theThing %>`, body };
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
static delete<%= t.TheThing %> = (
|
|
33
|
+
id: VovkParams<typeof <%= vars.ControllerName %>.delete<%= t.TheThing %>>['id']
|
|
34
|
+
) => {
|
|
35
|
+
return { message: `TODO: delete <%= t.theThing %>`, id };
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<% const vars = {
|
|
2
|
+
ModuleName: t.TheThing + 'Controller',
|
|
3
|
+
ServiceName: t.TheThing + 'Service',
|
|
4
|
+
}; %>
|
|
5
|
+
---
|
|
6
|
+
outDir: <%= t.defaultOutDir %>
|
|
7
|
+
fileName: <%= vars.ModuleName + '.ts' %>
|
|
8
|
+
sourceName: <%= vars.ModuleName %>
|
|
9
|
+
compiledName: <%= t.TheThing + 'RPC' %>
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
import { prefix, get, put, post, del, operation } from 'vovk';
|
|
13
|
+
import * as v from 'valibot';
|
|
14
|
+
import withValibot from '@/lib/withValibot<%= t.nodeNextResolutionExt.ts %>';
|
|
15
|
+
<% if(t.withService) { %>
|
|
16
|
+
import <%= vars.ServiceName %> from './<%= vars.ServiceName %><%= t.nodeNextResolutionExt.ts %>';
|
|
17
|
+
<% } %>
|
|
18
|
+
|
|
19
|
+
@prefix('<%= t['the-things'] %>')
|
|
20
|
+
export default class <%= vars.ModuleName %> {
|
|
21
|
+
@operation({
|
|
22
|
+
summary: 'Get <%= t.TheThings %>',
|
|
23
|
+
})
|
|
24
|
+
@get()
|
|
25
|
+
static get<%= t.TheThings %> = withValibot({
|
|
26
|
+
handle() {
|
|
27
|
+
<% if(t.withService) { %>
|
|
28
|
+
return <%= vars.ServiceName %>.get<%= t.TheThings %>();
|
|
29
|
+
<% } else { %>
|
|
30
|
+
return { message: 'TODO: get <%= t.theThings %>' };
|
|
31
|
+
<% } %>
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
@operation({
|
|
36
|
+
summary: 'Update <%= t.TheThing %>',
|
|
37
|
+
})
|
|
38
|
+
@put('{id}')
|
|
39
|
+
static update<%= t.TheThing %> = withValibot({
|
|
40
|
+
body: v.object({ todo: v.literal(true) }),
|
|
41
|
+
params: v.object({ id: v.string() }),
|
|
42
|
+
async handle(req, params) {
|
|
43
|
+
const { id } = params;
|
|
44
|
+
const body = await req.json();
|
|
45
|
+
<% if(t.withService) { %>
|
|
46
|
+
return <%= vars.ServiceName %>.update<%= t.TheThing %>(id, body);
|
|
47
|
+
<% } else { %>
|
|
48
|
+
return { message: `TODO: update <%= t.theThing %>`, id, body };
|
|
49
|
+
<% } %>
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
@post()
|
|
54
|
+
static create<%= t.TheThing %> = withValibot({
|
|
55
|
+
body: v.object({ todo: v.literal(true) }),
|
|
56
|
+
async handle(req) {
|
|
57
|
+
const body = await req.json();
|
|
58
|
+
<% if(t.withService) { %>
|
|
59
|
+
return <%= vars.ServiceName %>.create<%= t.TheThing %>(body);
|
|
60
|
+
<% } else { %>
|
|
61
|
+
return { message: `TODO: create <%= t.theThing %>`, body };
|
|
62
|
+
<% } %>
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
@del('{id}')
|
|
67
|
+
static delete<%= t.TheThing %> = withValibot({
|
|
68
|
+
params: v.object({ id: v.string() }),
|
|
69
|
+
handle(_req, params) {
|
|
70
|
+
const { id } = params;
|
|
71
|
+
<% if(t.withService) { %>
|
|
72
|
+
return <%= vars.ServiceName %>.delete<%= t.TheThing %>(id);
|
|
73
|
+
<% } else { %>
|
|
74
|
+
return { message: `TODO: delete <%= t.theThing %>`, id };
|
|
75
|
+
<% } %>
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vovk-cli",
|
|
3
|
-
"version": "0.0.1-draft.
|
|
3
|
+
"version": "0.0.1-draft.390",
|
|
4
4
|
"bin": {
|
|
5
5
|
"vovk": "./dist/index.mjs"
|
|
6
6
|
},
|
|
@@ -11,12 +11,11 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "rm -rf dist tsconfig.build.tsbuildinfo && tsc -P tsconfig.build.json",
|
|
13
13
|
"postbuild": "chmod +x ./dist/index.mjs",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"test
|
|
17
|
-
"test": "npm run pre-test && node --test --test-concurrency=1 test_dist/test/**/*.mjs",
|
|
14
|
+
"pre-test": "npm run build",
|
|
15
|
+
"test-only": "npm run pre-test && node --experimental-transform-types --experimental-strip-types --test --test-only test/spec/**/*.mts",
|
|
16
|
+
"test": "npm run pre-test && node --experimental-transform-types --experimental-strip-types --test --test-concurrency=1 test/spec/**/*.mts",
|
|
18
17
|
"tsc": "tsc --noEmit",
|
|
19
|
-
"ncu": "npm-check-updates -u",
|
|
18
|
+
"ncu": "npm-check-updates -u -x commander",
|
|
20
19
|
"npm-publish": "npm publish"
|
|
21
20
|
},
|
|
22
21
|
"repository": {
|
|
@@ -29,44 +28,62 @@
|
|
|
29
28
|
"cli",
|
|
30
29
|
"vovk"
|
|
31
30
|
],
|
|
32
|
-
"author": "
|
|
31
|
+
"author": "Andrey Gubanov",
|
|
33
32
|
"license": "MIT",
|
|
34
33
|
"bugs": {
|
|
35
34
|
"url": "https://github.com/finom/vovk/issues"
|
|
36
35
|
},
|
|
37
36
|
"homepage": "https://vovk.dev",
|
|
38
37
|
"peerDependencies": {
|
|
39
|
-
"vovk": "^3.0.0-draft.
|
|
38
|
+
"vovk": "^3.0.0-draft.467",
|
|
39
|
+
"vovk-ajv": "^0.0.0-draft.112",
|
|
40
|
+
"vovk-client": "^0.0.4-draft.139",
|
|
41
|
+
"vovk-python": "^0.0.1-draft.81",
|
|
42
|
+
"vovk-rust": "^0.0.1-draft.67"
|
|
43
|
+
},
|
|
44
|
+
"optionalDependencies": {
|
|
45
|
+
"@rolldown/binding-linux-x64-gnu": "1.0.0-beta.44"
|
|
40
46
|
},
|
|
41
47
|
"dependencies": {
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
48
|
+
"@iarna/toml": "^2.2.5",
|
|
49
|
+
"@inquirer/prompts": "^7.8.6",
|
|
50
|
+
"@npmcli/package-json": "^7.0.1",
|
|
51
|
+
"@types/json-schema": "^7.0.15",
|
|
52
|
+
"chalk": "^5.6.2",
|
|
53
|
+
"chokidar": "^4.0.3",
|
|
54
|
+
"clone-deep": "^4.0.1",
|
|
55
|
+
"commander": "^13.1.0",
|
|
56
|
+
"concurrently": "^9.2.1",
|
|
57
|
+
"dotenv": "^17.2.3",
|
|
49
58
|
"ejs": "^3.1.10",
|
|
59
|
+
"get-tsconfig": "^4.10.1",
|
|
60
|
+
"glob": "^11.0.3",
|
|
50
61
|
"gray-matter": "^4.0.3",
|
|
51
|
-
"inflection": "^3.0.
|
|
62
|
+
"inflection": "^3.0.2",
|
|
52
63
|
"jsonc-parser": "^3.3.1",
|
|
53
64
|
"lodash": "^4.17.21",
|
|
54
65
|
"loglevel": "^1.9.2",
|
|
66
|
+
"openapi3-ts": "^4.5.0",
|
|
55
67
|
"pluralize": "^8.0.0",
|
|
56
|
-
"prettier": "^3.
|
|
68
|
+
"prettier": "^3.6.2",
|
|
57
69
|
"tar-stream": "^3.1.7",
|
|
58
|
-
"ts-morph": "^
|
|
59
|
-
"
|
|
70
|
+
"ts-morph": "^27.0.0",
|
|
71
|
+
"type-fest": "^5.0.1",
|
|
72
|
+
"undici": "^7.16.0",
|
|
73
|
+
"yaml": "^2.8.1"
|
|
60
74
|
},
|
|
61
75
|
"devDependencies": {
|
|
62
76
|
"@types/concat-stream": "^2.0.3",
|
|
63
77
|
"@types/ejs": "^3.1.5",
|
|
78
|
+
"@types/js-yaml": "^4.0.9",
|
|
64
79
|
"@types/npmcli__package-json": "^4.0.4",
|
|
65
80
|
"@types/pluralize": "^0.0.33",
|
|
66
|
-
"@types/tar-stream": "^3.1.
|
|
81
|
+
"@types/tar-stream": "^3.1.4",
|
|
67
82
|
"concat-stream": "^2.0.0",
|
|
68
|
-
"create-next-app": "^15.
|
|
83
|
+
"create-next-app": "^15.5.4",
|
|
84
|
+
"http-server": "^14.1.1",
|
|
69
85
|
"node-pty": "^1.0.0",
|
|
70
|
-
"
|
|
86
|
+
"tsdown": "^0.15.9",
|
|
87
|
+
"zod": "^4.1.11"
|
|
71
88
|
}
|
|
72
89
|
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { VovkSchema } from 'vovk';
|
|
2
|
-
import type { _VovkControllerSchema, _VovkWorkerSchema } from 'vovk/types';
|
|
3
|
-
interface HandlersDiff {
|
|
4
|
-
nameOfClass: string;
|
|
5
|
-
added: string[];
|
|
6
|
-
removed: string[];
|
|
7
|
-
changed: string[];
|
|
8
|
-
}
|
|
9
|
-
interface WorkersOrControllersDiff {
|
|
10
|
-
added: string[];
|
|
11
|
-
removed: string[];
|
|
12
|
-
handlers: HandlersDiff[];
|
|
13
|
-
}
|
|
14
|
-
export interface DiffResult {
|
|
15
|
-
workers: WorkersOrControllersDiff;
|
|
16
|
-
controllers: WorkersOrControllersDiff;
|
|
17
|
-
}
|
|
18
|
-
export declare function diffHandlers<T extends _VovkWorkerSchema['handlers'] | _VovkControllerSchema['handlers']>(oldHandlers: T, newHandlers: T, nameOfClass: string): HandlersDiff;
|
|
19
|
-
export declare function diffWorkersOrControllers<T extends VovkSchema['controllers'] | VovkSchema['workers']>(oldItems: T, newItems: T): WorkersOrControllersDiff;
|
|
20
|
-
/**
|
|
21
|
-
example output:
|
|
22
|
-
{
|
|
23
|
-
workers: {
|
|
24
|
-
added: ["WorkerC"],
|
|
25
|
-
removed: ["WorkerA"],
|
|
26
|
-
handlers: []
|
|
27
|
-
},
|
|
28
|
-
controllers: {
|
|
29
|
-
added: ["ControllerC"],
|
|
30
|
-
removed: ["ControllerB"],
|
|
31
|
-
handlers: [
|
|
32
|
-
{
|
|
33
|
-
nameOfClass: "ControllerA",
|
|
34
|
-
added: ["handlerF"],
|
|
35
|
-
removed: [],
|
|
36
|
-
changed: ["handlerD"]
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
*/
|
|
42
|
-
export default function diffSchema(oldJson: VovkSchema, newJson: VovkSchema): DiffResult;
|
|
43
|
-
export {};
|