From c7ef041a252841e6868037ec6e10eaf6b97af2e1 Mon Sep 17 00:00:00 2001 From: Alex Guerrieri Date: Mon, 30 Mar 2026 22:24:24 +0200 Subject: [PATCH] feat: add type alias support --- .github/workflows/ci.yml | 2 +- _examples/hello-webrpc/hello-api.ridl | 3 +++ _examples/hello-webrpc/webapp/client.gen.js | 10 +++++++--- types.go.tmpl | 4 ++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0395d3a..d16f6aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v3 - name: Install webrpc-gen run: | - curl -o ./webrpc-gen -fLJO https://github.com/webrpc/webrpc/releases/download/v0.32.3/webrpc-gen.linux-amd64 + curl -o ./webrpc-gen -fLJO https://github.com/webrpc/webrpc/releases/download/v0.37.0/webrpc-gen.linux-amd64 chmod +x ./webrpc-gen echo $PWD >> $GITHUB_PATH diff --git a/_examples/hello-webrpc/hello-api.ridl b/_examples/hello-webrpc/hello-api.ridl index c2b6083..ac66dd5 100644 --- a/_examples/hello-webrpc/hello-api.ridl +++ b/_examples/hello-webrpc/hello-api.ridl @@ -7,6 +7,9 @@ enum Kind: uint32 - USER = 1 - ADMIN = 2 +type Username: string +type Age: uint32 + struct Empty struct User diff --git a/_examples/hello-webrpc/webapp/client.gen.js b/_examples/hello-webrpc/webapp/client.gen.js index c407063..4fd4fa7 100644 --- a/_examples/hello-webrpc/webapp/client.gen.js +++ b/_examples/hello-webrpc/webapp/client.gen.js @@ -1,6 +1,6 @@ -// hello-webrpc v1.0.0 7037367a376940060eaf2739a920c4dca4a6dc2e +// hello-webrpc v1.0.0 949b00a8db9810c69295f9dd9f02587a65d3c497 // -- -// Code generated by webrpc-gen@v0.32.3 with ../../ generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.37.0 with ../../ generator. DO NOT EDIT. // // webrpc-gen -schema=hello-api.ridl -target=../../ -exports=false -client -out=./webapp/client.gen.js @@ -11,12 +11,16 @@ const WebRPCVersion = "v1" const WebRPCSchemaVersion = "v1.0.0" // Schema hash generated from your RIDL schema -const WebRPCSchemaHash = "7037367a376940060eaf2739a920c4dca4a6dc2e" +const WebRPCSchemaHash = "949b00a8db9810c69295f9dd9f02587a65d3c497" // // Types // +// type Username = string + +// type Age = uint32 + var Kind; (function (Kind) { Kind["USER"] = "USER" diff --git a/types.go.tmpl b/types.go.tmpl index 1985322..1be9bac 100644 --- a/types.go.tmpl +++ b/types.go.tmpl @@ -19,6 +19,10 @@ })({{$enumName}} || ({{$enumName}} = {})) {{end -}} +{{- if isAliasType $type }} +// type {{$type.Name}} = {{$type.Type}} +{{end -}} + {{- if isStructType $type }} {{if $opts.exports}}export {{end}}class {{.Name}} { constructor(_data) {