diff --git a/_examples/node-ts/server/server.gen.ts b/_examples/node-ts/server/server.gen.ts index 862a5ac..00d5e2f 100644 --- a/_examples/node-ts/server/server.gen.ts +++ b/_examples/node-ts/server/server.gen.ts @@ -1,13 +1,13 @@ /* eslint-disable */ -// node-ts v1.0.0 6713366104e62b8479d628a193e2a7ca03f37edc +// node-ts v1.0.0 f5566a7aae2c4d2f76cc64d8e55f9ac841447e43 // -- -// Code generated by webrpc-gen@v0.21.4 with ../../../gen-typescript generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.22.0 with ../../../gen-typescript generator. DO NOT EDIT. // // webrpc-gen -schema=service.ridl -target=../../../gen-typescript -server -out=./server/server.gen.ts export const WebrpcHeader = "Webrpc" -export const WebrpcHeaderValue = "webrpc@v0.21.4;gen-typescript@unknown;node-ts@v1.0.0" +export const WebrpcHeaderValue = "webrpc@v0.22.0;gen-typescript@unknown;node-ts@v1.0.0" // WebRPC description and code-gen version export const WebRPCVersion = "v1" @@ -16,7 +16,7 @@ export const WebRPCVersion = "v1" export const WebRPCSchemaVersion = "v1.0.0" // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = "6713366104e62b8479d628a193e2a7ca03f37edc" +export const WebRPCSchemaHash = "f5566a7aae2c4d2f76cc64d8e55f9ac841447e43" type WebrpcGenVersions = { webrpcGenVersion: string; diff --git a/_examples/node-ts/service.ridl b/_examples/node-ts/service.ridl index a121481..386fd85 100644 --- a/_examples/node-ts/service.ridl +++ b/_examples/node-ts/service.ridl @@ -3,12 +3,10 @@ webrpc = v1 name = node-ts version = v1.0.0 - enum Kind: uint32 - USER - ADMIN - struct User - ID: uint64 + json = id @@ -25,11 +23,17 @@ struct User - createdAt?: timestamp - struct Page - num: uint32 - service ExampleService - Ping() => () - GetUser(userID: uint64) => (code: uint32, user: User) + +error 1000 Unauthorized "Unauthorized access" HTTP 401 +error 1001 PermissionDenied "Permission denied" HTTP 403 +error 1002 SessionExpired "Session expired" HTTP 403 +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 + diff --git a/_examples/node-ts/webapp/client.gen.ts b/_examples/node-ts/webapp/client.gen.ts index 8cb49d2..496c943 100644 --- a/_examples/node-ts/webapp/client.gen.ts +++ b/_examples/node-ts/webapp/client.gen.ts @@ -1,13 +1,13 @@ /* eslint-disable */ -// node-ts v1.0.0 6713366104e62b8479d628a193e2a7ca03f37edc +// node-ts v1.0.0 f5566a7aae2c4d2f76cc64d8e55f9ac841447e43 // -- -// Code generated by webrpc-gen@v0.21.4 with ../../../gen-typescript generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.22.0 with ../../../gen-typescript generator. DO NOT EDIT. // // webrpc-gen -schema=service.ridl -target=../../../gen-typescript -client -out=./webapp/client.gen.ts export const WebrpcHeader = "Webrpc" -export const WebrpcHeaderValue = "webrpc@v0.21.4;gen-typescript@unknown;node-ts@v1.0.0" +export const WebrpcHeaderValue = "webrpc@v0.22.0;gen-typescript@unknown;node-ts@v1.0.0" // WebRPC description and code-gen version export const WebRPCVersion = "v1" @@ -16,7 +16,7 @@ export const WebRPCVersion = "v1" export const WebRPCSchemaVersion = "v1.0.0" // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = "6713366104e62b8479d628a193e2a7ca03f37edc" +export const WebRPCSchemaHash = "f5566a7aae2c4d2f76cc64d8e55f9ac841447e43" type WebrpcGenVersions = { webrpcGenVersion: string; @@ -227,7 +227,7 @@ export class WebrpcEndpointError extends WebrpcError { constructor( name: string = 'WebrpcEndpoint', code: number = 0, - message: string = 'endpoint error', + message: string = `endpoint error`, status: number = 0, cause?: string ) { @@ -240,7 +240,7 @@ export class WebrpcRequestFailedError extends WebrpcError { constructor( name: string = 'WebrpcRequestFailed', code: number = -1, - message: string = 'request failed', + message: string = `request failed`, status: number = 0, cause?: string ) { @@ -253,7 +253,7 @@ export class WebrpcBadRouteError extends WebrpcError { constructor( name: string = 'WebrpcBadRoute', code: number = -2, - message: string = 'bad route', + message: string = `bad route`, status: number = 0, cause?: string ) { @@ -266,7 +266,7 @@ export class WebrpcBadMethodError extends WebrpcError { constructor( name: string = 'WebrpcBadMethod', code: number = -3, - message: string = 'bad method', + message: string = `bad method`, status: number = 0, cause?: string ) { @@ -279,7 +279,7 @@ export class WebrpcBadRequestError extends WebrpcError { constructor( name: string = 'WebrpcBadRequest', code: number = -4, - message: string = 'bad request', + message: string = `bad request`, status: number = 0, cause?: string ) { @@ -292,7 +292,7 @@ export class WebrpcBadResponseError extends WebrpcError { constructor( name: string = 'WebrpcBadResponse', code: number = -5, - message: string = 'bad response', + message: string = `bad response`, status: number = 0, cause?: string ) { @@ -305,7 +305,7 @@ export class WebrpcServerPanicError extends WebrpcError { constructor( name: string = 'WebrpcServerPanic', code: number = -6, - message: string = 'server panic', + message: string = `server panic`, status: number = 0, cause?: string ) { @@ -318,7 +318,7 @@ export class WebrpcInternalErrorError extends WebrpcError { constructor( name: string = 'WebrpcInternalError', code: number = -7, - message: string = 'internal error', + message: string = `internal error`, status: number = 0, cause?: string ) { @@ -331,7 +331,7 @@ export class WebrpcClientDisconnectedError extends WebrpcError { constructor( name: string = 'WebrpcClientDisconnected', code: number = -8, - message: string = 'client disconnected', + message: string = `client disconnected`, status: number = 0, cause?: string ) { @@ -344,7 +344,7 @@ export class WebrpcStreamLostError extends WebrpcError { constructor( name: string = 'WebrpcStreamLost', code: number = -9, - message: string = 'stream lost', + message: string = `stream lost`, status: number = 0, cause?: string ) { @@ -357,7 +357,7 @@ export class WebrpcStreamFinishedError extends WebrpcError { constructor( name: string = 'WebrpcStreamFinished', code: number = -10, - message: string = 'stream finished', + message: string = `stream finished`, status: number = 0, cause?: string ) { @@ -369,6 +369,84 @@ export class WebrpcStreamFinishedError extends WebrpcError { // Schema errors +export class UnauthorizedError extends WebrpcError { + constructor( + name: string = 'Unauthorized', + code: number = 1000, + message: string = `Unauthorized access`, + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, UnauthorizedError.prototype) + } +} + +export class PermissionDeniedError extends WebrpcError { + constructor( + name: string = 'PermissionDenied', + code: number = 1001, + message: string = `Permission denied`, + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, PermissionDeniedError.prototype) + } +} + +export class SessionExpiredError extends WebrpcError { + constructor( + name: string = 'SessionExpired', + code: number = 1002, + message: string = `Session expired`, + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, SessionExpiredError.prototype) + } +} + +export class GeoblockedError extends WebrpcError { + constructor( + name: string = 'Geoblocked', + code: number = 1003, + message: string = `Geoblocked region`, + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, GeoblockedError.prototype) + } +} + +export class RateLimitedError extends WebrpcError { + constructor( + name: string = 'RateLimited', + code: number = 1004, + message: string = `Rate-limited. Please slow down.`, + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, RateLimitedError.prototype) + } +} + +export class CorsDisallowedError extends WebrpcError { + constructor( + name: string = 'CorsDisallowed', + code: number = 1005, + message: string = `CORS disallowed. JWT can't be used from a web app.`, + status: number = 0, + cause?: string + ) { + super(name, code, message, status, cause) + Object.setPrototypeOf(this, CorsDisallowedError.prototype) + } +} + export enum errors { WebrpcEndpoint = 'WebrpcEndpoint', @@ -382,6 +460,12 @@ export enum errors { WebrpcClientDisconnected = 'WebrpcClientDisconnected', WebrpcStreamLost = 'WebrpcStreamLost', WebrpcStreamFinished = 'WebrpcStreamFinished', + Unauthorized = 'Unauthorized', + PermissionDenied = 'PermissionDenied', + SessionExpired = 'SessionExpired', + Geoblocked = 'Geoblocked', + RateLimited = 'RateLimited', + CorsDisallowed = 'CorsDisallowed', } export enum WebrpcErrorCodes { @@ -396,6 +480,12 @@ export enum WebrpcErrorCodes { WebrpcClientDisconnected = -8, WebrpcStreamLost = -9, WebrpcStreamFinished = -10, + Unauthorized = 1000, + PermissionDenied = 1001, + SessionExpired = 1002, + Geoblocked = 1003, + RateLimited = 1004, + CorsDisallowed = 1005, } export const webrpcErrorByCode: { [code: number]: any } = { @@ -410,6 +500,12 @@ export const webrpcErrorByCode: { [code: number]: any } = { [-8]: WebrpcClientDisconnectedError, [-9]: WebrpcStreamLostError, [-10]: WebrpcStreamFinishedError, + [1000]: UnauthorizedError, + [1001]: PermissionDeniedError, + [1002]: SessionExpiredError, + [1003]: GeoblockedError, + [1004]: RateLimitedError, + [1005]: CorsDisallowedError, } export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise diff --git a/_examples/sse/webapp/client.gen.ts b/_examples/sse/webapp/client.gen.ts index 0318db2..32d3550 100644 --- a/_examples/sse/webapp/client.gen.ts +++ b/_examples/sse/webapp/client.gen.ts @@ -1,13 +1,13 @@ /* eslint-disable */ // webrpc-sse-chat v1.0.0 a799dc63b082644f5d003c8881424546aee23a2c // -- -// Code generated by webrpc-gen@v0.21.4 with ../../ generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.22.0 with ../../ generator. DO NOT EDIT. // // webrpc-gen -schema=service.ridl -target=../../ -client -out=./webapp/client.gen.ts export const WebrpcHeader = "Webrpc" -export const WebrpcHeaderValue = "webrpc@v0.21.4;@unknown;webrpc-sse-chat@v1.0.0" +export const WebrpcHeaderValue = "webrpc@v0.22.0;@unknown;webrpc-sse-chat@v1.0.0" // WebRPC description and code-gen version export const WebRPCVersion = "v1" @@ -383,7 +383,7 @@ export class WebrpcEndpointError extends WebrpcError { constructor( name: string = 'WebrpcEndpoint', code: number = 0, - message: string = 'endpoint error', + message: string = `endpoint error`, status: number = 0, cause?: string ) { @@ -396,7 +396,7 @@ export class WebrpcRequestFailedError extends WebrpcError { constructor( name: string = 'WebrpcRequestFailed', code: number = -1, - message: string = 'request failed', + message: string = `request failed`, status: number = 0, cause?: string ) { @@ -409,7 +409,7 @@ export class WebrpcBadRouteError extends WebrpcError { constructor( name: string = 'WebrpcBadRoute', code: number = -2, - message: string = 'bad route', + message: string = `bad route`, status: number = 0, cause?: string ) { @@ -422,7 +422,7 @@ export class WebrpcBadMethodError extends WebrpcError { constructor( name: string = 'WebrpcBadMethod', code: number = -3, - message: string = 'bad method', + message: string = `bad method`, status: number = 0, cause?: string ) { @@ -435,7 +435,7 @@ export class WebrpcBadRequestError extends WebrpcError { constructor( name: string = 'WebrpcBadRequest', code: number = -4, - message: string = 'bad request', + message: string = `bad request`, status: number = 0, cause?: string ) { @@ -448,7 +448,7 @@ export class WebrpcBadResponseError extends WebrpcError { constructor( name: string = 'WebrpcBadResponse', code: number = -5, - message: string = 'bad response', + message: string = `bad response`, status: number = 0, cause?: string ) { @@ -461,7 +461,7 @@ export class WebrpcServerPanicError extends WebrpcError { constructor( name: string = 'WebrpcServerPanic', code: number = -6, - message: string = 'server panic', + message: string = `server panic`, status: number = 0, cause?: string ) { @@ -474,7 +474,7 @@ export class WebrpcInternalErrorError extends WebrpcError { constructor( name: string = 'WebrpcInternalError', code: number = -7, - message: string = 'internal error', + message: string = `internal error`, status: number = 0, cause?: string ) { @@ -487,7 +487,7 @@ export class WebrpcClientDisconnectedError extends WebrpcError { constructor( name: string = 'WebrpcClientDisconnected', code: number = -8, - message: string = 'client disconnected', + message: string = `client disconnected`, status: number = 0, cause?: string ) { @@ -500,7 +500,7 @@ export class WebrpcStreamLostError extends WebrpcError { constructor( name: string = 'WebrpcStreamLost', code: number = -9, - message: string = 'stream lost', + message: string = `stream lost`, status: number = 0, cause?: string ) { @@ -513,7 +513,7 @@ export class WebrpcStreamFinishedError extends WebrpcError { constructor( name: string = 'WebrpcStreamFinished', code: number = -10, - message: string = 'stream finished', + message: string = `stream finished`, status: number = 0, cause?: string ) { @@ -529,7 +529,7 @@ export class EmptyUsernameError extends WebrpcError { constructor( name: string = 'EmptyUsername', code: number = 100, - message: string = 'Username must be provided.', + message: string = `Username must be provided.`, status: number = 0, cause?: string ) { diff --git a/clientHelpers.go.tmpl b/clientHelpers.go.tmpl index d5c0320..a951b95 100644 --- a/clientHelpers.go.tmpl +++ b/clientHelpers.go.tmpl @@ -75,7 +75,7 @@ export class {{$error.Name}}Error extends WebrpcError { constructor( name: string = '{{$error.Name}}', code: number = {{$error.Code}}, - message: string = '{{$error.Message}}', + message: string = `{{$error.Message}}`, status: number = 0, cause?: string ) { @@ -91,7 +91,7 @@ export class {{$error.Name}}Error extends WebrpcError { constructor( name: string = '{{$error.Name}}', code: number = {{$error.Code}}, - message: string = '{{$error.Message}}', + message: string = `{{$error.Message}}`, status: number = 0, cause?: string ) {