From 359ffa017f6924bd9a4d73633d261368dd2c0585 Mon Sep 17 00:00:00 2001 From: Patryk Kalinowski Date: Wed, 7 Aug 2024 18:08:05 +0200 Subject: [PATCH] intents: skip client code generation --- intents/intent.gen.go | 5 +- intents/intent.gen.ts | 246 +----------------------------------------- intents/proto.go | 4 +- 3 files changed, 5 insertions(+), 250 deletions(-) diff --git a/intents/intent.gen.go b/intents/intent.gen.go index 373f15b9..18af93c4 100644 --- a/intents/intent.gen.go +++ b/intents/intent.gen.go @@ -2,7 +2,7 @@ // -- // Code generated by webrpc-gen@v0.19.3 with golang generator. DO NOT EDIT. // -// webrpc-gen -schema=intent.ridl -target=golang -pkg=intents -client -out=./intent.gen.go +// webrpc-gen -schema=intent.ridl -target=golang -pkg=intents -out=./intent.gen.go package intents import ( @@ -529,8 +529,7 @@ func (k *contextKey) String() string { } var ( - HTTPClientRequestHeadersCtxKey = &contextKey{"HTTPClientRequestHeaders"} - HTTPRequestCtxKey = &contextKey{"HTTPRequest"} + HTTPRequestCtxKey = &contextKey{"HTTPRequest"} ServiceNameCtxKey = &contextKey{"ServiceName"} diff --git a/intents/intent.gen.ts b/intents/intent.gen.ts index 20b5dec0..1a6b9e20 100644 --- a/intents/intent.gen.ts +++ b/intents/intent.gen.ts @@ -3,7 +3,7 @@ // -- // Code generated by webrpc-gen@v0.19.3 with typescript generator. DO NOT EDIT. // -// webrpc-gen -schema=intent.ridl -target=typescript -client -out=./intent.gen.ts +// webrpc-gen -schema=intent.ridl -target=typescript -out=./intent.gen.ts // WebRPC description and code-gen version export const WebRPCVersion = "v1" @@ -356,247 +356,3 @@ export interface Account { issuer?: string email?: string } - - - - const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => { - return { - method: 'POST', - headers: { ...headers, 'Content-Type': 'application/json' }, - body: JSON.stringify(body || {}), - signal - } -} - -const buildResponse = (res: Response): Promise => { - return res.text().then(text => { - let data - try { - data = JSON.parse(text) - } catch(error) { - let message = '' - if (error instanceof Error) { - message = error.message - } - throw WebrpcBadResponseError.new({ - status: res.status, - cause: `JSON.parse(): ${message}: response text: ${text}`}, - ) - } - if (!res.ok) { - const code: number = (typeof data.code === 'number') ? data.code : 0 - throw (webrpcErrorByCode[code] || WebrpcError).new(data) - } - return data - }) -} - -// -// Errors -// - -export class WebrpcError extends Error { - name: string - code: number - message: string - status: number - cause?: string - - /** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */ - msg: string - - constructor(name: string, code: number, message: string, status: number, cause?: string) { - super(message) - this.name = name || 'WebrpcError' - this.code = typeof code === 'number' ? code : 0 - this.message = message || `endpoint error ${this.code}` - this.msg = this.message - this.status = typeof status === 'number' ? status : 0 - this.cause = cause - Object.setPrototypeOf(this, WebrpcError.prototype) - } - - static new(payload: any): WebrpcError { - return new this(payload.error, payload.code, payload.message || payload.msg, payload.status, payload.cause) - } -} - -// Webrpc errors - -export class WebrpcEndpointError extends WebrpcError { - constructor( - name: string = 'WebrpcEndpoint', - code: number = 0, - message: string = 'endpoint error', - status: number = 0, - cause?: string - ) { - super(name, code, message, status, cause) - Object.setPrototypeOf(this, WebrpcEndpointError.prototype) - } -} - -export class WebrpcRequestFailedError extends WebrpcError { - constructor( - name: string = 'WebrpcRequestFailed', - code: number = -1, - message: string = 'request failed', - status: number = 0, - cause?: string - ) { - super(name, code, message, status, cause) - Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype) - } -} - -export class WebrpcBadRouteError extends WebrpcError { - constructor( - name: string = 'WebrpcBadRoute', - code: number = -2, - message: string = 'bad route', - status: number = 0, - cause?: string - ) { - super(name, code, message, status, cause) - Object.setPrototypeOf(this, WebrpcBadRouteError.prototype) - } -} - -export class WebrpcBadMethodError extends WebrpcError { - constructor( - name: string = 'WebrpcBadMethod', - code: number = -3, - message: string = 'bad method', - status: number = 0, - cause?: string - ) { - super(name, code, message, status, cause) - Object.setPrototypeOf(this, WebrpcBadMethodError.prototype) - } -} - -export class WebrpcBadRequestError extends WebrpcError { - constructor( - name: string = 'WebrpcBadRequest', - code: number = -4, - message: string = 'bad request', - status: number = 0, - cause?: string - ) { - super(name, code, message, status, cause) - Object.setPrototypeOf(this, WebrpcBadRequestError.prototype) - } -} - -export class WebrpcBadResponseError extends WebrpcError { - constructor( - name: string = 'WebrpcBadResponse', - code: number = -5, - message: string = 'bad response', - status: number = 0, - cause?: string - ) { - super(name, code, message, status, cause) - Object.setPrototypeOf(this, WebrpcBadResponseError.prototype) - } -} - -export class WebrpcServerPanicError extends WebrpcError { - constructor( - name: string = 'WebrpcServerPanic', - code: number = -6, - message: string = 'server panic', - status: number = 0, - cause?: string - ) { - super(name, code, message, status, cause) - Object.setPrototypeOf(this, WebrpcServerPanicError.prototype) - } -} - -export class WebrpcInternalErrorError extends WebrpcError { - constructor( - name: string = 'WebrpcInternalError', - code: number = -7, - message: string = 'internal error', - status: number = 0, - cause?: string - ) { - super(name, code, message, status, cause) - Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype) - } -} - -export class WebrpcClientDisconnectedError extends WebrpcError { - constructor( - name: string = 'WebrpcClientDisconnected', - code: number = -8, - message: string = 'client disconnected', - status: number = 0, - cause?: string - ) { - super(name, code, message, status, cause) - Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype) - } -} - -export class WebrpcStreamLostError extends WebrpcError { - constructor( - name: string = 'WebrpcStreamLost', - code: number = -9, - message: string = 'stream lost', - status: number = 0, - cause?: string - ) { - super(name, code, message, status, cause) - Object.setPrototypeOf(this, WebrpcStreamLostError.prototype) - } -} - -export class WebrpcStreamFinishedError extends WebrpcError { - constructor( - name: string = 'WebrpcStreamFinished', - code: number = -10, - message: string = 'stream finished', - status: number = 0, - cause?: string - ) { - super(name, code, message, status, cause) - Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype) - } -} - - -// Schema errors - - -export enum errors { - WebrpcEndpoint = 'WebrpcEndpoint', - WebrpcRequestFailed = 'WebrpcRequestFailed', - WebrpcBadRoute = 'WebrpcBadRoute', - WebrpcBadMethod = 'WebrpcBadMethod', - WebrpcBadRequest = 'WebrpcBadRequest', - WebrpcBadResponse = 'WebrpcBadResponse', - WebrpcServerPanic = 'WebrpcServerPanic', - WebrpcInternalError = 'WebrpcInternalError', - WebrpcClientDisconnected = 'WebrpcClientDisconnected', - WebrpcStreamLost = 'WebrpcStreamLost', - WebrpcStreamFinished = 'WebrpcStreamFinished', -} - -const webrpcErrorByCode: { [code: number]: any } = { - [0]: WebrpcEndpointError, - [-1]: WebrpcRequestFailedError, - [-2]: WebrpcBadRouteError, - [-3]: WebrpcBadMethodError, - [-4]: WebrpcBadRequestError, - [-5]: WebrpcBadResponseError, - [-6]: WebrpcServerPanicError, - [-7]: WebrpcInternalErrorError, - [-8]: WebrpcClientDisconnectedError, - [-9]: WebrpcStreamLostError, - [-10]: WebrpcStreamFinishedError, -} - -export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise - diff --git a/intents/proto.go b/intents/proto.go index 5b469512..573d2e43 100644 --- a/intents/proto.go +++ b/intents/proto.go @@ -1,5 +1,5 @@ // Client -//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=intent.ridl -target=golang -pkg=intents -client -out=./intent.gen.go -//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=intent.ridl -target=typescript -client -out=./intent.gen.ts +//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=intent.ridl -target=golang -pkg=intents -out=./intent.gen.go +//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=intent.ridl -target=typescript -out=./intent.gen.ts package intents