11import type { JSONRPCErrorInterface } from './dto/errors.ts'
22
3+ /**
4+ * This can be used for constrain of type that can be converted to json
5+ */
36export type JSONRPCValue = PrimitiveValue | StructuredValue
47
58export type PrimitiveValue = string | number | boolean | null
@@ -19,22 +22,20 @@ export type ArrayValue = Array<JSONRPCValue>
1922 *
2023 * If method throws a value that is not `JSONRPCError`, it will be treated as `JSONRPCInternalError`
2124 *
22- * Note that client is allowed to send no params, meaning that params can also be `undefined`
25+ * Note that client is allowed to send no params, meaning that params can also be `undefined`,
26+ * server may also send result `undefined`
2327 */
2428export interface JSONRPCMethods {
25- [ method : string ] : JSONRPCMethod
29+ // deno-lint-ignore no-explicit-any
30+ [ method : string ] : JSONRPCMethod < any , any >
2631}
2732
2833/**
2934 * Represent any json rpc method, any detailed method should extend it
30- *
31- * Note that for a request, `params` MUST be `JSONRPCValue`,
32- * however here `params` is `any` (just for simplicity)
3335 */
34- export type JSONRPCMethod = (
35- // deno-lint-ignore no-explicit-any
36- params : any , //! client may send any params to server
37- ) => Promise < JSONRPCValue > | JSONRPCValue
36+ export type JSONRPCMethod < Params , Result > = (
37+ params : Params ,
38+ ) => Promise < Result > | Result
3839
3940export type WithOptionalJSONRPCVersion < T extends object > =
4041 & Omit < T , 'jsonrpc' >
0 commit comments