ox 1.0.0-beta.3 → 1.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/zod/RpcSchema.d.ts +83 -14
- package/dist/zod/RpcSchema.d.ts.map +1 -1
- package/dist/zod/RpcSchema.js +30 -82
- package/dist/zod/RpcSchema.js.map +1 -1
- package/package.json +1 -1
- package/src/version.ts +1 -1
- package/src/zod/RpcSchema.ts +122 -28
- package/src/zod/_test/RpcSchema.test-d.ts +27 -0
- package/src/zod/_test/RpcSchema.test.ts +19 -0
package/dist/zod/RpcSchema.d.ts
CHANGED
|
@@ -3014,7 +3014,9 @@ export declare const Default: {
|
|
|
3014
3014
|
eth_uninstallFilter: Item<"eth_uninstallFilter", z.ZodMiniTuple<readonly [z.ZodMiniTemplateLiteral<`0x${string}`>], null>, z.ZodMiniBoolean<boolean>>;
|
|
3015
3015
|
};
|
|
3016
3016
|
/**
|
|
3017
|
-
* Looks up the `RpcSchema.Item` for a method on a namespace.
|
|
3017
|
+
* Looks up the `RpcSchema.Item` for a method on a namespace. Resolve a method
|
|
3018
|
+
* once and pass the item to the `decode*`/`encode*` codecs to encode params and
|
|
3019
|
+
* decode returns without repeating the namespace and method name.
|
|
3018
3020
|
*
|
|
3019
3021
|
* @example
|
|
3020
3022
|
* ```ts twoslash
|
|
@@ -3022,17 +3024,21 @@ export declare const Default: {
|
|
|
3022
3024
|
*
|
|
3023
3025
|
* const item = z.RpcSchema.parseItem(
|
|
3024
3026
|
* z.RpcSchema.Eth,
|
|
3025
|
-
* '
|
|
3027
|
+
* 'eth_getBlockTransactionCountByNumber'
|
|
3026
3028
|
* )
|
|
3029
|
+
*
|
|
3030
|
+
* const params = z.RpcSchema.encodeParams(item, [1n])
|
|
3031
|
+
* const count = z.RpcSchema.decodeReturns(item, '0x1')
|
|
3027
3032
|
* ```
|
|
3028
3033
|
*
|
|
3029
3034
|
* @throws `RpcSchema.MethodNotFoundError` if the method does not exist.
|
|
3030
3035
|
*/
|
|
3031
3036
|
export declare function parseItem<const namespace extends Namespace, method extends MethodName<namespace>>(namespace: namespace, method: method): namespace[method];
|
|
3032
3037
|
/**
|
|
3033
|
-
* Decodes (wire → native) the `params` for a method
|
|
3034
|
-
*
|
|
3035
|
-
*
|
|
3038
|
+
* Decodes (wire → native) the `params` for a method. Use on the receiving side
|
|
3039
|
+
* (e.g. a server) to coerce incoming wire params into their native
|
|
3040
|
+
* representation. Accepts either a namespace + method name, or a resolved
|
|
3041
|
+
* `RpcSchema.Item` (from {@link parseItem}/{@link from}).
|
|
3036
3042
|
*
|
|
3037
3043
|
* @example
|
|
3038
3044
|
* ```ts twoslash
|
|
@@ -3045,13 +3051,29 @@ export declare function parseItem<const namespace extends Namespace, method exte
|
|
|
3045
3051
|
* )
|
|
3046
3052
|
* ```
|
|
3047
3053
|
*
|
|
3054
|
+
* @example
|
|
3055
|
+
* ### From a Resolved Item
|
|
3056
|
+
*
|
|
3057
|
+
* ```ts twoslash
|
|
3058
|
+
* import { z } from 'ox/zod'
|
|
3059
|
+
*
|
|
3060
|
+
* const item = z.RpcSchema.parseItem(
|
|
3061
|
+
* z.RpcSchema.Eth,
|
|
3062
|
+
* 'eth_getBlockByNumber'
|
|
3063
|
+
* )
|
|
3064
|
+
*
|
|
3065
|
+
* const params = z.RpcSchema.decodeParams(item, ['0x1', true])
|
|
3066
|
+
* ```
|
|
3067
|
+
*
|
|
3048
3068
|
* @throws `RpcSchema.MethodNotFoundError` if the method does not exist.
|
|
3049
3069
|
*/
|
|
3070
|
+
export declare function decodeParams<const item extends Item>(item: item, params: z.input<item['params']>): z.output<item['params']>;
|
|
3050
3071
|
export declare function decodeParams<const namespace extends Namespace, method extends MethodName<namespace>>(namespace: namespace, method: method, params: z.input<namespace[method]['params']>): z.output<namespace[method]['params']>;
|
|
3051
3072
|
/**
|
|
3052
|
-
* Encodes (native → wire) the `params` for a method
|
|
3053
|
-
*
|
|
3054
|
-
* a
|
|
3073
|
+
* Encodes (native → wire) the `params` for a method. Use on the sending side
|
|
3074
|
+
* (e.g. a client) to serialize native params into the wire shape a JSON-RPC
|
|
3075
|
+
* endpoint expects. Accepts either a namespace + method name, or a resolved
|
|
3076
|
+
* `RpcSchema.Item` (from {@link parseItem}/{@link from}).
|
|
3055
3077
|
*
|
|
3056
3078
|
* @example
|
|
3057
3079
|
* ```ts twoslash
|
|
@@ -3064,13 +3086,29 @@ export declare function decodeParams<const namespace extends Namespace, method e
|
|
|
3064
3086
|
* )
|
|
3065
3087
|
* ```
|
|
3066
3088
|
*
|
|
3089
|
+
* @example
|
|
3090
|
+
* ### From a Resolved Item
|
|
3091
|
+
*
|
|
3092
|
+
* ```ts twoslash
|
|
3093
|
+
* import { z } from 'ox/zod'
|
|
3094
|
+
*
|
|
3095
|
+
* const item = z.RpcSchema.parseItem(
|
|
3096
|
+
* z.RpcSchema.Eth,
|
|
3097
|
+
* 'eth_getBlockByNumber'
|
|
3098
|
+
* )
|
|
3099
|
+
*
|
|
3100
|
+
* const params = z.RpcSchema.encodeParams(item, [1n, true])
|
|
3101
|
+
* ```
|
|
3102
|
+
*
|
|
3067
3103
|
* @throws `RpcSchema.MethodNotFoundError` if the method does not exist.
|
|
3068
3104
|
*/
|
|
3105
|
+
export declare function encodeParams<const item extends Item>(item: item, params: z.output<item['params']>): z.input<item['params']>;
|
|
3069
3106
|
export declare function encodeParams<const namespace extends Namespace, method extends MethodName<namespace>>(namespace: namespace, method: method, params: z.output<namespace[method]['params']>): z.input<namespace[method]['params']>;
|
|
3070
3107
|
/**
|
|
3071
|
-
* Decodes (wire → native) the `returns` value for a method on
|
|
3072
|
-
*
|
|
3073
|
-
* representation.
|
|
3108
|
+
* Decodes (wire → native) the `returns` value for a method. Use on the
|
|
3109
|
+
* receiving side (e.g. a client) to coerce a wire result into its native
|
|
3110
|
+
* representation. Accepts either a namespace + method name, or a resolved
|
|
3111
|
+
* `RpcSchema.Item` (from {@link parseItem}/{@link from}).
|
|
3074
3112
|
*
|
|
3075
3113
|
* @example
|
|
3076
3114
|
* ```ts twoslash
|
|
@@ -3083,13 +3121,29 @@ export declare function encodeParams<const namespace extends Namespace, method e
|
|
|
3083
3121
|
* )
|
|
3084
3122
|
* ```
|
|
3085
3123
|
*
|
|
3124
|
+
* @example
|
|
3125
|
+
* ### From a Resolved Item
|
|
3126
|
+
*
|
|
3127
|
+
* ```ts twoslash
|
|
3128
|
+
* import { z } from 'ox/zod'
|
|
3129
|
+
*
|
|
3130
|
+
* const item = z.RpcSchema.parseItem(
|
|
3131
|
+
* z.RpcSchema.Eth,
|
|
3132
|
+
* 'eth_blockNumber'
|
|
3133
|
+
* )
|
|
3134
|
+
*
|
|
3135
|
+
* const result = z.RpcSchema.decodeReturns(item, '0x1b4')
|
|
3136
|
+
* ```
|
|
3137
|
+
*
|
|
3086
3138
|
* @throws `RpcSchema.MethodNotFoundError` if the method does not exist.
|
|
3087
3139
|
*/
|
|
3140
|
+
export declare function decodeReturns<const item extends Item>(item: item, returns: z.input<item['returns']>): z.output<item['returns']>;
|
|
3088
3141
|
export declare function decodeReturns<const namespace extends Namespace, method extends MethodName<namespace>>(namespace: namespace, method: method, returns: z.input<namespace[method]['returns']>): z.output<namespace[method]['returns']>;
|
|
3089
3142
|
/**
|
|
3090
|
-
* Encodes (native → wire) the `returns` value for a method on
|
|
3091
|
-
*
|
|
3092
|
-
*
|
|
3143
|
+
* Encodes (native → wire) the `returns` value for a method. Use on the sending
|
|
3144
|
+
* side (e.g. a server) to serialize a native result into the wire shape.
|
|
3145
|
+
* Accepts either a namespace + method name, or a resolved `RpcSchema.Item`
|
|
3146
|
+
* (from {@link parseItem}/{@link from}).
|
|
3093
3147
|
*
|
|
3094
3148
|
* @example
|
|
3095
3149
|
* ```ts twoslash
|
|
@@ -3102,8 +3156,23 @@ export declare function decodeReturns<const namespace extends Namespace, method
|
|
|
3102
3156
|
* )
|
|
3103
3157
|
* ```
|
|
3104
3158
|
*
|
|
3159
|
+
* @example
|
|
3160
|
+
* ### From a Resolved Item
|
|
3161
|
+
*
|
|
3162
|
+
* ```ts twoslash
|
|
3163
|
+
* import { z } from 'ox/zod'
|
|
3164
|
+
*
|
|
3165
|
+
* const item = z.RpcSchema.parseItem(
|
|
3166
|
+
* z.RpcSchema.Eth,
|
|
3167
|
+
* 'eth_blockNumber'
|
|
3168
|
+
* )
|
|
3169
|
+
*
|
|
3170
|
+
* const result = z.RpcSchema.encodeReturns(item, 436n)
|
|
3171
|
+
* ```
|
|
3172
|
+
*
|
|
3105
3173
|
* @throws `RpcSchema.MethodNotFoundError` if the method does not exist.
|
|
3106
3174
|
*/
|
|
3175
|
+
export declare function encodeReturns<const item extends Item>(item: item, returns: z.output<item['returns']>): z.input<item['returns']>;
|
|
3107
3176
|
export declare function encodeReturns<const namespace extends Namespace, method extends MethodName<namespace>>(namespace: namespace, method: method, returns: z.output<namespace[method]['returns']>): z.input<namespace[method]['returns']>;
|
|
3108
3177
|
/**
|
|
3109
3178
|
* Decodes (wire → native) a full JSON-RPC request (`{ method, params }`)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpcSchema.d.ts","sourceRoot":"","sources":["../../src/zod/RpcSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAC3C,OAAO,KAAK,GAAG,MAAM,8BAA8B,CAAA;AAEnD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAA;AACzD,OAAO,KAAK,MAAM,MAAM,iCAAiC,CAAA;AACzD,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAE7B,YAAY,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAA;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,IAAI,CAClB,KAAK,CAAC,MAAM,SAAS,MAAM,EAC3B,MAAM,SAAS,CAAC,CAAC,WAAW,EAC5B,OAAO,SAAS,CAAC,CAAC,W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F,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAA;AAExB,0DAA0D;AAC1D,qBAAa,mBAAoB,SAAQ,MAAM,CAAC,SAAS;IACvD,SAAkB,IAAI,mCAAkC;gBAE5C,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE;CAG3C"}
|
package/dist/zod/RpcSchema.js
CHANGED
|
@@ -29,7 +29,9 @@ function requestSchema(namespace) {
|
|
|
29
29
|
return schema;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
|
-
* Looks up the `RpcSchema.Item` for a method on a namespace.
|
|
32
|
+
* Looks up the `RpcSchema.Item` for a method on a namespace. Resolve a method
|
|
33
|
+
* once and pass the item to the `decode*`/`encode*` codecs to encode params and
|
|
34
|
+
* decode returns without repeating the namespace and method name.
|
|
33
35
|
*
|
|
34
36
|
* @example
|
|
35
37
|
* ```ts twoslash
|
|
@@ -37,8 +39,11 @@ function requestSchema(namespace) {
|
|
|
37
39
|
*
|
|
38
40
|
* const item = z.RpcSchema.parseItem(
|
|
39
41
|
* z.RpcSchema.Eth,
|
|
40
|
-
* '
|
|
42
|
+
* 'eth_getBlockTransactionCountByNumber'
|
|
41
43
|
* )
|
|
44
|
+
*
|
|
45
|
+
* const params = z.RpcSchema.encodeParams(item, [1n])
|
|
46
|
+
* const count = z.RpcSchema.decodeReturns(item, '0x1')
|
|
42
47
|
* ```
|
|
43
48
|
*
|
|
44
49
|
* @throws `RpcSchema.MethodNotFoundError` if the method does not exist.
|
|
@@ -49,89 +54,32 @@ export function parseItem(namespace, method) {
|
|
|
49
54
|
throw new MethodNotFoundError({ method });
|
|
50
55
|
return item;
|
|
51
56
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
* ```ts twoslash
|
|
59
|
-
* import { z } from 'ox/zod'
|
|
60
|
-
*
|
|
61
|
-
* const params = z.RpcSchema.decodeParams(
|
|
62
|
-
* z.RpcSchema.Eth,
|
|
63
|
-
* 'eth_getBlockByNumber',
|
|
64
|
-
* ['0x1', true]
|
|
65
|
-
* )
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
* @throws `RpcSchema.MethodNotFoundError` if the method does not exist.
|
|
69
|
-
*/
|
|
70
|
-
export function decodeParams(namespace, method, params) {
|
|
71
|
-
return z.decode(parseItem(namespace, method).params, params);
|
|
57
|
+
// Resolves a codec function's arguments into `[item, value]`, accepting either
|
|
58
|
+
// `(item, value)` or `(namespace, method, value)`.
|
|
59
|
+
function resolveItem(args) {
|
|
60
|
+
if (args.length === 2)
|
|
61
|
+
return [args[0], args[1]];
|
|
62
|
+
return [parseItem(args[0], args[1]), args[2]];
|
|
72
63
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```ts twoslash
|
|
80
|
-
* import { z } from 'ox/zod'
|
|
81
|
-
*
|
|
82
|
-
* const params = z.RpcSchema.encodeParams(
|
|
83
|
-
* z.RpcSchema.Eth,
|
|
84
|
-
* 'eth_getBlockByNumber',
|
|
85
|
-
* [1n, true]
|
|
86
|
-
* )
|
|
87
|
-
* ```
|
|
88
|
-
*
|
|
89
|
-
* @throws `RpcSchema.MethodNotFoundError` if the method does not exist.
|
|
90
|
-
*/
|
|
91
|
-
export function encodeParams(namespace, method, params) {
|
|
92
|
-
return z.encode(parseItem(namespace, method).params, params);
|
|
64
|
+
// eslint-disable-next-line jsdoc-js/require-jsdoc
|
|
65
|
+
export function decodeParams(...args) {
|
|
66
|
+
const [item, params] = resolveItem(args);
|
|
67
|
+
return z.decode(item.params, params);
|
|
93
68
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```ts twoslash
|
|
101
|
-
* import { z } from 'ox/zod'
|
|
102
|
-
*
|
|
103
|
-
* const result = z.RpcSchema.decodeReturns(
|
|
104
|
-
* z.RpcSchema.Eth,
|
|
105
|
-
* 'eth_blockNumber',
|
|
106
|
-
* '0x1b4'
|
|
107
|
-
* )
|
|
108
|
-
* ```
|
|
109
|
-
*
|
|
110
|
-
* @throws `RpcSchema.MethodNotFoundError` if the method does not exist.
|
|
111
|
-
*/
|
|
112
|
-
export function decodeReturns(namespace, method, returns) {
|
|
113
|
-
return z.decode(parseItem(namespace, method).returns, returns);
|
|
69
|
+
// eslint-disable-next-line jsdoc-js/require-jsdoc
|
|
70
|
+
export function encodeParams(...args) {
|
|
71
|
+
const [item, params] = resolveItem(args);
|
|
72
|
+
return z.encode(item.params, params);
|
|
114
73
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
* const result = z.RpcSchema.encodeReturns(
|
|
125
|
-
* z.RpcSchema.Eth,
|
|
126
|
-
* 'eth_blockNumber',
|
|
127
|
-
* 436n
|
|
128
|
-
* )
|
|
129
|
-
* ```
|
|
130
|
-
*
|
|
131
|
-
* @throws `RpcSchema.MethodNotFoundError` if the method does not exist.
|
|
132
|
-
*/
|
|
133
|
-
export function encodeReturns(namespace, method, returns) {
|
|
134
|
-
return z.encode(parseItem(namespace, method).returns, returns);
|
|
74
|
+
// eslint-disable-next-line jsdoc-js/require-jsdoc
|
|
75
|
+
export function decodeReturns(...args) {
|
|
76
|
+
const [item, returns] = resolveItem(args);
|
|
77
|
+
return z.decode(item.returns, returns);
|
|
78
|
+
}
|
|
79
|
+
// eslint-disable-next-line jsdoc-js/require-jsdoc
|
|
80
|
+
export function encodeReturns(...args) {
|
|
81
|
+
const [item, returns] = resolveItem(args);
|
|
82
|
+
return z.encode(item.returns, returns);
|
|
135
83
|
}
|
|
136
84
|
/**
|
|
137
85
|
* Decodes (wire → native) a full JSON-RPC request (`{ method, params }`)
|
|
@@ -1 +1 @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,CAAA;AAkBlC,0DAA0D;AAC1D,MAAM,OAAO,mBAAoB,SAAQ,MAAM,CAAC,SAAS;IACrC,IAAI,GAAG,+BAA+B,CAAA;IAExD,YAAY,EAAE,MAAM,EAAsB;QACxC,KAAK,CAAC,YAAY,MAAM,kCAAkC,CAAC,CAAA;IAC7D,CAAC;CACF"}
|
package/package.json
CHANGED
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = '1.0.0-beta.
|
|
2
|
+
export const version = '1.0.0-beta.4'
|
package/src/zod/RpcSchema.ts
CHANGED
|
@@ -128,7 +128,9 @@ function requestSchema(namespace: Namespace): z.ZodMiniType {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
/**
|
|
131
|
-
* Looks up the `RpcSchema.Item` for a method on a namespace.
|
|
131
|
+
* Looks up the `RpcSchema.Item` for a method on a namespace. Resolve a method
|
|
132
|
+
* once and pass the item to the `decode*`/`encode*` codecs to encode params and
|
|
133
|
+
* decode returns without repeating the namespace and method name.
|
|
132
134
|
*
|
|
133
135
|
* @example
|
|
134
136
|
* ```ts twoslash
|
|
@@ -136,8 +138,11 @@ function requestSchema(namespace: Namespace): z.ZodMiniType {
|
|
|
136
138
|
*
|
|
137
139
|
* const item = z.RpcSchema.parseItem(
|
|
138
140
|
* z.RpcSchema.Eth,
|
|
139
|
-
* '
|
|
141
|
+
* 'eth_getBlockTransactionCountByNumber'
|
|
140
142
|
* )
|
|
143
|
+
*
|
|
144
|
+
* const params = z.RpcSchema.encodeParams(item, [1n])
|
|
145
|
+
* const count = z.RpcSchema.decodeReturns(item, '0x1')
|
|
141
146
|
* ```
|
|
142
147
|
*
|
|
143
148
|
* @throws `RpcSchema.MethodNotFoundError` if the method does not exist.
|
|
@@ -151,10 +156,18 @@ export function parseItem<
|
|
|
151
156
|
return item
|
|
152
157
|
}
|
|
153
158
|
|
|
159
|
+
// Resolves a codec function's arguments into `[item, value]`, accepting either
|
|
160
|
+
// `(item, value)` or `(namespace, method, value)`.
|
|
161
|
+
function resolveItem(args: readonly unknown[]): [item: Item, value: unknown] {
|
|
162
|
+
if (args.length === 2) return [args[0] as Item, args[1]]
|
|
163
|
+
return [parseItem(args[0] as Namespace, args[1] as string), args[2]]
|
|
164
|
+
}
|
|
165
|
+
|
|
154
166
|
/**
|
|
155
|
-
* Decodes (wire → native) the `params` for a method
|
|
156
|
-
*
|
|
157
|
-
*
|
|
167
|
+
* Decodes (wire → native) the `params` for a method. Use on the receiving side
|
|
168
|
+
* (e.g. a server) to coerce incoming wire params into their native
|
|
169
|
+
* representation. Accepts either a namespace + method name, or a resolved
|
|
170
|
+
* `RpcSchema.Item` (from {@link parseItem}/{@link from}).
|
|
158
171
|
*
|
|
159
172
|
* @example
|
|
160
173
|
* ```ts twoslash
|
|
@@ -167,8 +180,26 @@ export function parseItem<
|
|
|
167
180
|
* )
|
|
168
181
|
* ```
|
|
169
182
|
*
|
|
183
|
+
* @example
|
|
184
|
+
* ### From a Resolved Item
|
|
185
|
+
*
|
|
186
|
+
* ```ts twoslash
|
|
187
|
+
* import { z } from 'ox/zod'
|
|
188
|
+
*
|
|
189
|
+
* const item = z.RpcSchema.parseItem(
|
|
190
|
+
* z.RpcSchema.Eth,
|
|
191
|
+
* 'eth_getBlockByNumber'
|
|
192
|
+
* )
|
|
193
|
+
*
|
|
194
|
+
* const params = z.RpcSchema.decodeParams(item, ['0x1', true])
|
|
195
|
+
* ```
|
|
196
|
+
*
|
|
170
197
|
* @throws `RpcSchema.MethodNotFoundError` if the method does not exist.
|
|
171
198
|
*/
|
|
199
|
+
export function decodeParams<const item extends Item>(
|
|
200
|
+
item: item,
|
|
201
|
+
params: z.input<item['params']>,
|
|
202
|
+
): z.output<item['params']>
|
|
172
203
|
export function decodeParams<
|
|
173
204
|
const namespace extends Namespace,
|
|
174
205
|
method extends MethodName<namespace>,
|
|
@@ -176,14 +207,18 @@ export function decodeParams<
|
|
|
176
207
|
namespace: namespace,
|
|
177
208
|
method: method,
|
|
178
209
|
params: z.input<namespace[method]['params']>,
|
|
179
|
-
): z.output<namespace[method]['params']>
|
|
180
|
-
|
|
210
|
+
): z.output<namespace[method]['params']>
|
|
211
|
+
// eslint-disable-next-line jsdoc-js/require-jsdoc
|
|
212
|
+
export function decodeParams(...args: readonly unknown[]): unknown {
|
|
213
|
+
const [item, params] = resolveItem(args)
|
|
214
|
+
return z.decode(item.params, params as never) as never
|
|
181
215
|
}
|
|
182
216
|
|
|
183
217
|
/**
|
|
184
|
-
* Encodes (native → wire) the `params` for a method
|
|
185
|
-
*
|
|
186
|
-
* a
|
|
218
|
+
* Encodes (native → wire) the `params` for a method. Use on the sending side
|
|
219
|
+
* (e.g. a client) to serialize native params into the wire shape a JSON-RPC
|
|
220
|
+
* endpoint expects. Accepts either a namespace + method name, or a resolved
|
|
221
|
+
* `RpcSchema.Item` (from {@link parseItem}/{@link from}).
|
|
187
222
|
*
|
|
188
223
|
* @example
|
|
189
224
|
* ```ts twoslash
|
|
@@ -196,8 +231,26 @@ export function decodeParams<
|
|
|
196
231
|
* )
|
|
197
232
|
* ```
|
|
198
233
|
*
|
|
234
|
+
* @example
|
|
235
|
+
* ### From a Resolved Item
|
|
236
|
+
*
|
|
237
|
+
* ```ts twoslash
|
|
238
|
+
* import { z } from 'ox/zod'
|
|
239
|
+
*
|
|
240
|
+
* const item = z.RpcSchema.parseItem(
|
|
241
|
+
* z.RpcSchema.Eth,
|
|
242
|
+
* 'eth_getBlockByNumber'
|
|
243
|
+
* )
|
|
244
|
+
*
|
|
245
|
+
* const params = z.RpcSchema.encodeParams(item, [1n, true])
|
|
246
|
+
* ```
|
|
247
|
+
*
|
|
199
248
|
* @throws `RpcSchema.MethodNotFoundError` if the method does not exist.
|
|
200
249
|
*/
|
|
250
|
+
export function encodeParams<const item extends Item>(
|
|
251
|
+
item: item,
|
|
252
|
+
params: z.output<item['params']>,
|
|
253
|
+
): z.input<item['params']>
|
|
201
254
|
export function encodeParams<
|
|
202
255
|
const namespace extends Namespace,
|
|
203
256
|
method extends MethodName<namespace>,
|
|
@@ -205,14 +258,18 @@ export function encodeParams<
|
|
|
205
258
|
namespace: namespace,
|
|
206
259
|
method: method,
|
|
207
260
|
params: z.output<namespace[method]['params']>,
|
|
208
|
-
): z.input<namespace[method]['params']>
|
|
209
|
-
|
|
261
|
+
): z.input<namespace[method]['params']>
|
|
262
|
+
// eslint-disable-next-line jsdoc-js/require-jsdoc
|
|
263
|
+
export function encodeParams(...args: readonly unknown[]): unknown {
|
|
264
|
+
const [item, params] = resolveItem(args)
|
|
265
|
+
return z.encode(item.params, params as never) as never
|
|
210
266
|
}
|
|
211
267
|
|
|
212
268
|
/**
|
|
213
|
-
* Decodes (wire → native) the `returns` value for a method on
|
|
214
|
-
*
|
|
215
|
-
* representation.
|
|
269
|
+
* Decodes (wire → native) the `returns` value for a method. Use on the
|
|
270
|
+
* receiving side (e.g. a client) to coerce a wire result into its native
|
|
271
|
+
* representation. Accepts either a namespace + method name, or a resolved
|
|
272
|
+
* `RpcSchema.Item` (from {@link parseItem}/{@link from}).
|
|
216
273
|
*
|
|
217
274
|
* @example
|
|
218
275
|
* ```ts twoslash
|
|
@@ -225,8 +282,26 @@ export function encodeParams<
|
|
|
225
282
|
* )
|
|
226
283
|
* ```
|
|
227
284
|
*
|
|
285
|
+
* @example
|
|
286
|
+
* ### From a Resolved Item
|
|
287
|
+
*
|
|
288
|
+
* ```ts twoslash
|
|
289
|
+
* import { z } from 'ox/zod'
|
|
290
|
+
*
|
|
291
|
+
* const item = z.RpcSchema.parseItem(
|
|
292
|
+
* z.RpcSchema.Eth,
|
|
293
|
+
* 'eth_blockNumber'
|
|
294
|
+
* )
|
|
295
|
+
*
|
|
296
|
+
* const result = z.RpcSchema.decodeReturns(item, '0x1b4')
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
228
299
|
* @throws `RpcSchema.MethodNotFoundError` if the method does not exist.
|
|
229
300
|
*/
|
|
301
|
+
export function decodeReturns<const item extends Item>(
|
|
302
|
+
item: item,
|
|
303
|
+
returns: z.input<item['returns']>,
|
|
304
|
+
): z.output<item['returns']>
|
|
230
305
|
export function decodeReturns<
|
|
231
306
|
const namespace extends Namespace,
|
|
232
307
|
method extends MethodName<namespace>,
|
|
@@ -234,17 +309,18 @@ export function decodeReturns<
|
|
|
234
309
|
namespace: namespace,
|
|
235
310
|
method: method,
|
|
236
311
|
returns: z.input<namespace[method]['returns']>,
|
|
237
|
-
): z.output<namespace[method]['returns']>
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
) as never
|
|
312
|
+
): z.output<namespace[method]['returns']>
|
|
313
|
+
// eslint-disable-next-line jsdoc-js/require-jsdoc
|
|
314
|
+
export function decodeReturns(...args: readonly unknown[]): unknown {
|
|
315
|
+
const [item, returns] = resolveItem(args)
|
|
316
|
+
return z.decode(item.returns, returns as never) as never
|
|
242
317
|
}
|
|
243
318
|
|
|
244
319
|
/**
|
|
245
|
-
* Encodes (native → wire) the `returns` value for a method on
|
|
246
|
-
*
|
|
247
|
-
*
|
|
320
|
+
* Encodes (native → wire) the `returns` value for a method. Use on the sending
|
|
321
|
+
* side (e.g. a server) to serialize a native result into the wire shape.
|
|
322
|
+
* Accepts either a namespace + method name, or a resolved `RpcSchema.Item`
|
|
323
|
+
* (from {@link parseItem}/{@link from}).
|
|
248
324
|
*
|
|
249
325
|
* @example
|
|
250
326
|
* ```ts twoslash
|
|
@@ -257,8 +333,26 @@ export function decodeReturns<
|
|
|
257
333
|
* )
|
|
258
334
|
* ```
|
|
259
335
|
*
|
|
336
|
+
* @example
|
|
337
|
+
* ### From a Resolved Item
|
|
338
|
+
*
|
|
339
|
+
* ```ts twoslash
|
|
340
|
+
* import { z } from 'ox/zod'
|
|
341
|
+
*
|
|
342
|
+
* const item = z.RpcSchema.parseItem(
|
|
343
|
+
* z.RpcSchema.Eth,
|
|
344
|
+
* 'eth_blockNumber'
|
|
345
|
+
* )
|
|
346
|
+
*
|
|
347
|
+
* const result = z.RpcSchema.encodeReturns(item, 436n)
|
|
348
|
+
* ```
|
|
349
|
+
*
|
|
260
350
|
* @throws `RpcSchema.MethodNotFoundError` if the method does not exist.
|
|
261
351
|
*/
|
|
352
|
+
export function encodeReturns<const item extends Item>(
|
|
353
|
+
item: item,
|
|
354
|
+
returns: z.output<item['returns']>,
|
|
355
|
+
): z.input<item['returns']>
|
|
262
356
|
export function encodeReturns<
|
|
263
357
|
const namespace extends Namespace,
|
|
264
358
|
method extends MethodName<namespace>,
|
|
@@ -266,11 +360,11 @@ export function encodeReturns<
|
|
|
266
360
|
namespace: namespace,
|
|
267
361
|
method: method,
|
|
268
362
|
returns: z.output<namespace[method]['returns']>,
|
|
269
|
-
): z.input<namespace[method]['returns']>
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
) as never
|
|
363
|
+
): z.input<namespace[method]['returns']>
|
|
364
|
+
// eslint-disable-next-line jsdoc-js/require-jsdoc
|
|
365
|
+
export function encodeReturns(...args: readonly unknown[]): unknown {
|
|
366
|
+
const [item, returns] = resolveItem(args)
|
|
367
|
+
return z.encode(item.returns, returns as never) as never
|
|
274
368
|
}
|
|
275
369
|
|
|
276
370
|
/**
|
|
@@ -86,6 +86,33 @@ test('encode helpers infer params/returns by method', () => {
|
|
|
86
86
|
>()
|
|
87
87
|
})
|
|
88
88
|
|
|
89
|
+
test('codecs accept a resolved item and infer params/returns', () => {
|
|
90
|
+
const item = z_RpcSchema.parseItem(z_RpcSchema.Eth, 'eth_getTransactionCount')
|
|
91
|
+
|
|
92
|
+
// Params: native on encode input, wire on encode output.
|
|
93
|
+
expectTypeOf(
|
|
94
|
+
z_RpcSchema.encodeParams(item, [
|
|
95
|
+
'0x0000000000000000000000000000000000000000',
|
|
96
|
+
{ blockNumber: 436n },
|
|
97
|
+
]),
|
|
98
|
+
).toMatchTypeOf<
|
|
99
|
+
readonly [
|
|
100
|
+
core_Address.Address,
|
|
101
|
+
(
|
|
102
|
+
| core_Block.Number<core_Hex.Hex>
|
|
103
|
+
| core_Block.Tag
|
|
104
|
+
| core_Block.Identifier<core_Hex.Hex>
|
|
105
|
+
),
|
|
106
|
+
]
|
|
107
|
+
>()
|
|
108
|
+
|
|
109
|
+
// Returns: wire hex on decode input, native number on decode output.
|
|
110
|
+
expectTypeOf(z_RpcSchema.decodeReturns(item, '0x1b4')).toEqualTypeOf<number>()
|
|
111
|
+
expectTypeOf(
|
|
112
|
+
z_RpcSchema.encodeReturns(item, 436),
|
|
113
|
+
).toEqualTypeOf<core_Hex.Hex>()
|
|
114
|
+
})
|
|
115
|
+
|
|
89
116
|
test('from: namespace returns a decodable namespace', () => {
|
|
90
117
|
const schema = z_RpcSchema.from({
|
|
91
118
|
abe_foo: {
|
|
@@ -211,6 +211,25 @@ describe('parseItem', () => {
|
|
|
211
211
|
`[RpcSchema.MethodNotFoundError: Method \`eth_unknownMethod\` does not exist on the schema.]`,
|
|
212
212
|
)
|
|
213
213
|
})
|
|
214
|
+
|
|
215
|
+
test('codecs accept a resolved item', () => {
|
|
216
|
+
const item = z_RpcSchema.parseItem(
|
|
217
|
+
z_RpcSchema.Eth,
|
|
218
|
+
'eth_getBlockTransactionCountByNumber',
|
|
219
|
+
)
|
|
220
|
+
expect(z_RpcSchema.encodeParams(item, [1n])).toMatchInlineSnapshot(`
|
|
221
|
+
[
|
|
222
|
+
"0x1",
|
|
223
|
+
]
|
|
224
|
+
`)
|
|
225
|
+
expect(z_RpcSchema.decodeParams(item, ['0x1'])).toMatchInlineSnapshot(`
|
|
226
|
+
[
|
|
227
|
+
1n,
|
|
228
|
+
]
|
|
229
|
+
`)
|
|
230
|
+
expect(z_RpcSchema.decodeReturns(item, '0x1')).toMatchInlineSnapshot(`1`)
|
|
231
|
+
expect(z_RpcSchema.encodeReturns(item, 1)).toMatchInlineSnapshot(`"0x1"`)
|
|
232
|
+
})
|
|
214
233
|
})
|
|
215
234
|
|
|
216
235
|
describe('decodeRequest', () => {
|