vovk-cli 0.0.1-draft.339 → 0.0.1-draft.340

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.
@@ -1,8 +1,7 @@
1
1
  <%- t.getFirstLineBanner() %>
2
- const { fetcher } = require('<%= t.imports.fetcher %>');
3
- const { createRPC } = require('<%= t.imports.createRPC %>');
2
+ const { createRPC } = require('<%= t.commonImports.createRPC %>');
4
3
  const { schema } = require('./schema.cjs');
5
- const openapi = require('./openapi.json');
4
+ const openapi = require('./openapi.cjs');
6
5
  const { validateOnClient = null } = <%- t.imports.validateOnClient ? `require('${t.imports.validateOnClient}')` : '{}'%>;
7
6
  <% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment) => { %>
8
7
  <% Object.entries(t.segmentMeta[segment.segmentName].reExports).forEach(([reExportWhatCommaDivisible, reExportFrom]) => {
@@ -12,8 +11,8 @@ exports['<%= reExportWhat.split(/\s+as\s+/)[1] ?? reExportWhat %>'] = require('<
12
11
  }) %>
13
12
  <% Object.keys(segment.controllers).forEach((rpcModuleName) => { %>
14
13
  exports.<%= rpcModuleName %> = createRPC(
15
- schema, '<%= segment.segmentName %>', '<%= rpcModuleName %>', fetcher,
16
- { validateOnClient, <%- typeof t.segmentMeta[segment.segmentName].segmentNameOverride === 'string' ? `segmentNameOverride: '${t.segmentMeta[segment.segmentName].segmentNameOverride}', ` : '' %><%- segment.segmentType === 'mixin' ? '' : `apiRoot: '${t.segmentMeta[segment.segmentName].forceApiRoot ?? t.apiRoot}'` %> }
14
+ schema, '<%= segment.segmentName %>', '<%= rpcModuleName %>', require('<%= t.segmentImports[segment.segmentName].fetcher %>').fetcher,
15
+ { validateOnClient: <%= t.segmentImports[segment.segmentName].validateOnClient ? `require('${t.segmentImports[segment.segmentName].validateOnClient}').validateOnClient` : 'undefined' %>, <%- typeof t.segmentMeta[segment.segmentName].segmentNameOverride === 'string' ? `segmentNameOverride: '${t.segmentMeta[segment.segmentName].segmentNameOverride}', ` : '' %><%- segment.segmentType === 'mixin' ? '' : `apiRoot: '${t.segmentMeta[segment.segmentName].forceApiRoot ?? t.apiRoot}'` %> }
17
16
  );
18
17
  <% })
19
18
  }) %>
@@ -1,8 +1,6 @@
1
-
2
1
  <%- t.getFirstLineBanner() %>
3
2
  import type { VovkClientFetcher } from 'vovk';
4
- import type { fetcher } from '<%= t.imports.module.fetcher %>';
5
- import type { createRPC } from '<%= t.imports.module.createRPC %>';
3
+ import type { createRPC } from '<%= t.commonImports.module.createRPC %>';
6
4
  <% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { if(segment.segmentType !== 'mixin') { %>
7
5
  import type { Controllers as Controllers<%= i %> } from "<%= t.segmentMeta[segment.segmentName].segmentImportPath %>";
8
6
  <% }}) %>
@@ -10,17 +8,16 @@ import type { Controllers as Controllers<%= i %> } from "<%= t.segmentMeta[segme
10
8
  import type { Controllers as MixinControllers, Mixins } from "./mixins";
11
9
  <% } %>
12
10
 
13
- type Options = typeof fetcher extends VovkClientFetcher<infer U> ? U : never;
14
11
  <% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { %>
15
12
  <% Object.entries(t.segmentMeta[segment.segmentName].reExports).forEach(([reExportWhat, reExportFrom]) => { %>
16
13
  export { <%= reExportWhat %> } from '<%= reExportFrom %>';
17
14
  <% }) %>
18
15
  <% Object.keys(segment.controllers).forEach((rpcModuleName) => { %>
19
- export const <%= rpcModuleName %>: ReturnType<typeof createRPC<<%= segment.segmentType === 'mixin' ? `MixinControllers` : `Controllers${i}` %>["<%= rpcModuleName %>"], Options>>;
16
+ export const <%= rpcModuleName %>: ReturnType<typeof createRPC<<%= segment.segmentType === 'mixin' ? `MixinControllers` : `Controllers${i}` %>["<%= rpcModuleName %>"], typeof import('<%- t.segmentImports[segment.segmentName].module.fetcher %>').fetcher extends VovkClientFetcher<infer U> ? U : never>>;
20
17
  <% })
21
18
  }) %>
22
19
  export { schema } from './schema.cjs';
