# ClientBuilder API

ClientBuilder to generate clients, based on service definitions.

---
Canonical: /handbook/api/classes/_purista_core.ClientBuilder/
Source: ClientBuilder/ClientBuilder.impl.ts
Format: Markdown for agents
---

ClientBuilder to generate clients, based on service definitions.

Package: `@purista/core`

## Signature

```typescript
class ClientBuilder
```

## Members

### Constructors

- `new constructor(config?: Partial<{ buildAs: "esm"; definitionPath: string; eventBridgeClient: { clientName: string }; httpClient: { clientName: string }; outputPath: string; package: { description: string; name: string; private: boolean }; ... }>)`

### Properties

- `config: { buildAs: "esm"; definitionPath: string; eventBridgeClient: { clientName: string }; httpClient: { clientName: string }; outputPath: string; package: { description: string; name: string; private: boolean }; ... }`
- `rootPath: string` — The root path from where relative definition/config/output paths are resolved.
Defaults to the current working directory (`process.cwd()`).

### Methods

- `build(): Promise<void>` — Runs the tsc against the generated ts source files.
Generates plain ESM output.
- `cleanDistFolder(): Promise<void>` — Deletes the content of the output folder.
Should be called before generating the client
- `createIndex(): Promise<void>` — Creates a index.ts file which exports the client(s) and types.
Is used in generated package.json
- `createPackageJson(): Promise<void>` — Creates a package.json file in the output folder.
Exports the files which are build by tsc based on generated client files
- `destroy(): void` — Destroys the builder and cleans the event listeners
- `emit<K>(eventName: K, parameter?: ClientBuilderEvents[K]): void`
- `generateEventBridgeClient(serviceDefinition: FullServiceDefinition): Promise<void>` — Generates the zero-dependency EventBridge client source files.
- `generateHEventBridgeClient(serviceDefinition: FullServiceDefinition): Promise<void>`
- `generateHttpClient(serviceDefinition: FullServiceDefinition): Promise<void>` — Generate zero‑dependency HTTP client source files from the given definition.
- `getDefinitionPath(): string` — Resolves the definitions folder path from config with rootPath
- `getDefinitionsFromServiceBuilders(serviceBuilders: ServiceBuilder<ServiceBuilderTypes>[]): Promise<FullServiceDefinition>` — Gets the definitions from the provided service builders
- `getOutputPath(): string` — Resolves the output folder path from config with rootPath
- `loadConfig(path?: string): Promise<void>` — Loads the config from a JSON file.
If no path is provided, it loads `purista.client.json` from `rootPath`.
- `loadDefinitionFiles(path?: string): Promise<FullServiceDefinition>` — Load service definitions from JSON files.
- `off<K>(eventName: K, fn: EventReceiver<ClientBuilderEvents[K]>): void`
- `on<K>(eventName: K, fn: EventReceiver<ClientBuilderEvents[K]>): void`
- `removeAllListeners(): void`
- `writeConfig(path?: string): Promise<void>` — Writes the config to a config file.
Defaults to purista.client.json in rootPath directory
