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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
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
run: git clone --single-branch https://github.com/webrpc/webrpc.git --branch feat/type-alias && cd webrpc && make install

- name: Regenerate examples
run: cd _examples && make generate
Expand Down
5 changes: 5 additions & 0 deletions _examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ all: generate diff
generate:
cd node-ts && make generate
cd sse && make generate
# Strip webrpc-gen version from generated files to avoid git conflicts.
@VERSION=$$(webrpc-gen --version | awk '{print $$2}'); \
if [ -n "$$VERSION" ] && [ "$$VERSION" != "unknown" ]; then \
git grep -l "$$VERSION" -- '*.ts' | xargs sed -i "s/@$$VERSION//g"; \
fi

diff:
git diff --color --ignore-all-space --ignore-blank-lines --exit-code .
22 changes: 18 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 83e44adec2381759b0925cfad2f5e25da97ad163
// node-ts v1.0.0 305dd11845b5c89bc81db898e446009c1d713c4c
// --
// Code generated by Webrpc-gen@v0.36.0 with ../../../gen-typescript generator. DO NOT EDIT.
// Code generated by Webrpc-gen 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 = "83e44adec2381759b0925cfad2f5e25da97ad163"
export const WebrpcSchemaHash = "305dd11845b5c89bc81db898e446009c1d713c4c"


