Skip to content

Commit 72715f1

Browse files
authored
Support the new RIDL "basepath" keyword (#52)
* Support the new RIDL "basepath" keyword * Update webrpc * Update
1 parent 878ead3 commit 72715f1

11 files changed

Lines changed: 47 additions & 68 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up Go
1818
uses: actions/setup-go@v3
1919
with:
20-
go-version: "1.23"
20+
go-version: "1.23"
2121

2222
- name: Install webrpc-gen (development)
2323
run: git clone --single-branch https://github.com/webrpc/webrpc.git --branch master && cd webrpc && make install
@@ -27,29 +27,3 @@ jobs:
2727

2828
- name: Git diff of regenerated files
2929
run: cd _examples && make diff
30-
31-
# webrpc-tests:
32-
# strategy:
33-
# matrix:
34-
# webrpc-version: [v0.14.0]
35-
# runs-on: ubuntu-latest
36-
# steps:
37-
# - uses: actions/checkout@v3
38-
# - uses: actions/setup-node@v3
39-
# with:
40-
# node-version: 18
41-
# - name: Set up webrpc binary cache folder
42-
# uses: actions/cache@v3
43-
# with:
44-
# key: webrpc-binaries
45-
# path: tests/bin
46-
# - name: Install dependencies
47-
# run: cd tests && npm install
48-
# - name: Download webrpc binaries
49-
# run: cd tests && ./download.sh ${{ matrix.webrpc-version }} bin/${{ matrix.webrpc-version }}
50-
# - name: Export path of webrpc binaries
51-
# run: cd tests && echo "$PWD/bin/${{ matrix.webrpc-version }}" >> $GITHUB_PATH
52-
# - name: Run interoperability tests
53-
# run: cd tests && ./test.sh
54-
# - name: Run typescript check
55-
# run: cd tests && npm run ts-check

_examples/node-ts/server-fastify/server.gen.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable */
2-
// node-ts v1.0.0 21701cae51b73d035bf2180831cdb38220bbbccc
2+
// node-ts v1.0.0 83e44adec2381759b0925cfad2f5e25da97ad163
33
// --
4-
// Code generated by Webrpc-gen@v0.30.0 with ../../../gen-typescript generator. DO NOT EDIT.
4+
// Code generated by Webrpc-gen@v0.32.3 with ../../../gen-typescript generator. DO NOT EDIT.
55
//
66
// webrpc-gen -schema=service.ridl -target=../../../gen-typescript -server -out=./server-fastify/server.gen.ts
77

@@ -12,7 +12,7 @@ export const WebrpcVersion = "v1"
1212
export const WebrpcSchemaVersion = "v1.0.0"
1313

1414
// Schema hash generated from your RIDL schema
15-
export const WebrpcSchemaHash = "21701cae51b73d035bf2180831cdb38220bbbccc"
15+
export const WebrpcSchemaHash = "83e44adec2381759b0925cfad2f5e25da97ad163"
1616

1717

1818
//
@@ -555,7 +555,7 @@ export const webrpcErrorByCode: { [code: number]: any } = {
555555

556556
export const WebrpcHeader = "Webrpc"
557557

558-
export const WebrpcHeaderValue = "webrpc@v0.30.0;gen-typescript@unknown;node-ts@v1.0.0"
558+
export const WebrpcHeaderValue = "webrpc@v0.32.3;gen-typescript@unknown;node-ts@v1.0.0"
559559

560560
type WebrpcGenVersions = {
561561
WebrpcGenVersion: string;

_examples/node-ts/server-hono/server.gen.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable */
2-
// node-ts v1.0.0 21701cae51b73d035bf2180831cdb38220bbbccc
2+
// node-ts v1.0.0 83e44adec2381759b0925cfad2f5e25da97ad163
33
// --
4-
// Code generated by Webrpc-gen@v0.30.0 with ../../../gen-typescript generator. DO NOT EDIT.
4+
// Code generated by Webrpc-gen@v0.32.3 with ../../../gen-typescript generator. DO NOT EDIT.
55
//
66
// webrpc-gen -schema=service.ridl -target=../../../gen-typescript -server -out=./server-hono/server.gen.ts
77

@@ -12,7 +12,7 @@ export const WebrpcVersion = "v1"
1212
export const WebrpcSchemaVersion = "v1.0.0"
1313

1414
// Schema hash generated from your RIDL schema
15-
export const WebrpcSchemaHash = "21701cae51b73d035bf2180831cdb38220bbbccc"
15+
export const WebrpcSchemaHash = "83e44adec2381759b0925cfad2f5e25da97ad163"
1616

1717

1818
//
@@ -555,7 +555,7 @@ export const webrpcErrorByCode: { [code: number]: any } = {
555555

556556
export const WebrpcHeader = "Webrpc"
557557

558-
export const WebrpcHeaderValue = "webrpc@v0.30.0;gen-typescript@unknown;node-ts@v1.0.0"
558+
export const WebrpcHeaderValue = "webrpc@v0.32.3;gen-typescript@unknown;node-ts@v1.0.0"
559559

560560
type WebrpcGenVersions = {
561561
WebrpcGenVersion: string;

_examples/node-ts/server/server.gen.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable */
2-
// node-ts v1.0.0 21701cae51b73d035bf2180831cdb38220bbbccc
2+
// node-ts v1.0.0 83e44adec2381759b0925cfad2f5e25da97ad163
33
// --
4-
// Code generated by Webrpc-gen@v0.30.0 with ../../../gen-typescript generator. DO NOT EDIT.
4+
// Code generated by Webrpc-gen@v0.32.3 with ../../../gen-typescript generator. DO NOT EDIT.
55
//
66
// webrpc-gen -schema=service.ridl -target=../../../gen-typescript -server -out=./server/server.gen.ts
77

@@ -12,7 +12,7 @@ export const WebrpcVersion = "v1"
1212
export const WebrpcSchemaVersion = "v1.0.0"
1313

1414
// Schema hash generated from your RIDL schema
15-
export const WebrpcSchemaHash = "21701cae51b73d035bf2180831cdb38220bbbccc"
15+
export const WebrpcSchemaHash = "83e44adec2381759b0925cfad2f5e25da97ad163"
1616

1717

1818
//
@@ -555,7 +555,7 @@ export const webrpcErrorByCode: { [code: number]: any } = {
555555

556556
export const WebrpcHeader = "Webrpc"
557557

558-
export const WebrpcHeaderValue = "webrpc@v0.30.0;gen-typescript@unknown;node-ts@v1.0.0"
558+
export const WebrpcHeaderValue = "webrpc@v0.32.3;gen-typescript@unknown;node-ts@v1.0.0"
559559

560560
type WebrpcGenVersions = {
561561
WebrpcGenVersion: string;

_examples/node-ts/service.ridl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ webrpc = v1
22

33
name = node-ts
44
version = v1.0.0
5+
basepath = /rpc
6+
7+
service Example
8+
@deprecated:"Use /health endpoint instead."
9+
- Ping() => ()
10+
11+
# GetUser returns a user by ID.
12+
- GetUser(userId: uint64) => (code: uint32, user: User)
13+
14+
# Get article by id.
15+
- GetArticle(GetArticleRequest) => (GetArticleResponse)
516

617
enum Kind: uint32
718
- USER
@@ -39,13 +50,3 @@ error 1002 SessionExpired "Session expired"
3950
error 1003 Geoblocked "Geoblocked region" HTTP 451
4051
error 1004 RateLimited "Rate-limited. Please slow down." HTTP 429
4152
error 1005 CorsDisallowed "CORS disallowed. JWT can't be used from a web app." HTTP 403
42-
43-
service Example
44-
@deprecated:"Use /health endpoint instead."
45-
- Ping() => ()
46-
47-
# GetUser returns a user by ID.
48-
- GetUser(userId: uint64) => (code: uint32, user: User)
49-
50-
# Get article by id.
51-
- GetArticle(GetArticleRequest) => (GetArticleResponse)

_examples/node-ts/webapp/client.gen.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable */
2-
// node-ts v1.0.0 21701cae51b73d035bf2180831cdb38220bbbccc
2+
// node-ts v1.0.0 83e44adec2381759b0925cfad2f5e25da97ad163
33
// --
4-
// Code generated by Webrpc-gen@v0.30.0 with ../../../gen-typescript generator. DO NOT EDIT.
4+
// Code generated by Webrpc-gen@v0.32.3 with ../../../gen-typescript generator. DO NOT EDIT.
55
//
66
// webrpc-gen -schema=service.ridl -target=../../../gen-typescript -client -out=./webapp/client.gen.ts
77

@@ -12,7 +12,7 @@ export const WebrpcVersion = "v1"
1212
export const WebrpcSchemaVersion = "v1.0.0"
1313

1414
// Schema hash generated from your RIDL schema
15-
export const WebrpcSchemaHash = "21701cae51b73d035bf2180831cdb38220bbbccc"
15+
export const WebrpcSchemaHash = "83e44adec2381759b0925cfad2f5e25da97ad163"
1616

1717
//
1818
// Client interface
@@ -496,7 +496,7 @@ export const webrpcErrorByCode: { [code: number]: any } = {
496496

497497
export const WebrpcHeader = "Webrpc"
498498

499-
export const WebrpcHeaderValue = "webrpc@v0.30.0;gen-typescript@unknown;node-ts@v1.0.0"
499+
export const WebrpcHeaderValue = "webrpc@v0.32.3;gen-typescript@unknown;node-ts@v1.0.0"
500500

501501
type WebrpcGenVersions = {
502502
WebrpcGenVersion: string;

_examples/sse/service.ridl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ webrpc = v1
22

33
name = webrpc-sse-chat
44
version = v1.0.0
5+
basepath = /v1
6+
7+
service Chat
8+
- SendMessage(username: string, text: string)
9+
- SubscribeMessages(username: string) => stream (message: Message)
10+
- SubscribeUsers() => stream (username: string)
511

612
struct Message
713
- id: uint64
814
- username: string
915
- text: string
1016
- createdAt: timestamp
1117

12-
service Chat
13-
- SendMessage(username: string, text: string)
14-
- SubscribeMessages(username: string) => stream (message: Message)
15-
- SubscribeUsers() => stream (username: string)
16-
1718
error 100 EmptyUsername "Username must be provided." HTTP 400

_examples/sse/webapp/client.gen.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable */
2-
// webrpc-sse-chat v1.0.0 a799dc63b082644f5d003c8881424546aee23a2c
2+
// webrpc-sse-chat v1.0.0 8b6b6e0df6c23832e31534594d32955c3383689b
33
// --
4-
// Code generated by Webrpc-gen@v0.30.0 with ../../ generator. DO NOT EDIT.
4+
// Code generated by Webrpc-gen@v0.32.3 with ../../ generator. DO NOT EDIT.
55
//
66
// webrpc-gen -schema=service.ridl -target=../../ -client -out=./webapp/client.gen.ts
77

@@ -12,7 +12,7 @@ export const WebrpcVersion = "v1"
1212
export const WebrpcSchemaVersion = "v1.0.0"
1313

1414
// Schema hash generated from your RIDL schema
15-
export const WebrpcSchemaHash = "a799dc63b082644f5d003c8881424546aee23a2c"
15+
export const WebrpcSchemaHash = "8b6b6e0df6c23832e31534594d32955c3383689b"
1616

1717
//
1818
// Client interface
@@ -70,7 +70,7 @@ export interface SubscribeUsersResponse {
7070
export class Chat implements ChatClient {
7171
protected hostname: string
7272
protected fetch: Fetch
73-
protected path = '/rpc/Chat/'
73+
protected path = '/v1/Chat/'
7474

7575
constructor(hostname: string, fetch: Fetch) {
7676
this.hostname = hostname.replace(/\/*$/, '')
@@ -565,7 +565,7 @@ export const webrpcErrorByCode: { [code: number]: any } = {
565565

566566
export const WebrpcHeader = "Webrpc"
567567

568-
export const WebrpcHeaderValue = "webrpc@v0.30.0;@unknown;webrpc-sse-chat@v1.0.0"
568+
export const WebrpcHeaderValue = "webrpc@v0.32.3;@unknown;webrpc-sse-chat@v1.0.0"
569569

570570
type WebrpcGenVersions = {
571571
WebrpcGenVersion: string;

client.go.tmpl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{{- define "client" -}}
22

3+
{{- $basepath := .BasePath -}}
4+
{{- $services := .Services -}}
35
{{- $typeMap := .TypeMap -}}
46
{{- $opts := .Opts -}}
57

@@ -8,11 +10,11 @@
810
// Client
911
//
1012

11-
{{- "\n" -}}{{- range $serviceIndex, $service := .Services}}
13+
{{- "\n" -}}{{- range $serviceIndex, $service := $services}}
1214
export class {{$service.Name}} implements {{$service.Name}}Client {
1315
protected hostname: string
1416
protected fetch: Fetch
15-
protected path = '/rpc/{{$service.Name}}/'
17+
protected path = '{{$basepath}}{{$service.Name}}/'
1618

1719
constructor(hostname: string, fetch: Fetch) {
1820
this.hostname = hostname.replace(/\/*$/, '')

main.go.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ export const WebrpcSchemaHash = "{{.SchemaHash}}"
100100
{{- "\n" -}}
101101

102102
{{- if $opts.client -}}
103-
{{template "client" dict "Services" .Services "Opts" $opts "TypeMap" $typeMap}}
103+
{{template "client" dict "BasePath" .BasePath "Services" .Services "Opts" $opts "TypeMap" $typeMap}}
104104
{{template "clientHelpers" dict "WebrpcErrors" .WebrpcErrors "SchemaErrors" .Errors "Opts" $opts }}
105105
{{- end -}}
106106

107107
{{- "\n" -}}
108108

109109
{{- if $opts.server -}}
110-
{{template "server" dict "Services" .Services "Opts" $opts "TypeMap" $typeMap "UsesBigInts" $usesBigInts}}
110+
{{template "server" dict "BasePath" .BasePath "Services" .Services "Opts" $opts "TypeMap" $typeMap "UsesBigInts" $usesBigInts}}
111111
{{template "serverHelpers" dict "Types" .Types "TypeMap" $typeMap}}
112112
{{- end -}}
113113

0 commit comments

Comments
 (0)