add reflection service to valut

This commit is contained in:
iamBadgers
2025-06-12 19:28:42 -07:00
parent a4be179faf
commit 39a3783ebd
5 changed files with 383 additions and 238 deletions

View File

@@ -1,4 +1,11 @@
import { Server, ServerUnaryCall, sendUnaryData } from '@grpc/grpc-js'
import {
Server,
ServerUnaryCall,
sendUnaryData,
loadPackageDefinition,
} from '@grpc/grpc-js'
import { ReflectionService } from '@grpc/reflection'
import { loadSync } from '@grpc/proto-loader'
import {
Character,
@@ -6,35 +13,45 @@ import {
CreateCharacterRequest,
} from './proto/character'
import { characterManagerDefinition } from "./proto/character.grpc-server"
import { characterManagerDefinition } from './proto/character.grpc-server'
export function initCharacterService(server: Server) {
server.addService(characterManagerDefinition, {
createCharacter: createCharacter_Call,
getCharacter: getCharacter_Call,
})
new ReflectionService(loadSync('./src/proto/character.proto')).addToServer(
server,
)
}
function createCharacter_Call(call: ServerUnaryCall<CreateCharacterRequest, Character>, callback: sendUnaryData<Character>) {
function createCharacter_Call(
call: ServerUnaryCall<CreateCharacterRequest, Character>,
callback: sendUnaryData<Character>,
) {
callback(null, createCharacter(call.request))
}
function createCharacter(request: CreateCharacterRequest): Character {
return {
playerName: "test player",
characterName: "test character",
characterAlias: ["test alias"]
return {
playerName: 'test player',
characterName: 'test character',
characterAlias: ['test alias'],
}
}
function getCharacter_Call(call: ServerUnaryCall<GetCharacterRequest, Character>, callback: sendUnaryData<Character>) {
function getCharacter_Call(
call: ServerUnaryCall<GetCharacterRequest, Character>,
callback: sendUnaryData<Character>,
) {
callback(null, getCharacter(call.request))
}
function getCharacter(request: GetCharacterRequest): Character {
return {
playerName: "test player",
characterName: "test character",
characterAlias: ["test alias"]
playerName: 'test player',
characterName: 'test character',
characterAlias: ['test alias'],
}
}