vovk-cli 0.0.1-draft.337 → 0.0.1-draft.339
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/client-templates/cjs/index.cjs.ejs +3 -1
- package/client-templates/cjs/index.d.cts.ejs +1 -0
- package/client-templates/mjs/index.d.mts.ejs +1 -0
- package/client-templates/mjs/index.mjs.ejs +2 -1
- package/client-templates/openapiJson/openapi.json.ejs +1 -0
- package/client-templates/ts/index.ts.ejs +2 -1
- package/dist/generate/generate.mjs +12 -1
- package/dist/generate/writeOneClientFile.d.mts +3 -1
- package/dist/generate/writeOneClientFile.mjs +2 -1
- package/dist/getProjectInfo/getConfig/getTemplateDefs.d.mts +1 -0
- package/dist/getProjectInfo/getConfig/getTemplateDefs.mjs +7 -0
- package/dist/getProjectInfo/getConfig/index.d.mts +1 -1
- package/dist/getProjectInfo/getConfig/index.mjs +4 -2
- package/dist/getProjectInfo/getMetaSchema.d.mts +26 -1
- package/dist/getProjectInfo/getMetaSchema.mjs +22 -1
- package/module-templates/type/controller.ts.ejs +1 -1
- package/package.json +2 -2
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const { fetcher } = require('<%= t.imports.fetcher %>');
|
|
3
3
|
const { createRPC } = require('<%= t.imports.createRPC %>');
|
|
4
4
|
const { schema } = require('./schema.cjs');
|
|
5
|
+
const openapi = require('./openapi.json');
|
|
5
6
|
const { validateOnClient = null } = <%- t.imports.validateOnClient ? `require('${t.imports.validateOnClient}')` : '{}'%>;
|
|
6
7
|
<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment) => { %>
|
|
7
8
|
<% Object.entries(t.segmentMeta[segment.segmentName].reExports).forEach(([reExportWhatCommaDivisible, reExportFrom]) => {
|
|
@@ -16,4 +17,5 @@ exports.<%= rpcModuleName %> = createRPC(
|
|
|
16
17
|
);
|
|
17
18
|
<% })
|
|
18
19
|
}) %>
|
|
19
|
-
exports.schema = schema;
|
|
20
|
+
exports.schema = schema;
|
|
21
|
+
exports.openapi = openapi;
|
|
@@ -20,6 +20,7 @@ export const <%= rpcModuleName %>: ReturnType<typeof createRPC<<%= segment.segme
|
|
|
20
20
|
<% })
|
|
21
21
|
}) %>
|
|
22
22
|
export { schema } from './schema.cjs';
|
|
23
|
+
export { default as openapi } from './openapi.json' assert { type: 'json' };
|
|
23
24
|
<% if (t.hasMixins) { %>
|
|
24
25
|
export { Mixins };
|
|
25
26
|
<% } %>
|
|
@@ -20,6 +20,7 @@ export const <%= rpcModuleName %>: ReturnType<typeof createRPC<<%= segment.segme
|
|
|
20
20
|
<% })
|
|
21
21
|
}) %>
|
|
22
22
|
export { schema } from './schema.cjs';
|
|
23
|
+
export { default as openapi } from './openapi.json' with { type: 'json' };
|
|
23
24
|
<% if (t.hasMixins) { %>
|
|
24
25
|
export { Mixins };
|
|
25
26
|
<% } %>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { fetcher } from '<%= t.imports.module.fetcher %>';
|
|
3
3
|
import { createRPC } from '<%= t.imports.module.createRPC %>';
|
|
4
4
|
import { schema } from './schema.cjs';
|
|
5
|
+
import openapi from './openapi.json' with { type: 'json' };
|
|
5
6
|
<% if (t.imports.module.validateOnClient) { %>
|
|
6
7
|
import { validateOnClient } from '<%= t.imports.module.validateOnClient %>';
|
|
7
8
|
<% } else { %>
|
|
@@ -20,4 +21,4 @@ export const <%= rpcModuleName %> = createRPC(
|
|
|
20
21
|
});
|
|
21
22
|
});
|
|
22
23
|
%>
|
|
23
|
-
export { schema };
|
|
24
|
+
export { schema, openapi };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%- JSON.stringify(t.openapi, null, 2) %>
|
|
@@ -3,6 +3,7 @@ import type { VovkClientFetcher } from 'vovk';
|
|
|
3
3
|
import { fetcher } from '<%= t.imports.fetcher %>';
|
|
4
4
|
import { createRPC } from '<%= t.imports.createRPC %>';
|
|
5
5
|
import { schema } from './schema<%= t.nodeNextResolutionExt.ts %>';
|
|
6
|
+
import openapi from './openapi.json' with { type: 'json' };
|
|
6
7
|
<% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { if(segment.segmentType !== 'mixin') { %>
|
|
7
8
|
import type { Controllers as Controllers<%= i %> } from "<%= t.segmentMeta[segment.segmentName].segmentImportPath %>";
|
|
8
9
|
<% }
|
|
@@ -27,7 +28,7 @@ export const <%= rpcModuleName %> = createRPC<<%= segment.segmentType === 'mixin
|
|
|
27
28
|
);
|
|
28
29
|
<% })
|
|
29
30
|
}) %>
|
|
30
|
-
export { schema };
|
|
31
|
+
export { schema, openapi };
|
|
31
32
|
<% if (t.hasMixins) { %>
|
|
32
33
|
export { Mixins };
|
|
33
34
|
<% } %>
|
|
@@ -2,7 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
3
|
import matter from 'gray-matter';
|
|
4
4
|
import _ from 'lodash';
|
|
5
|
-
import { getGeneratorConfig, openAPIToVovkSchema, } from 'vovk';
|
|
5
|
+
import { getGeneratorConfig, openAPIToVovkSchema, vovkSchemaToOpenAPI, } from 'vovk';
|
|
6
6
|
import getClientTemplateFiles from './getClientTemplateFiles.mjs';
|
|
7
7
|
import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
|
|
8
8
|
import pickSegmentFullSchema from '../utils/pickSegmentFullSchema.mjs';
|
|
@@ -144,6 +144,10 @@ export async function generate({ isEnsuringClient = false, isBundle = false, pro
|
|
|
144
144
|
config: templateDef.generatorConfig,
|
|
145
145
|
isBundle,
|
|
146
146
|
});
|
|
147
|
+
const openapi = vovkSchemaToOpenAPI({
|
|
148
|
+
schema: fullSchema,
|
|
149
|
+
rootEntry: config.rootEntry,
|
|
150
|
+
});
|
|
147
151
|
const composedFullSchema = pickSegmentFullSchema(fullSchema, segmentNames);
|
|
148
152
|
const hasMixins = Object.values(composedFullSchema.segments).some((segment) => segment.segmentType === 'mixin');
|
|
149
153
|
if (templateName === BuiltInTemplateName.mixins && !hasMixins) {
|
|
@@ -159,6 +163,7 @@ export async function generate({ isEnsuringClient = false, isBundle = false, pro
|
|
|
159
163
|
imports: clientImports.composedClient,
|
|
160
164
|
templateContent,
|
|
161
165
|
matterResult,
|
|
166
|
+
openapi,
|
|
162
167
|
package: packageJson,
|
|
163
168
|
readme,
|
|
164
169
|
snippets,
|
|
@@ -229,6 +234,11 @@ export async function generate({ isEnsuringClient = false, isBundle = false, pro
|
|
|
229
234
|
if (templateName === BuiltInTemplateName.mixins && !hasMixins) {
|
|
230
235
|
return null;
|
|
231
236
|
}
|
|
237
|
+
const openapi = vovkSchemaToOpenAPI({
|
|
238
|
+
schema: fullSchema,
|
|
239
|
+
rootEntry: config.rootEntry,
|
|
240
|
+
segmentName,
|
|
241
|
+
});
|
|
232
242
|
const { written } = await writeOneClientFile({
|
|
233
243
|
cwd,
|
|
234
244
|
projectInfo,
|
|
@@ -239,6 +249,7 @@ export async function generate({ isEnsuringClient = false, isBundle = false, pro
|
|
|
239
249
|
imports: clientImports.segmentedClient[segmentName],
|
|
240
250
|
templateContent,
|
|
241
251
|
matterResult,
|
|
252
|
+
openapi,
|
|
242
253
|
package: packageJson,
|
|
243
254
|
readme,
|
|
244
255
|
snippets,
|
|
@@ -4,8 +4,9 @@ import type { ProjectInfo } from '../getProjectInfo/index.mjs';
|
|
|
4
4
|
import type { ClientTemplateFile } from './getClientTemplateFiles.mjs';
|
|
5
5
|
import type { ClientImports } from './getTemplateClientImports.mjs';
|
|
6
6
|
import type { Segment } from '../locateSegments.mjs';
|
|
7
|
+
import { OpenAPIObject } from 'openapi3-ts/oas31';
|
|
7
8
|
export declare function normalizeOutTemplatePath(out: string, packageJson: PackageJson): string;
|
|
8
|
-
export default function writeOneClientFile({ cwd, projectInfo, clientTemplateFile, fullSchema, prettifyClient, segmentName, imports, templateContent, matterResult: { data, content }, package: packageJson, readme, snippets, isEnsuringClient, outCwdRelativeDir, locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage, isBundle, origin, }: {
|
|
9
|
+
export default function writeOneClientFile({ cwd, projectInfo, clientTemplateFile, fullSchema, prettifyClient, segmentName, imports, templateContent, matterResult: { data, content }, openapi, package: packageJson, readme, snippets, isEnsuringClient, outCwdRelativeDir, locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage, isBundle, origin, }: {
|
|
9
10
|
cwd: string;
|
|
10
11
|
projectInfo: ProjectInfo;
|
|
11
12
|
clientTemplateFile: ClientTemplateFile;
|
|
@@ -20,6 +21,7 @@ export default function writeOneClientFile({ cwd, projectInfo, clientTemplateFil
|
|
|
20
21
|
};
|
|
21
22
|
content: string;
|
|
22
23
|
};
|
|
24
|
+
openapi: OpenAPIObject;
|
|
23
25
|
package: PackageJson;
|
|
24
26
|
readme: VovkReadmeConfig;
|
|
25
27
|
snippets: VovkSnippetsConfig;
|
|
@@ -11,7 +11,7 @@ import { compileJSONSchemaToTypeScriptType } from '../utils/compileJSONSchemaToT
|
|
|
11
11
|
export function normalizeOutTemplatePath(out, packageJson) {
|
|
12
12
|
return out.replace('[package_name]', packageJson.name?.replace(/-/g, '_') ?? 'my_package_name');
|
|
13
13
|
}
|
|
14
|
-
export default async function writeOneClientFile({ cwd, projectInfo, clientTemplateFile, fullSchema, prettifyClient, segmentName, imports, templateContent, matterResult: { data, content }, package: packageJson, readme, snippets, isEnsuringClient, outCwdRelativeDir,
|
|
14
|
+
export default async function writeOneClientFile({ cwd, projectInfo, clientTemplateFile, fullSchema, prettifyClient, segmentName, imports, templateContent, matterResult: { data, content }, openapi, package: packageJson, readme, snippets, isEnsuringClient, outCwdRelativeDir,
|
|
15
15
|
// templateDef,
|
|
16
16
|
locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage, isBundle, origin, }) {
|
|
17
17
|
const { config, apiRoot } = projectInfo;
|
|
@@ -41,6 +41,7 @@ locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage,
|
|
|
41
41
|
package: packageJson,
|
|
42
42
|
readme,
|
|
43
43
|
snippets,
|
|
44
|
+
openapi,
|
|
44
45
|
ROOT_SEGMENT_FILE_NAME,
|
|
45
46
|
apiRoot: origin ? `${origin}/${config.rootEntry}` : apiRoot,
|
|
46
47
|
imports,
|
|
@@ -13,6 +13,7 @@ export var BuiltInTemplateName;
|
|
|
13
13
|
// misc
|
|
14
14
|
BuiltInTemplateName["readme"] = "readme";
|
|
15
15
|
BuiltInTemplateName["packageJson"] = "packageJson";
|
|
16
|
+
BuiltInTemplateName["openapiJson"] = "openapiJson";
|
|
16
17
|
BuiltInTemplateName["mixins"] = "mixins";
|
|
17
18
|
// other languages (packages installed separately)
|
|
18
19
|
BuiltInTemplateName["rsSrc"] = "rsSrc";
|
|
@@ -31,6 +32,7 @@ export default function getTemplateDefs(userTemplateDefs = {}) {
|
|
|
31
32
|
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.ts}/`,
|
|
32
33
|
requires: {
|
|
33
34
|
[BuiltInTemplateName.schemaTs]: '.',
|
|
35
|
+
[BuiltInTemplateName.openapiJson]: '.',
|
|
34
36
|
[BuiltInTemplateName.mixins]: '.', // used conditionally if OpenAPI mixins are used
|
|
35
37
|
},
|
|
36
38
|
},
|
|
@@ -38,6 +40,7 @@ export default function getTemplateDefs(userTemplateDefs = {}) {
|
|
|
38
40
|
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.cjs}/`,
|
|
39
41
|
requires: {
|
|
40
42
|
[BuiltInTemplateName.schemaCjs]: '.',
|
|
43
|
+
[BuiltInTemplateName.openapiJson]: '.',
|
|
41
44
|
[BuiltInTemplateName.mixins]: '.', // used conditionally if OpenAPI mixins are used
|
|
42
45
|
},
|
|
43
46
|
},
|
|
@@ -45,6 +48,7 @@ export default function getTemplateDefs(userTemplateDefs = {}) {
|
|
|
45
48
|
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.mjs}/`,
|
|
46
49
|
requires: {
|
|
47
50
|
[BuiltInTemplateName.schemaCjs]: '.',
|
|
51
|
+
[BuiltInTemplateName.openapiJson]: '.',
|
|
48
52
|
[BuiltInTemplateName.mixins]: '.', // used conditionally if OpenAPI mixins are used
|
|
49
53
|
},
|
|
50
54
|
},
|
|
@@ -63,6 +67,9 @@ export default function getTemplateDefs(userTemplateDefs = {}) {
|
|
|
63
67
|
[BuiltInTemplateName.packageJson]: {
|
|
64
68
|
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.packageJson}/`,
|
|
65
69
|
},
|
|
70
|
+
[BuiltInTemplateName.openapiJson]: {
|
|
71
|
+
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.openapiJson}/`,
|
|
72
|
+
},
|
|
66
73
|
[BuiltInTemplateName.mixins]: {
|
|
67
74
|
templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.mixins}/`,
|
|
68
75
|
},
|
|
@@ -49,7 +49,7 @@ export default function getConfig({ configPath, cwd, logLevel, }: {
|
|
|
49
49
|
prebundleOutDir?: string;
|
|
50
50
|
keepPrebundleDir?: boolean;
|
|
51
51
|
tsdownBuildOptions?: Parameters<typeof import("tsdown/config-9hj-APNF.mjs").build>[0];
|
|
52
|
-
generatorConfig
|
|
52
|
+
generatorConfig?: import("vovk").VovkGeneratorConfigCommon;
|
|
53
53
|
} & ({
|
|
54
54
|
excludeSegments?: never;
|
|
55
55
|
includeSegments?: string[];
|
|
@@ -12,7 +12,8 @@ export default async function getConfig({ configPath, cwd, logLevel, }) {
|
|
|
12
12
|
cwd,
|
|
13
13
|
});
|
|
14
14
|
const conf = userConfig ?? {};
|
|
15
|
-
|
|
15
|
+
logLevel = logLevel ?? conf.logLevel ?? 'info';
|
|
16
|
+
const log = getLogger(logLevel);
|
|
16
17
|
const env = process.env;
|
|
17
18
|
const clientTemplateDefs = getTemplateDefs(conf.clientTemplateDefs);
|
|
18
19
|
const srcRoot = await getRelativeSrcRoot({ cwd });
|
|
@@ -51,6 +52,7 @@ export default async function getConfig({ configPath, cwd, logLevel, }) {
|
|
|
51
52
|
requires: {
|
|
52
53
|
[BuiltInTemplateName.readme]: '.',
|
|
53
54
|
[BuiltInTemplateName.packageJson]: '.',
|
|
55
|
+
[BuiltInTemplateName.openapiJson]: '.',
|
|
54
56
|
},
|
|
55
57
|
generatorConfig: {},
|
|
56
58
|
...conf.bundle,
|
|
@@ -63,7 +65,7 @@ export default async function getConfig({ configPath, cwd, logLevel, }) {
|
|
|
63
65
|
schemaOutDir: env.VOVK_SCHEMA_OUT_DIR ?? conf.schemaOutDir ?? './.vovk-schema',
|
|
64
66
|
rootEntry: env.VOVK_ROOT_ENTRY ?? conf.rootEntry ?? 'api',
|
|
65
67
|
rootSegmentModulesDirName: conf.rootSegmentModulesDirName ?? '',
|
|
66
|
-
logLevel
|
|
68
|
+
logLevel,
|
|
67
69
|
devHttps: conf.devHttps ?? false,
|
|
68
70
|
moduleTemplates: {
|
|
69
71
|
service: 'vovk-cli/module-templates/service.ts.ejs',
|
|
@@ -6,5 +6,30 @@ export default function getMetaSchema({ config, package: packageJson, }: {
|
|
|
6
6
|
}): {
|
|
7
7
|
config: VovkStrictConfig;
|
|
8
8
|
$schema: VovkSchemaIdEnum;
|
|
9
|
-
package:
|
|
9
|
+
package: {
|
|
10
|
+
main: string;
|
|
11
|
+
module: string;
|
|
12
|
+
types: string;
|
|
13
|
+
exports: {
|
|
14
|
+
'.': {
|
|
15
|
+
import: string;
|
|
16
|
+
require: string;
|
|
17
|
+
types: string;
|
|
18
|
+
};
|
|
19
|
+
'./schema': {
|
|
20
|
+
import: string;
|
|
21
|
+
require: string;
|
|
22
|
+
types: string;
|
|
23
|
+
};
|
|
24
|
+
'./openapi': {
|
|
25
|
+
import: string;
|
|
26
|
+
require: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
name?: string | undefined;
|
|
30
|
+
version?: string | undefined;
|
|
31
|
+
description?: string | undefined;
|
|
32
|
+
author?: PackageJson.Person | undefined;
|
|
33
|
+
license?: string | undefined;
|
|
34
|
+
};
|
|
10
35
|
};
|
|
@@ -3,7 +3,28 @@ import pick from 'lodash/pick.js';
|
|
|
3
3
|
export default function getMetaSchema({ config, package: packageJson, }) {
|
|
4
4
|
return {
|
|
5
5
|
$schema: VovkSchemaIdEnum.META,
|
|
6
|
-
package:
|
|
6
|
+
package: {
|
|
7
|
+
...pick(packageJson, ['name', 'version', 'description', 'author', 'license']),
|
|
8
|
+
main: './index.cjs',
|
|
9
|
+
module: './index.mjs',
|
|
10
|
+
types: './index.d.mts',
|
|
11
|
+
exports: {
|
|
12
|
+
'.': {
|
|
13
|
+
import: './index.mjs',
|
|
14
|
+
require: './index.cjs',
|
|
15
|
+
types: './index.d.mts',
|
|
16
|
+
},
|
|
17
|
+
'./schema': {
|
|
18
|
+
import: './schema.cjs',
|
|
19
|
+
require: './schema.cjs',
|
|
20
|
+
types: './schema.d.cts',
|
|
21
|
+
},
|
|
22
|
+
'./openapi': {
|
|
23
|
+
import: './openapi.json',
|
|
24
|
+
require: './openapi.json',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
7
28
|
...{
|
|
8
29
|
config: (config
|
|
9
30
|
? pick(config, [...config.emitConfig, '$schema'])
|
|
@@ -9,7 +9,7 @@ sourceName: <%= vars.rpcModuleName %>
|
|
|
9
9
|
compiledName: <%= t.TheThing + 'RPC' %>
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
-
import { prefix, get, put, post, del,
|
|
12
|
+
import { prefix, get, put, post, del, operation, type VovkRequest } from 'vovk';
|
|
13
13
|
<% if(t.withService) { %>
|
|
14
14
|
import <%= vars.ServiceName %> from './<%= vars.ServiceName %><%= t.nodeNextResolutionExt.ts %>';
|
|
15
15
|
<% } %>
|
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.339",
|
|
4
4
|
"bin": {
|
|
5
5
|
"vovk": "./dist/index.mjs"
|
|
6
6
|
},
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://vovk.dev",
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"vovk": "^3.0.0-draft.
|
|
38
|
+
"vovk": "^3.0.0-draft.401"
|
|
39
39
|
},
|
|
40
40
|
"optionalDependencies": {
|
|
41
41
|
"@rolldown/binding-linux-x64-gnu": "1.0.0-beta.31"
|