Skip to content

CLI

cmd-ipc includes a CLI for generating TypeScript schemas from remote services. This enables type-safe client development without sharing code between projects.

The CLI is included with the main package:

Terminal window
npm install @coralstack/cmd-ipc

You can run it via npx:

Terminal window
npx cmd-ipc --help

Or add it to your package.json scripts:

{
"scripts": {
"generate-schema": "cmd-ipc generate-schema --host http://localhost:8787 --output src/generated/api.ts"
}
}

Fetches command definitions from a remote CommandRegistry and generates a TypeScript schema file.

Terminal window
cmd-ipc generate-schema [options]
OptionRequiredDescription
--hostYesHost URL without trailing slash (e.g., https://api.example.com)
--outputYesOutput path for generated TypeScript file
--prefixNoPrefix to add to all command IDs

Basic usage:

Terminal window
cmd-ipc generate-schema \
--host http://localhost:8787 \
--output src/generated/api-schema.ts

With prefix:

Terminal window
cmd-ipc generate-schema \
--host https://api.example.com \
--output src/generated/cloud-schema.ts \
--prefix cloud
  1. Fetch Schema: The CLI fetches the command list from the server’s /cmds.json endpoint
  2. Parse Response: It receives the list of commands with their schemas
  3. Convert Schemas: JSON Schema definitions are converted to Valibot schemas
  4. Generate TypeScript: A .ts file is written with full type definitions

The generated file exports a schema named based on the --prefix option:

  • No prefix: RemoteCommandSchema
  • With prefix: ${PascalCasePrefix}CommandSchema (e.g., --prefix cloudCloudCommandSchema, --prefix my-apiMyApiCommandSchema)
// Auto-generated by cmd-ipc CLI - DO NOT EDIT
// Generated from: http://localhost:8787
// Generated at: 2024-01-15T10:30:00.000Z
import * as v from 'valibot'
import type { CommandSchemaMap } from '@coralstack/cmd-ipc'
export const RemoteCommandSchema = {
'user.create': {
description: 'Creates a new user account',
request: v.object({
name: v.string(),
email: v.pipe(v.string(), v.email()),
}),
response: v.object({
id: v.string(),
name: v.string(),
email: v.string(),
}),
},
'user.delete': {
description: 'Deletes a user by ID',
request: v.object({
id: v.string(),
}),
response: v.object({
success: v.boolean(),
}),
},
} as const satisfies CommandSchemaMap