npm NuGet v1.1.1 MIT

Protobuf to Angular Client Generator

@metaengine/protobuf-angular

Convert Protobuf 3 to Angular gRPC-Web services and message types with inject() DI, interceptors, gRPC-native error handling, and the new Angular 22 @Service() decorator. Idiomatic Angular 19+ over the Connect protocol.

Protobuf 3.xMetaEngine IRTypeScript · Angular
Install

Pick your registry

The same generator, published to every ecosystem we support. Install however your project expects.

npmPrimary@metaengine/protobuf-angular
$npm install @metaengine/protobuf-angular
v1.1.1
NuGetMetaEngine.TypeScript.Protobuf.Angular
$dotnet add package MetaEngine.TypeScript.Protobuf.Angular
v1.1.1
Usage

Drive it from the CLI or programmatically

npm ships a zero-config CLI. NuGet ships the same generator as a C# fluent API — same options, same output.

npm · npx · CI-friendly

After install, point the CLI at your schema. It writes the generated tree to your chosen output directory.

Basic syntax
terminal
npx @metaengine/protobuf-angular <input> <output> [options]

Generates Angular gRPC-Web services and message types from Protobuf 3 .proto files.

Quick examples
Generate from a .proto file
npx @metaengine/protobuf-angular service.proto ./src/app/api
With Angular best practices
npx @metaengine/protobuf-angular service.proto ./src/app/api \
  --provided-in root \
  --inject-function \
  --error-handling \
  --documentation
With the Angular 22 @Service() decorator
npx @metaengine/protobuf-angular service.proto ./src/app/api \
  --service-decorator \
  --documentation
Production setup with auth and timeout
npx @metaengine/protobuf-angular service.proto ./src/app/api \
  --bearer-auth API_TOKEN \
  --timeout 30 \
  --error-handling
CLI options
Option
Description
--provided-in <value>
Angular injection scope (root, any, platform)
--base-url-token <name>
Injection token name for base URL [default: BASE_URL]
--service-suffix <suffix>
Service naming suffix [default: Service]
--options-threshold <n>
Parameter count to use options object [default: 4]
--documentation
Generate JSDoc comments
--inject-function
Use inject() instead of constructor injection (Angular 14+)
--service-decorator [scope]
Emit the Angular 22 @Service() decorator instead of @Injectable (auto-enables inject()). scope: auto-provided (default) or component-scoped for @Service({ autoProvided: false })
--error-handling
Enable gRPC-native error handling keyed on gRPC status codes
--bearer-auth <env-var-name>
Bearer token via DI injection token (e.g. API_TOKEN). Generates an Angular auth interceptor.
--basic-auth <userEnv:passEnv>
Basic auth from env vars. Format: <username-env>:<password-env> (e.g. API_USER:API_PASS). Generates an Angular auth interceptor.
--timeout <seconds>
Request timeout in seconds, emitted as a grpc-timeout header on every call
--custom-header <header-name>
Declare a static header for runtime population. Repeatable (e.g. X-Tenant-ID). Rendered as an empty header slot — Angular has no env-var access in the browser.
--date-transformation
Convert google.protobuf.Timestamp fields in responses to JavaScript Date objects
--types-barrel
Emit an index.ts barrel per folder plus a root index.ts re-exporting everything
--type-mapping <mapping>
Override TS type for a protobuf type. Repeatable. Targets: string · number · Date · boolean (e.g. google.protobuf.Timestamp=string)
--clean
Clean output directory (remove files not in generation)
--verbose
Enable verbose logging
--help, -h
Show help message
Options reference

Every knob, documented

Every option is available on the C# fluent API as a method, and most are also exposed as CLI flags. Cross-cutting auth, headers, retries and timeouts apply across frameworks.

Angular Options

