vovk-cli 0.0.1-draft.37 → 0.0.1-draft.371

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.
Files changed (142) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +29 -1
  3. package/client-templates/cjs/index.cjs.ejs +19 -0
  4. package/client-templates/cjs/index.d.cts.ejs +22 -0
  5. package/client-templates/mixins/mixins.d.ts.ejs +64 -0
  6. package/client-templates/mixins/mixins.json.ejs +1 -0
  7. package/client-templates/mjs/index.d.mts.ejs +22 -0
  8. package/client-templates/mjs/index.mjs.ejs +18 -0
  9. package/client-templates/openapiCjs/openapi.cjs.ejs +4 -0
  10. package/client-templates/openapiCjs/openapi.d.cts.ejs +4 -0
  11. package/client-templates/openapiJson/openapi.json.ejs +1 -0
  12. package/client-templates/openapiTs/openapi.ts.ejs +4 -0
  13. package/client-templates/packageJson/package.json.ejs +1 -0
  14. package/client-templates/readme/README.md.ejs +39 -0
  15. package/client-templates/schemaCjs/schema.cjs.ejs +24 -0
  16. package/client-templates/schemaCjs/schema.d.cts.ejs +10 -0
  17. package/client-templates/schemaJson/schema.json.ejs +1 -0
  18. package/client-templates/schemaTs/schema.ts.ejs +28 -0
  19. package/client-templates/ts/index.ts.ejs +27 -0
  20. package/dist/bundle/index.d.mts +8 -0
  21. package/dist/bundle/index.mjs +103 -0
  22. package/dist/dev/diffSegmentSchema.d.mts +36 -0
  23. package/dist/dev/{diffSchema.mjs → diffSegmentSchema.mjs} +3 -11
  24. package/dist/dev/ensureSchemaFiles.d.mts +4 -1
  25. package/dist/dev/ensureSchemaFiles.mjs +15 -31
  26. package/dist/dev/index.d.mts +5 -1
  27. package/dist/dev/index.mjs +191 -80
  28. package/dist/dev/logDiffResult.d.mts +1 -1
  29. package/dist/dev/logDiffResult.mjs +6 -43
  30. package/dist/dev/writeMetaJson.d.mts +2 -0
  31. package/dist/dev/writeMetaJson.mjs +20 -0
  32. package/dist/dev/writeOneSegmentSchemaFile.d.mts +12 -0
  33. package/dist/dev/{writeOneSchemaFile.mjs → writeOneSegmentSchemaFile.mjs} +10 -6
  34. package/dist/generate/ensureClient.d.mts +3 -0
  35. package/dist/generate/ensureClient.mjs +28 -0
  36. package/dist/generate/generate.d.mts +13 -0
  37. package/dist/generate/generate.mjs +306 -0
  38. package/dist/generate/getClientTemplateFiles.d.mts +20 -0
  39. package/dist/generate/getClientTemplateFiles.mjs +85 -0
  40. package/dist/generate/getProjectFullSchema.d.mts +8 -0
  41. package/dist/generate/getProjectFullSchema.mjs +66 -0
  42. package/dist/generate/getTemplateClientImports.d.mts +19 -0
  43. package/dist/generate/getTemplateClientImports.mjs +49 -0
  44. package/dist/generate/index.d.mts +33 -0
  45. package/dist/generate/index.mjs +186 -0
  46. package/dist/generate/writeOneClientFile.d.mts +42 -0
  47. package/dist/generate/writeOneClientFile.mjs +139 -0
  48. package/dist/getProjectInfo/getConfig/getConfigAbsolutePaths.d.mts +5 -0
  49. package/dist/getProjectInfo/{getConfigAbsolutePaths.mjs → getConfig/getConfigAbsolutePaths.mjs} +4 -1
  50. package/dist/getProjectInfo/{getRelativeSrcRoot.d.mts → getConfig/getRelativeSrcRoot.d.mts} +1 -1
  51. package/dist/getProjectInfo/{getRelativeSrcRoot.mjs → getConfig/getRelativeSrcRoot.mjs} +2 -2
  52. package/dist/getProjectInfo/getConfig/getTemplateDefs.d.mts +24 -0
  53. package/dist/getProjectInfo/getConfig/getTemplateDefs.mjs +165 -0
  54. package/dist/getProjectInfo/{getUserConfig.d.mts → getConfig/getUserConfig.d.mts} +3 -2
  55. package/dist/getProjectInfo/{getUserConfig.mjs → getConfig/getUserConfig.mjs} +3 -3
  56. package/dist/getProjectInfo/{importUncachedModule.mjs → getConfig/importUncachedModule.mjs} +1 -4
  57. package/dist/getProjectInfo/getConfig/index.d.mts +78 -0
  58. package/dist/getProjectInfo/getConfig/index.mjs +91 -0
  59. package/dist/getProjectInfo/getMetaSchema.d.mts +8 -0
  60. package/dist/getProjectInfo/getMetaSchema.mjs +27 -0
  61. package/dist/getProjectInfo/index.d.mts +14 -9
  62. package/dist/getProjectInfo/index.mjs +24 -22
  63. package/dist/index.d.mts +2 -2
  64. package/dist/index.mjs +117 -35
  65. package/dist/init/createConfig.d.mts +2 -2
  66. package/dist/init/createConfig.mjs +40 -13
  67. package/dist/init/createStandardSchemaValidatorFile.d.mts +4 -0
  68. package/dist/init/createStandardSchemaValidatorFile.mjs +52 -0
  69. package/dist/init/getTemplateFilesFromPackage.mjs +10 -5
  70. package/dist/init/index.d.mts +2 -2
  71. package/dist/init/index.mjs +123 -72
  72. package/dist/init/installDependencies.mjs +4 -2
  73. package/dist/init/logUpdateDependenciesError.d.mts +3 -1
  74. package/dist/init/logUpdateDependenciesError.mjs +7 -1
  75. package/dist/init/updateDependenciesWithoutInstalling.mjs +39 -9
  76. package/dist/init/updateNPMScripts.d.mts +3 -1
  77. package/dist/init/updateNPMScripts.mjs +10 -7
  78. package/dist/init/updateTypeScriptConfig.d.mts +4 -1
  79. package/dist/init/updateTypeScriptConfig.mjs +11 -7
  80. package/dist/initProgram.d.mts +1 -1
  81. package/dist/initProgram.mjs +17 -17
  82. package/dist/locateSegments.d.mts +8 -1
  83. package/dist/locateSegments.mjs +13 -3
  84. package/dist/new/addClassToSegmentCode.d.mts +1 -2
  85. package/dist/new/addClassToSegmentCode.mjs +3 -3
  86. package/dist/new/index.d.mts +2 -1
  87. package/dist/new/index.mjs +5 -3
  88. package/dist/new/newModule.d.mts +5 -2
  89. package/dist/new/newModule.mjs +26 -24
  90. package/dist/new/newSegment.d.mts +4 -1
  91. package/dist/new/newSegment.mjs +20 -12
  92. package/dist/new/render.d.mts +7 -3
  93. package/dist/new/render.mjs +31 -10
  94. package/dist/types.d.mts +66 -44
  95. package/dist/utils/compileJSONSchemaToTypeScriptType.d.mts +5 -0
  96. package/dist/utils/compileJSONSchemaToTypeScriptType.mjs +9 -0
  97. package/dist/utils/compileTs.d.mts +12 -0
  98. package/dist/utils/compileTs.mjs +261 -0
  99. package/dist/utils/debounceWithArgs.d.mts +2 -2
  100. package/dist/utils/debounceWithArgs.mjs +24 -6
  101. package/dist/utils/deepExtend.d.mts +54 -0
  102. package/dist/utils/deepExtend.mjs +129 -0
  103. package/dist/utils/formatLoggedSegmentName.d.mts +3 -1
  104. package/dist/utils/formatLoggedSegmentName.mjs +3 -2
  105. package/dist/utils/generateFnName.d.mts +23 -0
  106. package/dist/utils/generateFnName.mjs +76 -0
  107. package/dist/utils/getPackageJson.d.mts +3 -0
  108. package/dist/utils/getPackageJson.mjs +22 -0
  109. package/dist/utils/getPublicModuleNameFromPath.d.mts +4 -0
  110. package/dist/utils/getPublicModuleNameFromPath.mjs +9 -0
  111. package/dist/utils/normalizeOpenAPIMixin.d.mts +14 -0
  112. package/dist/utils/normalizeOpenAPIMixin.mjs +114 -0
  113. package/dist/utils/pickSegmentFullSchema.d.mts +3 -0
  114. package/dist/utils/pickSegmentFullSchema.mjs +15 -0
  115. package/dist/utils/removeUnlistedDirectories.d.mts +10 -0
  116. package/dist/utils/removeUnlistedDirectories.mjs +61 -0
  117. package/dist/utils/resolveAbsoluteModulePath.d.mts +2 -0
  118. package/dist/utils/resolveAbsoluteModulePath.mjs +32 -0
  119. package/module-templates/arktype/controller.ts.ejs +68 -0
  120. package/module-templates/type/controller.ts.ejs +56 -0
  121. package/module-templates/type/service.ts.ejs +28 -0
  122. package/module-templates/valibot/controller.ts.ejs +68 -0
  123. package/package.json +40 -22
  124. package/dist/dev/diffSchema.d.mts +0 -43
  125. package/dist/dev/ensureClient.d.mts +0 -5
  126. package/dist/dev/ensureClient.mjs +0 -31
  127. package/dist/dev/isMetadataEmpty.d.mts +0 -2
  128. package/dist/dev/isMetadataEmpty.mjs +0 -4
  129. package/dist/dev/writeOneSchemaFile.d.mts +0 -11
  130. package/dist/generateClient.d.mts +0 -7
  131. package/dist/generateClient.mjs +0 -97
  132. package/dist/getProjectInfo/getConfig.d.mts +0 -11
  133. package/dist/getProjectInfo/getConfig.mjs +0 -29
  134. package/dist/getProjectInfo/getConfigAbsolutePaths.d.mts +0 -4
  135. package/dist/postinstall.d.mts +0 -1
  136. package/dist/postinstall.mjs +0 -24
  137. package/templates/controller.ejs +0 -52
  138. package/templates/service.ejs +0 -27
  139. package/templates/worker.ejs +0 -24
  140. /package/dist/getProjectInfo/{importUncachedModule.d.mts → getConfig/importUncachedModule.d.mts} +0 -0
  141. /package/dist/getProjectInfo/{importUncachedModuleWorker.d.mts → getConfig/importUncachedModuleWorker.d.mts} +0 -0
  142. /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,3 @@