//
Expand All @@ -29,6 +29,10 @@ export interface ExampleServer<Context = unknown> {
// Schema types
//

export type Username = string

export type Age = number

export enum Kind {
USER = 'USER',
ADMIN = 'ADMIN'
Expand Down Expand Up @@ -160,6 +164,14 @@ const JS_TYPES = [
"undefined"
]

const validateUsername = (value: any) => {
return true
}

const validateAge = (value: any) => {
return true
}

const validateKind = (value: any) => {
if (!("USER" in value) || !validateType(value["USER"], "number")) {
return false
Expand Down Expand Up @@ -217,6 +229,8 @@ const validateGetArticleResponse = (value: any) => {
}

const TYPE_VALIDATORS: { [type: string]: (value: any) => boolean } = {
Username: validateUsername,
Age: validateAge,
Kind: validateKind,
User: validateUser,
Page: validatePage,
Expand Down Expand Up @@ -555,7 +569,7 @@ export const webrpcErrorByCode: { [code: number]: any } = {

export const WebrpcHeader = "Webrpc"

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

type WebrpcGenVersions = {
WebrpcGenVersion: string;
Expand Down
22 changes: 18 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 83e44adec2381759b0925cfad2f5e25da97ad163
// node-ts v1.0.0 305dd11845b5c89bc81db898e446009c1d713c4c
// --
// Code generated by Webrpc-gen@v0.36.0 with ../../../gen-typescript generator. DO NOT EDIT.
// Code generated by Webrpc-gen 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 = "83e44adec2381759b0925cfad2f5e25da97ad163"
export const WebrpcSchemaHash = "305dd11845b5c89bc81db898e446009c1d713c4c"


//
Expand All @@ -29,6 +29,10 @@ export interface ExampleServer<Context = unknown> {
// Schema types
//

export type Username = string

export type Age = number

export enum Kind {
USER = 'USER',
ADMIN = 'ADMIN'
Expand Down Expand Up @@ -160,6 +164,14 @@ const JS_TYPES = [
"undefined"
]

const validateUsername = (value: any) => {
return true
}

const validateAge = (value: any) => {
return true
}

const validateKind = (value: any) => {
if (!("USER" in value) || !validateType(value["USER"], "number")) {
return false
Expand Down Expand Up @@ -217,6 +229,8 @@ const validateGetArticleResponse = (value: any) => {
}

const TYPE_VALIDATORS: { [type: string]: (value: any) => boolean } = {
Username: validateUsername,
Age: validateAge,
Kind: validateKind,
User: validateUser,
Page: validatePage,
Expand Down Expand Up @@ -555,7 +569,7 @@ export const webrpcErrorByCode: { [code: number]: any } = {

export const WebrpcHeader = "Webrpc"

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

type WebrpcGenVersions = {
WebrpcGenVersion: string;
Expand Down
22 changes: 18 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 83e44adec2381759b0925cfad2f5e25da97ad163
// node-ts v1.0.0 305dd11845b5c89bc81db898e446009c1d713c4c
// --
// Code generated by Webrpc-gen@v0.36.0 with ../../../gen-typescript generator. DO NOT EDIT.
// Code generated by Webrpc-gen 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 = "83e44adec2381759b0925cfad2f5e25da97ad163"
export const WebrpcSchemaHash = "305dd11845b5c89bc81db898e446009c1d713c4c"


//
Expand All @@ -29,6 +29,10 @@ export interface ExampleServer<Context = unknown> {
// Schema types
//

export type Username = string

export type Age = number

export enum Kind {
USER = 'USER',
ADMIN = 'ADMIN'
Expand Down Expand Up @@ -160,6 +164,14 @@ const JS_TYPES = [
"undefined"
]

const validateUsername = (value: any) => {
return true
}

const validateAge = (value: any) => {
return true
}

const validateKind = (value: any) => {
if (!("USER" in value) || !validateType(value["USER"], "number")) {
return false
Expand Down Expand Up @@ -217,6 +229,8 @@ const validateGetArticleResponse = (value: any) => {
}

const TYPE_VALIDATORS: { [type: string]: (value: any) => boolean } = {
Username: validateUsername,
Age: validateAge,
Kind: validateKind,
User: validateUser,
Page: validatePage,
Expand Down Expand Up @@ -555,7 +569,7 @@ export const webrpcErrorByCode: { [code: number]: any } = {

export const WebrpcHeader = "Webrpc"

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

type WebrpcGenVersions = {
WebrpcGenVersion: string;
Expand Down
4 changes: 4 additions & 0 deletions _examples/node-ts/service.ridl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ service Example
# Get article by id.
- GetArticle(GetArticleRequest) => (GetArticleResponse)

type Username: string

type Age: uint32

enum Kind: uint32
- USER
- ADMIN
Expand Down
12 changes: 8 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 83e44adec2381759b0925cfad2f5e25da97ad163
// node-ts v1.0.0 305dd11845b5c89bc81db898e446009c1d713c4c
// --
// Code generated by Webrpc-gen@v0.36.0 with ../../../gen-typescript generator. DO NOT EDIT.
// Code generated by Webrpc-gen 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 = "83e44adec2381759b0925cfad2f5e25da97ad163"
export const WebrpcSchemaHash = "305dd11845b5c89bc81db898e446009c1d713c4c"

//
// Client interface
Expand Down Expand Up @@ -40,6 +40,10 @@ export interface ExampleClient {
// Schema types
//

export type Username = string

export type Age = number

export enum Kind {
USER = 'USER',
ADMIN = 'ADMIN'
Expand Down Expand Up @@ -496,7 +500,7 @@ export const webrpcErrorByCode: { [code: number]: any } = {

export const WebrpcHeader = "Webrpc"

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

type WebrpcGenVersions = {
WebrpcGenVersion: string;
Expand Down
4 changes: 2 additions & 2 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 8b6b6e0df6c23832e31534594d32955c3383689b
// --
// Code generated by Webrpc-gen@v0.36.0 with ../../ generator. DO NOT EDIT.
// Code generated by Webrpc-gen with ../../ generator. DO NOT EDIT.
//
// webrpc-gen -schema=service.ridl -target=../../ -client -out=./webapp/client.gen.ts

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

export const WebrpcHeader = "Webrpc"

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

type WebrpcGenVersions = {
WebrpcGenVersion: string;
Expand Down
4 changes: 4 additions & 0 deletions types.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export enum {{$type.Name}} {
}
{{end -}}

{{- if isAliasType $type }}
export type {{$type.Name}} = {{template "type" dict "Type" $type.Type "TypeMap" $typeMap}}
{{end -}}

{{- if isStructType $type }}
export interface {{$type.Name}} {
{{- range $_, $field := $type.Fields}}
Expand Down
Loading