7
  • WithBaseUrlToken(string)Injection token name for base URL (default: "BASE_URL")
  • WithInjectFunction()Use inject() instead of constructor DI (Angular 14+)
  • WithProvidedIn(string)Injection scope ("root", "platform", "any")
  • WithServiceDecorator()Emit the Angular 22 @Service() decorator instead of @Injectable — a root-provided singleton that auto-enables inject() DI (mutually exclusive with WithProvidedIn, last wins)
  • WithServiceDecorator(x => x.ComponentScoped())Angular 22 @Service({ autoProvided: false }) — a manually-provided, component/route-scoped service
  • WithInterceptors()Generate interceptor infrastructure (ApiMiddleware type + provideApiInterceptors factory) so auth / headers live in interceptors
  • WithResponseDateTransformation()Convert google.protobuf.Timestamp fields in responses to Date objects

Auth · Headers · Resilience

9
  • WithErrorHandling()Enable gRPC-native error handling keyed on gRPC status codes (NOT_FOUND / PERMISSION_DENIED → null · INVALID_ARGUMENT / FAILED_PRECONDITION → error body · UNAUTHENTICATED / INTERNAL / UNAVAILABLE → throw)
  • WithErrorHandling(grpc => grpc...)Tune the gRPC taxonomy: ReturnNullForCodes(...) · ReturnErrorForCodes(...) · ThrowForCodes(...) · MapGrpcCode(code, behavior). Overrides merge on top of the defaults
  • WithBearerAuth()Bearer token from env var (default API_TOKEN) — adds Authorization header
  • WithBearerAuth(string)Bearer token from a specific env var name
  • WithBearerAuth(string, string)Bearer token with custom header name
  • WithBasicAuth(string, string)HTTP Basic auth from username + password env vars
  • WithCustomHeader(string, string)Static header from env var. Repeatable (e.g. X-Tenant-ID ← TENANT_ID)
  • WithTimeout(double)Request timeout in seconds, emitted as a grpc-timeout header on every call
  • WithTimeout(double?, double?, double?, double?)Granular timeout: connect · read · write · pool

Protobuf Options

5
  • WithDocumentation()Generate JSDoc comments from .proto field and service descriptions
  • WithTypeFilter(Func)Filter extracted proto types before registration — only types returning true are generated
  • WithTypeMapping(string, Type)Override the TS mapping for a protobuf well-known type by fully-qualified name (e.g. google.protobuf.Timestamp → string)
  • WithMethodNames(Func)Custom method naming rule
  • WithOptionsObjectThreshold(int)Parameter count for options object (default: 4)

TypeScript Output

1
  • WithTypesBarrel()Emit an index.ts barrel per folder plus a root index.ts re-exporting everything

Naming Transformations

3
  • Types(Func)Transform type names
  • Paths(Func)Transform output paths
  • FileNames(Func)Transform file names

File Management

5
  • CleanDestination()Clean output directory before generation
  • AlwaysOverwrite()Always overwrite existing files
  • OnlyWhenModelChanged()Update only when model changes
  • OnlyWhenNew()Write only new files, preserve existing
  • CleanDirectories(...)Clean specific subdirectories

Diagnostics

2
  • Verbose()Enable verbose logging
  • WithLogger(Action<string>)Route generation log output to a custom sink
Features

Why this package is different

Tree-shakeable
One file per tag (or per operation) means bundlers drop unused clients at build time. No runtime dispatch table.
Strict, no any
Output compiles under strict with no any. Unions, nullability and enums are modelled precisely so tsc catches drift.
Zero runtime
The default emit is types plus a thin client — no decorators, no reflection, no dependency surface beyond your HTTP lib.
Deterministic output
Same spec + same options produce byte-identical files. Safe to commit, safe to diff in review, safe to cache in CI.
Flexible naming
Case conventions are configurable per role — types, properties, operations, enums. Idiomatic in the target by default.
Semver-honest
Spec diff drives the version bump. Additive changes = minor, removed operations = major. Never a surprise in your lockfile.