1
+ import { type VovkSchema } from 'vovk';
2
+ export default function pickSegmentFullSchema(schema: VovkSchema, segmentNames: string[]): VovkSchema;
3
+ export declare function omitSegmentFullSchema(schema: VovkSchema, segmentNames: string[]): VovkSchema;
@@ -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,2 @@
1
+ export declare function getPathUpToModule(moduleName: string, fullPath: string): string;
2
+ export default function resolveAbsoluteModulePath(modulePath: string, cwd: string): string;
@@ -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,68 @@
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
+ query: type({ search: type('string') }),
27
+ handle(req) {
28
+ const search = req.nextUrl.searchParams.get('search');
29
+ <% if(t.withService) { %>
30
+ return <%= vars.ServiceName %>.get<%= t.TheThings %>(search);
31
+ <% } else { %>
32
+ return { results: [], search };
33
+ <% } %>
34
+ }
35
+ });
36
+
37
+ @operation({
38
+ summary: 'Update <%= t.TheThing %>',
39
+ })
40
+ @put('{id}')
41
+ static update<%= t.TheThing %> = withArk({
42
+ body: type({
43
+ foo: type('"bar" | "baz"'),
44
+ }),
45
+ query: type({ q: type('string') }),
46
+ params: type({ id: type('string') }),
47
+ async handle(req, params) {
48
+ const { id } = params;
49
+ const body = await req.json();
50
+ const q = req.nextUrl.searchParams.get('q');
51
+ <% if(t.withService) { %>
52
+ return <%= vars.ServiceName %>.update<%= t.TheThing %>(id, q, body);
53
+ <% } else { %>
54
+ return { id, body, q };
55
+ <% } %>
56
+ }
57
+ });
58
+
59
+ @post()
60
+ static create<%= t.TheThing %> = () => {
61
+ // ...
62
+ };
63
+
64
+ @del(':id')
65
+ static delete<%= t.TheThing %> = () => {
66
+ // ...
67
+ };
68
+ }
@@ -0,0 +1,56 @@
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 %> = async (req: VovkRequest<null, { search: string }>) => {
24
+ const search = req.nextUrl.searchParams.get('search');
25
+ <% if(t.withService) { %>
26
+ return <%= vars.ServiceName %>.get<%= t.TheThings %>(search);
27
+ <% } else { %>
28
+ return { results: [], search };
29
+ <% } %>
30
+ }
31
+
32
+ @operation({
33
+ summary: 'Update <%= t.TheThing %>',
34
+ })
35
+ @put('{id}')
36
+ static update<%= t.TheThing %> = async (req: VovkRequest<{ foo: 'bar' | 'baz' }, { q: string }>, params: { id: string }) => {
37
+ const { id } = params;
38
+ const body = await req.json();
39
+ const q = req.nextUrl.searchParams.get('q');
40
+ <% if(t.withService) { %>
41
+ return <%= vars.ServiceName %>.update<%= t.TheThing %>(id, q, body);
42
+ <% } else { %>
43
+ return { id, body, q };
44
+ <% } %>
45
+ };
46
+
47
+ @post()
48
+ static create<%= t.TheThing %> = () => {
49
+ // ...
50
+ };
51
+
52
+ @del(':id')
53
+ static delete<%= t.TheThing %> = () => {
54
+ // ...
55
+ };
56
+ }
@@ -0,0 +1,28 @@
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, VovkQuery } 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 %> = (search: VovkQuery<typeof <%= vars.ControllerName %>.get<%= t.TheThings %>>['search']) => {
16
+ return { results: [], search };
17
+ };
18
+
19
+ static update<%= t.TheThing %> = (
20
+ id: string,
21
+ q: VovkQuery<typeof <%= vars.ControllerName %>.update<%= t.TheThing %>>['q'],
22
+ body: VovkBody<typeof <%= vars.ControllerName %>.update<%= t.TheThing %>>
23
+ ) => {
24
+ return { id, q, body };
25
+ };
26
+
27
+ // ...
28
+ }
@@ -0,0 +1,68 @@
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
+ query: v.object({ search: v.string() }),
27
+ handle(req) {
28
+ const search = req.nextUrl.searchParams.get('search');
29
+ <% if(t.withService) { %>
30
+ return <%= vars.ServiceName %>.get<%= t.TheThings %>(search);
31
+ <% } else { %>
32
+ return { results: [], search };
33
+ <% } %>
34
+ }
35
+ });
36
+
37
+ @operation({
38
+ summary: 'Update <%= t.TheThing %>',
39
+ })
40
+ @put('{id}')
41
+ static update<%= t.TheThing %> = withValibot({
42
+ body: v.object({
43
+ foo: v.union([v.literal('bar'), v.literal('baz')]),
44
+ }),
45
+ query: v.object({ q: v.string() }),
46
+ params: v.object({ id: v.string() }),
47
+ async handle(req, params) {
48
+ const { id } = params;
49
+ const body = await req.json();
50
+ const q = req.nextUrl.searchParams.get('q');
51
+ <% if(t.withService) { %>
52
+ return <%= vars.ServiceName %>.update<%= t.TheThing %>(id, q, body);
53
+ <% } else { %>
54
+ return { id, body, q };
55
+ <% } %>
56
+ }
57
+ });
58
+
59
+ @post()
60
+ static create<%= t.TheThing %> = () => {
61
+ // ...
62
+ };
63
+
64
+ @del(':id')
65
+ static delete<%= t.TheThing %> = () => {
66
+ // ...
67
+ };
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk-cli",
3
- "version": "0.0.1-draft.37",
3
+ "version": "0.0.1-draft.371",
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
- "build-test": "rm -rf test_dist && tsc -P tsconfig.test.json",
15
- "pre-test": "npm run build && npm run build-test",
16
- "test-only": "npm run pre-test && node --test --test-only test_dist/test/**/*.mjs",
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,63 @@
29
28
  "cli",
