vovk-cli 0.0.1-draft.304 → 0.0.1-draft.307

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
+ import type { DevOptions } from '../types.mjs';
1
2
  export declare class VovkDev {
2
3
  #private;
3
- constructor({ schemaOut }: {
4
- schemaOut: string | undefined;
5
- });
4
+ constructor({ schemaOut, devHttps }: Pick<DevOptions, 'schemaOut' | 'devHttps'>);
6
5
  start({ exit }: {
7
6
  exit: boolean;
8
7
  }): Promise<void>;
@@ -36,8 +36,10 @@ export class VovkDev {
36
36
  #segmentWatcher = null;
37
37
  #onFirstTimeGenerate = null;
38
38
  #schemaOut = null;
39
- constructor({ schemaOut }) {
39
+ #devHttps;
40
+ constructor({ schemaOut, devHttps }) {
40
41
  this.#schemaOut = schemaOut ?? null;
42
+ this.#devHttps = devHttps ?? false;
41
43
  }
42
44
  #watchSegments = (callback) => {
43
45
  const segmentReg = /\/?\[\[\.\.\.[a-zA-Z-_]+\]\]\/route.ts$/;
@@ -252,7 +254,7 @@ export class VovkDev {
252
254
  };
253
255
  #requestSchema = debounceWithArgs(async (segmentName) => {
254
256
  const { apiRoot, log, port, config } = this.#projectInfo;
255
- const { devHttps } = config;
257
+ const devHttps = this.#devHttps ?? config.devHttps;
256
258
  const endpoint = `${apiRoot.startsWith(`http${devHttps ? 's' : ''}://`) ? apiRoot : `http${devHttps ? 's' : ''}://localhost:${port}${apiRoot}`}/${segmentName ? `${segmentName}/` : ''}_schema_`;
257
259
  log.debug(`Requesting schema for ${formatLoggedSegmentName(segmentName)} at ${endpoint}`);
258
260
  try {
@@ -326,7 +328,8 @@ export class VovkDev {
326
328
  log.info('The schemas and the RPC client have been generated. Exiting...');
327
329
  });
328
330
  }
329
- if (config.devHttps) {
331
+ const devHttps = this.#devHttps ?? config.devHttps;
332
+ if (devHttps) {
330
333
  const agent = new Agent({
331
334
  connect: {
332
335
  rejectUnauthorized: false,
@@ -382,7 +385,10 @@ export class VovkDev {
382
385
  }
383
386
  const env = process.env;
384
387
  if (env.__VOVK_START_WATCHER_IN_STANDALONE_MODE__ === 'true') {
385
- void new VovkDev({ schemaOut: env.__VOVK_SCHEMA_OUT_FLAG__ || undefined }).start({
388
+ void new VovkDev({
389
+ schemaOut: env.__VOVK_SCHEMA_OUT_FLAG__ || undefined,
390
+ devHttps: env.__VOVK_DEV_HTTPS_FLAG__ === 'true',
391
+ }).start({
386
392
  exit: env.__VOVK_EXIT__ === 'true',
387
393
  });
388
394
  }
@@ -5,7 +5,7 @@ import { META_FILE_NAME } from './writeOneSegmentSchemaFile.mjs';
5
5
  import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
6
6
  export default async function writeMetaJson(schemaOutAbsolutePath, projectInfo) {
7
7
  const metaJsonPath = path.join(schemaOutAbsolutePath, META_FILE_NAME + '.json');
8
- const metaStr = JSON.stringify({ config: projectInfo ? pick(projectInfo.config, projectInfo.config.emitConfig) : {} }, null, 2);
8
+ const metaStr = JSON.stringify({ config: projectInfo ? pick(projectInfo.config, [...projectInfo.config.emitConfig, '$schema']) : {} }, null, 2);
9
9
  const existingStr = await fs.readFile(metaJsonPath, 'utf-8').catch(() => null);
10
10
  if (existingStr !== metaStr) {
11
11
  await fs.writeFile(metaJsonPath, metaStr);
@@ -3,7 +3,6 @@ import { glob } from 'glob';
3
3
  import resolveAbsoluteModulePath from '../utils/resolveAbsoluteModulePath.mjs';
4
4
  import getFileSystemEntryType, { FileSystemEntryType } from '../utils/getFileSystemEntryType.mjs';
5
5
  import getPublicModuleNameFromPath from '../utils/getPublicModuleNameFromPath.mjs';
6
- import { BuiltInTemplateName } from '../getProjectInfo/getConfig/getTemplateDefs.mjs';
7
6
  export default async function getClientTemplateFiles({ config, cwd, log, configKey, cliGenerateOptions, }) {
8
7
  const usedTemplateDefs = {};
9
8
  const fromTemplates = configKey === 'composedClient'
@@ -19,19 +18,8 @@ export default async function getClientTemplateFiles({ config, cwd, log, configK
19
18
  if (!(templateName in config.clientTemplateDefs)) {
20
19
  throw new Error(`Unknown template name: ${templateName}`);
21
20
  }
22
- let usedDef = config.clientTemplateDefs[templateName];
23
- if (usedDef.isTsClient) {
24
- usedDef = {
25
- ...usedDef,
26
- requires: {
27
- ...usedDef.requires,
28
- [BuiltInTemplateName.mixins]: '.',
29
- },
30
- };
31
- }
32
- usedTemplateDefs[templateName] = usedDef;
21
+ usedTemplateDefs[templateName] = config.clientTemplateDefs[templateName];
33
22
  }
34
- // $openapi['github']['components']['schemas']['User'];
35
23
  const templateFiles = [];
36
24
  const entries = Object.entries(usedTemplateDefs);
37
25
  for (let i = 0; i < entries.length; i++) {
@@ -12,9 +12,11 @@ export declare enum BuiltInTemplateName {
12
12
  mixins = "mixins",
13
13
  rsSrc = "rsSrc",
14
14
  rsPkg = "rsPkg",
15
+ rsReadme = "rsReadme",
15
16
  rs = "rs",
16
17
  pySrc = "pySrc",
17
18
  pyPkg = "pyPkg",
19
+ pyReadme = "pyReadme",
18
20
  py = "py"
19
21
  }
20
22
  export default function getTemplateDefs(userTemplateDefs?: VovkStrictConfig['clientTemplateDefs']): VovkStrictConfig['clientTemplateDefs'];
@@ -17,9 +17,11 @@ export var BuiltInTemplateName;
17
17
  // other languages (packages installed separately)
18
18
  BuiltInTemplateName["rsSrc"] = "rsSrc";
19
19
  BuiltInTemplateName["rsPkg"] = "rsPkg";
20
+ BuiltInTemplateName["rsReadme"] = "rsReadme";
20
21
  BuiltInTemplateName["rs"] = "rs";
21
22
  BuiltInTemplateName["pySrc"] = "pySrc";
22
23
  BuiltInTemplateName["pyPkg"] = "pyPkg";
24
+ BuiltInTemplateName["pyReadme"] = "pyReadme";
23
25
  BuiltInTemplateName["py"] = "py";
24
26
  })(BuiltInTemplateName || (BuiltInTemplateName = {}));
25
27
  export default function getTemplateDefs(userTemplateDefs = {}) {
@@ -27,18 +29,24 @@ export default function getTemplateDefs(userTemplateDefs = {}) {
27
29
  const builtInDefs = {
28
30
  [BuiltInTemplateName.ts]: {
29
31
  templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.ts}/`,
30
- requires: { [BuiltInTemplateName.schemaTs]: '.' },
31
- isTsClient: true,
32
+ requires: {
33
+ [BuiltInTemplateName.schemaTs]: '.',
34
+ [BuiltInTemplateName.mixins]: '.', // used conditionally if OpenAPI mixins are used
35
+ },
32
36
  },
33
37
  [BuiltInTemplateName.cjs]: {
34
38
  templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.cjs}/`,
35
- requires: { [BuiltInTemplateName.schemaCjs]: '.' },
36
- isTsClient: true,
39
+ requires: {
40
+ [BuiltInTemplateName.schemaCjs]: '.',
41
+ [BuiltInTemplateName.mixins]: '.', // used conditionally if OpenAPI mixins are used
42
+ },
37
43
  },
38
44
  [BuiltInTemplateName.mjs]: {
39
45
  templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.mjs}/`,
40
- requires: { [BuiltInTemplateName.schemaCjs]: '.' },
41
- isTsClient: true,
46
+ requires: {
47
+ [BuiltInTemplateName.schemaCjs]: '.',
48
+ [BuiltInTemplateName.mixins]: '.', // used conditionally if OpenAPI mixins are used
49
+ },
42
50
  },
43
51
  [BuiltInTemplateName.schemaTs]: {
44
52
  templatePath: `vovk-cli/client-templates/${BuiltInTemplateName.schemaTs}/`,
@@ -66,6 +74,12 @@ export default function getTemplateDefs(userTemplateDefs = {}) {
66
74
  },
67
75
  [BuiltInTemplateName.rsPkg]: {
68
76
  templatePath: `vovk-rust/client-templates/${BuiltInTemplateName.rsPkg}/`,
77
+ requires: {
78
+ [BuiltInTemplateName.rsReadme]: './',
79
+ },
80
+ },
81
+ [BuiltInTemplateName.rsReadme]: {
82
+ templatePath: `vovk-rust/client-templates/${BuiltInTemplateName.rsReadme}/`,
69
83
  },
70
84
  [BuiltInTemplateName.rs]: {
71
85
  composedClient: {
@@ -84,6 +98,12 @@ export default function getTemplateDefs(userTemplateDefs = {}) {
84
98
  },
85
99
  [BuiltInTemplateName.pyPkg]: {
86
100
  templatePath: `vovk-python/client-templates/${BuiltInTemplateName.pyPkg}/`,
101
+ requires: {
102
+ [BuiltInTemplateName.pyReadme]: './',
103
+ },
104
+ },
105
+ [BuiltInTemplateName.pyReadme]: {
106
+ templatePath: `vovk-python/client-templates/${BuiltInTemplateName.pyReadme}/`,
87
107
  },
88
108
  [BuiltInTemplateName.py]: {
89
109
  composedClient: {
@@ -75,7 +75,7 @@ export default async function getConfig({ configPath, cwd }) {
75
75
  openApiMixins: {},
76
76
  };
77
77
  if (typeof conf.emitConfig === 'undefined') {
78
- config.emitConfig = ['$schema', 'libs'];
78
+ config.emitConfig = ['libs'];
79
79
  }
80
80
  else if (conf.emitConfig === true) {
81
81
  config.emitConfig = Object.keys(config);
package/dist/index.mjs CHANGED
@@ -24,8 +24,9 @@ program
24
24
  .option('--next-dev', 'start schema watcher and Next.js with automatic port allocation')
25
25
  .option('--exit', 'kill the processe when schema and client is generated')
26
26
  .option('--schema-out <path>', 'path to schema output directory (default: .vovk-schema)')
27
+ .option('--https, --dev-https', 'use HTTPS for the dev server (default: false)')
27
28
  .action(async (nextArgs, options) => {
28
- const { nextDev, exit = false, schemaOut } = options;
29
+ const { nextDev, exit = false, schemaOut, devHttps } = options;
29
30
  const portAttempts = 30;
30
31
  const PORT = !nextDev
31
32
  ? process.env.PORT
@@ -52,6 +53,7 @@ program
52
53
  PORT,
53
54
  __VOVK_START_WATCHER_IN_STANDALONE_MODE__: 'true',
54
55
  __VOVK_SCHEMA_OUT_FLAG__: schemaOut ?? '',
56
+ __VOVK_DEV_HTTPS_FLAG__: devHttps ? 'true' : 'false',
55
57
  __VOVK_EXIT__: exit ? 'true' : 'false',
56
58
  },
57
59
  },
@@ -68,7 +70,7 @@ program
68
70
  }
69
71
  }
70
72
  else {
71
- void new VovkDev({ schemaOut }).start({ exit });
73
+ void new VovkDev({ schemaOut, devHttps }).start({ exit });
72
74
  }
73
75
  });
74
76
  program
@@ -1,9 +1,9 @@
1
1
  import type getLogger from '../utils/getLogger.mjs';
2
2
  import type { InitOptions } from '../types.mjs';
3
- export default function createConfig({ root, log, options: { validationLibrary, reactQuery, lang, channel, dryRun }, }: {
3
+ export default function createConfig({ root, log, options: { validationLibrary, lang, channel, dryRun }, }: {
4
4
  root: string;
5
5
  log: ReturnType<typeof getLogger>;
6
- options: Pick<InitOptions, 'validationLibrary' | 'reactQuery' | 'lang' | 'channel' | 'dryRun'>;
6
+ options: Pick<InitOptions, 'validationLibrary' | 'lang' | 'channel' | 'dryRun'>;
7
7
  }): Promise<{
8
8
  configAbsolutePath: string;
9
9
  }>;
@@ -3,7 +3,7 @@ import fs from 'node:fs/promises';
3
3
  import getTemplateFilesFromPackage from './getTemplateFilesFromPackage.mjs';
4
4
  import prettify from '../utils/prettify.mjs';
5
5
  import getFileSystemEntryType, { FileSystemEntryType } from '../utils/getFileSystemEntryType.mjs';
6
- export default async function createConfig({ root, log, options: { validationLibrary, reactQuery, lang, channel, dryRun }, }) {
6
+ export default async function createConfig({ root, log, options: { validationLibrary, lang, channel, dryRun }, }) {
7
7
  const config = {};
8
8
  const dotConfigPath = path.join(root, '.config');
9
9
  const dir = (await getFileSystemEntryType(dotConfigPath)) === FileSystemEntryType.DIRECTORY ? dotConfigPath : root;
@@ -30,10 +30,6 @@ export default async function createConfig({ root, log, options: { validationLib
30
30
  config.composedClient ??= {};
31
31
  config.composedClient.fromTemplates = ['mjs', 'cjs', ...lang];
32
32
  }
33
- if (reactQuery) {
34
- config.imports ??= {};
35
- config.imports.createRPC = 'vovk-react-query';
36
- }
37
33
  config.moduleTemplates = moduleTemplates;
38
34
  const configStr = await prettify(`// @ts-check
39
35
  /** @type {import('vovk').VovkConfig} */
@@ -4,5 +4,5 @@ export declare class Init {
4
4
  #private;
5
5
  root: string;
6
6
  log: ReturnType<typeof getLogger>;
7
- main(prefix: string, { yes, logLevel, useNpm, useYarn, usePnpm, useBun, skipInstall, updateTsConfig, updateScripts, validationLibrary, reactQuery, lang, dryRun, channel, }: InitOptions): Promise<void>;
7
+ main(prefix: string, { yes, logLevel, useNpm, useYarn, usePnpm, useBun, skipInstall, updateTsConfig, updateScripts, validationLibrary, lang, dryRun, channel, }: InitOptions): Promise<void>;
8
8
  }
@@ -17,7 +17,7 @@ import chalkHighlightThing from '../utils/chalkHighlightThing.mjs';
17
17
  export class Init {
18
18
  root;
19
19
  log;
20
- async #init({ configPaths, pkgJson, }, { useNpm, useYarn, usePnpm, useBun, skipInstall, updateTsConfig, updateScripts, validationLibrary, reactQuery, lang, dryRun, channel, }) {
20
+ async #init({ configPaths, pkgJson, }, { useNpm, useYarn, usePnpm, useBun, skipInstall, updateTsConfig, updateScripts, validationLibrary, lang, dryRun, channel, }) {
21
21
  const { log, root } = this;
22
22
  const dependencies = ['vovk', 'vovk-client', 'vovk-ajv', 'openapi3-ts'];
23
23
  const devDependencies = ['vovk-cli'];
@@ -38,9 +38,6 @@ export class Init {
38
38
  'vovk-dto': ['class-validator', 'class-transformer', 'dto-mapped-types', 'reflect-metadata'],
39
39
  }[validationLibrary] ?? []));
40
40
  }
41
- if (reactQuery) {
42
- dependencies.push('vovk-react-query', '@tanstack/react-query');
43
- }
44
41
  if (updateScripts) {
45
42
  try {
46
43
  if (!dryRun)
@@ -127,7 +124,7 @@ export class Init {
127
124
  const { configAbsolutePath } = await createConfig({
128
125
  root,
129
126
  log,
130
- options: { validationLibrary, reactQuery, channel, lang, dryRun },
127
+ options: { validationLibrary, channel, lang, dryRun },
131
128
  });
132
129
  log.info('Config created successfully at ' + chalkHighlightThing(configAbsolutePath));
133
130
  }
@@ -135,7 +132,7 @@ export class Init {
135
132
  log.error(`Failed to create config: ${error.message}`);
136
133
  }
137
134
  }
138
- async main(prefix, { yes, logLevel, useNpm, useYarn, usePnpm, useBun, skipInstall, updateTsConfig, updateScripts, validationLibrary, reactQuery, lang, dryRun, channel, }) {
135
+ async main(prefix, { yes, logLevel, useNpm, useYarn, usePnpm, useBun, skipInstall, updateTsConfig, updateScripts, validationLibrary, lang, dryRun, channel, }) {
139
136
  const cwd = process.cwd();
140
137
  const root = path.resolve(cwd, prefix);
141
138
  const log = getLogger(logLevel);
@@ -153,7 +150,6 @@ export class Init {
153
150
  updateTsConfig: updateTsConfig ?? true,
154
151
  updateScripts: updateScripts ?? 'implicit',
155
152
  validationLibrary: validationLibrary?.toLocaleLowerCase() === 'none' ? null : (validationLibrary ?? 'vovk-zod'),
156
- reactQuery: reactQuery ?? true,
157
153
  dryRun: dryRun ?? false,
158
154
  channel: channel ?? 'latest',
159
155
  lang: lang ?? [],
@@ -213,10 +209,6 @@ export class Init {
213
209
  },
214
210
  ],
215
211
  });
216
- reactQuery ??= await confirm({
217
- default: false,
218
- message: 'Do you want to use @tanstack/react-query for data fetching at React components?',
219
- });
220
212
  if (typeof updateTsConfig === 'undefined') {
221
213
  let shouldAsk = false;
222
214
  try {
@@ -236,7 +228,7 @@ export class Init {
236
228
  }
237
229
  }
238
230
  lang ??= await checkbox({
239
- message: 'Do you want to generate RPC client for other languages besides TypeScript?',
231
+ message: 'Do you want to generate RPC client for other languages besides TypeScript (beta)?',
240
232
  choices: [
241
233
  { name: 'Python', value: 'py' },
242
234
  { name: 'Rust', value: 'rs' },
@@ -251,7 +243,6 @@ export class Init {
251
243
  updateTsConfig,
252
244
  updateScripts,
253
245
  validationLibrary,
254
- reactQuery,
255
246
  lang,
256
247
  dryRun,
257
248
  channel,
@@ -15,7 +15,6 @@ export function initProgram(program) {
15
15
  .option('--update-scripts <mode>', 'update package.json scripts ("implicit" or "explicit")')
16
16
  .option('--lang <languages...>', 'generate client for other programming languages by default ("py" for Python and "rs" for Rust are supported)')
17
17
  .option('--validation-library <library>', 'validation library to use ("vovk-zod", "vovk-dto" or another); set to "none" to skip')
18
- .option('--react-query', 'use @tanstack/react-query for data fetching inside components')
19
18
  .option('--channel <channel>', 'channel to use for fetching packages', 'latest')
20
19
  .option('--dry-run', 'do not write files to disk')
21
20
  .action((prefix = '.', options) => new Init().main(prefix, options));
package/dist/types.d.mts CHANGED
@@ -11,6 +11,7 @@ export interface DevOptions {
11
11
  schemaOut?: string;
12
12
  nextDev?: boolean;
13
13
  exit?: boolean;
14
+ devHttps?: boolean;
14
15
  }
15
16
  export interface GenerateOptions {
16
17
  prettify?: boolean;
@@ -55,7 +56,6 @@ export interface InitOptions {
55
56
  updateTsConfig?: boolean;
56
57
  updateScripts?: 'implicit' | 'explicit';
57
58
  validationLibrary?: string | null;
58
- reactQuery?: boolean;
59
59
  dryRun?: boolean;
60
60
  lang?: string[];
61
61
  channel?: 'latest' | 'beta' | 'draft';
@@ -80,5 +80,6 @@ export type VovkEnv = {
80
80
  VOVK_DEV_HTTPS?: string;
81
81
  __VOVK_START_WATCHER_IN_STANDALONE_MODE__?: 'true';
82
82
  __VOVK_SCHEMA_OUT_FLAG__?: string;
83
+ __VOVK_DEV_HTTPS_FLAG__?: 'true' | 'false';
83
84
  __VOVK_EXIT__?: 'true' | 'false';
84
85
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk-cli",
3
- "version": "0.0.1-draft.304",
3
+ "version": "0.0.1-draft.307",
4
4
  "bin": {
5
5
  "vovk": "./dist/index.mjs"
6
6
  },
@@ -35,10 +35,10 @@
35
35
  },
36
36
  "homepage": "https://vovk.dev",
37
37
  "peerDependencies": {
38
- "vovk": "^3.0.0-draft.348"
38
+ "vovk": "^3.0.0-draft.352"
39
39
  },
40
40
  "optionalDependencies": {
41
- "vovk-python": "^0.0.1-draft.56"
41
+ "vovk-python": "^0.0.1-draft.57"
42
42
  },
43
43
  "dependencies": {
44
44
  "@iarna/toml": "^2.2.5",