vovk-cli 0.0.1-draft.21 → 0.0.1-draft.210
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 +29 -1
- package/client-templates/cjs/index.cjs.ejs +14 -0
- package/client-templates/cjs/index.d.cts.ejs +23 -0
- package/client-templates/mjs/index.d.mts.ejs +23 -0
- package/client-templates/mjs/index.mjs.ejs +20 -0
- package/client-templates/packageJson/package.json.ejs +1 -0
- package/client-templates/readme/README.md.ejs +35 -0
- package/client-templates/schemaCjs/schema.cjs.ejs +20 -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 +22 -0
- package/client-templates/standaloneTypesTs/types.d.ts.ejs +13 -0
- package/client-templates/ts/index.ts.ejs +31 -0
- package/dist/bundle/index.d.mts +8 -0
- package/dist/bundle/index.mjs +83 -0
- package/dist/dev/diffSegmentSchema.d.mts +36 -0
- package/dist/dev/{diffSchema.mjs → diffSegmentSchema.mjs} +4 -12
- package/dist/dev/ensureSchemaFiles.d.mts +3 -0
- package/dist/dev/ensureSchemaFiles.mjs +14 -31
- package/dist/dev/index.d.mts +5 -2
- package/dist/dev/index.mjs +173 -78
- 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 +17 -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 +31 -0
- package/dist/generate/generate.d.mts +12 -0
- package/dist/generate/generate.mjs +219 -0
- package/dist/generate/getClientTemplateFiles.d.mts +21 -0
- package/dist/generate/getClientTemplateFiles.mjs +88 -0
- package/dist/generate/getProjectFullSchema.d.mts +3 -0
- package/dist/generate/getProjectFullSchema.mjs +64 -0
- package/dist/generate/getTemplateClientImports.d.mts +18 -0
- package/dist/generate/getTemplateClientImports.mjs +38 -0
- package/dist/generate/index.d.mts +40 -0
- package/dist/generate/index.mjs +216 -0
- package/dist/generate/mergePackages.d.mts +9 -0
- package/dist/generate/mergePackages.mjs +78 -0
- package/dist/generate/writeOneClientFile.d.mts +32 -0
- package/dist/generate/writeOneClientFile.mjs +98 -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 +15 -0
- package/dist/getProjectInfo/getConfig/getTemplateDefs.mjs +94 -0
- package/dist/getProjectInfo/{getUserConfig.d.mts → getConfig/getUserConfig.d.mts} +3 -2
- package/dist/getProjectInfo/{getUserConfig.mjs → getConfig/getUserConfig.mjs} +6 -4
- package/dist/getProjectInfo/{importUncachedModule.mjs → getConfig/importUncachedModule.mjs} +1 -5
- package/dist/getProjectInfo/{importUncachedModuleWorker.mjs → getConfig/importUncachedModuleWorker.mjs} +0 -1
- package/dist/getProjectInfo/getConfig/index.d.mts +17 -0
- package/dist/getProjectInfo/getConfig/index.mjs +83 -0
- package/dist/getProjectInfo/index.d.mts +7 -9
- package/dist/getProjectInfo/index.mjs +13 -22
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +90 -38
- package/dist/init/createConfig.d.mts +2 -2
- package/dist/init/createConfig.mjs +18 -12
- package/dist/init/getTemplateFilesFromPackage.mjs +7 -5
- package/dist/init/index.d.mts +2 -2
- package/dist/init/index.mjs +89 -53
- 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 +41 -13
- package/dist/init/updateNPMScripts.d.mts +3 -1
- package/dist/init/updateNPMScripts.mjs +10 -7
- 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 -16
- package/dist/locateSegments.d.mts +8 -1
- package/dist/locateSegments.mjs +14 -4
- package/dist/new/addClassToSegmentCode.d.mts +1 -2
- package/dist/new/addClassToSegmentCode.mjs +3 -3
- package/dist/new/addCommonTerms.mjs +1 -0
- package/dist/new/index.d.mts +1 -1
- package/dist/new/index.mjs +3 -2
- package/dist/new/newModule.d.mts +2 -1
- package/dist/new/newModule.mjs +18 -16
- package/dist/new/newSegment.d.mts +2 -1
- package/dist/new/newSegment.mjs +21 -10
- package/dist/new/render.d.mts +7 -3
- package/dist/new/render.mjs +29 -8
- package/dist/types.d.mts +42 -41
- package/dist/utils/convertJSONSchemaToTypeScriptDef.d.mts +2 -0
- package/dist/utils/convertJSONSchemaToTypeScriptDef.mjs +153 -0
- package/dist/utils/debounceWithArgs.d.mts +2 -2
- package/dist/utils/debounceWithArgs.mjs +24 -9
- package/dist/utils/formatLoggedSegmentName.d.mts +2 -1
- package/dist/utils/formatLoggedSegmentName.mjs +2 -2
- package/dist/utils/getAvailablePort.mjs +1 -1
- package/dist/utils/getPublicModuleNameFromPath.d.mts +4 -0
- package/dist/utils/getPublicModuleNameFromPath.mjs +9 -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/Controller.ts.ejs +50 -0
- package/module-templates/Service.ts.ejs +28 -0
- package/package.json +38 -21
- 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 -51
- 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/new/newModule.mjs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
|
+
import { getTsconfig } from 'get-tsconfig';
|
|
3
4
|
import render from './render.mjs';
|
|
4
5
|
import addClassToSegmentCode from './addClassToSegmentCode.mjs';
|
|
5
6
|
import getProjectInfo from '../getProjectInfo/index.mjs';
|
|
6
|
-
import locateSegments from '../locateSegments.mjs';
|
|
7
7
|
import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
|
|
8
8
|
import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
|
|
9
9
|
import getFileSystemEntryType from '../utils/getFileSystemEntryType.mjs';
|
|
10
10
|
import prettify from '../utils/prettify.mjs';
|
|
11
|
+
import resolveAbsoluteModulePath from '../utils/resolveAbsoluteModulePath.mjs';
|
|
12
|
+
import { locateSegments } from '../locateSegments.mjs';
|
|
11
13
|
function splitByLast(str, delimiter = '/') {
|
|
12
14
|
const index = str.lastIndexOf(delimiter);
|
|
13
15
|
if (index === -1) {
|
|
@@ -18,19 +20,19 @@ function splitByLast(str, delimiter = '/') {
|
|
|
18
20
|
const after = str.substring(index + delimiter.length);
|
|
19
21
|
return [before, after];
|
|
20
22
|
}
|
|
21
|
-
export default async function newModule({ what, moduleNameWithOptionalSegment, dryRun, dir: dirFlag, templates: templatesFlag, noSegmentUpdate, overwrite, }) {
|
|
22
|
-
const { config, log,
|
|
23
|
-
|
|
23
|
+
export default async function newModule({ what, moduleNameWithOptionalSegment, dryRun, dir: dirFlag, templates: templatesFlag, noSegmentUpdate, overwrite, empty, }) {
|
|
24
|
+
const { config, log, cwd, apiDirAbsolutePath } = await getProjectInfo();
|
|
25
|
+
const segments = await locateSegments({ dir: apiDirAbsolutePath, config, log });
|
|
26
|
+
const isNodeNextResolution = ['node16', 'nodenext'].includes((await getTsconfig(cwd)?.config?.compilerOptions?.moduleResolution?.toLowerCase()) ?? '');
|
|
27
|
+
let templates = config.moduleTemplates;
|
|
24
28
|
const [segmentName, moduleName] = splitByLast(moduleNameWithOptionalSegment);
|
|
25
|
-
// replace c by controller, s by service,
|
|
29
|
+
// replace c by controller, s by service, everything else keeps the same
|
|
26
30
|
what = what.map((s) => {
|
|
27
31
|
switch (s) {
|
|
28
32
|
case 'c':
|
|
29
33
|
return 'controller';
|
|
30
34
|
case 's':
|
|
31
35
|
return 'service';
|
|
32
|
-
case 'w':
|
|
33
|
-
return 'worker';
|
|
34
36
|
default:
|
|
35
37
|
return s;
|
|
36
38
|
}
|
|
@@ -49,16 +51,13 @@ export default async function newModule({ what, moduleNameWithOptionalSegment, d
|
|
|
49
51
|
throw new Error(`Template for "${type}" not found`);
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
|
-
const segments = await locateSegments(apiDir);
|
|
53
54
|
const segment = segments.find((s) => s.segmentName === segmentName);
|
|
54
55
|
if (!segment) {
|
|
55
56
|
throw new Error(`Unable to create module. Segment "${segmentName}" not found. Run "vovk new segment ${segmentName}" to create it`);
|
|
56
57
|
}
|
|
57
58
|
for (const type of what) {
|
|
58
59
|
const templatePath = templates[type];
|
|
59
|
-
const templateAbsolutePath = templatePath
|
|
60
|
-
? path.resolve(cwd, templatePath)
|
|
61
|
-
: path.resolve(cwd, './node_modules', templatePath);
|
|
60
|
+
const templateAbsolutePath = resolveAbsoluteModulePath(templatePath, cwd);
|
|
62
61
|
const templateCode = await fs.readFile(templateAbsolutePath, 'utf-8');
|
|
63
62
|
const { dir: renderedDir, fileName, sourceName, compiledName, code, } = await render(templateCode, {
|
|
64
63
|
cwd,
|
|
@@ -66,6 +65,9 @@ export default async function newModule({ what, moduleNameWithOptionalSegment, d
|
|
|
66
65
|
withService: what.includes('service'),
|
|
67
66
|
segmentName,
|
|
68
67
|
moduleName,
|
|
68
|
+
empty,
|
|
69
|
+
templateFileName: templateAbsolutePath,
|
|
70
|
+
isNodeNextResolution,
|
|
69
71
|
});
|
|
70
72
|
const dir = dirFlag || renderedDir;
|
|
71
73
|
if (!dir) {
|
|
@@ -84,24 +86,24 @@ export default async function newModule({ what, moduleNameWithOptionalSegment, d
|
|
|
84
86
|
else {
|
|
85
87
|
await fs.mkdir(absoluteModuleDir, { recursive: true });
|
|
86
88
|
await fs.writeFile(absoluteModulePath, prettiedCode);
|
|
87
|
-
log.info(`Created ${chalkHighlightThing(
|
|
89
|
+
log.info(`Created${empty ? ' empty' : ''} ${chalkHighlightThing(absoluteModulePath)} using ${chalkHighlightThing(`"${type}"`)} template for ${formatLoggedSegmentName(segmentName)}`);
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
|
-
if (type === 'controller'
|
|
92
|
+
if (type === 'controller') {
|
|
91
93
|
if (!sourceName) {
|
|
92
94
|
throw new Error(`The template for "${type}" does not provide a sourceName`);
|
|
93
95
|
}
|
|
94
96
|
if (!compiledName) {
|
|
95
|
-
throw new Error(
|
|
97
|
+
throw new Error(`The template for "${type}" does not provide a compiledName`);
|
|
96
98
|
}
|
|
97
99
|
const { routeFilePath } = segment;
|
|
98
100
|
const segmentSourceCode = await fs.readFile(routeFilePath, 'utf-8');
|
|
99
|
-
|
|
101
|
+
let importPath = path.relative(path.dirname(routeFilePath) + '/', absoluteModulePath).replace(/\.(ts|tsx)$/, '');
|
|
102
|
+
importPath += isNodeNextResolution ? '.ts' : '';
|
|
100
103
|
if (!noSegmentUpdate) {
|
|
101
104
|
const newSegmentCode = await prettify(addClassToSegmentCode(segmentSourceCode, {
|
|
102
105
|
sourceName,
|
|
103
106
|
compiledName,
|
|
104
|
-
type,
|
|
105
107
|
importPath,
|
|
106
108
|
}), routeFilePath);
|
|
107
109
|
if (!dryRun) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export default function newSegment({ segmentName, overwrite, dryRun, }: {
|
|
1
|
+
export default function newSegment({ segmentName, isStaticSegment, overwrite, dryRun, }: {
|
|
2
2
|
segmentName: string;
|
|
3
|
+
isStaticSegment?: boolean;
|
|
3
4
|
overwrite?: boolean;
|
|
4
5
|
dryRun?: boolean;
|
|
5
6
|
}): Promise<void>;
|
package/dist/new/newSegment.mjs
CHANGED
|
@@ -5,23 +5,32 @@ import getFileSystemEntryType from '../utils/getFileSystemEntryType.mjs';
|
|
|
5
5
|
import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
|
|
6
6
|
import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
|
|
7
7
|
import prettify from '../utils/prettify.mjs';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
export default async function newSegment({ segmentName, isStaticSegment, overwrite, dryRun, }) {
|
|
10
|
+
const { apiDirAbsolutePath, log, config } = await getProjectInfo();
|
|
11
|
+
if (!apiDirAbsolutePath) {
|
|
12
|
+
throw new Error('No API directory found. Please ensure you are in a Nest.js project.');
|
|
13
|
+
}
|
|
14
|
+
const absoluteSegmentRoutePath = path.join(apiDirAbsolutePath, segmentName, '[[...vovk]]/route.ts');
|
|
11
15
|
if (!overwrite && (await getFileSystemEntryType(absoluteSegmentRoutePath))) {
|
|
12
16
|
throw new Error(`Unable to create new segment. ${formatLoggedSegmentName(segmentName, { upperFirst: true })} already exists.`);
|
|
13
17
|
}
|
|
14
|
-
const code = await prettify(`import { initVovk } from 'vovk';
|
|
18
|
+
const code = await prettify(`import { initVovk${isStaticSegment ? ', generateStaticAPI' : ''} } from 'vovk';
|
|
19
|
+
|
|
20
|
+
export const runtime = 'edge';
|
|
15
21
|
|
|
16
22
|
const controllers = {};
|
|
17
|
-
const workers = {};
|
|
18
23
|
|
|
19
24
|
export type Controllers = typeof controllers;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export
|
|
25
|
+
${isStaticSegment
|
|
26
|
+
? `
|
|
27
|
+
export function generateStaticParams() {
|
|
28
|
+
return generateStaticAPI(controllers);
|
|
29
|
+
}
|
|
30
|
+
`
|
|
31
|
+
: ''}
|
|
32
|
+
export const { GET${isStaticSegment ? '' : ', POST, PATCH, PUT, HEAD, OPTIONS, DELETE'} } = initVovk({
|
|
23
33
|
${segmentName ? ` segmentName: '${segmentName}',\n` : ''} emitSchema: true,
|
|
24
|
-
workers,
|
|
25
34
|
controllers,
|
|
26
35
|
});
|
|
27
36
|
`, absoluteSegmentRoutePath);
|
|
@@ -29,5 +38,7 @@ ${segmentName ? ` segmentName: '${segmentName}',\n` : ''} emitSchema: true,
|
|
|
29
38
|
await fs.mkdir(path.dirname(absoluteSegmentRoutePath), { recursive: true });
|
|
30
39
|
await fs.writeFile(absoluteSegmentRoutePath, code);
|
|
31
40
|
}
|
|
32
|
-
log.info(`${formatLoggedSegmentName(segmentName, { upperFirst: true })} created at ${absoluteSegmentRoutePath}
|
|
41
|
+
log.info(`${formatLoggedSegmentName(segmentName, { upperFirst: true, isStatic: isStaticSegment })} created at ${absoluteSegmentRoutePath}.`);
|
|
42
|
+
const dir = chalk.cyanBright([segmentName, 'thing'].filter(Boolean).join('/'));
|
|
43
|
+
log.info(`Run ${chalkHighlightThing(`npx vovk new service controller ${dir}`)} to create a new controller with a service at ${path.join(config.modulesDir, dir)} folder for this segment`);
|
|
33
44
|
}
|
package/dist/new/render.d.mts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { VovkStrictConfig } from 'vovk';
|
|
2
|
+
import type { VovkModuleRenderResult } from '../types.mjs';
|
|
3
|
+
export default function render(codeTemplate: string, { config, withService, segmentName, moduleName, empty, templateFileName, isNodeNextResolution, }: {
|
|
3
4
|
cwd: string;
|
|
4
|
-
config:
|
|
5
|
+
config: VovkStrictConfig;
|
|
5
6
|
withService: boolean;
|
|
6
7
|
segmentName: string;
|
|
7
8
|
moduleName: string;
|
|
9
|
+
empty?: boolean;
|
|
10
|
+
templateFileName: string;
|
|
11
|
+
isNodeNextResolution: boolean;
|
|
8
12
|
}): Promise<VovkModuleRenderResult>;
|
package/dist/new/render.mjs
CHANGED
|
@@ -4,25 +4,46 @@ import _ from 'lodash';
|
|
|
4
4
|
import pluralize from 'pluralize';
|
|
5
5
|
import addCommonTerms from './addCommonTerms.mjs';
|
|
6
6
|
addCommonTerms();
|
|
7
|
-
export default async function render(codeTemplate, { config, withService, segmentName, moduleName, }) {
|
|
7
|
+
export default async function render(codeTemplate, { config, withService, segmentName, moduleName, empty, templateFileName, isNodeNextResolution, }) {
|
|
8
8
|
const getModuleDirName = (givenSegmentName, givenModuleName) => [config.modulesDir, givenSegmentName || config.rootSegmentModulesDirName, _.camelCase(givenModuleName)]
|
|
9
9
|
.filter(Boolean)
|
|
10
10
|
.join('/');
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const theThing = _.camelCase(moduleName);
|
|
12
|
+
const TheThing = _.upperFirst(theThing);
|
|
13
|
+
const the_thing = _.snakeCase(moduleName);
|
|
14
|
+
const THE_THING = _.toUpper(the_thing);
|
|
15
|
+
const the__thing = _.kebabCase(moduleName);
|
|
16
|
+
const t = {
|
|
17
|
+
// module name variations
|
|
18
|
+
moduleName,
|
|
19
|
+
theThing,
|
|
20
|
+
theThings: pluralize(theThing),
|
|
21
|
+
TheThing,
|
|
22
|
+
TheThings: pluralize(TheThing),
|
|
23
|
+
the_thing,
|
|
24
|
+
the_things: pluralize(the_thing),
|
|
25
|
+
THE_THING,
|
|
26
|
+
THE_THINGS: pluralize(THE_THING),
|
|
27
|
+
'the-thing': the__thing,
|
|
28
|
+
'the-things': pluralize(the__thing),
|
|
29
|
+
// data
|
|
13
30
|
config,
|
|
14
31
|
withService,
|
|
15
32
|
segmentName,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
33
|
+
nodeNextResolutionExt: {
|
|
34
|
+
ts: isNodeNextResolution ? '.ts' : '',
|
|
35
|
+
js: isNodeNextResolution ? '.js' : '',
|
|
36
|
+
cjs: isNodeNextResolution ? '.cjs' : '',
|
|
37
|
+
mjs: isNodeNextResolution ? '.mjs' : '',
|
|
38
|
+
},
|
|
39
|
+
defaultDir: getModuleDirName(segmentName, theThing),
|
|
19
40
|
// libraries
|
|
20
41
|
_, // lodash
|
|
21
42
|
pluralize,
|
|
22
43
|
};
|
|
23
|
-
const parsed = matter((await ejs.render(codeTemplate,
|
|
44
|
+
const parsed = matter((await ejs.render(codeTemplate, { t }, { async: true, filename: templateFileName })).trim());
|
|
24
45
|
const { dir, fileName, sourceName, compiledName } = parsed.data;
|
|
25
|
-
const code = parsed.content;
|
|
46
|
+
const code = empty ? (sourceName ? `export default class ${sourceName} {}` : '') : parsed.content;
|
|
26
47
|
return {
|
|
27
48
|
dir,
|
|
28
49
|
fileName,
|
package/dist/types.d.mts
CHANGED
|
@@ -1,42 +1,5 @@
|
|
|
1
1
|
import type { LogLevelNames } from 'loglevel';
|
|
2
|
-
|
|
3
|
-
export type VovkDevEnv = {
|
|
4
|
-
PORT?: string;
|
|
5
|
-
VOVK_CLIENT_OUT_DIR?: string;
|
|
6
|
-
VOVK_SCHEMA_OUT_DIR?: string;
|
|
7
|
-
VOVK_FETCHER?: string;
|
|
8
|
-
VOVK_VALIDATE_ON_CLIENT?: string;
|
|
9
|
-
VOVK_MODULES_DIR?: string;
|
|
10
|
-
VOVK_VALIDATION_LIBRARY?: string;
|
|
11
|
-
VOVK_ORIGIN?: string;
|
|
12
|
-
VOVK_ROOT_ENTRY?: string;
|
|
13
|
-
VOVK_API_ENTRY_POINT?: string;
|
|
14
|
-
VOVK_ROOT_SEGMENT_MODULES_DIR_NAME?: string;
|
|
15
|
-
VOVK_LOG_LEVEL?: LogLevelNames;
|
|
16
|
-
VOVK_PRETTIFY_CLIENT?: string;
|
|
17
|
-
VOVK_DEV_HTTPS?: string;
|
|
18
|
-
__VOVK_START_WATCHER_IN_STANDALONE_MODE__?: 'true';
|
|
19
|
-
};
|
|
20
|
-
export type VovkConfig = {
|
|
21
|
-
clientOutDir?: string;
|
|
22
|
-
schemaOutDir?: string;
|
|
23
|
-
fetcher?: string;
|
|
24
|
-
validateOnClient?: string | null;
|
|
25
|
-
modulesDir?: string;
|
|
26
|
-
validationLibrary?: string | null;
|
|
27
|
-
rootEntry?: string;
|
|
28
|
-
origin?: string;
|
|
29
|
-
rootSegmentModulesDirName?: string;
|
|
30
|
-
logLevel?: LogLevelNames;
|
|
31
|
-
prettifyClient?: boolean;
|
|
32
|
-
devHttps?: boolean;
|
|
33
|
-
templates?: {
|
|
34
|
-
service?: string;
|
|
35
|
-
controller?: string;
|
|
36
|
-
worker?: string;
|
|
37
|
-
[key: string]: string | undefined;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
2
|
+
import type { VovkStrictConfig } from 'vovk';
|
|
40
3
|
export type VovkModuleRenderResult = {
|
|
41
4
|
fileName: string;
|
|
42
5
|
dir: string;
|
|
@@ -45,11 +8,33 @@ export type VovkModuleRenderResult = {
|
|
|
45
8
|
code: string;
|
|
46
9
|
};
|
|
47
10
|
export interface DevOptions {
|
|
48
|
-
|
|
11
|
+
schemaOut?: string;
|
|
49
12
|
nextDev?: boolean;
|
|
13
|
+
exit?: boolean;
|
|
50
14
|
}
|
|
51
15
|
export interface GenerateOptions {
|
|
52
|
-
|
|
16
|
+
prettify?: boolean;
|
|
17
|
+
configPath?: string;
|
|
18
|
+
schemaPath?: string;
|
|
19
|
+
openapiSpec?: string;
|
|
20
|
+
watch?: boolean | string;
|
|
21
|
+
forceTsStandalone?: boolean;
|
|
22
|
+
composedFrom?: string[];
|
|
23
|
+
composedOut?: string;
|
|
24
|
+
composedOnly?: boolean;
|
|
25
|
+
composedIncludeSegments?: string[];
|
|
26
|
+
composedExcludeSegments?: string[];
|
|
27
|
+
segmentedFrom?: string[];
|
|
28
|
+
segmentedOut?: string;
|
|
29
|
+
segmentedOnly?: boolean;
|
|
30
|
+
segmentedIncludeSegments?: string[];
|
|
31
|
+
segmentedExcludeSegments?: string[];
|
|
32
|
+
}
|
|
33
|
+
export interface BundleOptions extends Partial<Omit<VovkStrictConfig['bundle'], 'requires'>> {
|
|
34
|
+
config?: string;
|
|
35
|
+
schema?: string;
|
|
36
|
+
openapiSpec?: string;
|
|
37
|
+
forceTsStandalone?: boolean;
|
|
53
38
|
}
|
|
54
39
|
export interface InitOptions {
|
|
55
40
|
yes?: boolean;
|
|
@@ -62,8 +47,9 @@ export interface InitOptions {
|
|
|
62
47
|
updateTsConfig?: boolean;
|
|
63
48
|
updateScripts?: 'implicit' | 'explicit';
|
|
64
49
|
validationLibrary?: string | null;
|
|
65
|
-
|
|
50
|
+
reactQuery?: boolean;
|
|
66
51
|
dryRun?: boolean;
|
|
52
|
+
lang?: string[];
|
|
67
53
|
channel?: 'latest' | 'beta' | 'draft';
|
|
68
54
|
}
|
|
69
55
|
export interface NewOptions {
|
|
@@ -72,4 +58,19 @@ export interface NewOptions {
|
|
|
72
58
|
dir?: string;
|
|
73
59
|
overwrite?: boolean;
|
|
74
60
|
noSegmentUpdate?: boolean;
|
|
61
|
+
empty?: boolean;
|
|
62
|
+
static?: boolean;
|
|
75
63
|
}
|
|
64
|
+
export type VovkEnv = {
|
|
65
|
+
PORT?: string;
|
|
66
|
+
VOVK_SCHEMA_OUT_DIR?: string;
|
|
67
|
+
VOVK_ORIGIN?: string;
|
|
68
|
+
VOVK_ROOT_ENTRY?: string;
|
|
69
|
+
VOVK_API_ENTRY_POINT?: string;
|
|
70
|
+
VOVK_LOG_LEVEL?: LogLevelNames;
|
|
71
|
+
VOVK_PRETTIFY_CLIENT?: string;
|
|
72
|
+
VOVK_DEV_HTTPS?: string;
|
|
73
|
+
__VOVK_START_WATCHER_IN_STANDALONE_MODE__?: 'true';
|
|
74
|
+
__VOVK_SCHEMA_OUT_FLAG__?: string;
|
|
75
|
+
__VOVK_EXIT__?: 'true' | 'false';
|
|
76
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
export function convertJSONSchemaToTypeScriptDef(schema) {
|
|
2
|
+
if (!schema)
|
|
3
|
+
return null;
|
|
4
|
+
// Helper function to get JSDoc from schema
|
|
5
|
+
const getJSDoc = (schema, indentation = '') => {
|
|
6
|
+
if (typeof schema === 'boolean') {
|
|
7
|
+
return '';
|
|
8
|
+
}
|
|
9
|
+
const description = schema.description || schema.title;
|
|
10
|
+
if (!description) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
return `${indentation}/**\n${indentation} * ${description}\n${indentation} */`;
|
|
14
|
+
};
|
|
15
|
+
// Helper function to convert schema to TypeScript type
|
|
16
|
+
const schemaToType = (schema, indentation = ' ') => {
|
|
17
|
+
if (typeof schema === 'boolean') {
|
|
18
|
+
return schema ? 'KnownAny' : 'never';
|
|
19
|
+
}
|
|
20
|
+
if (schema.enum) {
|
|
21
|
+
return schema.enum
|
|
22
|
+
.map((value) => {
|
|
23
|
+
if (typeof value === 'string') {
|
|
24
|
+
return `'${value}'`;
|
|
25
|
+
}
|
|
26
|
+
else if (value === null) {
|
|
27
|
+
return 'null';
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return String(value);
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
.join(' | ');
|
|
34
|
+
}
|
|
35
|
+
if (schema.const !== undefined) {
|
|
36
|
+
if (typeof schema.const === 'string') {
|
|
37
|
+
return `'${schema.const}'`;
|
|
38
|
+
}
|
|
39
|
+
else if (schema.const === null) {
|
|
40
|
+
return 'null';
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return String(schema.const);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (schema.oneOf) {
|
|
47
|
+
return schema.oneOf.map((s) => schemaToType(s, indentation)).join(' | ');
|
|
48
|
+
}
|
|
49
|
+
if (schema.anyOf) {
|
|
50
|
+
return schema.anyOf.map((s) => schemaToType(s, indentation)).join(' | ');
|
|
51
|
+
}
|
|
52
|
+
if (schema.allOf) {
|
|
53
|
+
return schema.allOf.map((s) => schemaToType(s, indentation)).join(' & ');
|
|
54
|
+
}
|
|
55
|
+
if (schema.type === 'object' || schema.properties) {
|
|
56
|
+
const properties = schema.properties || {};
|
|
57
|
+
const required = schema.required || [];
|
|
58
|
+
const propertyEntries = Object.entries(properties);
|
|
59
|
+
if (propertyEntries.length === 0) {
|
|
60
|
+
// Handle additional properties
|
|
61
|
+
if (schema.additionalProperties) {
|
|
62
|
+
if (typeof schema.additionalProperties === 'boolean') {
|
|
63
|
+
return schema.additionalProperties ? 'Record<string, KnownAny>' : '{}';
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const valueType = schemaToType(schema.additionalProperties, indentation);
|
|
67
|
+
return `Record<string, ${valueType}>`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return '{}';
|
|
71
|
+
}
|
|
72
|
+
const props = propertyEntries
|
|
73
|
+
.map(([propName, propSchema]) => {
|
|
74
|
+
if (typeof propSchema === 'boolean') {
|
|
75
|
+
const type = propSchema ? 'KnownAny' : 'never';
|
|
76
|
+
const isOptional = !required.includes(propName);
|
|
77
|
+
const jsDoc = getJSDoc(propSchema, indentation);
|
|
78
|
+
return `${jsDoc}\n${indentation}${propName}${isOptional ? '?' : ''}: ${type};`;
|
|
79
|
+
}
|
|
80
|
+
const isOptional = !required.includes(propName);
|
|
81
|
+
const defaultValue = propSchema.default !== undefined ? ` // default: ${JSON.stringify(propSchema.default)}` : '';
|
|
82
|
+
const jsDoc = getJSDoc(propSchema, indentation);
|
|
83
|
+
const propType = schemaToType(propSchema, indentation + ' ');
|
|
84
|
+
return `${jsDoc}\n${indentation}${propName}${isOptional ? '?' : ''}: ${propType};${defaultValue}`;
|
|
85
|
+
})
|
|
86
|
+
.join('\n');
|
|
87
|
+
// Handle additional properties
|
|
88
|
+
let additionalPropsType = '';
|
|
89
|
+
if (schema.additionalProperties) {
|
|
90
|
+
if (typeof schema.additionalProperties === 'boolean') {
|
|
91
|
+
if (schema.additionalProperties) {
|
|
92
|
+
additionalPropsType = `\n${indentation}[key: string]: KnownAny;`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const valueType = schemaToType(schema.additionalProperties, indentation + ' ');
|
|
97
|
+
additionalPropsType = `\n${indentation}[key: string]: ${valueType};`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return `{\n${props}${additionalPropsType}\n${indentation.slice(2)}}`;
|
|
101
|
+
}
|
|
102
|
+
if (schema.type === 'array' && schema.items) {
|
|
103
|
+
if (Array.isArray(schema.items)) {
|
|
104
|
+
// Tuple
|
|
105
|
+
const tupleTypes = schema.items.map((item) => schemaToType(item, indentation));
|
|
106
|
+
let tupleType = `[${tupleTypes.join(', ')}]`;
|
|
107
|
+
// Handle additional items
|
|
108
|
+
if (schema.additionalItems === true) {
|
|
109
|
+
tupleType += ' & KnownAny[]';
|
|
110
|
+
}
|
|
111
|
+
else if (typeof schema.additionalItems === 'object') {
|
|
112
|
+
const additionalType = schemaToType(schema.additionalItems, indentation);
|
|
113
|
+
tupleType += ` & ${additionalType}[]`;
|
|
114
|
+
}
|
|
115
|
+
return tupleType;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// Array
|
|
119
|
+
return `${schemaToType(schema.items, indentation)}[]`;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Handle multiple types
|
|
123
|
+
if (Array.isArray(schema.type)) {
|
|
124
|
+
return schema.type
|
|
125
|
+
.map((t) => {
|
|
126
|
+
const singleTypeSchema = { ...schema, type: t };
|
|
127
|
+
singleTypeSchema.type = t;
|
|
128
|
+
return schemaToType(singleTypeSchema, indentation);
|
|
129
|
+
})
|
|
130
|
+
.join(' | ');
|
|
131
|
+
}
|
|
132
|
+
// Handle primitive types
|
|
133
|
+
switch (schema.type) {
|
|
134
|
+
case 'string':
|
|
135
|
+
return 'string';
|
|
136
|
+
case 'number':
|
|
137
|
+
case 'integer':
|
|
138
|
+
return 'number';
|
|
139
|
+
case 'boolean':
|
|
140
|
+
return 'boolean';
|
|
141
|
+
case 'null':
|
|
142
|
+
return 'null';
|
|
143
|
+
case 'array':
|
|
144
|
+
return 'KnownAny[]'; // For arrays with no items defined
|
|
145
|
+
default:
|
|
146
|
+
return 'KnownAny';
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
// Generate the interface
|
|
150
|
+
const jsDoc = getJSDoc(schema);
|
|
151
|
+
const interfaceBody = schemaToType(schema);
|
|
152
|
+
return `${jsDoc}\n${interfaceBody}`;
|
|
153
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { KnownAny } from '
|
|
2
|
-
export default function debounceWithArgs<
|
|
1
|
+
import type { KnownAny } from 'vovk';
|
|
2
|
+
export default function debounceWithArgs<Callback extends (...args: KnownAny[]) => KnownAny>(callback: Callback, wait: number): (...args: Parameters<Callback>) => Promise<Awaited<ReturnType<Callback>>>;
|
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
1
|
+
export default function debounceWithArgs(callback, wait) {
|
|
2
|
+
// Stores timeouts keyed by the stringified arguments
|
|
3
|
+
const timeouts = new Map();
|
|
4
4
|
return (...args) => {
|
|
5
|
+
// Convert arguments to a JSON string (or any other stable key generation)
|
|
5
6
|
const key = JSON.stringify(args);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const debouncedFn = debouncedFunctions.get(key);
|
|
10
|
-
if (debouncedFn) {
|
|
11
|
-
debouncedFn(...args);
|
|
7
|
+
// Clear any existing timer for this specific key
|
|
8
|
+
if (timeouts.has(key)) {
|
|
9
|
+
clearTimeout(timeouts.get(key));
|
|
12
10
|
}
|
|
11
|
+
// Return a promise that resolves/rejects after the debounce delay
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const timeoutId = setTimeout(async () => {
|
|
14
|
+
try {
|
|
15
|
+
const result = await callback(...args);
|
|
16
|
+
resolve(result);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
reject(error);
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
// Remove the entry once the callback is invoked
|
|
23
|
+
timeouts.delete(key);
|
|
24
|
+
}
|
|
25
|
+
}, wait);
|
|
26
|
+
timeouts.set(key, timeoutId);
|
|
27
|
+
});
|
|
13
28
|
};
|
|
14
29
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export default function formatLoggedSegmentName(segmentName: string, { withChalk, upperFirst }?: {
|
|
1
|
+
export default function formatLoggedSegmentName(segmentName: string, { withChalk, upperFirst, isStatic, }?: {
|
|
2
2
|
withChalk?: boolean;
|
|
3
3
|
upperFirst?: boolean;
|
|
4
|
+
isStatic?: boolean;
|
|
4
5
|
}): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import upperFirstLodash from 'lodash/upperFirst.js';
|
|
2
2
|
import chalkHighlightThing from './chalkHighlightThing.mjs';
|
|
3
|
-
export default function formatLoggedSegmentName(segmentName, { withChalk = true, upperFirst = false } = {}) {
|
|
4
|
-
let text = segmentName ?
|
|
3
|
+
export default function formatLoggedSegmentName(segmentName, { withChalk = true, upperFirst = false, isStatic = false, } = {}) {
|
|
4
|
+
let text = segmentName ? `${isStatic ? 'static ' : ''}segment "${segmentName}"` : 'the root segment';
|
|
5
5
|
text = upperFirst ? upperFirstLodash(text) : text;
|
|
6
6
|
return withChalk ? chalkHighlightThing(text) : text;
|
|
7
7
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default function getPublicModuleNameFromPath(modulePath) {
|
|
2
|
+
if (modulePath && !modulePath.startsWith('.') && !modulePath.startsWith('/')) {
|
|
3
|
+
const pathParts = modulePath.split('/');
|
|
4
|
+
const moduleName = pathParts[0].startsWith('@') ? `${pathParts[0]}/${pathParts[1]}` : pathParts[0];
|
|
5
|
+
const restPath = pathParts.slice(pathParts[0].startsWith('@') ? 2 : 1).join('/');
|
|
6
|
+
return { moduleName, restPath };
|
|
7
|
+
}
|
|
8
|
+
return { moduleName: null, restPath: modulePath };
|
|
9
|
+
}
|
|
@@ -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;
|