-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
33a6cba
commit f33cf3b
Showing
3 changed files
with
208 additions
and
0 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,53 @@ | ||
import type { | ||
BrpRequest, | ||
DestroyRequest, | ||
GetRequest, | ||
GetWatchRequest, | ||
InsertRequest, | ||
ListRequest, | ||
ListWatchRequest, | ||
QueryRequest, | ||
RemoveRequest, | ||
ReparentRequest, | ||
SpawnRequest, | ||
} from "./request"; | ||
import type { | ||
BrpResponse, | ||
DestroyResponse, | ||
GetResponse, | ||
GetWatchResponse, | ||
InsertResponse, | ||
ListResponse, | ||
ListWatchResponse, | ||
QueryResponse, | ||
RemoveResponse, | ||
ReparentResponse, | ||
SpawnResponse, | ||
} from "./response"; | ||
|
||
export async function brpRequest(request: GetRequest): Promise<GetResponse>; | ||
export async function brpRequest(request: QueryRequest): Promise<QueryResponse>; | ||
export async function brpRequest(request: SpawnRequest): Promise<SpawnResponse>; | ||
export async function brpRequest(request: DestroyRequest): Promise<DestroyResponse>; | ||
export async function brpRequest(request: RemoveRequest): Promise<RemoveResponse>; | ||
export async function brpRequest(request: InsertRequest): Promise<InsertResponse>; | ||
export async function brpRequest(request: ReparentRequest): Promise<ReparentResponse>; | ||
export async function brpRequest(request: ListRequest): Promise<ListResponse>; | ||
export async function brpRequest(request: GetWatchRequest): Promise<GetWatchResponse>; | ||
export async function brpRequest(request: ListWatchRequest): Promise<ListWatchResponse>; | ||
|
||
export async function brpRequest( | ||
req: BrpRequest, | ||
): Promise<BrpResponse> { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const request: BrpRequest = { | ||
...req, | ||
jsonrpc: req.jsonrpc ?? "2.0", | ||
}; | ||
|
||
return { | ||
jsonrpc: "2.0", | ||
id: null, | ||
error: { code: 0, message: "Not implmented" }, | ||
}; | ||
} |
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,87 @@ | ||
// deno-fmt-ignore-file | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
interface JsonRpcRequest<TParams> { | ||
jsonrpc?: "2.0"; | ||
id?: number | string | null; | ||
method: string; | ||
params: TParams; | ||
} | ||
|
||
interface GetParams { | ||
entity: number; | ||
components: string[]; | ||
strict?: boolean; | ||
} | ||
|
||
interface QueryParams { | ||
data?: { | ||
components?: string[]; | ||
option?: string[]; | ||
has?: string[]; | ||
}; | ||
filter?: { | ||
with?: string[]; | ||
without?: string[]; | ||
}; | ||
} | ||
|
||
interface SpawnParams { | ||
components: Record<string, any>; | ||
} | ||
|
||
interface DestroyParams { | ||
entity: number; | ||
} | ||
|
||
interface RemoveParams { | ||
entity: number; | ||
components: string[]; | ||
} | ||
|
||
interface InsertParams { | ||
entity: number; | ||
components: Record<string, any>; | ||
} | ||
|
||
interface ReparentParams { | ||
entities: number[]; | ||
parent?: number; | ||
} | ||
|
||
interface ListParams { | ||
entity?: number; | ||
} | ||
|
||
interface GetWatchParams { | ||
entity: number; | ||
components: string[]; | ||
strict?: boolean; | ||
} | ||
|
||
interface ListWatchParams { | ||
entity: number; | ||
} | ||
|
||
export type GetRequest = JsonRpcRequest<GetParams> & { method: "bevy/get" }; | ||
export type QueryRequest = JsonRpcRequest<QueryParams> & { method: "bevy/query" }; | ||
export type SpawnRequest = JsonRpcRequest<SpawnParams> & { method: "bevy/spawn" }; | ||
export type DestroyRequest = JsonRpcRequest<DestroyParams> & { method: "bevy/destroy" }; | ||
export type RemoveRequest = JsonRpcRequest<RemoveParams> & { method: "bevy/remove" }; | ||
export type InsertRequest = JsonRpcRequest<InsertParams> & { method: "bevy/insert" }; | ||
export type ReparentRequest = JsonRpcRequest<ReparentParams> & { method: "bevy/reparent" }; | ||
export type ListRequest = JsonRpcRequest<ListParams> & { method: "bevy/list" }; | ||
export type GetWatchRequest = JsonRpcRequest<GetWatchParams> & { method: "bevy/get+watch" }; | ||
export type ListWatchRequest = JsonRpcRequest<ListWatchParams> & { method: "bevy/list+watch" }; | ||
|
||
export type BrpRequest = | ||
| GetRequest | ||
| QueryRequest | ||
| SpawnRequest | ||
| DestroyRequest | ||
| RemoveRequest | ||
| InsertRequest | ||
| ReparentRequest | ||
| ListRequest | ||
| GetWatchRequest | ||
| ListWatchRequest; |
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,68 @@ | ||
// deno-fmt-ignore-file | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
interface JsonRpcResponse<TResult> { | ||
jsonrpc: "2.0"; | ||
id?: number | string | null; | ||
result?: TResult; | ||
error?: JsonRpcError; | ||
} | ||
|
||
interface JsonRpcError { | ||
code: number; | ||
message: string; | ||
data?: any; | ||
} | ||
|
||
interface GetResult { | ||
components: Record<string, any>; | ||
errors?: Record<string, JsonRpcError>; | ||
} | ||
|
||
interface QueryResult { | ||
entity: number; | ||
components: Record<string, any>; | ||
has?: Record<string, boolean>; | ||
} | ||
|
||
interface SpawnResult { | ||
entity: number; | ||
} | ||
|
||
interface ListResult { | ||
components: string[]; | ||
} | ||
|
||
interface GetWatchResult { | ||
components: Record<string, any>; | ||
removed: string[]; | ||
errors?: Record<string, JsonRpcError>; | ||
} | ||
|
||
interface ListWatchResult { | ||
added: string[]; | ||
removed: string[]; | ||
} | ||
|
||
export type GetResponse = JsonRpcResponse<GetResult>; | ||
export type QueryResponse = JsonRpcResponse<QueryResult[]>; | ||
export type SpawnResponse = JsonRpcResponse<SpawnResult>; | ||
export type DestroyResponse = JsonRpcResponse<null>; | ||
export type RemoveResponse = JsonRpcResponse<null>; | ||
export type InsertResponse = JsonRpcResponse<null>; | ||
export type ReparentResponse = JsonRpcResponse<null>; | ||
export type ListResponse = JsonRpcResponse<ListResult>; | ||
export type GetWatchResponse = JsonRpcResponse<GetWatchResult>; | ||
export type ListWatchResponse = JsonRpcResponse<ListWatchResult>; | ||
|
||
export type BrpResponse = | ||
| GetResponse | ||
| QueryResponse | ||
| SpawnResponse | ||
| DestroyResponse | ||
| RemoveResponse | ||
| InsertResponse | ||
| ReparentResponse | ||
| ListResponse | ||
| GetWatchResponse | ||
| ListWatchResponse; |