https://github.com/einride/protoc-gen-typescript-aip
Generates Typescript for gRPC APIs conforming to AIP https://aip.dev
https://github.com/einride/protoc-gen-typescript-aip
aip protoc typescript
Last synced: about 1 year ago
JSON representation
Generates Typescript for gRPC APIs conforming to AIP https://aip.dev
- Host: GitHub
- URL: https://github.com/einride/protoc-gen-typescript-aip
- Owner: einride
- License: mit
- Created: 2021-04-28T09:00:08.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-12-16T20:36:06.000Z (over 1 year ago)
- Last Synced: 2025-04-03T06:23:37.494Z (about 1 year ago)
- Topics: aip, protoc, typescript
- Language: Go
- Homepage:
- Size: 2.77 MB
- Stars: 8
- Watchers: 14
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# protoc-gen-typescript-aip
Generates Typescript helpers for Protobuf APIs conforming to
[AIP](https://aip.dev).
### Install the plugin
```bash
go get go.einride.tech/protoc-gen-typescript-aip
```
Or download a prebuilt binary from
[releases](https://github.com/einride/protoc-gen-typescript-aip/releases).
### Invocation
#### protoc
```bash
protoc
--typescript-aip_out [OUTPUT DIR] \
[.proto files ...]
```
#### buf
```yaml
plugins:
- name: typescript-aip
out: [OUTPUT DIR]
strategy: all
```
### Configuration
```
filename Name of the file to generate the code to.
Default: `index.ts`.
insertion_point If non-empty, indicates that the named file should already exist,
and the content here is to be inserted into that file at a defined
insertion point.
exclude_resource_definitions
If set to true, resource names will not be generated for resource definitions
in the file scope, only on messages. Default: false.
```
______________________________________________________________________
## Features
### Resource names
Generates helpers for working with resource names, based on
[ResourceDescriptor](https://github.com/googleapis/googleapis/blob/master/google/api/resource.proto)
annotations.
#### Example
A resource annotated with
```proto
option (google.api.resource) = {
type: "account-example.einride.tech/User"
pattern: "tenants/{tenant}/users/{user}"
singular: "user"
plural: "users"
};
```
generates the following API
```ts
// Parsing a string:
const name = UserResourceName.parse("tenants/1/users/2")
// Getting variable segments:
console.log(name.tenant); // "1"
console.log(name.user); // "2"
// Getting the string back:
console.log(name.toString()) // "tenants/1/users/2"
// Traversing the resource hierarchy:
const tenant = name.tenantResourceName();
console.log(tenant.toString()) // "tenants/1"
// Constructing the resource name from segments:
const name = UserResourceName.from("tenant", "user")
console.log(name.tenant) // "tenant"
console.log(name.user) // "user"
console.log(name.toString()) // "tenants/tenant/users/user"
```