-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
intents: skip client code generation (#149)
- Loading branch information
Showing
3 changed files
with
5 additions
and
250 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
// -- | ||
// Code generated by [email protected] 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<any> => { | ||
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<Response> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |