Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into grpc-web
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Nov 18, 2022
2 parents 598d66a + 9be68ea commit e6ca731
Show file tree
Hide file tree
Showing 223 changed files with 34,060 additions and 11,008 deletions.
2 changes: 2 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
examples
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ test --incompatible_strict_action_env
build --deleted_packages=examples/bazel
query --deleted_packages=examples/bazel

try-import %workspace%/user.bazelrc
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
3 changes: 3 additions & 0 deletions .github/workflows/ci.windows.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
startup --output_user_root=C:/tmp
build --noshow_progress
test --test_output=errors
6 changes: 2 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ jobs:
protoc_version: [3.x]
steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-node@v2
with:
node-version: ${{matrix.node_version}}
- uses: arduino/setup-protoc@v1
with:
version: ${{matrix.protoc_version}}
repo-token: ${{ secrets.GITHUB_TOKEN }}

- run: copy .github/workflows/ci.windows.bazelrc user.bazelrc
if: ${{ matrix.os == 'windows-latest' }}
- run: yarn --frozen-lockfile
- run: yarn codegen
- run: yarn test --test_tag_filters=-no-${{ matrix.os }}
- run: cd examples/pure && yarn --frozen-lockfile && yarn test
12 changes: 2 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@ ast*.json
bazel-*
.devcontainer
.editorconfig

test/**/*.ts
!test/**/*.spec.ts

