Function: jsonRPCRequestOfContext()
jsonRPCRequestOfContext(
context):JSONRPCRequestInfo|undefined
Get the JSON-RPC request behind a service action's request, when jsonRPCServiceEntrypoint serves it (to tell a notification from a request, or read the transport).
Parameters
context
The service action's context (this.context in a controller).
Returns
JSONRPCRequestInfo | undefined
The request's method, id and transport, or undefined when another adapter serves the request.
Example
typescript
import {Controller, ServiceContext} from 'lakutata/com/entrypoint'
import {ServiceAction} from 'lakutata/decorator/ctrl'
import {jsonRPCRequestOfContext, type JSONRPCRequestInfo} from 'lakutata/adapter/jsonrpc'
class LogController extends Controller {
//{"jsonrpc": "2.0", "method": "log.write", "params": {"line": "started"}}: a notification, no id
@ServiceAction({method: 'log.write'})
public async write(input: {line: string}): Promise<void> {
const request: JSONRPCRequestInfo | undefined = jsonRPCRequestOfContext(this.context as ServiceContext)
console.log(`${request?.transport}: ${input.line}`)
}
}