Skip to Content
Composed Mode

Composed Client Mode

By default, Vovk.ts generates one RPC client with the RPC modules of every segment: the Composed Client. It fits single-page apps, where one import gives you all RPC modules. The files go to the src/client folder when the app is in src/app (otherwise client; you can change it), and you import them as @/client with the default Next.js path alias.

The default ts template generates this src/client folder:

    • index.ts
    • schema.ts
    • openapi.ts
    • openapi.json

The client comes from the committed schema and source code, so you don’t commit it: vovk init adds the output folder to .gitignore and sets up the NPM scripts, so vovk generate generates the client again on every build.

This CLI command does the same as the default generation:

npx vovk generate --from ts --out src/client

The composed client exports each RPC module by its name, so two segments can’t both have a UserRPC: generation fails with a message that names both segments. Rename the module in one segment’s controllers object, or leave that segment out with excludeSegments and import it from the segmented client.

Composed Client Config

The options of the composed client:

vovk.config.mjs
/** @type {import('vovk').VovkConfig} */ const config = { composedClient: { enabled: true, // default fromTemplates: ['ts'], // default outDir: './src/client', // default; './client' when there is no src/app folder includeSegments: ['foo'], // or excludeSegments: ['bar'], not both }, }; export default config;

enabled

false turns off the composed client, for example when you want only segmented clients.

fromTemplates

The templates that generate the composed client. The default, ["ts"], produces TypeScript modules that compile together with the rest of your app. You can mix built-in templates and custom ones.

outDir

Where the composed client is generated. Defaults to ./src/client when the project has a src/app folder (and no root app folder), or ./client otherwise. The path is relative to the current working directory (CWD). If the folder already has files with the generated names, such as a hand-written index.ts, generation stops and names them; see --force.

includeSegments

The segments the composed client includes. By default, all segments.

excludeSegments

The segments the composed client leaves out. By default, none. You can’t use it together with includeSegments.

prettifyClient

Whether to format the generated code. Defaults to true. The CLI uses the Prettier  package of your project, with your Prettier config; the CLI doesn’t install it. Without Prettier, the CLI writes unformatted code; it warns about the missing Prettier only when you set prettifyClient: true (or pass --prettify) yourself.

outputConfig

Overrides the root outputConfig options.

Last updated on