30
29
  "vovk"
31
30
  ],
32
- "author": "Andrii Gubanov",
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.33"
38
+ "vovk": "^3.0.0-draft.441",
39
+ "vovk-ajv": "^0.0.0-draft.104",
40
+ "vovk-client": "^0.0.4-draft.132",
41
+ "vovk-python": "^0.0.1-draft.74",
42
+ "vovk-rust": "^0.0.1-draft.60"
43
+ },
44
+ "optionalDependencies": {
45
+ "@rolldown/binding-linux-x64-gnu": "1.0.0-beta.36"
40
46
  },
41
47
  "dependencies": {
42
- "@inquirer/prompts": "^7.1.0",
43
- "@npmcli/package-json": "^6.1.0",
44
- "chalk": "^5.3.0",
45
- "chokidar": "^4.0.1",
46
- "commander": "^12.1.0",
47
- "concurrently": "^9.1.0",
48
- "dotenv": "^16.4.5",
48
+ "@iarna/toml": "^2.2.5",
49
+ "@inquirer/prompts": "^7.8.4",
50
+ "@npmcli/package-json": "^7.0.0",
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.2",
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.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.4.1",
68
+ "prettier": "^3.6.2",
57
69
  "tar-stream": "^3.1.7",
58
- "ts-morph": "^24.0.0",
59
- "undici": "^7.0.0"
70
+ "ts-morph": "^27.0.0",
71
+ "tsdown": "^0.15.0",
72
+ "type-fest": "^4.41.0",
73
+ "undici": "^7.15.0",
74
+ "vovk-openapi": "^0.0.1-draft.112",
75
+ "yaml": "^2.8.1"
60
76
  },