23
- export { default as openapi } from './openapi.json' assert { type: 'json' };
20
+ export { openapi } from './openapi.cjs';
24
21
  <% if (t.hasMixins) { %>
25
22
  export { Mixins };
26
23
  <% } %>
@@ -1,8 +1,6 @@
1
-
2
1
  <%- t.getFirstLineBanner() %>
3
2
  import type { VovkClientFetcher } from 'vovk';
4
- import type { fetcher } from '<%= t.imports.module.fetcher %>';
5
- import type { createRPC } from '<%= t.imports.module.createRPC %>';
3
+ import type { createRPC } from '<%= t.commonImports.module.createRPC %>';
6
4
  <% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { if(segment.segmentType !== 'mixin') { %>
7
5
  import type { Controllers as Controllers<%= i %> } from "<%= t.segmentMeta[segment.segmentName].segmentImportPath %>";
8
6
  <% }}) %>
@@ -10,17 +8,16 @@ import type { Controllers as Controllers<%= i %> } from "<%= t.segmentMeta[segme
10
8
  import type { Controllers as MixinControllers, Mixins } from "./mixins";
11
9
  <% } %>
12
10
 
13
- type Options = typeof fetcher extends VovkClientFetcher<infer U> ? U : never;
14
11
  <% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { %>
15
12
  <% Object.entries(t.segmentMeta[segment.segmentName].reExports).forEach(([reExportWhat, reExportFrom]) => { %>
16
13
  export { <%= reExportWhat %> } from '<%= reExportFrom %>';
17
14
  <% }) %>
18
15
  <% Object.keys(segment.controllers).forEach((rpcModuleName) => { %>
19
- export const <%= rpcModuleName %>: ReturnType<typeof createRPC<<%= segment.segmentType === 'mixin' ? `MixinControllers` : `Controllers${i}` %>["<%= rpcModuleName %>"], Options>>;
16
+ export const <%= rpcModuleName %>: ReturnType<typeof createRPC<<%= segment.segmentType === 'mixin' ? `MixinControllers` : `Controllers${i}` %>["<%= rpcModuleName %>"], typeof import('<%- t.segmentImports[segment.segmentName].module.fetcher %>').fetcher extends VovkClientFetcher<infer U> ? U : never>>;
20
17
  <% })
21
18
  }) %>
22
19
  export { schema } from './schema.cjs';
23
- export { default as openapi } from './openapi.json' with { type: 'json' };
20
+ export { openapi } from './openapi.cjs';
24
21
  <% if (t.hasMixins) { %>
25
22
  export { Mixins };
26
23
  <% } %>
@@ -1,21 +1,15 @@
1
1
  <%- t.getFirstLineBanner() %>
2
- import { fetcher } from '<%= t.imports.module.fetcher %>';
3
- import { createRPC } from '<%= t.imports.module.createRPC %>';
2
+ import { createRPC } from '<%= t.commonImports.module.createRPC %>';
4
3
  import { schema } from './schema.cjs';
