@kontor/kontor-sdk 1.0.0-alpha.39 → 1.0.0-alpha.40

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.
Files changed (270) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/sdk/actions/kontor/public/call-view.js.map +1 -1
  3. package/dist/cjs/sdk/chains/definitions/signet.js +2 -2
  4. package/dist/cjs/sdk/test/e2e.test-deprecated.js +2 -0
  5. package/dist/cjs/sdk/test/e2e.test-deprecated.js.map +1 -0
  6. package/dist/cjs/sdk/utils/wit/codecs/bool.js +9 -21
  7. package/dist/cjs/sdk/utils/wit/codecs/bool.js.map +1 -1
  8. package/dist/cjs/sdk/utils/wit/codecs/contract-address.js +92 -0
  9. package/dist/cjs/sdk/utils/wit/codecs/contract-address.js.map +1 -0
  10. package/dist/cjs/sdk/utils/wit/codecs/index.js +29 -0
  11. package/dist/cjs/sdk/utils/wit/codecs/index.js.map +1 -0
  12. package/dist/cjs/sdk/utils/wit/codecs/list.js +21 -95
  13. package/dist/cjs/sdk/utils/wit/codecs/list.js.map +1 -1
  14. package/dist/cjs/sdk/utils/wit/codecs/numerics.js +228 -0
  15. package/dist/cjs/sdk/utils/wit/codecs/numerics.js.map +1 -0
  16. package/dist/cjs/sdk/utils/wit/codecs/option.js +21 -72
  17. package/dist/cjs/sdk/utils/wit/codecs/option.js.map +1 -1
  18. package/dist/cjs/sdk/utils/wit/codecs/result.js +32 -0
  19. package/dist/cjs/sdk/utils/wit/codecs/result.js.map +1 -0
  20. package/dist/cjs/sdk/utils/wit/codecs/string.js +16 -21
  21. package/dist/cjs/sdk/utils/wit/codecs/string.js.map +1 -1
  22. package/dist/cjs/sdk/utils/wit/codecs/unit.js +11 -19
  23. package/dist/cjs/sdk/utils/wit/codecs/unit.js.map +1 -1
  24. package/dist/cjs/sdk/utils/wit/codecs/util.js +185 -0
  25. package/dist/cjs/sdk/utils/wit/codecs/util.js.map +1 -0
  26. package/dist/cjs/sdk/utils/wit/decode-wit-parameter.js +297 -163
  27. package/dist/cjs/sdk/utils/wit/decode-wit-parameter.js.map +1 -1
  28. package/dist/cjs/sdk/utils/wit/encode-wit-parameters.js +214 -221
  29. package/dist/cjs/sdk/utils/wit/encode-wit-parameters.js.map +1 -1
  30. package/dist/cjs/tsconfig.build.tsbuildinfo +1 -1
  31. package/dist/cjs/wit/built-ins.js +19 -0
  32. package/dist/cjs/wit/built-ins.js.map +1 -0
  33. package/dist/cjs/wit/regex.js +1 -1
  34. package/dist/cjs/wit/regex.js.map +1 -1
  35. package/dist/cjs/wit/wit-parser/core/errors/signature.js +17 -2
  36. package/dist/cjs/wit/wit-parser/core/errors/signature.js.map +1 -1
  37. package/dist/cjs/wit/wit-parser/core/signatures.js +18 -0
  38. package/dist/cjs/wit/wit-parser/core/signatures.js.map +1 -1
  39. package/dist/cjs/wit/wit-parser/core/types/{records.js → user-defined.js} +1 -1
  40. package/dist/cjs/wit/wit-parser/core/types/user-defined.js.map +1 -0
  41. package/dist/cjs/wit/wit-parser/core/user-defined.js +271 -0
  42. package/dist/cjs/wit/wit-parser/core/user-defined.js.map +1 -0
  43. package/dist/cjs/wit/wit-parser/core/utils.js +29 -7
  44. package/dist/cjs/wit/wit-parser/core/utils.js.map +1 -1
  45. package/dist/cjs/wit/wit-parser/parse-wit-parameter.js +9 -3
  46. package/dist/cjs/wit/wit-parser/parse-wit-parameter.js.map +1 -1
  47. package/dist/cjs/wit/wit-parser/parse-wit.js +7 -3
  48. package/dist/cjs/wit/wit-parser/parse-wit.js.map +1 -1
  49. package/dist/esm/sdk/actions/kontor/public/call-view.js.map +1 -1
  50. package/dist/esm/sdk/chains/definitions/signet.js +2 -2
  51. package/dist/esm/sdk/test/e2e.test-deprecated.js +197 -0
  52. package/dist/esm/sdk/test/e2e.test-deprecated.js.map +1 -0
  53. package/dist/esm/sdk/utils/wit/codecs/bool.js +9 -21
  54. package/dist/esm/sdk/utils/wit/codecs/bool.js.map +1 -1
  55. package/dist/esm/sdk/utils/wit/codecs/contract-address.js +92 -0
  56. package/dist/esm/sdk/utils/wit/codecs/contract-address.js.map +1 -0
  57. package/dist/esm/sdk/utils/wit/codecs/index.js +9 -0
  58. package/dist/esm/sdk/utils/wit/codecs/index.js.map +1 -0
  59. package/dist/esm/sdk/utils/wit/codecs/list.js +20 -114
  60. package/dist/esm/sdk/utils/wit/codecs/list.js.map +1 -1
  61. package/dist/esm/sdk/utils/wit/codecs/numerics.js +234 -0
  62. package/dist/esm/sdk/utils/wit/codecs/numerics.js.map +1 -0
  63. package/dist/esm/sdk/utils/wit/codecs/option.js +21 -88
  64. package/dist/esm/sdk/utils/wit/codecs/option.js.map +1 -1
  65. package/dist/esm/sdk/utils/wit/codecs/result.js +29 -0
  66. package/dist/esm/sdk/utils/wit/codecs/result.js.map +1 -0
  67. package/dist/esm/sdk/utils/wit/codecs/string.js +22 -22
  68. package/dist/esm/sdk/utils/wit/codecs/string.js.map +1 -1
  69. package/dist/esm/sdk/utils/wit/codecs/unit.js +12 -21
  70. package/dist/esm/sdk/utils/wit/codecs/unit.js.map +1 -1
  71. package/dist/esm/sdk/utils/wit/codecs/util.js +181 -0
  72. package/dist/esm/sdk/utils/wit/codecs/util.js.map +1 -0
  73. package/dist/esm/sdk/utils/wit/decode-wit-parameter.js +322 -188
  74. package/dist/esm/sdk/utils/wit/decode-wit-parameter.js.map +1 -1
  75. package/dist/esm/sdk/utils/wit/encode-wit-parameters.js +230 -233
  76. package/dist/esm/sdk/utils/wit/encode-wit-parameters.js.map +1 -1
  77. package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
  78. package/dist/esm/wit/built-ins.js +16 -0
  79. package/dist/esm/wit/built-ins.js.map +1 -0
  80. package/dist/esm/wit/regex.js +1 -1
  81. package/dist/esm/wit/regex.js.map +1 -1
  82. package/dist/esm/wit/wit-parser/core/errors/signature.js +15 -1
  83. package/dist/esm/wit/wit-parser/core/errors/signature.js.map +1 -1
  84. package/dist/esm/wit/wit-parser/core/signatures.js +14 -0
  85. package/dist/esm/wit/wit-parser/core/signatures.js.map +1 -1
  86. package/dist/esm/wit/wit-parser/core/types/signatures.js.map +1 -1
  87. package/dist/esm/wit/wit-parser/core/types/user-defined.js +2 -0
  88. package/dist/esm/wit/wit-parser/core/types/user-defined.js.map +1 -0
  89. package/dist/esm/wit/wit-parser/core/types/utils.js +25 -0
  90. package/dist/esm/wit/wit-parser/core/types/utils.js.map +1 -1
  91. package/dist/esm/wit/wit-parser/core/user-defined.js +280 -0
  92. package/dist/esm/wit/wit-parser/core/user-defined.js.map +1 -0
  93. package/dist/esm/wit/wit-parser/core/utils.js +33 -36
  94. package/dist/esm/wit/wit-parser/core/utils.js.map +1 -1
  95. package/dist/esm/wit/wit-parser/parse-wit-parameter.js +10 -4
  96. package/dist/esm/wit/wit-parser/parse-wit-parameter.js.map +1 -1
  97. package/dist/esm/wit/wit-parser/parse-wit.js +8 -4
  98. package/dist/esm/wit/wit-parser/parse-wit.js.map +1 -1
  99. package/dist/types/sdk/actions/kontor/public/call-view.d.ts +2 -1
  100. package/dist/types/sdk/actions/kontor/public/call-view.d.ts.map +1 -1
  101. package/dist/types/sdk/chains/definitions/signet.d.ts +2 -2
  102. package/dist/types/sdk/test/e2e.test-deprecated.d.ts +2 -0
  103. package/dist/types/sdk/test/e2e.test-deprecated.d.ts.map +1 -0
  104. package/dist/types/sdk/types/contract.d.ts +5 -5
  105. package/dist/types/sdk/types/contract.d.ts.map +1 -1
  106. package/dist/types/sdk/utils/wit/codecs/bool.d.ts +2 -2
  107. package/dist/types/sdk/utils/wit/codecs/bool.d.ts.map +1 -1
  108. package/dist/types/sdk/utils/wit/codecs/contract-address.d.ts +5 -0
  109. package/dist/types/sdk/utils/wit/codecs/contract-address.d.ts.map +1 -0
  110. package/dist/types/sdk/utils/wit/codecs/index.d.ts +9 -0
  111. package/dist/types/sdk/utils/wit/codecs/index.d.ts.map +1 -0
  112. package/dist/types/sdk/utils/wit/codecs/list.d.ts +2 -16
  113. package/dist/types/sdk/utils/wit/codecs/list.d.ts.map +1 -1
  114. package/dist/types/sdk/utils/wit/codecs/numerics.d.ts +14 -0
  115. package/dist/types/sdk/utils/wit/codecs/numerics.d.ts.map +1 -0
  116. package/dist/types/sdk/utils/wit/codecs/option.d.ts +3 -23
  117. package/dist/types/sdk/utils/wit/codecs/option.d.ts.map +1 -1
  118. package/dist/types/sdk/utils/wit/codecs/result.d.ts +4 -0
  119. package/dist/types/sdk/utils/wit/codecs/result.d.ts.map +1 -0
  120. package/dist/types/sdk/utils/wit/codecs/string.d.ts +6 -2
  121. package/dist/types/sdk/utils/wit/codecs/string.d.ts.map +1 -1
  122. package/dist/types/sdk/utils/wit/codecs/types.d.ts +4 -0
  123. package/dist/types/sdk/utils/wit/codecs/types.d.ts.map +1 -1
  124. package/dist/types/sdk/utils/wit/codecs/unit.d.ts +2 -11
  125. package/dist/types/sdk/utils/wit/codecs/unit.d.ts.map +1 -1
  126. package/dist/types/sdk/utils/wit/codecs/util.d.ts +12 -0
  127. package/dist/types/sdk/utils/wit/codecs/util.d.ts.map +1 -0
  128. package/dist/types/sdk/utils/wit/decode-wit-parameter.d.ts +9 -31
  129. package/dist/types/sdk/utils/wit/decode-wit-parameter.d.ts.map +1 -1
  130. package/dist/types/sdk/utils/wit/encode-wit-parameters.d.ts +9 -1
  131. package/dist/types/sdk/utils/wit/encode-wit-parameters.d.ts.map +1 -1
  132. package/dist/types/wit/built-ins.d.ts +6 -0
  133. package/dist/types/wit/built-ins.d.ts.map +1 -0
  134. package/dist/types/wit/regex.d.ts.map +1 -1
  135. package/dist/types/wit/utils.d.ts +53 -33
  136. package/dist/types/wit/utils.d.ts.map +1 -1
  137. package/dist/types/wit/wit-parser/core/errors/signature.d.ts +7 -1
  138. package/dist/types/wit/wit-parser/core/errors/signature.d.ts.map +1 -1
  139. package/dist/types/wit/wit-parser/core/signatures.d.ts +10 -0
  140. package/dist/types/wit/wit-parser/core/signatures.d.ts.map +1 -1
  141. package/dist/types/wit/wit-parser/core/types/signatures.d.ts +6 -2
  142. package/dist/types/wit/wit-parser/core/types/signatures.d.ts.map +1 -1
  143. package/dist/types/wit/wit-parser/core/types/user-defined.d.ts +134 -0
  144. package/dist/types/wit/wit-parser/core/types/user-defined.d.ts.map +1 -0
  145. package/dist/types/wit/wit-parser/core/types/utils.d.ts +86 -11
  146. package/dist/types/wit/wit-parser/core/types/utils.d.ts.map +1 -1
  147. package/dist/types/wit/wit-parser/core/user-defined.d.ts +19 -0
  148. package/dist/types/wit/wit-parser/core/user-defined.d.ts.map +1 -0
  149. package/dist/types/wit/wit-parser/core/utils.d.ts +8 -4
  150. package/dist/types/wit/wit-parser/core/utils.d.ts.map +1 -1
  151. package/dist/types/wit/wit-parser/parse-wit-parameter.d.ts +11 -5
  152. package/dist/types/wit/wit-parser/parse-wit-parameter.d.ts.map +1 -1
  153. package/dist/types/wit/wit-parser/parse-wit.d.ts +7 -3
  154. package/dist/types/wit/wit-parser/parse-wit.d.ts.map +1 -1
  155. package/dist/types/wit/wit.d.ts +20 -12
  156. package/dist/types/wit/wit.d.ts.map +1 -1
  157. package/package.json +1 -1
  158. package/src/sdk/actions/get-contract.test-d.ts +430 -50
  159. package/src/sdk/actions/get-contract.test.ts +324 -24
  160. package/src/sdk/actions/kontor/public/call-view.ts +2 -1
  161. package/src/sdk/actions/kontor/public/proc-contract.test-d.ts +107 -0
  162. package/src/sdk/actions/kontor/public/proc-contract.test.ts +234 -21
  163. package/src/sdk/actions/kontor/public/view-contract.test-d.ts +240 -0
  164. package/src/sdk/actions/kontor/public/view-contract.test.ts +613 -18
  165. package/src/sdk/chains/definitions/signet.ts +2 -2
  166. package/src/sdk/clients/base/create-rpc-client.test.ts +2 -2
  167. package/src/sdk/clients/create-public-client.test.ts +2 -2
  168. package/src/sdk/clients/kontor/create-public-client.test.ts +2 -2
  169. package/src/sdk/clients/transports/http-rpc.test.ts +0 -24
  170. package/src/sdk/test/e2e.test-deprecated.ts +195 -0
  171. package/src/sdk/types/contract.test-d.ts +489 -55
  172. package/src/sdk/types/contract.ts +6 -7
  173. package/src/sdk/utils/wit/codecs/bool.test.ts +29 -0
  174. package/src/sdk/utils/wit/codecs/bool.ts +10 -25
  175. package/src/sdk/utils/wit/codecs/contract-address.test.ts +37 -0
  176. package/src/sdk/utils/wit/codecs/contract-address.ts +114 -0
  177. package/src/sdk/utils/wit/codecs/index.ts +20 -0
  178. package/src/sdk/utils/wit/codecs/list.test-d.ts +13 -0
  179. package/src/sdk/utils/wit/codecs/list.test.ts +55 -0
  180. package/src/sdk/utils/wit/codecs/list.ts +21 -150
  181. package/src/sdk/utils/wit/codecs/numerics.test.ts +399 -0
  182. package/src/sdk/utils/wit/codecs/numerics.ts +304 -0
  183. package/src/sdk/utils/wit/codecs/option.test.ts +71 -0
  184. package/src/sdk/utils/wit/codecs/option.ts +21 -120
  185. package/src/sdk/utils/wit/codecs/result.test.ts +82 -0
  186. package/src/sdk/utils/wit/codecs/result.ts +37 -0
  187. package/src/sdk/utils/wit/codecs/string.test.ts +62 -0
  188. package/src/sdk/utils/wit/codecs/string.ts +23 -25
  189. package/src/sdk/utils/wit/codecs/types.ts +5 -0
  190. package/src/sdk/utils/wit/codecs/unit.test.ts +27 -0
  191. package/src/sdk/utils/wit/codecs/unit.ts +14 -38
  192. package/src/sdk/utils/wit/codecs/util.test.ts +221 -0
  193. package/src/sdk/utils/wit/codecs/util.ts +193 -0
  194. package/src/sdk/utils/wit/decode-wit-parameter.test.ts +1264 -32
  195. package/src/sdk/utils/wit/decode-wit-parameter.ts +508 -211
  196. package/src/sdk/utils/wit/encode-wit-parameters.test.ts +955 -91
  197. package/src/sdk/utils/wit/encode-wit-parameters.ts +277 -274
  198. package/src/sdk/utils/wit/get-wit-item.test.ts +1 -1
  199. package/src/wit/built-ins.ts +23 -0
  200. package/src/wit/regex.ts +1 -1
  201. package/src/wit/utils.ts +120 -74
  202. package/src/wit/wit-parser/core/errors/signature.ts +13 -2
  203. package/src/wit/wit-parser/core/signatures.ts +28 -0
  204. package/src/wit/wit-parser/core/types/signatures.test-d.ts +21 -0
  205. package/src/wit/wit-parser/core/types/signatures.ts +19 -2
  206. package/src/wit/wit-parser/core/types/user-defined.test-d.ts +1308 -0
  207. package/src/wit/wit-parser/core/types/user-defined.ts +412 -0
  208. package/src/wit/wit-parser/core/types/utils.test-d.ts +43 -2
  209. package/src/wit/wit-parser/core/types/utils.ts +143 -14
  210. package/src/wit/wit-parser/core/user-defined.test.ts +609 -0
  211. package/src/wit/wit-parser/core/user-defined.ts +392 -0
  212. package/src/wit/wit-parser/core/utils.test.ts +334 -115
  213. package/src/wit/wit-parser/core/utils.ts +54 -38
  214. package/src/wit/wit-parser/parse-wit-parameter.test.ts +282 -4
  215. package/src/wit/wit-parser/parse-wit-parameter.ts +37 -11
  216. package/src/wit/wit-parser/parse-wit.test.ts +738 -12
  217. package/src/wit/wit-parser/parse-wit.ts +25 -10
  218. package/src/wit/wit.ts +37 -16
  219. package/vitest.config.ts +5 -0
  220. package/dist/cjs/sdk/utils/wit/codecs/decimal.js +0 -148
  221. package/dist/cjs/sdk/utils/wit/codecs/decimal.js.map +0 -1
  222. package/dist/cjs/sdk/utils/wit/codecs/enum.js +0 -94
  223. package/dist/cjs/sdk/utils/wit/codecs/enum.js.map +0 -1
  224. package/dist/cjs/sdk/utils/wit/codecs/integer.js +0 -125
  225. package/dist/cjs/sdk/utils/wit/codecs/integer.js.map +0 -1
  226. package/dist/cjs/sdk/utils/wit/codecs/s64.js +0 -57
  227. package/dist/cjs/sdk/utils/wit/codecs/s64.js.map +0 -1
  228. package/dist/cjs/sdk/utils/wit/codecs/u64.js +0 -56
  229. package/dist/cjs/sdk/utils/wit/codecs/u64.js.map +0 -1
  230. package/dist/cjs/wit/wit-parser/core/records.js +0 -70
  231. package/dist/cjs/wit/wit-parser/core/records.js.map +0 -1
  232. package/dist/cjs/wit/wit-parser/core/types/records.js.map +0 -1
  233. package/dist/esm/sdk/utils/wit/codecs/decimal.js +0 -165
  234. package/dist/esm/sdk/utils/wit/codecs/decimal.js.map +0 -1
  235. package/dist/esm/sdk/utils/wit/codecs/enum.js +0 -104
  236. package/dist/esm/sdk/utils/wit/codecs/enum.js.map +0 -1
  237. package/dist/esm/sdk/utils/wit/codecs/integer.js +0 -167
  238. package/dist/esm/sdk/utils/wit/codecs/integer.js.map +0 -1
  239. package/dist/esm/sdk/utils/wit/codecs/s64.js +0 -65
  240. package/dist/esm/sdk/utils/wit/codecs/s64.js.map +0 -1
  241. package/dist/esm/sdk/utils/wit/codecs/u64.js +0 -63
  242. package/dist/esm/sdk/utils/wit/codecs/u64.js.map +0 -1
  243. package/dist/esm/wit/wit-parser/core/records.js +0 -73
  244. package/dist/esm/wit/wit-parser/core/records.js.map +0 -1
  245. package/dist/esm/wit/wit-parser/core/types/records.js +0 -2
  246. package/dist/esm/wit/wit-parser/core/types/records.js.map +0 -1
  247. package/dist/types/sdk/utils/wit/codecs/decimal.d.ts +0 -42
  248. package/dist/types/sdk/utils/wit/codecs/decimal.d.ts.map +0 -1
  249. package/dist/types/sdk/utils/wit/codecs/enum.d.ts +0 -49
  250. package/dist/types/sdk/utils/wit/codecs/enum.d.ts.map +0 -1
  251. package/dist/types/sdk/utils/wit/codecs/integer.d.ts +0 -36
  252. package/dist/types/sdk/utils/wit/codecs/integer.d.ts.map +0 -1
  253. package/dist/types/sdk/utils/wit/codecs/s64.d.ts +0 -23
  254. package/dist/types/sdk/utils/wit/codecs/s64.d.ts.map +0 -1
  255. package/dist/types/sdk/utils/wit/codecs/u64.d.ts +0 -23
  256. package/dist/types/sdk/utils/wit/codecs/u64.d.ts.map +0 -1
  257. package/dist/types/wit/wit-parser/core/records.d.ts +0 -4
  258. package/dist/types/wit/wit-parser/core/records.d.ts.map +0 -1
  259. package/dist/types/wit/wit-parser/core/types/records.d.ts +0 -51
  260. package/dist/types/wit/wit-parser/core/types/records.d.ts.map +0 -1
  261. package/src/sdk/test/e2e.test.ts +0 -194
  262. package/src/sdk/utils/wit/codecs/decimal.ts +0 -215
  263. package/src/sdk/utils/wit/codecs/enum.ts +0 -114
  264. package/src/sdk/utils/wit/codecs/integer.ts +0 -193
  265. package/src/sdk/utils/wit/codecs/s64.ts +0 -76
  266. package/src/sdk/utils/wit/codecs/u64.ts +0 -73
  267. package/src/wit/wit-parser/core/records.test.ts +0 -69
  268. package/src/wit/wit-parser/core/records.ts +0 -101
  269. package/src/wit/wit-parser/core/types/records.test-d.ts +0 -331
  270. package/src/wit/wit-parser/core/types/records.ts +0 -91
