-
Notifications
You must be signed in to change notification settings - Fork 19
/
config.ts
185 lines (176 loc) · 5.16 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
export type Ok<T> = { Ok: T }
export type Err<E> = { Err: E }
export type Result<T, E> = Ok<T> | Err<E>
// Note that Option<Option<number>> = T | undefined | undefined which is the same
// as Option<number>, is this what we want for Option ?
export type Option<T> = T | undefined
export type U256 = {
low: bigint
high: bigint
}
export type Calldata = string[] & { readonly __compiled__?: boolean }
export type Call = {
contractAddress: string
entrypoint: string
calldata?: Calldata
}
export interface Config<OptionT = any, ResultT = any, ErrorT = any> {}
export type ResolvedConfig<OptionT = any, ResultT = any, ErrorT = any> = {
/**
* TypeScript type to use for `ContractAddress` and `EthAddress` values
* @default `0x${string}`
*/
AddressType: Config extends { AddressType: infer type }
? type
: DefaultConfig['AddressType']
/**
* TypeScript type to use for `ClassHash` values
* @default `0x${string}`
*/
ClassHashType: Config extends { ClassHashType: infer type }
? type
: DefaultConfig['ClassHashType']
/**
* TypeScript type to use for `felt` values
* @default `0x${string}`
*/
FeltType: Config extends { FeltType: infer type }
? type
: DefaultConfig['FeltType']
/**
* TypeScript type to use for `u64` and `u128` values
* @default bigint
*/
BigIntType: Config extends { BigIntType: infer type }
? type
: DefaultConfig['BigIntType']
/**
* TypeScript type to use for `u265` values
* @default bigint
*/
U256Type: Config extends { U256Type: infer type }
? type
: DefaultConfig['U256Type']
/**
* TypeScript type to use for `u512` values
* @default string
*/
U512Type: Config extends { U512Type: infer type }
? type
: DefaultConfig['U512Type']
/**
* TypeScript type to use for `u8`, `u16` and `u32` values
* @default number
*/
IntType: Config extends { IntType: infer type }
? type
: DefaultConfig['IntType']
/**
* TypeScript type to use for `Option::<T>` values
* @default T | undefined
*/
Option: Config<OptionT> extends { Option: infer type }
? type
: DefaultConfig<OptionT>['Option']
/**
* TypeScript type to use for tuples `(T1, T2, ...)` values
* @default infer the types of the tuple element and return a TS tuple
*/
Tuple: Config extends { Tuple: infer type } ? type : DefaultConfig['Tuple']
/**
* TypeScript type to use for tuples `Result<T, E>` values
* @default Ok<T> | Err<E>
*/
Result: Config<OptionT, ResultT, ErrorT> extends { Result: infer type }
? type
: DefaultConfig<OptionT, ResultT, ErrorT>['Result']
/**
* TypeScript type to use for enums
* @default infer the types of the enum and return a union of objects
*/
Enum: Config extends { Enum: infer type } ? type : DefaultConfig['Enum']
/**
* TypeScript type to use for bytes31
* @default string
*/
Bytes31Type: Config extends { Bytes31Type: infer type }
? type
: DefaultConfig['Bytes31Type']
/**
* TypeScript type to use for ByteArray
* @default string
*/
ByteArray: Config extends { ByteArray: infer type }
? type
: DefaultConfig['ByteArrayType']
/**
* TypeScript type to use for Secp256k1Point
* @default string
*/
Secp256k1PointType: Config extends { ByteArray: infer type }
? type
: DefaultConfig['Secp256k1PointType']
/**
* TypeScript type to use for Calldata used in function calls
* @default decimal-string array
*/
Calldata: Config extends { Calldata: infer type }
? type
: DefaultConfig<OptionT>['Calldata']
/**
* TypeScript type to use for populate return values
* @default
* {
* contractAddress: string
* entrypoint: string
* calldata?: Calldata
* }
*/
Call: Config extends { Call: infer type }
? type
: DefaultConfig<OptionT>['Call']
/**
* TypeScript type to use for CallOptions used in function calls
* @default unknown
*/
CallOptions: Config extends { CallOptions: infer type }
? type
: DefaultConfig<OptionT>['CallOptions']
/**
* TypeScript type to use for InvokeOptions used in function calls
* @default unknown
*/
InvokeOptions: Config extends { InvokeOptions: infer type }
? type
: DefaultConfig<OptionT>['InvokeOptions']
/**
* TypeScript type to use for invoke function return values
* @default unknown
*/
InvokeFunctionResponse: Config extends { InvokeFunctionResponse: infer type }
? type
: DefaultConfig<OptionT>['InvokeFunctionResponse']
}
export type DefaultConfig<OptionT = any, ResultT = any, ErrorT = any> = {
AddressType: string
ClassHashType: string
FeltType: number | bigint | string
BigIntType: number | bigint
U256Type: number | bigint | U256
U512Type: string
IntType: number | bigint
Option: Option<OptionT>
/** By default, abiwan will infer the types of the tuple element and return a TS tuple */
Tuple: never
Result: Result<ResultT, ErrorT>
/** By default, abiwan will infer the types of the enum and return a union of objects */
Enum: never
Bytes31Type: string
ByteArrayType: string
Secp256k1PointType: string
Calldata: Calldata
Call: Call
CallOptions: unknown
InvokeOptions: unknown
InvokeFunctionResponse: unknown
}