5
- import openapi from './openapi.json' with { type: 'json' };
6
- <% if (t.imports.module.validateOnClient) { %>
7
- import { validateOnClient } from '<%= t.imports.module.validateOnClient %>';
8
- <% } else { %>
9
- const validateOnClient = undefined;
10
- <% }
11
- Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { %>
4
+ import { openapi } from './openapi.cjs';
5
+ <% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { %>
12
6
  <% Object.entries(t.segmentMeta[segment.segmentName].reExports).forEach(([reExportWhat, reExportFrom]) => { %>
13
7
  export { <%= reExportWhat %> } from '<%= reExportFrom %>';
14
8
  <% }) %>
15
9
  <% Object.keys(segment.controllers).forEach((rpcModuleName) => { %>
16
10
  export const <%= rpcModuleName %> = createRPC(
17
- schema, '<%= segment.segmentName %>', '<%= rpcModuleName %>', fetcher,
18
- { validateOnClient, <%- typeof t.segmentMeta[segment.segmentName].segmentNameOverride === 'string' ? `segmentNameOverride: '${t.segmentMeta[segment.segmentName].segmentNameOverride}', ` : '' %><%- segment.segmentType === 'mixin' ? '' : `apiRoot: '${t.segmentMeta[segment.segmentName].forceApiRoot ?? t.apiRoot}'` %> }
11
+ schema, '<%= segment.segmentName %>', '<%= rpcModuleName %>', import('<%- t.segmentImports[segment.segmentName].module.fetcher %>'),
12
+ { validateOnClient: <%- t.segmentImports[segment.segmentName].module.validateOnClient ? `import('${t.segmentImports[segment.segmentName].validateOnClient}')` : 'undefined' %>, <%- typeof t.segmentMeta[segment.segmentName].segmentNameOverride === 'string' ? `segmentNameOverride: '${t.segmentMeta[segment.segmentName].segmentNameOverride}', ` : '' %><%- segment.segmentType === 'mixin' ? '' : `apiRoot: '${t.segmentMeta[segment.segmentName].forceApiRoot ?? t.apiRoot}'` %> }
19
13
  );
20
14
  <%
21
15
  });
@@ -0,0 +1,4 @@
1
+ <%- t.getFirstLineBanner() %>
2
+ const openapi = require('./openapi.json');
3
+
4
+ module.exports.openapi = openapi;
@@ -0,0 +1,4 @@
1
+ <%- t.getFirstLineBanner() %>
2
+ import type { OpenAPIObject } from 'openapi3-ts/oas31';
3
+
4
+ export const openapi: OpenAPIObject;
@@ -0,0 +1,4 @@
1
+ <%- t.getFirstLineBanner() %>
2
+ import openapi from './openapi.json' with { type: "json" };
3
+
4
+ export { openapi };
@@ -1,30 +1,23 @@
1
1
  <%- t.getFirstLineBanner() %>
2
2
  import type { VovkClientFetcher } from 'vovk';
3
- import { fetcher } from '<%= t.imports.fetcher %>';
4
- import { createRPC } from '<%= t.imports.createRPC %>';
3
+ import { createRPC } from '<%= t.commonImports.module.createRPC %>';
5
4
  import { schema } from './schema<%= t.nodeNextResolutionExt.ts %>';
6
- import openapi from './openapi.json' with { type: 'json' };
5
+ import { openapi } from './openapi<%= t.nodeNextResolutionExt.cjs %>';
7
6
  <% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { if(segment.segmentType !== 'mixin') { %>
8
7
  import type { Controllers as Controllers<%= i %> } from "<%= t.segmentMeta[segment.segmentName].segmentImportPath %>";
9
8
  <% }
10
9
  });
11
10
  if (t.hasMixins) { %>
12
11
  import type { Controllers as MixinControllers, Mixins } from "./mixins.d.ts";
13
- <% }
14
- if (t.imports.validateOnClient) { %>
15
- import { validateOnClient } from '<%= t.imports.validateOnClient %>';
16
- <% } else { %>
17
- const validateOnClient = undefined;
18
12
  <% } %>
19
- type Options = typeof fetcher extends VovkClientFetcher<infer U> ? U : never;
20
13
  <% Object.values(t.schema.segments).filter((segment) => segment.emitSchema).forEach((segment, i) => { %>
21
14
  <% Object.entries(t.segmentMeta[segment.segmentName].reExports).forEach(([reExportWhat, reExportFrom]) => { %>
22
15
  export { <%= reExportWhat %> } from '<%= reExportFrom %>';
23
16
  <% }) %>
24
17
  <% Object.keys(segment.controllers).forEach((rpcModuleName) => { %>
25
- export const <%= rpcModuleName %> = createRPC<<%= segment.segmentType === 'mixin' ? `MixinControllers` : `Controllers${i}` %>["<%= rpcModuleName %>"], Options>(
26
- schema, '<%= segment.segmentName %>', '<%= rpcModuleName %>', fetcher,
27
- { validateOnClient, <%- typeof t.segmentMeta[segment.segmentName].segmentNameOverride === 'string' ? `segmentNameOverride: '${t.segmentMeta[segment.segmentName].segmentNameOverride}', ` : '' %><%- segment.segmentType === 'mixin' ? '' : `apiRoot: '${t.segmentMeta[segment.segmentName].forceApiRoot ?? t.apiRoot}'` %> }
18
+ export const <%= rpcModuleName %> = createRPC<<%= segment.segmentType === 'mixin' ? `MixinControllers` : `Controllers${i}` %>["<%= rpcModuleName %>"], typeof import('<%- t.segmentImports[segment.segmentName].module.fetcher %>').fetcher extends VovkClientFetcher<infer U> ? U : never>(
19
+ schema, '<%= segment.segmentName %>', '<%= rpcModuleName %>', import('<%- t.segmentImports[segment.segmentName].module.fetcher %>'),
20
+ { validateOnClient: <%- t.segmentImports[segment.segmentName].module.validateOnClient ? `import('${t.segmentImports[segment.segmentName].validateOnClient}')` : 'undefined' %>, <%- typeof t.segmentMeta[segment.segmentName].segmentNameOverride === 'string' ? `segmentNameOverride: '${t.segmentMeta[segment.segmentName].segmentNameOverride}', ` : '' %><%- segment.segmentType === 'mixin' ? '' : `apiRoot: '${t.segmentMeta[segment.segmentName].forceApiRoot ?? t.apiRoot}'` %> }
28
21
  );
29
22
  <% })
30
23
  }) %>
@@ -1,5 +1,6 @@
1
1
  import { VovkSchemaIdEnum } from 'vovk';
2
2
  import { generate } from './generate.mjs';
3
+ import getMetaSchema from '../getProjectInfo/getMetaSchema.mjs';
3
4
  const getEmptySegmentRecordSchema = (segmentNames) => {
4
5
  const result = {};
5
6
  for (const segmentName of segmentNames) {
@@ -20,12 +21,7 @@ export default async function ensureClient(projectInfo, locatedSegments) {
20
21
  fullSchema: {
21
22
  $schema: VovkSchemaIdEnum.SCHEMA,
22
23
  segments: getEmptySegmentRecordSchema(locatedSegments.map(({ segmentName }) => segmentName)),
23
- meta: {
24
- $schema: VovkSchemaIdEnum.META,
25
- config: {
26
- $schema: VovkSchemaIdEnum.CONFIG,
27
- },
28
- },
24
+ meta: getMetaSchema({ config: projectInfo.config, package: projectInfo.packageJson }),
29
25
  },
30
26
  locatedSegments,
31
27
  });
@@ -7,7 +7,6 @@ import getClientTemplateFiles from './getClientTemplateFiles.mjs';
7
7
  import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
8
8
  import pickSegmentFullSchema from '../utils/pickSegmentFullSchema.mjs';
9
9
  import removeUnlistedDirectories from '../utils/removeUnlistedDirectories.mjs';
10
- import getTemplateClientImports from './getTemplateClientImports.mjs';
11
10
  import writeOneClientFile, { normalizeOutTemplatePath } from './writeOneClientFile.mjs';
12
11
  import { ROOT_SEGMENT_FILE_NAME } from '../dev/writeOneSegmentSchemaFile.mjs';
13
12
  import { getTsconfig } from 'get-tsconfig';
@@ -134,15 +133,11 @@ export async function generate({ isEnsuringClient = false, isBundle = false, pro
134
133
  const matterResult = templateFilePath.endsWith('.ejs')
135
134
  ? matter(templateContent)
136
135
  : { data: { imports: [] }, content: templateContent };
137
- const clientImports = await getTemplateClientImports({
138
- config,
139
- fullSchema,
140
- outCwdRelativeDir,
141
- });
142
136
  const { package: packageJson, readme, origin, snippets, } = getGeneratorConfig({
143
137
  schema: fullSchema,
144
138
  config: templateDef.generatorConfig,
145
139
  isBundle,
140
+ segmentName: null,
146
141
  });
147
142
  const openapi = vovkSchemaToOpenAPI({
148
143
  schema: fullSchema,
@@ -160,7 +155,6 @@ export async function generate({ isEnsuringClient = false, isBundle = false, pro
160
155
  fullSchema: composedFullSchema,
161
156
  prettifyClient: config.composedClient.prettifyClient,
162
157
  segmentName: null,
163
- imports: clientImports.composedClient,
164
158
  templateContent,
165
159
  matterResult,
166
160
  openapi,
@@ -177,6 +171,7 @@ export async function generate({ isEnsuringClient = false, isBundle = false, pro
177
171
  vovkCliPackage,
178
172
  isBundle,
179
173
  origin: cliGenerateOptions?.origin ?? origin,
174
+ configKey: 'composedClient',
180
175
  });
181
176
  const outAbsoluteDir = path.resolve(cwd, outCwdRelativeDir);
182
177
  return {
@@ -217,11 +212,6 @@ export async function generate({ isEnsuringClient = false, isBundle = false, pro
217
212
  const matterResult = templateFilePath.endsWith('.ejs')
218
213
  ? matter(templateContent)
219
214
  : { data: { imports: [] }, content: templateContent };
220
- const clientImports = await getTemplateClientImports({
221
- config,
222
- fullSchema,
223
- outCwdRelativeDir,
224
- });
225
215
  const results = await Promise.all(segmentNames.map(async (segmentName) => {
226
216
  const { package: packageJson, readme, origin, snippets, } = getGeneratorConfig({
227
217
  schema: fullSchema,
@@ -246,7 +236,6 @@ export async function generate({ isEnsuringClient = false, isBundle = false, pro
246
236
  fullSchema: segmentedFullSchema,
247
237
  prettifyClient: config.segmentedClient.prettifyClient,
248
238
  segmentName,
249
- imports: clientImports.segmentedClient[segmentName],
250
239
  templateContent,
251
240
  matterResult,
252
241
  openapi,
@@ -263,6 +252,7 @@ export async function generate({ isEnsuringClient = false, isBundle = false, pro
263
252
  vovkCliPackage,
264
253
  isBundle,
265
254
  origin: cliGenerateOptions?.origin ?? origin,
255
+ configKey: 'segmentedClient',
266
256
  });
267
257
  return {
268
258
  written,
@@ -1,6 +1,6 @@
1
1
  import { VovkStrictConfig, type VovkSchema } from 'vovk';
2
2
  import type { ProjectInfo } from '../getProjectInfo/index.mjs';
3
- import { PackageJson } from 'type-fest';
3
+ import type { PackageJson } from 'type-fest';
4
4
  export declare function getProjectFullSchema({ schemaOutAbsolutePath, isNextInstalled, log, package: packageJson, config, }: {
5
5
  schemaOutAbsolutePath: string;
6
6
  isNextInstalled: boolean;
@@ -1,13 +1,14 @@
1
- import type { VovkSchema, VovkStrictConfig } from 'vovk';
1
+ import { type VovkSchema } from 'vovk';
2
2
  export type ClientImports = {
3
3
  fetcher: string;
4
4
  validateOnClient: string | null;
5
5
  createRPC: string;
6
6
  };
7
- export default function getTemplateClientImports({ config, fullSchema, outCwdRelativeDir, }: {
8
- config: VovkStrictConfig;
7
+ export default function getTemplateClientImports({ fullSchema, outCwdRelativeDir, segmentName, isBundle, }: {
9
8
  fullSchema: VovkSchema;
10
9
  outCwdRelativeDir: string;
10
+ segmentName: string | null;
11
+ isBundle: boolean;
11
12
  }): {
12
13
  composedClient: ClientImports & {
13
14
  module: ClientImports;
@@ -1,7 +1,8 @@
1
1
  import path from 'node:path';
2
+ import { getGeneratorConfig } from 'vovk';
2
3
  import { ROOT_SEGMENT_FILE_NAME } from '../dev/writeOneSegmentSchemaFile.mjs';
3
- export default function getTemplateClientImports({ config, fullSchema, outCwdRelativeDir, }) {
4
- const { imports } = config;
4
+ export default function getTemplateClientImports({ fullSchema, outCwdRelativeDir, segmentName, isBundle, }) {
5
+ const { imports } = getGeneratorConfig({ schema: fullSchema, segmentName, isBundle });
5
6
  const getImportPath = (p, s = '') => p.startsWith('.') ? path.relative(path.join(outCwdRelativeDir, s), p) : p;
6
7
  const clientImports = {
7
8
  composedClient: {
@@ -2,18 +2,16 @@ import { VovkReadmeConfig, VovkSnippetsConfig, type VovkSchema, type VovkStrictC
2
2
  import type { PackageJson } from 'type-fest';
3
3
  import type { ProjectInfo } from '../getProjectInfo/index.mjs';
4
4
  import type { ClientTemplateFile } from './getClientTemplateFiles.mjs';
5
- import type { ClientImports } from './getTemplateClientImports.mjs';
6
5
  import type { Segment } from '../locateSegments.mjs';
7
6
  import { OpenAPIObject } from 'openapi3-ts/oas31';
8
7
  export declare function normalizeOutTemplatePath(out: string, packageJson: PackageJson): string;
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, }: {
8
+ export default function writeOneClientFile({ cwd, projectInfo, clientTemplateFile, fullSchema, prettifyClient, segmentName, templateContent, matterResult: { data, content }, openapi, package: packageJson, readme, snippets, isEnsuringClient, outCwdRelativeDir, locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage, isBundle, origin, configKey, }: {
10
9
  cwd: string;
11
10
  projectInfo: ProjectInfo;
12
11
  clientTemplateFile: ClientTemplateFile;
13
12
  fullSchema: VovkSchema;
14
13
  prettifyClient: boolean;
15
14
  segmentName: string | null;
16
- imports: ClientImports;
17
15
  templateContent: string;
18
16
  matterResult: {
19
17
  data: {
@@ -35,6 +33,7 @@ export default function writeOneClientFile({ cwd, projectInfo, clientTemplateFil
35
33
  vovkCliPackage: PackageJson;
36
34
  isBundle: boolean;
37
35
  origin: string | null;
36
+ configKey: 'composedClient' | 'segmentedClient';
38
37
  }): Promise<{
39
38
  written: boolean;
40
39
  }>;
@@ -8,19 +8,24 @@ import TOML from '@iarna/toml';
8
8
  import prettify from '../utils/prettify.mjs';
9
9
  import { ROOT_SEGMENT_FILE_NAME } from '../dev/writeOneSegmentSchemaFile.mjs';
10
10
  import { compileJSONSchemaToTypeScriptType } from '../utils/compileJSONSchemaToTypeScriptType.mjs';
11
+ import getTemplateClientImports from './getTemplateClientImports.mjs';
11
12
  export function normalizeOutTemplatePath(out, packageJson) {
12
13
  return out.replace('[package_name]', packageJson.name?.replace(/-/g, '_') ?? 'my_package_name');
13
14
  }
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
+ export default async function writeOneClientFile({ cwd, projectInfo, clientTemplateFile, fullSchema, prettifyClient, segmentName,
16
+ // imports,
17
+ templateContent, matterResult: { data, content }, openapi, package: packageJson, readme, snippets, isEnsuringClient, outCwdRelativeDir,
15
18
  // templateDef,
16
- locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage, isBundle, origin, }) {
19
+ locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage, isBundle, origin, configKey, }) {
17
20
  const { config, apiRoot } = projectInfo;
18
21
  const { templateFilePath, relativeDir } = clientTemplateFile;
19
22
  const locatedSegmentsByName = _.keyBy(locatedSegments, 'segmentName');
20
23
  const outPath = normalizeOutTemplatePath(path.resolve(cwd, outCwdRelativeDir, typeof segmentName === 'string' ? segmentName || ROOT_SEGMENT_FILE_NAME : '', relativeDir, path.basename(templateFilePath).replace('.ejs', '')), packageJson);
21
- let placeholder = `// This is a temporary placeholder to avoid compilation errors if client is imported before it's generated.
24
+ let placeholder = !templateFilePath.endsWith('.json.ejs')
25
+ ? `// This is a temporary placeholder to avoid compilation errors if client is imported before it's generated.
22
26
  // If you still see this text, the client is not generated yet because of an unknown problem.
23
- // Feel free to report an issue at https://github.com/finom/vovk/issues`;
27
+ // Feel free to report an issue at https://github.com/finom/vovk/issues`
28
+ : '{}';
24
29
  placeholder = outPath.endsWith('.py') ? placeholder.replace(/\/\//g, '#') : placeholder;
25
30
  const getFirstLineBanner = (type = 'c') => {
26
31
  const text = `auto-generated by vovk-cli v${vovkCliPackage.version} at ${new Date().toISOString()}`;
@@ -44,7 +49,7 @@ locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage,
44
49
  openapi,
45
50
  ROOT_SEGMENT_FILE_NAME,
46
51
  apiRoot: origin ? `${origin}/${config.rootEntry}` : apiRoot,
47
- imports,
52
+ imports: {},
48
53
  schema: fullSchema,
49
54
  VovkSchemaIdEnum,
50
55
  createCodeExamples,
@@ -61,6 +66,12 @@ locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage,
61
66
  schemaOutDir: typeof segmentName === 'string'
62
67
  ? path.relative(path.join(outCwdRelativeDir, segmentName || ROOT_SEGMENT_FILE_NAME), config.schemaOutDir)
63
68
  : path.relative(outCwdRelativeDir, config.schemaOutDir),
69
+ commonImports: getTemplateClientImports({ fullSchema, isBundle, outCwdRelativeDir, segmentName })['composedClient'],
70
+ segmentImports: Object.fromEntries(Object.values(fullSchema.segments).map(({ segmentName: sName }) => {
71
+ const clientImports = getTemplateClientImports({ fullSchema, segmentName: sName, isBundle, outCwdRelativeDir });
72
+ const imports = configKey === 'composedClient' ? clientImports['composedClient'] : clientImports['segmentedClient'][sName];
73
+ return [sName, imports];
74
+ })),
64
75
  segmentMeta: Object.fromEntries(Object.values(fullSchema.segments).map(({ segmentName: sName, forceApiRoot }) => {
65
76
  const { routeFilePath = null } = locatedSegmentsByName[sName] ?? {};
66
77
  const segmentImportPath = routeFilePath
@@ -95,7 +106,6 @@ locatedSegments, isNodeNextResolution, hasMixins, isVovkProject, vovkCliPackage,
95
106
  if (data.imports instanceof Array) {
96
107
  for (const imp of data.imports) {
97
108
  t.imports = {
98
- ...t.imports,
99
109
  [imp]: await import(imp),
100
110
  };
101
111
  }
@@ -6,10 +6,11 @@ export declare enum BuiltInTemplateName {
6
6
  schemaTs = "schemaTs",
7
7
  schemaCjs = "schemaCjs",
8
8
  schemaJson = "schemaJson",
9
- standaloneTypesTs = "standaloneTypesTs",
9
+ openapiTs = "openapiTs",
10
+ openapiCjs = "openapiCjs",
11
+ openapiJson = "openapiJson",
10
12
  readme = "readme",
11
13
  packageJson = "packageJson",
12
- openapiJson = "openapiJson",
13
14
  mixins = "mixins",
14
15
  rsSrc = "rsSrc",
15
16
  rsPkg = "rsPkg",
@@ -8,12 +8,13 @@ export var BuiltInTemplateName;
8
8
  BuiltInTemplateName["schemaTs"] = "schemaTs";
9
9
  BuiltInTemplateName["schemaCjs"] = "schemaCjs";
10
10
  BuiltInTemplateName["schemaJson"] = "schemaJson";
11
- // types
12
- BuiltInTemplateName["standaloneTypesTs"] = "standaloneTypesTs";
11
+ // openapi
12
+ BuiltInTemplateName["openapiTs"] = "openapiTs";
13
+ BuiltInTemplateName["openapiCjs"] = "openapiCjs";
14
+ BuiltInTemplateName["openapiJson"] = "openapiJson";
13
15
  // misc
14
16
  BuiltInTemplateName["readme"] = "readme";
15
17
  BuiltInTemplateName["packageJson"] = "packageJson";
16
- BuiltInTemplateName["openapiJson"] = "openapiJson";
17
18
  BuiltInTemplateName["mixins"] = "mixins";
18
19
  // other languages (packages installed separately)
19
20
  BuiltInTemplateName["rsSrc"] = "rsSrc";
@@ -28,28 +29,43 @@ export var BuiltInTemplateName;
28
29
  export default function getTemplateDefs(userTemplateDefs = {}) {
29
30
  const defs = {};
30
31
  const builtInDefs = {
32
+ [BuiltInTemplateName.openapiTs]: {
33
+ templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.openapiTs}/`,
34
+ requires: {
35
+ [BuiltInTemplateName.openapiJson]: './',
36
+ },
37
+ },
38
+ [BuiltInTemplateName.openapiCjs]: {
39
+ templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.openapiCjs}/`,
40
+ requires: {
41
+ [BuiltInTemplateName.openapiJson]: './',
42
+ },
43
+ },
44
+ [BuiltInTemplateName.openapiJson]: {
45
+ templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.openapiJson}/`,
46
+ },
31
47
  [BuiltInTemplateName.ts]: {
32
48
  templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.ts}/`,
33
49
  requires: {
34
- [BuiltInTemplateName.schemaTs]: '.',
35
- [BuiltInTemplateName.openapiJson]: '.',
36
- [BuiltInTemplateName.mixins]: '.', // used conditionally if OpenAPI mixins are used
50
+ [BuiltInTemplateName.schemaTs]: './',
51
+ [BuiltInTemplateName.openapiTs]: './',
52
+ [BuiltInTemplateName.mixins]: './', // used conditionally if OpenAPI mixins are used
37
53
  },
38
54
  },
39
55
  [BuiltInTemplateName.cjs]: {
40
56
  templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.cjs}/`,
41
57
  requires: {
42
- [BuiltInTemplateName.schemaCjs]: '.',
43
- [BuiltInTemplateName.openapiJson]: '.',
44
- [BuiltInTemplateName.mixins]: '.', // used conditionally if OpenAPI mixins are used
58
+ [BuiltInTemplateName.schemaCjs]: './',
59
+ [BuiltInTemplateName.openapiCjs]: './',
60
+ [BuiltInTemplateName.mixins]: './', // used conditionally if OpenAPI mixins are used
45
61
  },
46
62
  },
47
63
  [BuiltInTemplateName.mjs]: {
48
64
  templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.mjs}/`,
49
65
  requires: {
50
- [BuiltInTemplateName.schemaCjs]: '.',
51
- [BuiltInTemplateName.openapiJson]: '.',
52
- [BuiltInTemplateName.mixins]: '.', // used conditionally if OpenAPI mixins are used
66
+ [BuiltInTemplateName.schemaCjs]: './',
67
+ [BuiltInTemplateName.openapiCjs]: './',
68
+ [BuiltInTemplateName.mixins]: './', // used conditionally if OpenAPI mixins are used
53
69
  },
54
70
  },
55
71
  [BuiltInTemplateName.schemaTs]: {
@@ -67,9 +83,6 @@ export default function getTemplateDefs(userTemplateDefs = {}) {
67
83
  [BuiltInTemplateName.packageJson]: {
68
84
  templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.packageJson}/`,
69
85
  },
70
- [BuiltInTemplateName.openapiJson]: {
71
- templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.openapiJson}/`,
72
- },
73
86
  [BuiltInTemplateName.mixins]: {
74
87
  templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.mixins}/`,
75
88
  },
@@ -98,7 +111,7 @@ export default function getTemplateDefs(userTemplateDefs = {}) {
98
111
  [BuiltInTemplateName.pySrc]: {
99
112
  templatePath: `vovk-python/client-templates/${BuiltInTemplateName.pySrc}/`,
100
113
  requires: {
101
- [BuiltInTemplateName.schemaJson]: '.',
114
+ [BuiltInTemplateName.schemaJson]: './',
102
115
  },
103
116
  },
104
117
  [BuiltInTemplateName.pyPkg]: {
@@ -58,11 +58,6 @@ export default function getConfig({ configPath, cwd, logLevel, }: {
58
58
  includeSegments?: never;
59
59
  });
60
60
  clientTemplateDefs?: Record<string, import("vovk/types").ClientTemplateDef>;
61
- imports?: {
62
- fetcher?: string | [string, string] | [string];
63
- validateOnClient?: string | [string, string] | [string];
64
- createRPC?: string | [string, string] | [string];
65
- };
66
61
  rootSegmentModulesDirName?: string;
67
62
  moduleTemplates?: {
68
63
  service?: string;
@@ -17,9 +17,9 @@ export default async function getConfig({ configPath, cwd, logLevel, }) {
17
17
  const env = process.env;
18
18
  const clientTemplateDefs = getTemplateDefs(conf.clientTemplateDefs);
19
19
  const srcRoot = await getRelativeSrcRoot({ cwd });
20
- const validateOnClientImport = conf.imports?.validateOnClient ?? null;
21
- const fetcherImport = conf.imports?.fetcher ?? 'vovk';
22
- const createRPCImport = conf.imports?.createRPC ?? 'vovk';
20
+ const validateOnClientImport = conf.generatorConfig?.imports?.validateOnClient ?? null;
21
+ const fetcherImport = conf.generatorConfig?.imports?.fetcher ?? 'vovk';
22
+ const createRPCImport = conf.generatorConfig?.imports?.createRPC ?? 'vovk';
23
23
  const imports = {
24
24
  fetcher: typeof fetcherImport === 'string' ? [fetcherImport] : fetcherImport,
25
25
  validateOnClient: typeof validateOnClientImport === 'string'
@@ -30,7 +30,6 @@ export default async function getConfig({ configPath, cwd, logLevel, }) {
30
30
  const config = {
31
31
  $schema: VovkSchemaIdEnum.CONFIG,
32
32
  clientTemplateDefs,
33
- imports,
34
33
  emitConfig: [],
35
34
  composedClient: {
36
35
  ...conf.composedClient,
@@ -75,6 +74,7 @@ export default async function getConfig({ configPath, cwd, logLevel, }) {
75
74
  libs: conf.libs ?? {},
76
75
  generatorConfig: {
77
76
  ...conf.generatorConfig,
77
+ imports,
78
78
  origin: (env.VOVK_ORIGIN ?? conf?.generatorConfig?.origin ?? '').replace(/\/$/, ''), // Remove trailing slash
79
79
  segments: Object.fromEntries(await Promise.all(Object.entries(conf.generatorConfig?.segments ?? {}).map(async ([key, value]) => [
80
80
  key,
@@ -24,6 +24,7 @@ export default function getMetaSchema({ config, package: packageJson, }: {
24
24
  './openapi': {
25
25
  import: string;
26
26
  require: string;
27
+ types: string;
27
28
  };
28
29
  };
29
30
  name?: string | undefined;
@@ -20,9 +20,10 @@ export default function getMetaSchema({ config, package: packageJson, }) {
20
20
  types: './schema.d.cts',
21
21
  },
22
22
  './openapi': {
23
- import: './openapi.json',
24
- require: './openapi.json',
25
- },
23
+ import: './openapi.cjs',
24
+ require: './openapi.cjs',
25
+ types: './openapi.d.cts',
26
+ }
26
27
  },
27
28
  },
28
29
  ...{
@@ -36,8 +36,10 @@ export default async function createConfig({ root, log, options: { validationLib
36
36
  },
37
37
  }[validationLibrary ?? 'type'],
38
38
  };
39
- config.imports ??= {};
40
- config.imports.validateOnClient = validationLibrary === 'class-validator' ? 'vovk-dto/validateOnClient' : 'vovk-ajv';
39
+ config.generatorConfig ??= {};
40
+ config.generatorConfig.imports ??= {};
41
+ config.generatorConfig.imports.validateOnClient =
42
+ validationLibrary === 'class-validator' ? 'vovk-dto/validateOnClient' : 'vovk-ajv';
41
43
  if (validationLibrary && !moduleTemplates) {
42
44
  try {
43
45
  // TODO: Legacy, is it useful to keep it?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk-cli",
3
- "version": "0.0.1-draft.339",
3
+ "version": "0.0.1-draft.340",
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.401"
38
+ "vovk": "^3.0.0-draft.405"
39
39
  },
40
40
  "optionalDependencies": {
41
41
  "@rolldown/binding-linux-x64-gnu": "1.0.0-beta.31"