@@ -5,9 +5,10 @@ import type {
5
5
  ContractFunctionReturnType,
6
6
  } from "./contract.js";
7
7
  import { nativeToken as nativeToken_ } from "../contracts/wits.js";
8
+ import { parseWit } from "../../wit/wit-parser/parse-wit.js";
9
+ import type { WitError } from "src/wit/built-ins.js";
8
10
 
9
11
  const nativeToken = nativeToken_.wit;
10
-
11
12
  test("ContractFunctionName", () => {
12
13
  type All = ContractFunctionName<typeof nativeToken>;
13
14
  expectTypeOf<All>().toEqualTypeOf<
@@ -63,31 +64,25 @@ test("ContractFunctionArgs", () => {
63
64
  test("ContractFunctionReturnType", () => {
64
65
  type Mint = ContractFunctionReturnType<typeof nativeToken, "proc", "mint">;
65
66
  expectTypeOf<Mint>().toEqualTypeOf<
66
- | {
67
- ok: false;
68
- error: string;
69
- }
70
- | {
71
- ok: true;
72
- value: {
67
+ | ["err", WitError.T]
68
+ | [
69
+ "ok",
70
+ {
73
71
  dst: string;
74
72
  amt: [bigint, number];
75
- };
76
- }
73
+ },
74
+ ]
77
75
  >;
78
76
  type Burn = ContractFunctionReturnType<typeof nativeToken, "proc", "burn">;
79
77
  expectTypeOf<Burn>().toEqualTypeOf<
80
- | {
81
- ok: false;
82
- error: string;
83
- }
84
- | {
85
- ok: true;
86
- value: {
78
+ | ["err", WitError.T]
79
+ | [
80
+ "ok",
81
+ {
87
82
  src: string;
88
83
  amt: [bigint, number];
89
- };
90
- }
84
+ },
85
+ ]
91
86
  >;
92
87
 
93
88
  type Transfer = ContractFunctionReturnType<
@@ -96,33 +91,22 @@ test("ContractFunctionReturnType", () => {
96
91
  "transfer"
97
92
  >;
98
93
  expectTypeOf<Transfer>().toEqualTypeOf<
99
- | {
100
- ok: false;
101
- error: string;
102
- }
103
- | {
104
- ok: true;
105
- value: {
94
+ | ["err", WitError.T]
95
+ | [
96
+ "ok",
97
+ {
106
98
  src: string;
107
99
  dst: string;
108
100
  amt: [bigint, number];
109
- };
110
- }
101
+ },
102
+ ]
111
103
  >;
112
104
  type Balance = ContractFunctionReturnType<
113
105
  typeof nativeToken,
114
106
  "view",
115
107
  "balance"
116
108
  >;
117
- expectTypeOf<Balance>().toEqualTypeOf<
118
- | {
119
- kind: "none";
120
- }
121
- | {
122
- kind: "some";
123
- value: [bigint, number];
124
- }
125
- >;
109
+ expectTypeOf<Balance>().toEqualTypeOf<["none"] | ["some", [bigint, number]]>;
126
110
 
127
111
  type Balances = ContractFunctionReturnType<
128
112
  typeof nativeToken,
@@ -146,18 +130,15 @@ test("ContractFunctionReturnType", () => {
146
130
  "attach"
147
131
  >;
148
132
  expectTypeOf<Attach>().toEqualTypeOf<
149
- | {
150
- ok: false;
151
- error: string;
152
- }
153
- | {
154
- ok: true;
155
- value: {
133
+ | ["err", WitError.T]
134
+ | [
135
+ "ok",
136
+ {
156
137
  src: string;
157
138
  dst: string;
158
139
  amt: [bigint, number];
159
- };
160
- }
140
+ },
141
+ ]
161
142
  >;
162
143
 
163
144
  type Detach = ContractFunctionReturnType<
@@ -166,17 +147,470 @@ test("ContractFunctionReturnType", () => {
166
147
  "detach"
167
148
  >;
168
149
  expectTypeOf<Detach>().toEqualTypeOf<
169
- | {
170
- ok: false;
171
- error: string;
172
- }
173
- | {
174
- ok: true;
175
- value: {
150
+ | ["err", WitError.T]
151
+ | [
152
+ "ok",
153
+ {
176
154
  src: string;
177
155
  dst: string;
178
156
  amt: [bigint, number];
179
- };
180
- }
157
+ },
158
+ ]
159
+ >;
160
+ });
161
+
162
+ // Color Palette Contract - demonstrates variants and enums in WIT
163
+ const colorPaletteWit = [
164
+ // Records
165
+ "record rgb { r: u8, g: u8, b: u8 }",
166
+ "record hsv { h: u16, s: u8, v: u8 }",
167
+ "record palette-info { name: string, size: u32, owner: string }",
168
+
169
+ // Enums
170
+ "enum palette-status { active, archived, locked, readonly }",
171
+ "enum sort-order { alphabetical, creation-date, usage-count }",
172
+
173
+ // Variants
174
+ "variant color { hex(string), rgb(rgb), hsv(hsv), named(string) }",
175
+ "variant query { by-name(string), by-index(u32), all, by-status(palette-status) }",
176
+ "variant palette-event { created(palette-info), color-added(color), color-removed(u32), status-changed(palette-status) }",
177
+
178
+ // Proc functions
179
+ "export add-color: func(ctx: borrow<proc-context>, c: color) -> result<list<color>, error>;",
180
+ "export remove-color: func(ctx: borrow<proc-context>, index: u32) -> result<color, error>;",
181
+ "export set-status: func(ctx: borrow<proc-context>, status: palette-status) -> result<palette-status, error>;",
182
+ "export sort-colors: func(ctx: borrow<proc-context>, order: sort-order) -> result<_, error>;",
183
+
184
+ // View functions
185
+ "export get-colors: func(ctx: borrow<view-context>) -> list<color>;",
186
+ "export get-color: func(ctx: borrow<view-context>, index: u32) -> option<color>;",
187
+ "export get-status: func(ctx: borrow<view-context>) -> palette-status;",
188
+ "export get-info: func(ctx: borrow<view-context>) -> palette-info;",
189
+ "export query-colors: func(ctx: borrow<view-context>, q: query) -> list<color>;",
190
+ "export find-color: func(ctx: borrow<view-context>, c: color) -> option<u32>;",
191
+ "export get-recent-events: func(ctx: borrow<view-context>, limit: u32) -> list<palette-event>;",
192
+ ] as const;
193
+
194
+ const colorPalette = parseWit(colorPaletteWit);
195
+
196
+ test("ContractFunctionName - color palette", () => {
197
+ type All = ContractFunctionName<typeof colorPalette>;
198
+ expectTypeOf<All>().toEqualTypeOf<
199
+ | "add-color"
200
+ | "remove-color"
201
+ | "set-status"
202
+ | "sort-colors"
203
+ | "get-colors"
204
+ | "get-color"
205
+ | "get-status"
206
+ | "get-info"
207
+ | "query-colors"
208
+ | "find-color"
209
+ | "get-recent-events"
210
+ >;
211
+
212
+ type View = ContractFunctionName<typeof colorPalette, "view">;
213
+ expectTypeOf<View>().toEqualTypeOf<
214
+ | "get-colors"
215
+ | "get-color"
216
+ | "get-status"
217
+ | "get-info"
218
+ | "query-colors"
219
+ | "find-color"
220
+ | "get-recent-events"
221
+ >;
222
+
223
+ type Proc = ContractFunctionName<typeof colorPalette, "proc">;
224
+ expectTypeOf<Proc>().toEqualTypeOf<
225
+ "add-color" | "remove-color" | "set-status" | "sort-colors"
226
+ >;
227
+ });
228
+
229
+ test("ContractFunctionArgs - procs with variants and enums", () => {
230
+ // Proc with variant parameter
231
+ //
232
+ type AddColor = ContractFunctionArgs<
233
+ typeof colorPalette,
234
+ "proc",
235
+ "add-color"
236
+ >;
237
+
238
+ expectTypeOf<AddColor>().toEqualTypeOf<
239
+ readonly [
240
+ | ["hex", string]
241
+ | ["rgb", { r: number; g: number; b: number }]
242
+ | ["hsv", { h: number; s: number; v: number }]
243
+ | ["named", string],
244
+ ]
181
245
  >;
246
+
247
+ // Proc with simple parameter
248
+ type RemoveColor = ContractFunctionArgs<
249
+ typeof colorPalette,
250
+ "proc",
251
+ "remove-color"
252
+ >;
253
+ expectTypeOf<RemoveColor>().toEqualTypeOf<readonly [number]>;
254
+
255
+ // Proc with enum parameter
256
+ type SetStatus = ContractFunctionArgs<
257
+ typeof colorPalette,
258
+ "proc",
259
+ "set-status"
260
+ >;
261
+ expectTypeOf<SetStatus>().toEqualTypeOf<
262
+ readonly ["active" | "archived" | "locked" | "readonly"]
263
+ >;
264
+
265
+ // Proc with enum parameter
266
+ type SortColors = ContractFunctionArgs<
267
+ typeof colorPalette,
268
+ "proc",
269
+ "sort-colors"
270
+ >;
271
+ expectTypeOf<SortColors>().toEqualTypeOf<
272
+ readonly ["alphabetical" | "creation-date" | "usage-count"]
273
+ >;
274
+ });
275
+ test("ContractFunctionArgs - views with variants and enums", () => {
276
+ // View with no parameters
277
+ type GetColors = ContractFunctionArgs<
278
+ typeof colorPalette,
279
+ "view",
280
+ "get-colors"
281
+ >;
282
+ expectTypeOf<GetColors>().toEqualTypeOf<readonly []>;
283
+
284
+ // View with simple parameter
285
+ type GetColor = ContractFunctionArgs<
286
+ typeof colorPalette,
287
+ "view",
288
+ "get-color"
289
+ >;
290
+ expectTypeOf<GetColor>().toEqualTypeOf<readonly [number]>;
291
+
292
+ // View with no parameters
293
+ type GetStatus = ContractFunctionArgs<
294
+ typeof colorPalette,
295
+ "view",
296
+ "get-status"
297
+ >;
298
+ expectTypeOf<GetStatus>().toEqualTypeOf<readonly []>;
299
+
300
+ // View with no parameters
301
+ type GetInfo = ContractFunctionArgs<typeof colorPalette, "view", "get-info">;
302
+ expectTypeOf<GetInfo>().toEqualTypeOf<readonly []>;
303
+
304
+ // View with variant parameter
305
+ type QueryColors = ContractFunctionArgs<
306
+ typeof colorPalette,
307
+ "view",
308
+ "query-colors"
309
+ >;
310
+
311
+ expectTypeOf<QueryColors>().toEqualTypeOf<
312
+ readonly [
313
+ | ["by-name", string]
314
+ | ["by-index", number]
315
+ | ["all"]
316
+ | ["by-status", "active" | "archived" | "locked" | "readonly"],
317
+ ]
318
+ >;
319
+
320
+ // View with variant parameter
321
+ type FindColor = ContractFunctionArgs<
322
+ typeof colorPalette,
323
+ "view",
324
+ "find-color"
325
+ >;
326
+ expectTypeOf<FindColor>().toEqualTypeOf<
327
+ readonly [
328
+ | ["hex", string]
329
+ | ["rgb", { r: number; g: number; b: number }]
330
+ | ["hsv", { h: number; s: number; v: number }]
331
+ | ["named", string],
332
+ ]
333
+ >;
334
+
335
+ // View with simple parameter
336
+ type GetRecentEvents = ContractFunctionArgs<
337
+ typeof colorPalette,
338
+ "view",
339
+ "get-recent-events"
340
+ >;
341
+ expectTypeOf<GetRecentEvents>().toEqualTypeOf<readonly [number]>;
342
+ });
343
+
344
+ test("ContractFunctionReturnType - procs with variants and enums", () => {});
345
+ // Proc returning list of variants
346
+ // type AddColor = ContractFunctionReturnType<
347
+ // typeof colorPalette,
348
+ // "proc",
349
+ // "add-color"
350
+ // >;
351
+ // expectTypeOf<AddColor>().toEqualTypeOf<
352
+ // | { ok: false; error: string }
353
+ // | {
354
+ // ok: true;
355
+ // value: readonly (
356
+ // | { kind: "hex"; value: string }
357
+ // | { kind: "rgb"; value: { r: number; g: number; b: number } }
358
+ // | { kind: "hsv"; value: { h: number; s: number; v: number } }
359
+ // | { kind: "named"; value: string }
360
+ // )[];
361
+ // }
362
+ // >;
363
+ //
364
+ // // Proc returning variant
365
+ // type RemoveColor = ContractFunctionReturnType<
366
+ // typeof colorPalette,
367
+ // "proc",
368
+ // "remove-color"
369
+ // >;
370
+ // expectTypeOf<RemoveColor>().toEqualTypeOf<
371
+ // | { ok: false; error: string }
372
+ // | {
373
+ // ok: true;
374
+ // value:
375
+ // | { kind: "hex"; value: string }
376
+ // | { kind: "rgb"; value: { r: number; g: number; b: number } }
377
+ // | { kind: "hsv"; value: { h: number; s: number; v: number } }
378
+ // | { kind: "named"; value: string };
379
+ // }
380
+ // >;
381
+ //
382
+ // // Proc returning enum
383
+ // type SetStatus = ContractFunctionReturnType<
384
+ // typeof colorPalette,
385
+ // "proc",
386
+ // "set-status"
387
+ // >;
388
+ // expectTypeOf<SetStatus>().toEqualTypeOf<
389
+ // | { ok: false; error: string }
390
+ // | { ok: true; value: "active" | "archived" | "locked" | "readonly" }
391
+ // >;
392
+ //
393
+ // // Proc returning unit (result<_, error>)
394
+ // type SortColors = ContractFunctionReturnType<
395
+ // typeof colorPalette,
396
+ // "proc",
397
+ // "sort-colors"
398
+ // >;
399
+ // expectTypeOf<SortColors>().toEqualTypeOf<
400
+ // { ok: false; error: string } | { ok: true; value: undefined }
401
+ // >;
402
+ //
403
+ // // Proc returning count
404
+ // type BatchAdd = ContractFunctionReturnType<
405
+ // typeof colorPalette,
406
+ // "proc",
407
+ // "batch-add"
408
+ // >;
409
+ // expectTypeOf<BatchAdd>().toEqualTypeOf<
410
+ // { ok: false; error: string } | { ok: true; value: number }
411
+ // >;
412
+ // });
413
+ //
414
+ // });
415
+ test("ContractFunctionReturnType - views with variants and enums", () => {
416
+ // View returning list of variants
417
+ type GetColors = ContractFunctionReturnType<
418
+ typeof colorPalette,
419
+ "view",
420
+ "get-colors"
421
+ >;
422
+ expectTypeOf<GetColors>().toEqualTypeOf<
423
+ readonly (
424
+ | ["hex", string]
425
+ | ["rgb", { r: number; g: number; b: number }]
426
+ | ["hsv", { h: number; s: number; v: number }]
427
+ | ["named", string]
428
+ )[]
429
+ >;
430
+
431
+ // View returning option of variant
432
+ type GetColor = ContractFunctionReturnType<
433
+ typeof colorPalette,
434
+ "view",
435
+ "get-color"
436
+ >;
437
+ expectTypeOf<GetColor>().toEqualTypeOf<
438
+ | ["none"]
439
+ | [
440
+ "some",
441
+ (
442
+ | ["hex", string]
443
+ | ["named", string]
444
+ | [
445
+ "rgb",
446
+ {
447
+ r: number;
448
+ g: number;
449
+ b: number;
450
+ },
451
+ ]
452
+ | [
453
+ "hsv",
454
+ {
455
+ h: number;
456
+ s: number;
457
+ v: number;
458
+ },
459
+ ]
460
+ ),
461
+ ]
462
+ >;
463
+
464
+ // View returning enum
465
+ type GetStatus = ContractFunctionReturnType<
466
+ typeof colorPalette,
467
+ "view",
468
+ "get-status"
469
+ >;
470
+ expectTypeOf<GetStatus>().toEqualTypeOf<
471
+ "active" | "archived" | "locked" | "readonly"
472
+ >;
473
+
474
+ // View returning record
475
+ type GetInfo = ContractFunctionReturnType<
476
+ typeof colorPalette,
477
+ "view",
478
+ "get-info"
479
+ >;
480
+ expectTypeOf<GetInfo>().toEqualTypeOf<{
481
+ name: string;
482
+ size: number;
483
+ owner: string;
484
+ }>;
485
+
486
+ // View returning list of variants
487
+ type QueryColors = ContractFunctionReturnType<
488
+ typeof colorPalette,
489
+ "view",
490
+ "query-colors"
491
+ >;
492
+ expectTypeOf<QueryColors>().toEqualTypeOf<
493
+ readonly (
494
+ | ["hex", string]
495
+ | ["rgb", { r: number; g: number; b: number }]
496
+ | ["hsv", { h: number; s: number; v: number }]
497
+ | ["named", string]
498
+ )[]
499
+ >;
500
+
501
+ // View returning option of number
502
+ type FindColor = ContractFunctionReturnType<
503
+ typeof colorPalette,
504
+ "view",
505
+ "find-color"
506
+ >;
507
+ expectTypeOf<FindColor>().toEqualTypeOf<["none"] | ["some", number]>;
508
+
509
+ // View returning list of variants (events)
510
+ type GetRecentEvents = ContractFunctionReturnType<
511
+ typeof colorPalette,
512
+ "view",
513
+ "get-recent-events"
514
+ >;
515
+ expectTypeOf<GetRecentEvents>().toEqualTypeOf<
516
+ readonly (
517
+ | [
518
+ "created",
519
+ {
520
+ name: string;
521
+ size: number;
522
+ owner: string;
523
+ },
524
+ ]
525
+ | [
526
+ "color-added",
527
+ (
528
+ | ["hex", string]
529
+ | ["named", string]
530
+ | [
531
+ "rgb",
532
+ {
533
+ r: number;
534
+ g: number;
535
+ b: number;
536
+ },
537
+ ]
538
+ | [
539
+ "hsv",
540
+ {
541
+ h: number;
542
+ s: number;
543
+ v: number;
544
+ },
545
+ ]
546
+ ),
547
+ ]
548
+ | ["color-removed", number]
549
+ | ["status-changed", "active" | "archived" | "locked" | "readonly"]
550
+ )[]
551
+ >;
552
+ });
553
+ //
554
+ test("Complex nested variant and enum patterns", () => {
555
+ // Variant containing an enum
556
+ type QueryWithEnum = ContractFunctionArgs<
557
+ typeof colorPalette,
558
+ "view",
559
+ "query-colors"
560
+ >;
561
+ type QueryVariant = QueryWithEnum[0];
562
+
563
+ // Should be able to construct query with enum
564
+ expectTypeOf<QueryVariant>().toEqualTypeOf<
565
+ | ["by-name", string]
566
+ | ["by-index", number]
567
+ | ["all"]
568
+ | ["by-status", "active" | "archived" | "locked" | "readonly"]
569
+ >();
570
+
571
+ // Variant containing another variant
572
+ type EventWithVariant = ContractFunctionReturnType<
573
+ typeof colorPalette,
574
+ "view",
575
+ "get-recent-events"
576
+ >;
577
+
578
+ // Should be able to construct event with nested color variant
579
+ expectTypeOf<EventWithVariant>().toEqualTypeOf<
580
+ readonly (
581
+ | ["color-removed", number]
582
+ | ["status-changed", "active" | "archived" | "locked" | "readonly"]
583
+ | [
584
+ "created",
585
+ {
586
+ name: string;
587
+ size: number;
588
+ owner: string;
589
+ },
590
+ ]
591
+ | [
592
+ "color-added",
593
+ (
594
+ | ["hex", string]
595
+ | ["named", string]
596
+ | [
597
+ "rgb",
598
+ {
599
+ r: number;
600
+ g: number;
601
+ b: number;
602
+ },
603
+ ]
604
+ | [
605
+ "hsv",
606
+ {
607
+ h: number;
608
+ s: number;
609
+ v: number;
610
+ },
611
+ ]
612
+ ),
613
+ ]
614
+ )[]
615
+ >();
182
616
  });
@@ -89,7 +89,6 @@ export type Widen<T> =
89
89
  : never);
90
90
 
91
91
  export type UnionWiden<type> = type extends any ? Widen<type> : never;
92
-
93
92
  export type ContractFunctionParameters<
94
93
  wit extends Wit | readonly unknown[] = Wit,
95
94
  mutability extends WitStateMutability = WitStateMutability,
@@ -107,12 +106,12 @@ export type ContractFunctionParameters<
107
106
  > = {
108
107
  wit: wit;
109
108
  functionName:
110
- | allFunctionNames // show all options
111
- | (functionName extends allFunctionNames ? functionName : never); // infer value
112
- args?: (wit extends Wit ? UnionWiden<args> : never) | allArgs | undefined;
113
- } & (readonly [] extends allArgs ? {} : { args: Widen<args> }) & {
114
- contractAddress: ResolvedRegister["contractAddress"];
115
- };
109
+ | allFunctionNames
110
+ | (functionName extends allFunctionNames ? functionName : never);
111
+ contractAddress: ResolvedRegister["contractAddress"];
112
+ } & (readonly [] extends allArgs
113
+ ? { args?: allArgs | undefined } // Changed: allow allArgs (readonly []) or undefined
114
+ : { args: args });
116
115
 
117
116
  export type ContractFunctionReturnType<
118
117
  wit extends Wit | readonly unknown[] = Wit,
@@ -0,0 +1,29 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { BoolCodec } from "./bool.js";
3
+
4
+ describe("BoolCodec", () => {
5
+ it("decodes true/false (with whitespace)", () => {
6
+ expect(BoolCodec.decodeWave("true")).toBe(true);
7
+ expect(BoolCodec.decodeWave("false")).toBe(false);
8
+ expect(BoolCodec.decodeWave(" true ")).toBe(true);
9
+ expect(BoolCodec.decodeWave("\nfalse\t")).toBe(false);
10
+ });
11
+
12
+ it("encodes true/false", () => {
13
+ expect(BoolCodec.encodeWave(true)).toBe("true");
14
+ expect(BoolCodec.encodeWave(false)).toBe("false");
15
+ });
16
+
17
+ it("round-trips", () => {
18
+ for (const v of [true, false]) {
19
+ expect(BoolCodec.decodeWave(BoolCodec.encodeWave(v))).toBe(v);
20
+ }
21
+ });
22
+
23
+ it("throws on invalid input", () => {
24
+ expect(() => BoolCodec.decodeWave("True")).toThrow("invalid bool: True");
25
+ expect(() => BoolCodec.decodeWave("0")).toThrow("invalid bool: 0");
26
+ expect(() => BoolCodec.decodeWave("null")).toThrow("invalid bool: null");
27
+ expect(() => BoolCodec.decodeWave("")).toThrow("invalid bool:");
28
+ });
29
+ });
@@ -1,29 +1,14 @@
1
- import type { CodecConstructor, CodecInstance, WaveExpr } from "./types.js";
1
+ import type { Codec } from "./types.js";
2
2
 
3
- export const BoolCodec = {
4
- fromJs(value: boolean) {
5
- return {
6
- toWave(): WaveExpr {
7
- return `${value}` as WaveExpr;
8
- },
9
- toJs(): boolean {
10
- return value;
11
- },
12
- };
3
+ export const BoolCodec: Codec<boolean> = {
4
+ decodeWave(expr: string): boolean {
5
+ const s = expr.trim();
6
+ if (s === "true") return true;
7
+ if (s === "false") return false;
8
+ throw new Error(`invalid bool: ${expr}`);
13
9
  },
14
10
 
15
- fromKontor(data: boolean) {
16
- return {
17
- toWave(): WaveExpr {
18
- return `${data}` as WaveExpr;
19
- },
20
- toJs(): boolean {
21
- return data as boolean;
22
- },
23
- };
11
+ encodeWave(value: boolean): string {
12
+ return value ? "true" : "false";
24
13
  },
25
-
26
- parseWave(expr: string): boolean {
27
- return JSON.parse(expr);
28
- },
29
- } as unknown as CodecConstructor<boolean, CodecInstance<boolean>, boolean>;
14
+ };