src/compiler/*
!src/compiler/BUILD.bazel
!src/compiler/index.ts
!src/compiler/*.js
src/compiler/index.js
.idea

.DS_Store
target
user.bazelrc
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

4 changes: 0 additions & 4 deletions .npmignore

This file was deleted.

31 changes: 31 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("@bazel_gazelle//:def.bzl", "gazelle")

package(default_visibility = ["//visibility:public"])

# gazelle:prefix github.com/thesayyn/protoc-gen-ts
gazelle(name = "gazelle")

gazelle(
name = "gazelle-update-repos",
args = [
"-from_file=go.mod",
"-to_macro=deps.bzl%go_dependencies",
"-prune",
],
command = "update-repos",
)

pkg_npm(
name = "package",
package_name = "protoc-gen-ts",
srcs = [
"README.md",
"index.bzl",
"package.json",
"//bin:protoc-gen-ts.js",
],
deps = [
"//src:pkg",
],
)
72 changes: 42 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
# Protoc Gen Typescript

[![test](https://github.com/thesayyn/protoc-gen-ts/actions/workflows/test.yaml/badge.svg?branch=master)](https://github.com/thesayyn/protoc-gen-ts/actions/workflows/test.yaml)
![npm](https://img.shields.io/npm/v/protoc-gen-ts)
![npm](https://img.shields.io/npm/dm/protoc-gen-ts)
[![npm](https://img.shields.io/npm/v/protoc-gen-ts)](https://www.npmjs.com/package/protoc-gen-ts?activeTab=versions)
[![npm](https://img.shields.io/npm/dm/protoc-gen-ts)](https://www.npmjs.com/package/protoc-gen-ts?activeTab=versions)
[![npm](https://opencollective.com/protoc-gen-ts/tiers/backer/badge.svg?label=Backer&color=brightgreen)](https://opencollective.com/protoc-gen-ts)

Aim of this protoc plugin is to make usage of protocol buffers easy in Javascript/Typescript by taking modern approaches. This plugin generates plain **Typescript** files that can be used AMD, UMD, CommonJS module systems.
Aim of this protoc plugin is to make usage of protocol buffers easy in Javascript/Typescript by taking a modern approach.
This plugin generates plain **TypeScript** sources that can be used in ESM, AMD, UMD, and CommonJS module system.

## Key Differences

- No `d.ts` files. Just plain typescript sources with actual code.
- Fields as **getter** **setters**.
- Enums as **enums**.
- Messages within a **namespace** if the proto has a **package** directive. (can be controlled via --ts_opt=no_namespace)
- **fromObject** and **toObject** methods to work with json data.
- Support for gRPC Node and gRPC Web (Work-in-progress) [#102](https://github.com/thesayyn/protoc-gen-ts/pull/102)
- You get what you define in proto files. No such prefixes as "getField" or "getFieldList".
- Generates bindings with either as-is names (`message.field_name`) or JSON-compatible names (`message.fieldName`).

## Example

Expand Down Expand Up @@ -94,16 +106,6 @@ this generated gRPC interfaces will use `@grpc/grpc-js`.

Checkout [rpcs](docs/rpc.md).

## Key Differences

This protoc plugin does generate;

- Fields as **getter** **setters**.
- No such prefixes as "getField" or "getFieldList". If you have repeated field named `users`, then the generated message class will have a `getter` named `users` not `getUsersList`
- Enums as **enums**.
- Messages within a **namespace** if the proto has a **package** directive.


## Usage

### Without Bazel
Expand All @@ -115,9 +117,8 @@ protoc -I=sourcedir --ts_out=dist myproto.proto
### With Bazel
```py
# Add protoc-gen-ts to dependencies section of your package.json file.
# Then use it like you would use the other bazel compatible npm packages.

load("@npm//protoc-gen-ts//:index.bzl", "ts_proto_library")
load("@npm//protoc-gen-ts:index.bzl", "ts_proto_library")

ts_proto_library(
name = "protos",
Expand All @@ -131,10 +132,28 @@ ts_proto_library(

## Supported Options

* With `--ts_opt=unary_rpc_promise=true`, the service definition will contain a promise based rpc with a calling pattern of `const result = await client.METHOD(message)`. Note: all othe `metadata` and `options` parameters are still available to you.
* With `--ts_opt=unary_rpc_promise=true`, the service definition will contain a promise based rpc with a calling pattern of `const result = await client.METHOD(message)`. Note: all of the `metadata` and `options` parameters are still available to you.

* With `--ts_opt=grpc_package=xxxx`, you can specify a different package to import rather than `@grpc/grpc-js`.

* With `--ts_opt=no_namespace`, you can control whether you get nested messages inside namespaces or prefixed with their parent message or directive.

* With `--ts_opt=json_names`, fields will be converted to lowerCamelCase, for compatibility with the [JSON mapping][] done by the first-party protobuf libraries.

[JSON mapping]: https://developers.google.com/protocol-buffers/docs/proto3#json

* With `--ts_opt=explicit_override`, inherited methods are generated with `override` modifier, this fixes transpilation error when `noImplicitOverride` is enabled.

## Support

We need your constant support to keep protoc-gen-ts well maintained and add new features.

If your corporate has a OSS funding scheme, please consider supporting us monthly through open collective.

<a href="https://opencollective.com/protoc-gen-ts">
<img height="100px" src="https://opencollective.com/protoc-gen-ts/tiers/backer.svg?avatarHeight=36">
</a>

## Roadmap

- <s>Support for repeated non-integer fields</s>
Expand All @@ -145,7 +164,8 @@ ts_proto_library(
- <s>Make services strongly typed.</s>
- <s>Support oneof fields</s>
- <s>Support `map<TYPE, TYPE>` types as ES `Map`.</s>
- Support grpc-web without any manual intervention.
- <s>Support for `@deprecated` annotations via deprecated option.</s>
- Support for grpc-web without any manual intervention.
- Interopability with well knowns.


Expand All @@ -163,24 +183,16 @@ ts_proto_library(
Generates appropriate Protocol Buffer sources from Proto files directly through _TypeScript Compiler API_.

```sh
# to run test invoke
# when you make changes to the plugin, you will have to run the command below
yarn update_checked_in_test
# this command will run the plugin with your changes and update generated test source accordingly.

# then invoke the tests
yarn test
# additionally if you want to see error details
yarn test --test_output=errors

```

## Contributors

![GitHub Contributors Image](https://contrib.rocks/image?repo=thesayyn/protoc-gen-ts)


## Support

If you find this plugin useful please consider giving us a star to get into open collective.

You can also support me directly by buying us some coffees.

<a href="https://www.buymeacoffee.com/thesayyn">
<img height="40px" src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=🙌&slug=thesayyn&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff">
</a>
Loading

0 comments on commit e6ca731

Please sign in to comment.