Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.23"
go-version: "1.23"

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

- name: Git diff of regenerated files
run: cd _examples && make diff

# webrpc-tests:
# strategy:
# matrix:
# webrpc-version: [v0.14.0]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-node@v3
# with:
# node-version: 18
# - name: Set up webrpc binary cache folder
# uses: actions/cache@v3
# with:
# key: webrpc-binaries
# path: tests/bin
# - name: Install dependencies
# run: cd tests && npm install
# - name: Download webrpc binaries
# run: cd tests && ./download.sh ${{ matrix.webrpc-version }} bin/${{ matrix.webrpc-version }}
# - name: Export path of webrpc binaries
# run: cd tests && echo "$PWD/bin/${{ matrix.webrpc-version }}" >> $GITHUB_PATH
# - name: Run interoperability tests
# run: cd tests && ./test.sh
# - name: Run typescript check
# run: cd tests && npm run ts-check
8 changes: 4 additions & 4 deletions _examples/node-ts/server-fastify/server.gen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
// node-ts v1.0.0 21701cae51b73d035bf2180831cdb38220bbbccc
// node-ts v1.0.0 83e44adec2381759b0925cfad2f5e25da97ad163
// --
// Code generated by Webrpc-gen@v0.30.0 with ../../../gen-typescript generator. DO NOT EDIT.
// Code generated by Webrpc-gen@v0.32.3 with ../../../gen-typescript generator. DO NOT EDIT.
//
// webrpc-gen -schema=service.ridl -target=../../../gen-typescript -server -out=./server-fastify/server.gen.ts

Expand All @@ -12,7 +12,7 @@ export const WebrpcVersion = "v1"
export const WebrpcSchemaVersion = "v1.0.0"

// Schema hash generated from your RIDL schema
export const WebrpcSchemaHash = "21701cae51b73d035bf2180831cdb38220bbbccc"
export const WebrpcSchemaHash = "83e44adec2381759b0925cfad2f5e25da97ad163"


