1
1
import type { JSONRPCErrorInterface } from './dto/errors.ts'
2
2
3
+ /**
4
+ * This can be used for constrain of type that can be converted to json
5
+ */
3
6
export type JSONRPCValue = PrimitiveValue | StructuredValue
4
7
5
8
export type PrimitiveValue = string | number | boolean | null
@@ -19,22 +22,20 @@ export type ArrayValue = Array<JSONRPCValue>
19
22
*
20
23
* If method throws a value that is not `JSONRPCError`, it will be treated as `JSONRPCInternalError`
21
24
*
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`
23
27
*/
24
28
export interface JSONRPCMethods {
25
- [ method : string ] : JSONRPCMethod
29
+ // deno-lint-ignore no-explicit-any
30
+ [ method : string ] : JSONRPCMethod < any , any >
26
31
}
27
32
28
33
/**
29
34
* 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)
33
35
*/
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
38
39
39
40
export type WithOptionalJSONRPCVersion < T extends object > =
40
41
& Omit < T , 'jsonrpc' >
0 commit comments