61
77
  "devDependencies": {
62
78
  "@types/concat-stream": "^2.0.3",
63
79
  "@types/ejs": "^3.1.5",
80
+ "@types/js-yaml": "^4.0.9",
64
81
  "@types/npmcli__package-json": "^4.0.4",
65
82
  "@types/pluralize": "^0.0.33",
66
- "@types/tar-stream": "^3.1.3",
83
+ "@types/tar-stream": "^3.1.4",
67
84
  "concat-stream": "^2.0.0",
68
- "create-next-app": "^15.0.3",
85
+ "create-next-app": "^15.5.2",
86
+ "http-server": "^14.1.1",
69
87
  "node-pty": "^1.0.0",
70
- "type-fest": "^4.29.0"
88
+ "zod": "^4.1.5"
71
89
  }
72
90
  }
@@ -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 {};
@@ -1,5 +0,0 @@
1
- import type { ProjectInfo } from '../getProjectInfo/index.mjs';
2
- export default function ensureClient(projectInfo: ProjectInfo): Promise<{
3
- written: boolean;
4
- path: string;
5
- }>;
@@ -1,31 +0,0 @@
1
- import path from 'node:path';
2
- import fs from 'node:fs/promises';
3
- export default async function ensureClient(projectInfo) {
4
- const { config, cwd, log } = projectInfo;
5
- const now = Date.now();
6
- const clientoOutDirAbsolutePath = path.join(cwd, config.clientOutDir);
7
- const dts = `// auto-generated
8
- // This is a temporary placeholder to avoid errors if client is imported before it's generated.
9
- // If you still see this text, the client is not generated yet because of an unknown problem.
10
- // Feel free to report an issue at https://github.com/finom/vovk/issues`;
11
- const js = dts;
12
- const ts = dts;
13
- const localJsAbsolutePath = path.join(clientoOutDirAbsolutePath, 'client.js');
14
- const localDtsAbsolutePath = path.join(clientoOutDirAbsolutePath, 'client.d.ts');
15
- const localTsAbsolutePath = path.join(clientoOutDirAbsolutePath, 'index.ts');
16
- const existingJs = await fs.readFile(localJsAbsolutePath, 'utf-8').catch(() => null);
17
- const existingDts = await fs.readFile(localDtsAbsolutePath, 'utf-8').catch(() => null);
18
- const existingTs = await fs.readFile(localTsAbsolutePath, 'utf-8').catch(() => null);
19
- if (existingJs && existingDts && existingTs) {
20
- return { written: false, path: clientoOutDirAbsolutePath };
21
- }
22
- await fs.mkdir(clientoOutDirAbsolutePath, { recursive: true });
23
- if (!existingJs)
24
- await fs.writeFile(localJsAbsolutePath, js);
25
- if (!existingDts)
26
- await fs.writeFile(localDtsAbsolutePath, dts);
27
- if (!existingTs)
28
- await fs.writeFile(localTsAbsolutePath, ts);
29
- log.info(`Empty client files are generated in ${Date.now() - now}ms`);
30
- return { written: true, path: clientoOutDirAbsolutePath };
31
- }
@@ -1,2 +0,0 @@
1
- import type { VovkSchema } from 'vovk';
2
- export default function isSchemaEmpty(schema: VovkSchema): boolean;
@@ -1,4 +0,0 @@
1
- import isEmpty from 'lodash/isEmpty.js';
2
- export default function isSchemaEmpty(schema) {
3
- return isEmpty(schema.controllers) && isEmpty(schema.workers);
4
- }