//
Expand Down Expand Up @@ -555,7 +555,7 @@ export const webrpcErrorByCode: { [code: number]: any } = {

export const WebrpcHeader = "Webrpc"

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

type WebrpcGenVersions = {
WebrpcGenVersion: string;
Expand Down
8 changes: 4 additions & 4 deletions _examples/node-ts/server-hono/server.gen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
// node-ts v1.0.0 21701cae51b73d035bf2180831cdb38220bbbccc
// node-ts v1.0.0 83e44adec2381759b0925cfad2f5e25da97ad163
// --
// Code generated by Webrpc-gen@v0.30.0 with ../../../gen-typescript generator. DO NOT EDIT.
// Code generated by Webrpc-gen@v0.32.3 with ../../../gen-typescript generator. DO NOT EDIT.
//
// webrpc-gen -schema=service.ridl -target=../../../gen-typescript -server -out=./server-hono/server.gen.ts

Expand All @@ -12,7 +12,7 @@ export const WebrpcVersion = "v1"
export const WebrpcSchemaVersion = "v1.0.0"

// Schema hash generated from your RIDL schema
export const WebrpcSchemaHash = "21701cae51b73d035bf2180831cdb38220bbbccc"
export const WebrpcSchemaHash = "83e44adec2381759b0925cfad2f5e25da97ad163"


//
Expand Down Expand Up @@ -555,7 +555,7 @@ export const webrpcErrorByCode: { [code: number]: any } = {

export const WebrpcHeader = "Webrpc"

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

type WebrpcGenVersions = {
WebrpcGenVersion: string;
Expand Down
8 changes: 4 additions & 4 deletions _examples/node-ts/server/server.gen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
// node-ts v1.0.0 21701cae51b73d035bf2180831cdb38220bbbccc
// node-ts v1.0.0 83e44adec2381759b0925cfad2f5e25da97ad163
// --
// Code generated by Webrpc-gen@v0.30.0 with ../../../gen-typescript generator. DO NOT EDIT.
// Code generated by Webrpc-gen@v0.32.3 with ../../../gen-typescript generator. DO NOT EDIT.
//
// webrpc-gen -schema=service.ridl -target=../../../gen-typescript -server -out=./server/server.gen.ts

Expand All @@ -12,7 +12,7 @@ export const WebrpcVersion = "v1"
export const WebrpcSchemaVersion = "v1.0.0"

// Schema hash generated from your RIDL schema
export const WebrpcSchemaHash = "21701cae51b73d035bf2180831cdb38220bbbccc"
export const WebrpcSchemaHash = "83e44adec2381759b0925cfad2f5e25da97ad163"


//
Expand Down Expand Up @@ -555,7 +555,7 @@ export const webrpcErrorByCode: { [code: number]: any } = {

export const WebrpcHeader = "Webrpc"

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

type WebrpcGenVersions = {
WebrpcGenVersion: string;
Expand Down
21 changes: 11 additions & 10 deletions _examples/node-ts/service.ridl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ webrpc = v1

name = node-ts
version = v1.0.0
basepath = /rpc

service Example
@deprecated:"Use /health endpoint instead."
- Ping() => ()

# GetUser returns a user by ID.
- GetUser(userId: uint64) => (code: uint32, user: User)

# Get article by id.
- GetArticle(GetArticleRequest) => (GetArticleResponse)

enum Kind: uint32
- USER
Expand Down Expand Up @@ -39,13 +50,3 @@ error 1002 SessionExpired "Session expired"
error 1003 Geoblocked "Geoblocked region" HTTP 451
error 1004 RateLimited "Rate-limited. Please slow down." HTTP 429
error 1005 CorsDisallowed "CORS disallowed. JWT can't be used from a web app." HTTP 403

service Example
@deprecated:"Use /health endpoint instead."
- Ping() => ()

# GetUser returns a user by ID.
- GetUser(userId: uint64) => (code: uint32, user: User)

# Get article by id.
- GetArticle(GetArticleRequest) => (GetArticleResponse)
8 changes: 4 additions & 4 deletions _examples/node-ts/webapp/client.gen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
// node-ts v1.0.0 21701cae51b73d035bf2180831cdb38220bbbccc
// node-ts v1.0.0 83e44adec2381759b0925cfad2f5e25da97ad163
// --
// Code generated by Webrpc-gen@v0.30.0 with ../../../gen-typescript generator. DO NOT EDIT.
// Code generated by Webrpc-gen@v0.32.3 with ../../../gen-typescript generator. DO NOT EDIT.
//
// webrpc-gen -schema=service.ridl -target=../../../gen-typescript -client -out=./webapp/client.gen.ts

Expand All @@ -12,7 +12,7 @@ export const WebrpcVersion = "v1"
export const WebrpcSchemaVersion = "v1.0.0"

// Schema hash generated from your RIDL schema
export const WebrpcSchemaHash = "21701cae51b73d035bf2180831cdb38220bbbccc"
export const WebrpcSchemaHash = "83e44adec2381759b0925cfad2f5e25da97ad163"

//
// Client interface
Expand Down Expand Up @@ -496,7 +496,7 @@ export const webrpcErrorByCode: { [code: number]: any } = {

export const WebrpcHeader = "Webrpc"

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

type WebrpcGenVersions = {
WebrpcGenVersion: string;
Expand Down
11 changes: 6 additions & 5 deletions _examples/sse/service.ridl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ webrpc = v1

name = webrpc-sse-chat
version = v1.0.0
basepath = /v1

service Chat
- SendMessage(username: string, text: string)
- SubscribeMessages(username: string) => stream (message: Message)
- SubscribeUsers() => stream (username: string)

struct Message
- id: uint64
- username: string
- text: string
- createdAt: timestamp

service Chat
- SendMessage(username: string, text: string)
- SubscribeMessages(username: string) => stream (message: Message)
- SubscribeUsers() => stream (username: string)

error 100 EmptyUsername "Username must be provided." HTTP 400
10 changes: 5 additions & 5 deletions _examples/sse/webapp/client.gen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
// webrpc-sse-chat v1.0.0 a799dc63b082644f5d003c8881424546aee23a2c
// webrpc-sse-chat v1.0.0 8b6b6e0df6c23832e31534594d32955c3383689b
// --
// Code generated by Webrpc-gen@v0.30.0 with ../../ generator. DO NOT EDIT.
// Code generated by Webrpc-gen@v0.32.3 with ../../ generator. DO NOT EDIT.
//
// webrpc-gen -schema=service.ridl -target=../../ -client -out=./webapp/client.gen.ts

Expand All @@ -12,7 +12,7 @@ export const WebrpcVersion = "v1"
export const WebrpcSchemaVersion = "v1.0.0"

// Schema hash generated from your RIDL schema
export const WebrpcSchemaHash = "a799dc63b082644f5d003c8881424546aee23a2c"
export const WebrpcSchemaHash = "8b6b6e0df6c23832e31534594d32955c3383689b"

//
// Client interface
Expand Down Expand Up @@ -70,7 +70,7 @@ export interface SubscribeUsersResponse {
export class Chat implements ChatClient {
protected hostname: string
protected fetch: Fetch
protected path = '/rpc/Chat/'
protected path = '/v1/Chat/'

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

export const WebrpcHeader = "Webrpc"

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

type WebrpcGenVersions = {
WebrpcGenVersion: string;
Expand Down
6 changes: 4 additions & 2 deletions client.go.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{{- define "client" -}}

{{- $basepath := .BasePath -}}
{{- $services := .Services -}}
{{- $typeMap := .TypeMap -}}
{{- $opts := .Opts -}}

Expand All @@ -8,11 +10,11 @@
// Client
//

{{- "\n" -}}{{- range $serviceIndex, $service := .Services}}
{{- "\n" -}}{{- range $serviceIndex, $service := $services}}
export class {{$service.Name}} implements {{$service.Name}}Client {
protected hostname: string
protected fetch: Fetch
protected path = '/rpc/{{$service.Name}}/'
protected path = '{{$basepath}}{{$service.Name}}/'

constructor(hostname: string, fetch: Fetch) {
this.hostname = hostname.replace(/\/*$/, '')
Expand Down
4 changes: 2 additions & 2 deletions main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ export const WebrpcSchemaHash = "{{.SchemaHash}}"
{{- "\n" -}}

{{- if $opts.client -}}
{{template "client" dict "Services" .Services "Opts" $opts "TypeMap" $typeMap}}
{{template "client" dict "BasePath" .BasePath "Services" .Services "Opts" $opts "TypeMap" $typeMap}}
{{template "clientHelpers" dict "WebrpcErrors" .WebrpcErrors "SchemaErrors" .Errors "Opts" $opts }}
{{- end -}}

{{- "\n" -}}

{{- if $opts.server -}}
{{template "server" dict "Services" .Services "Opts" $opts "TypeMap" $typeMap "UsesBigInts" $usesBigInts}}
{{template "server" dict "BasePath" .BasePath "Services" .Services "Opts" $opts "TypeMap" $typeMap "UsesBigInts" $usesBigInts}}
{{template "serverHelpers" dict "Types" .Types "TypeMap" $typeMap}}
{{- end -}}

Expand Down
3 changes: 2 additions & 1 deletion server.go.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{- define "server" -}}

{{- $basepath := .BasePath -}}
{{- $services := .Services -}}
{{- $typeMap := .TypeMap -}}
{{- $usesBigInts := .UsesBigInts -}}
Expand All @@ -10,7 +11,7 @@
//
{{range $_, $service := $services }}
export const serve{{$service.Name}}Rpc = async <Context>(service: {{$service.Name}}Server<Context>, ctx: Context, urlPath: string, body: any) => {
if (!urlPath.startsWith('/rpc/')) return null
if (!urlPath.startsWith('{{$basepath}}')) return null
const parts = urlPath.split('/').filter(Boolean)
if (parts.length !== 3 || parts[0] !== 'rpc' || parts[1] !== '{{$service.Name}}') return null
const method = parts[2]!
Expand Down