-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
57 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
export function proxify(namespace: string) { | ||
return new Proxy({}, { | ||
get(target: unknown, prop: string): unknown { | ||
return (...args: unknown[]) => { | ||
return {}; | ||
}; | ||
} | ||
}) | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
export type JSONRPC_Message = { | ||
jsonrpc: '2.0-rc'; | ||
}; | ||
|
||
export type SuccessResponse = JSONRPC_Message & { | ||
id: string; | ||
result: any; | ||
}; | ||
|
||
export type ErrorResponse = JSONRPC_Message & { | ||
error: { | ||
code: number; | ||
message: string; | ||
data?: Record<string, unknown>; | ||
}; | ||
id: string | null; | ||
}; | ||
|
||
export type JSONRPC_Response = SuccessResponse | ErrorResponse; | ||
|
||
const encoder = new TextEncoder(); | ||
|
||
export async function errorResponse({ error: { message, code = -32000, data }, id }: Omit<ErrorResponse, 'jsonrpc'>): Promise<void> { | ||
const rpc: ErrorResponse = { | ||
jsonrpc: '2.0-rc', | ||
id, | ||
error: { message, code, ...(data && { data }) }, | ||
}; | ||
|
||
const encoded = this.encoder.encode(JSON.stringify(rpc)); | ||
Deno.stdout.write(encoded); | ||
} | ||
|
||
export async function successResponse(id: string, ...result: unknown[]): Promise<void> { | ||
const rpc: SuccessResponse = { | ||
jsonrpc: '2.0-rc', | ||
id, | ||
result, | ||
}; | ||
const encoded = this.encoder.encode(JSON.stringify(rpc)); | ||
await Deno.stdout.write(encoded); | ||
} |
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
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