@sentio/sdk 4.0.0-rc.1 → 4.0.0-rc.3

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 (331) hide show
  1. package/lib/aptos/aptos-plugin.d.ts +1 -1
  2. package/lib/aptos/aptos-plugin.d.ts.map +1 -1
  3. package/lib/aptos/aptos-plugin.js +43 -42
  4. package/lib/aptos/aptos-plugin.js.map +1 -1
  5. package/lib/aptos/aptos-processor.d.ts +1 -1
  6. package/lib/aptos/aptos-processor.d.ts.map +1 -1
  7. package/lib/aptos/aptos-processor.js +25 -25
  8. package/lib/aptos/aptos-processor.js.map +1 -1
  9. package/lib/aptos/aptos-resource-processor-template.d.ts +1 -1
  10. package/lib/aptos/aptos-resource-processor-template.d.ts.map +1 -1
  11. package/lib/aptos/aptos-resource-processor-template.js +10 -5
  12. package/lib/aptos/aptos-resource-processor-template.js.map +1 -1
  13. package/lib/aptos/context.d.ts +1 -1
  14. package/lib/aptos/context.d.ts.map +1 -1
  15. package/lib/aptos/context.js +8 -6
  16. package/lib/aptos/context.js.map +1 -1
  17. package/lib/aptos/data.d.ts +4 -4
  18. package/lib/aptos/data.d.ts.map +1 -1
  19. package/lib/core/base-context.d.ts +3 -2
  20. package/lib/core/base-context.d.ts.map +1 -1
  21. package/lib/core/base-context.js +12 -11
  22. package/lib/core/base-context.js.map +1 -1
  23. package/lib/core/core-plugin.d.ts.map +1 -1
  24. package/lib/core/core-plugin.js +6 -4
  25. package/lib/core/core-plugin.js.map +1 -1
  26. package/lib/core/event-logger.d.ts +10 -2
  27. package/lib/core/event-logger.d.ts.map +1 -1
  28. package/lib/core/event-logger.js +42 -26
  29. package/lib/core/event-logger.js.map +1 -1
  30. package/lib/core/exporter.d.ts.map +1 -1
  31. package/lib/core/exporter.js +5 -3
  32. package/lib/core/exporter.js.map +1 -1
  33. package/lib/core/handler-options.d.ts +1 -1
  34. package/lib/core/handler-options.d.ts.map +1 -1
  35. package/lib/core/handler-register.d.ts +1 -1
  36. package/lib/core/handler-register.d.ts.map +1 -1
  37. package/lib/core/handler-register.js +2 -2
  38. package/lib/core/handler-register.js.map +1 -1
  39. package/lib/core/meter.d.ts +4 -3
  40. package/lib/core/meter.d.ts.map +1 -1
  41. package/lib/core/meter.js +5 -4
  42. package/lib/core/meter.js.map +1 -1
  43. package/lib/core/normalization.d.ts +1 -1
  44. package/lib/core/normalization.d.ts.map +1 -1
  45. package/lib/core/normalization.js +41 -31
  46. package/lib/core/normalization.js.map +1 -1
  47. package/lib/core/numberish.d.ts +1 -1
  48. package/lib/core/numberish.d.ts.map +1 -1
  49. package/lib/core/numberish.js +35 -30
  50. package/lib/core/numberish.js.map +1 -1
  51. package/lib/core/partition-handler-manager.d.ts +1 -1
  52. package/lib/core/partition-handler-manager.d.ts.map +1 -1
  53. package/lib/core/partition-handler-manager.js +10 -9
  54. package/lib/core/partition-handler-manager.js.map +1 -1
  55. package/lib/cosmos/context.d.ts.map +1 -1
  56. package/lib/cosmos/context.js +4 -2
  57. package/lib/cosmos/context.js.map +1 -1
  58. package/lib/cosmos/cosmos-plugin.d.ts.map +1 -1
  59. package/lib/cosmos/cosmos-plugin.js +11 -10
  60. package/lib/cosmos/cosmos-plugin.js.map +1 -1
  61. package/lib/cosmos/cosmos-processor.js.map +1 -1
  62. package/lib/eth/abi-decoder/decode-worker.js +2 -2
  63. package/lib/eth/abi-decoder/decode-worker.js.map +1 -1
  64. package/lib/eth/account-processor.d.ts +2 -2
  65. package/lib/eth/account-processor.d.ts.map +1 -1
  66. package/lib/eth/account-processor.js +10 -9
  67. package/lib/eth/account-processor.js.map +1 -1
  68. package/lib/eth/base-processor-template.d.ts +3 -3
  69. package/lib/eth/base-processor-template.d.ts.map +1 -1
  70. package/lib/eth/base-processor-template.js +12 -8
  71. package/lib/eth/base-processor-template.js.map +1 -1
  72. package/lib/eth/base-processor.d.ts +1 -1
  73. package/lib/eth/base-processor.d.ts.map +1 -1
  74. package/lib/eth/base-processor.js +53 -46
  75. package/lib/eth/base-processor.js.map +1 -1
  76. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts.map +1 -1
  77. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +48 -46
  78. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
  79. package/lib/eth/builtin/internal/erc1155-processor.d.ts.map +1 -1
  80. package/lib/eth/builtin/internal/erc1155-processor.js +18 -16
  81. package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
  82. package/lib/eth/builtin/internal/erc20-processor.d.ts.map +1 -1
  83. package/lib/eth/builtin/internal/erc20-processor.js +38 -36
  84. package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
  85. package/lib/eth/builtin/internal/erc20bytes-processor.d.ts.map +1 -1
  86. package/lib/eth/builtin/internal/erc20bytes-processor.js +20 -18
  87. package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
  88. package/lib/eth/builtin/internal/erc721-processor.d.ts.map +1 -1
  89. package/lib/eth/builtin/internal/erc721-processor.js +30 -28
  90. package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
  91. package/lib/eth/builtin/internal/weth9-processor.d.ts.map +1 -1
  92. package/lib/eth/builtin/internal/weth9-processor.js +24 -22
  93. package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
  94. package/lib/eth/codegen/file.d.ts.map +1 -1
  95. package/lib/eth/codegen/file.js +2 -1
  96. package/lib/eth/codegen/file.js.map +1 -1
  97. package/lib/eth/codegen/function-calls.js +1 -1
  98. package/lib/eth/context.d.ts +1 -1
  99. package/lib/eth/context.d.ts.map +1 -1
  100. package/lib/eth/context.js +17 -11
  101. package/lib/eth/context.js.map +1 -1
  102. package/lib/eth/eth-plugin.d.ts.map +1 -1
  103. package/lib/eth/eth-plugin.js +83 -75
  104. package/lib/eth/eth-plugin.js.map +1 -1
  105. package/lib/eth/eth.d.ts +6 -6
  106. package/lib/eth/eth.d.ts.map +1 -1
  107. package/lib/eth/eth.js +39 -26
  108. package/lib/eth/eth.js.map +1 -1
  109. package/lib/eth/index.d.ts +1 -1
  110. package/lib/eth/index.d.ts.map +1 -1
  111. package/lib/eth/index.js +0 -1
  112. package/lib/eth/index.js.map +1 -1
  113. package/lib/fuel/asset-processor.d.ts +2 -2
  114. package/lib/fuel/asset-processor.d.ts.map +1 -1
  115. package/lib/fuel/asset-processor.js +5 -3
  116. package/lib/fuel/asset-processor.js.map +1 -1
  117. package/lib/fuel/context.d.ts.map +1 -1
  118. package/lib/fuel/context.js +4 -2
  119. package/lib/fuel/context.js.map +1 -1
  120. package/lib/fuel/fuel-plugin.d.ts.map +1 -1
  121. package/lib/fuel/fuel-plugin.js +41 -53
  122. package/lib/fuel/fuel-plugin.js.map +1 -1
  123. package/lib/fuel/fuel-processor-template.d.ts.map +1 -1
  124. package/lib/fuel/fuel-processor-template.js +7 -5
  125. package/lib/fuel/fuel-processor-template.js.map +1 -1
  126. package/lib/fuel/fuel-processor.d.ts.map +1 -1
  127. package/lib/fuel/fuel-processor.js +30 -20
  128. package/lib/fuel/fuel-processor.js.map +1 -1
  129. package/lib/fuel/global-processor.d.ts.map +1 -1
  130. package/lib/fuel/global-processor.js +2 -1
  131. package/lib/fuel/global-processor.js.map +1 -1
  132. package/lib/fuel/types.d.ts +10 -4
  133. package/lib/fuel/types.d.ts.map +1 -1
  134. package/lib/fuel/types.js.map +1 -1
  135. package/lib/iota/context.d.ts +1 -1
  136. package/lib/iota/context.d.ts.map +1 -1
  137. package/lib/iota/context.js +8 -6
  138. package/lib/iota/context.js.map +1 -1
  139. package/lib/iota/iota-object-processor-template.d.ts +1 -1
  140. package/lib/iota/iota-object-processor-template.d.ts.map +1 -1
  141. package/lib/iota/iota-object-processor-template.js +17 -12
  142. package/lib/iota/iota-object-processor-template.js.map +1 -1
  143. package/lib/iota/iota-object-processor.d.ts +1 -1
  144. package/lib/iota/iota-object-processor.d.ts.map +1 -1
  145. package/lib/iota/iota-object-processor.js +23 -16
  146. package/lib/iota/iota-object-processor.js.map +1 -1
  147. package/lib/iota/iota-plugin-part.d.ts +1 -1
  148. package/lib/iota/iota-plugin-part.d.ts.map +1 -1
  149. package/lib/iota/iota-plugin-part.js +16 -15
  150. package/lib/iota/iota-plugin-part.js.map +1 -1
  151. package/lib/iota/iota-processor.d.ts +1 -1
  152. package/lib/iota/iota-processor.d.ts.map +1 -1
  153. package/lib/iota/iota-processor.js +18 -17
  154. package/lib/iota/iota-processor.js.map +1 -1
  155. package/lib/iota/network.js +2 -2
  156. package/lib/iota/network.js.map +1 -1
  157. package/lib/move/filter.d.ts +1 -1
  158. package/lib/move/filter.d.ts.map +1 -1
  159. package/lib/move/index.d.ts +1 -1
  160. package/lib/move/index.d.ts.map +1 -1
  161. package/lib/move/index.js +0 -1
  162. package/lib/move/index.js.map +1 -1
  163. package/lib/solana/builtin/types.d.ts +4 -4
  164. package/lib/solana/solana-context.d.ts.map +1 -1
  165. package/lib/solana/solana-context.js +4 -3
  166. package/lib/solana/solana-context.js.map +1 -1
  167. package/lib/solana/solana-plugin.d.ts.map +1 -1
  168. package/lib/solana/solana-plugin.js +19 -18
  169. package/lib/solana/solana-plugin.js.map +1 -1
  170. package/lib/solana/solana-processor.d.ts.map +1 -1
  171. package/lib/solana/solana-processor.js +8 -3
  172. package/lib/solana/solana-processor.js.map +1 -1
  173. package/lib/store/cache.d.ts.map +1 -1
  174. package/lib/store/cache.js +22 -17
  175. package/lib/store/cache.js.map +1 -1
  176. package/lib/store/convert.d.ts +1 -1
  177. package/lib/store/convert.d.ts.map +1 -1
  178. package/lib/store/convert.js +67 -104
  179. package/lib/store/convert.js.map +1 -1
  180. package/lib/store/decorators.d.ts +1 -1
  181. package/lib/store/decorators.d.ts.map +1 -1
  182. package/lib/store/decorators.js +3 -1
  183. package/lib/store/decorators.js.map +1 -1
  184. package/lib/store/store.d.ts.map +1 -1
  185. package/lib/store/store.js +24 -16
  186. package/lib/store/store.js.map +1 -1
  187. package/lib/store/types.js +24 -32
  188. package/lib/store/types.js.map +1 -1
  189. package/lib/store/util.d.ts +1 -1
  190. package/lib/store/util.d.ts.map +1 -1
  191. package/lib/store/util.js +13 -17
  192. package/lib/store/util.js.map +1 -1
  193. package/lib/sui/context.d.ts +1 -1
  194. package/lib/sui/context.d.ts.map +1 -1
  195. package/lib/sui/context.js +8 -6
  196. package/lib/sui/context.js.map +1 -1
  197. package/lib/sui/sui-object-processor-template.d.ts +1 -1
  198. package/lib/sui/sui-object-processor-template.d.ts.map +1 -1
  199. package/lib/sui/sui-object-processor-template.js +17 -12
  200. package/lib/sui/sui-object-processor-template.js.map +1 -1
  201. package/lib/sui/sui-object-processor.d.ts +1 -1
  202. package/lib/sui/sui-object-processor.d.ts.map +1 -1
  203. package/lib/sui/sui-object-processor.js +23 -16
  204. package/lib/sui/sui-object-processor.js.map +1 -1
  205. package/lib/sui/sui-plugin-part.d.ts +1 -1
  206. package/lib/sui/sui-plugin-part.d.ts.map +1 -1
  207. package/lib/sui/sui-plugin-part.js +16 -15
  208. package/lib/sui/sui-plugin-part.js.map +1 -1
  209. package/lib/sui/sui-plugin.d.ts +1 -1
  210. package/lib/sui/sui-plugin.d.ts.map +1 -1
  211. package/lib/sui/sui-plugin.js +35 -34
  212. package/lib/sui/sui-plugin.js.map +1 -1
  213. package/lib/sui/sui-processor.d.ts +1 -1
  214. package/lib/sui/sui-processor.d.ts.map +1 -1
  215. package/lib/sui/sui-processor.js +18 -17
  216. package/lib/sui/sui-processor.js.map +1 -1
  217. package/lib/testing/aptos-facet.d.ts.map +1 -1
  218. package/lib/testing/aptos-facet.js +18 -11
  219. package/lib/testing/aptos-facet.js.map +1 -1
  220. package/lib/testing/cosmos-facet.d.ts.map +1 -1
  221. package/lib/testing/cosmos-facet.js +10 -6
  222. package/lib/testing/cosmos-facet.js.map +1 -1
  223. package/lib/testing/eth-facet.d.ts +1 -1
  224. package/lib/testing/eth-facet.d.ts.map +1 -1
  225. package/lib/testing/eth-facet.js +34 -18
  226. package/lib/testing/eth-facet.js.map +1 -1
  227. package/lib/testing/fuel-facet.d.ts.map +1 -1
  228. package/lib/testing/fuel-facet.js +28 -18
  229. package/lib/testing/fuel-facet.js.map +1 -1
  230. package/lib/testing/iota-facet.d.ts.map +1 -1
  231. package/lib/testing/iota-facet.js +32 -20
  232. package/lib/testing/iota-facet.js.map +1 -1
  233. package/lib/testing/memory-database.d.ts +11 -3
  234. package/lib/testing/memory-database.d.ts.map +1 -1
  235. package/lib/testing/memory-database.js +84 -71
  236. package/lib/testing/memory-database.js.map +1 -1
  237. package/lib/testing/metric-utils.d.ts +2 -2
  238. package/lib/testing/metric-utils.d.ts.map +1 -1
  239. package/lib/testing/metric-utils.js +13 -12
  240. package/lib/testing/metric-utils.js.map +1 -1
  241. package/lib/testing/solana-facet.d.ts +3 -2
  242. package/lib/testing/solana-facet.d.ts.map +1 -1
  243. package/lib/testing/solana-facet.js +8 -5
  244. package/lib/testing/solana-facet.js.map +1 -1
  245. package/lib/testing/sui-facet.d.ts.map +1 -1
  246. package/lib/testing/sui-facet.js +30 -20
  247. package/lib/testing/sui-facet.js.map +1 -1
  248. package/lib/testing/test-processor-server.d.ts +1453 -16
  249. package/lib/testing/test-processor-server.d.ts.map +1 -1
  250. package/lib/testing/test-processor-server.js +108 -45
  251. package/lib/testing/test-processor-server.js.map +1 -1
  252. package/lib/utils/price.d.ts +1 -1
  253. package/lib/utils/price.d.ts.map +1 -1
  254. package/lib/utils/price.js +19 -12
  255. package/lib/utils/price.js.map +1 -1
  256. package/package.json +5 -7
  257. package/src/aptos/aptos-plugin.ts +105 -91
  258. package/src/aptos/aptos-processor.ts +33 -25
  259. package/src/aptos/aptos-resource-processor-template.ts +15 -6
  260. package/src/aptos/context.ts +8 -7
  261. package/src/aptos/data.ts +4 -4
  262. package/src/core/base-context.ts +19 -12
  263. package/src/core/core-plugin.ts +10 -7
  264. package/src/core/event-logger.ts +63 -34
  265. package/src/core/exporter.ts +5 -4
  266. package/src/core/handler-options.ts +1 -1
  267. package/src/core/handler-register.ts +3 -3
  268. package/src/core/meter.ts +9 -7
  269. package/src/core/normalization.ts +53 -31
  270. package/src/core/numberish.ts +46 -30
  271. package/src/core/partition-handler-manager.ts +13 -11
  272. package/src/cosmos/context.ts +4 -3
  273. package/src/cosmos/cosmos-plugin.ts +19 -15
  274. package/src/cosmos/cosmos-processor.ts +2 -2
  275. package/src/eth/abi-decoder/decode-worker.ts +2 -2
  276. package/src/eth/account-processor.ts +21 -12
  277. package/src/eth/base-processor-template.ts +22 -10
  278. package/src/eth/base-processor.ts +66 -54
  279. package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +177 -116
  280. package/src/eth/builtin/internal/erc1155-processor.ts +73 -38
  281. package/src/eth/builtin/internal/erc20-processor.ts +152 -91
  282. package/src/eth/builtin/internal/erc20bytes-processor.ts +80 -46
  283. package/src/eth/builtin/internal/erc721-processor.ts +109 -65
  284. package/src/eth/builtin/internal/weth9-processor.ts +95 -56
  285. package/src/eth/codegen/file.ts +2 -1
  286. package/src/eth/codegen/function-calls.ts +1 -1
  287. package/src/eth/context.ts +29 -13
  288. package/src/eth/eth-plugin.ts +135 -118
  289. package/src/eth/eth.ts +46 -32
  290. package/src/eth/index.ts +1 -1
  291. package/src/fuel/asset-processor.ts +16 -8
  292. package/src/fuel/context.ts +4 -3
  293. package/src/fuel/fuel-plugin.ts +71 -73
  294. package/src/fuel/fuel-processor-template.ts +7 -6
  295. package/src/fuel/fuel-processor.ts +35 -23
  296. package/src/fuel/global-processor.ts +3 -3
  297. package/src/fuel/types.ts +10 -4
  298. package/src/iota/context.ts +8 -7
  299. package/src/iota/iota-object-processor-template.ts +25 -15
  300. package/src/iota/iota-object-processor.ts +33 -22
  301. package/src/iota/iota-plugin-part.ts +41 -34
  302. package/src/iota/iota-processor.ts +25 -17
  303. package/src/iota/network.ts +2 -2
  304. package/src/move/filter.ts +1 -1
  305. package/src/move/index.ts +1 -1
  306. package/src/solana/solana-context.ts +4 -3
  307. package/src/solana/solana-plugin.ts +27 -24
  308. package/src/solana/solana-processor.ts +14 -6
  309. package/src/store/cache.ts +22 -18
  310. package/src/store/convert.ts +68 -104
  311. package/src/store/decorators.ts +3 -2
  312. package/src/store/store.ts +30 -22
  313. package/src/store/types.ts +24 -33
  314. package/src/store/util.ts +13 -18
  315. package/src/sui/context.ts +8 -7
  316. package/src/sui/sui-object-processor-template.ts +25 -15
  317. package/src/sui/sui-object-processor.ts +33 -22
  318. package/src/sui/sui-plugin-part.ts +41 -34
  319. package/src/sui/sui-plugin.ts +49 -47
  320. package/src/sui/sui-processor.ts +25 -17
  321. package/src/testing/aptos-facet.ts +18 -11
  322. package/src/testing/cosmos-facet.ts +10 -6
  323. package/src/testing/eth-facet.ts +40 -18
  324. package/src/testing/fuel-facet.ts +28 -18
  325. package/src/testing/iota-facet.ts +32 -20
  326. package/src/testing/memory-database.ts +126 -88
  327. package/src/testing/metric-utils.ts +15 -14
  328. package/src/testing/solana-facet.ts +11 -6
  329. package/src/testing/sui-facet.ts +30 -20
  330. package/src/testing/test-processor-server.ts +169 -79
  331. package/src/utils/price.ts +20 -13
@@ -1,4 +1,5 @@
1
- import { RichValue, RichValue_NullValue } from '@sentio/protos'
1
+ import { type RichValue, RichValueSchema, RichValue_NullValue, timestampDate, timestampFromDate } from '@sentio/protos'
2
+ import { create } from '@bufbuild/protobuf'
2
3
  import type { String, Int, Float, ID, Bytes, Timestamp, Boolean } from './types.js'
3
4
  import { BigDecimal } from '@sentio/bigdecimal'
4
5
  import { toBigInteger, toBigDecimal } from '../core/numberish.js'
@@ -14,6 +15,10 @@ export interface ValueConverter<T> {
14
15
 
15
16
  export const ValueRequiredError = new Error('Value is required but received null or undefined')
16
17
 
18
+ function nullRichValue(): RichValue {
19
+ return create(RichValueSchema, { value: { case: 'nullValue', value: RichValue_NullValue.NULL_VALUE } })
20
+ }
21
+
17
22
  export function required_<T>(converter: ValueConverter<T | undefined>): ValueConverter<T> {
18
23
  const { from, to, ...rest } = converter
19
24
  return {
@@ -24,7 +29,7 @@ export function required_<T>(converter: ValueConverter<T | undefined>): ValueCon
24
29
  return from(value)
25
30
  },
26
31
  to: (value: RichValue) => {
27
- if (value == null || value.nullValue) {
32
+ if (value == null || value.value.case === 'nullValue') {
28
33
  throw ValueRequiredError
29
34
  }
30
35
  return to(value)!
@@ -37,14 +42,17 @@ export function required_<T>(converter: ValueConverter<T | undefined>): ValueCon
37
42
  export function array_<T>(converter: ValueConverter<T>): ValueConverter<T[]> {
38
43
  return {
39
44
  from: (value: T[]) => {
40
- return {
41
- listValue: {
42
- values: value.map(converter.from)
45
+ return create(RichValueSchema, {
46
+ value: {
47
+ case: 'listValue',
48
+ value: {
49
+ values: value.map(converter.from)
50
+ }
43
51
  }
44
- }
52
+ })
45
53
  },
46
54
  to: (value: RichValue) => {
47
- return value.listValue?.values.map(converter.to) || []
55
+ return value.value.case === 'listValue' ? value.value.value.values.map(converter.to) : []
48
56
  },
49
57
  isArray: true,
50
58
  isRelation: converter.isRelation,
@@ -56,16 +64,14 @@ export function enumerate_<T extends string | number>(values: Record<T, string>)
56
64
  return {
57
65
  from: (value?: T) => {
58
66
  if (value == null) {
59
- return {
60
- nullValue: RichValue_NullValue.NULL_VALUE
61
- }
62
- }
63
- return {
64
- stringValue: values[value]
67
+ return nullRichValue()
65
68
  }
69
+ return create(RichValueSchema, {
70
+ value: { case: 'stringValue', value: values[value] }
71
+ })
66
72
  },
67
73
  to(v: RichValue): T {
68
- return v.stringValue as T
74
+ return (v.value.case === 'stringValue' ? v.value.value : undefined) as T
69
75
  }
70
76
  }
71
77
  }
@@ -74,28 +80,24 @@ export function objectId_<T>(entityName: string): ValueConverter<T | ID> {
74
80
  return {
75
81
  from: (value: T | ID) => {
76
82
  if (typeof value == 'string') {
77
- return {
78
- stringValue: value
79
- }
83
+ return create(RichValueSchema, { value: { case: 'stringValue', value } })
80
84
  }
81
85
  if (value instanceof Uint8Array) {
82
- return {
83
- stringValue: `0x${Buffer.from(value).toString('hex')}`
84
- }
86
+ return create(RichValueSchema, {
87
+ value: { case: 'stringValue', value: `0x${Buffer.from(value).toString('hex')}` }
88
+ })
85
89
  }
86
90
 
87
91
  if (typeof value == 'object') {
88
92
  const entity = value as any
89
- return {
90
- stringValue: entity.id.toString()
91
- }
92
- }
93
- return {
94
- nullValue: RichValue_NullValue.NULL_VALUE
93
+ return create(RichValueSchema, {
94
+ value: { case: 'stringValue', value: entity.id.toString() }
95
+ })
95
96
  }
97
+ return nullRichValue()
96
98
  },
97
99
  to(v) {
98
- return v.stringValue as T | ID
100
+ return (v.value.case === 'stringValue' ? v.value.value : undefined) as T | ID
99
101
  },
100
102
  isRelation: true,
101
103
  relationName: entityName
@@ -105,137 +107,105 @@ export function objectId_<T>(entityName: string): ValueConverter<T | ID> {
105
107
  export const StringConverter: ValueConverter<String | undefined> = {
106
108
  from: (value?: String) => {
107
109
  if (value == null) {
108
- return {
109
- nullValue: RichValue_NullValue.NULL_VALUE
110
- }
111
- }
112
- return {
113
- stringValue: value
110
+ return nullRichValue()
114
111
  }
112
+ return create(RichValueSchema, { value: { case: 'stringValue', value } })
115
113
  },
116
114
  to(v) {
117
- return v.stringValue
115
+ return v.value.case === 'stringValue' ? v.value.value : undefined
118
116
  }
119
117
  }
120
118
 
121
119
  export const IntConverter: ValueConverter<Int | undefined> = {
122
120
  from: (value?: Int) => {
123
121
  if (value == null) {
124
- return {
125
- nullValue: RichValue_NullValue.NULL_VALUE
126
- }
127
- }
128
- return {
129
- intValue: Math.floor(value)
122
+ return nullRichValue()
130
123
  }
124
+ return create(RichValueSchema, { value: { case: 'intValue', value: Math.floor(value) } })
131
125
  },
132
126
  to(v) {
133
- return v.intValue as Int
127
+ return (v.value.case === 'intValue' ? v.value.value : undefined) as Int
134
128
  }
135
129
  }
136
130
 
137
131
  export const Int8Converter: ValueConverter<bigint | undefined> = {
138
132
  from: (value?: bigint) => {
139
133
  if (value == null) {
140
- return {
141
- nullValue: RichValue_NullValue.NULL_VALUE
142
- }
143
- }
144
- return {
145
- int64Value: BigInt(value)
134
+ return nullRichValue()
146
135
  }
136
+ return create(RichValueSchema, { value: { case: 'int64Value', value: BigInt(value) } })
147
137
  },
148
138
  to(v) {
149
- return v.int64Value
139
+ return v.value.case === 'int64Value' ? v.value.value : undefined
150
140
  }
151
141
  }
152
142
 
153
143
  export const FloatConverter: ValueConverter<Float | undefined> = {
154
144
  from: (value?: Float) => {
155
145
  if (value == null) {
156
- return {
157
- nullValue: RichValue_NullValue.NULL_VALUE
158
- }
159
- }
160
- return {
161
- floatValue: value
146
+ return nullRichValue()
162
147
  }
148
+ return create(RichValueSchema, { value: { case: 'floatValue', value } })
163
149
  },
164
150
  to(v) {
165
- return v.floatValue
151
+ return v.value.case === 'floatValue' ? v.value.value : undefined
166
152
  }
167
153
  }
168
154
 
169
155
  export const BooleanConverter: ValueConverter<Boolean | undefined> = {
170
156
  from: (value?: Boolean) => {
171
157
  if (value == null) {
172
- return {
173
- nullValue: RichValue_NullValue.NULL_VALUE
174
- }
175
- }
176
- return {
177
- boolValue: value
158
+ return nullRichValue()
178
159
  }
160
+ return create(RichValueSchema, { value: { case: 'boolValue', value } })
179
161
  },
180
162
  to(v) {
181
- return v.boolValue
163
+ return v.value.case === 'boolValue' ? v.value.value : undefined
182
164
  }
183
165
  }
184
166
 
185
167
  export const TimestampConverter: ValueConverter<Timestamp | undefined> = {
186
168
  from: (value: Timestamp | undefined) => {
187
169
  if (value == null) {
188
- return {
189
- nullValue: RichValue_NullValue.NULL_VALUE
190
- }
191
- }
192
- return {
193
- timestampValue: value
170
+ return nullRichValue()
194
171
  }
172
+ return create(RichValueSchema, { value: { case: 'timestampValue', value: timestampFromDate(value) } })
195
173
  },
196
174
  to(v) {
197
- return v.timestampValue
175
+ return v.value.case === 'timestampValue' ? timestampDate(v.value.value) : undefined
198
176
  }
199
177
  }
200
178
 
201
179
  export const BytesConverter: ValueConverter<Bytes | undefined> = {
202
180
  from: (value?: Bytes) => {
203
181
  if (value == null) {
204
- return {
205
- nullValue: RichValue_NullValue.NULL_VALUE
206
- }
207
- }
208
- return {
209
- bytesValue: value
182
+ return nullRichValue()
210
183
  }
184
+ return create(RichValueSchema, { value: { case: 'bytesValue', value } })
211
185
  },
212
186
  to(v) {
213
- return v.bytesValue
187
+ return v.value.case === 'bytesValue' ? v.value.value : undefined
214
188
  }
215
189
  }
216
190
 
217
191
  export const IDConverter: ValueConverter<ID | undefined> = {
218
192
  from(value: ID | undefined): RichValue {
219
193
  if (typeof value == 'string') {
220
- return {
221
- stringValue: value
222
- }
194
+ return create(RichValueSchema, { value: { case: 'stringValue', value } })
223
195
  }
224
196
  if (value instanceof Uint8Array) {
225
- return {
226
- stringValue: `0x${Buffer.from(value).toString('hex')}`
227
- }
228
- }
229
- return {
230
- nullValue: RichValue_NullValue.NULL_VALUE
197
+ return create(RichValueSchema, {
198
+ value: { case: 'stringValue', value: `0x${Buffer.from(value).toString('hex')}` }
199
+ })
231
200
  }
201
+ return nullRichValue()
232
202
  },
233
203
  to(value: RichValue): ID | undefined {
234
- if (value.stringValue) {
235
- return value.stringValue as ID
204
+ if (value.value.case === 'stringValue' && value.value.value) {
205
+ return value.value.value as ID
236
206
  }
237
- if (value.bytesValue) {
238
- const v = `0x${Buffer.from(value.bytesValue).toString('hex')}`
207
+ if (value.value.case === 'bytesValue' && value.value.value) {
208
+ const v = `0x${Buffer.from(value.value.value).toString('hex')}`
239
209
  return v as ID
240
210
  }
241
211
  return undefined
@@ -245,15 +215,13 @@ export const IDConverter: ValueConverter<ID | undefined> = {
245
215
  export const BigDecimalConverter: ValueConverter<BigDecimal | undefined> = {
246
216
  from: (value?: BigDecimal): RichValue => {
247
217
  if (value == null) {
248
- return {
249
- nullValue: RichValue_NullValue.NULL_VALUE
250
- }
218
+ return nullRichValue()
251
219
  }
252
- return { bigdecimalValue: toBigDecimal(value) }
220
+ return create(RichValueSchema, { value: { case: 'bigdecimalValue', value: toBigDecimal(value) } })
253
221
  },
254
222
  to(v) {
255
- const d = v.bigdecimalValue
256
- if (d) {
223
+ if (v.value.case === 'bigdecimalValue') {
224
+ const d = v.value.value
257
225
  const i = bytesToBigInt(d.value!.data)
258
226
  let ret = new BigDecimal(i.toString())
259
227
  if (d.exp < 0) {
@@ -270,18 +238,14 @@ export const BigDecimalConverter: ValueConverter<BigDecimal | undefined> = {
270
238
  export const BigIntConverter: ValueConverter<bigint | undefined> = {
271
239
  from: (value?: bigint) => {
272
240
  if (value == null) {
273
- return {
274
- nullValue: RichValue_NullValue.NULL_VALUE
275
- }
276
- }
277
- return {
278
- bigintValue: toBigInteger(value)
241
+ return nullRichValue()
279
242
  }
243
+ return create(RichValueSchema, { value: { case: 'bigintValue', value: toBigInteger(value) } })
280
244
  },
281
245
  to(v) {
282
- if (v.bigintValue) {
283
- let res = bytesToBigInt(v.bigintValue?.data)
284
- if (v.bigintValue.negative) {
246
+ if (v.value.case === 'bigintValue') {
247
+ let res = bytesToBigInt(v.value.value.data)
248
+ if (v.value.value.negative) {
285
249
  res = -res
286
250
  }
287
251
  return res
@@ -16,7 +16,8 @@ import {
16
16
  TypeConverters,
17
17
  ValueConverter
18
18
  } from './convert.js'
19
- import { RichStruct } from '@sentio/protos'
19
+ import { type RichStruct, RichStructSchema } from '@sentio/protos'
20
+ import { create } from '@bufbuild/protobuf'
20
21
  import { getStore } from './store.js'
21
22
 
22
23
  type Constructor = { new (...args: any[]): any }
@@ -90,7 +91,7 @@ export function Entity(entityName: string) {
90
91
  }
91
92
 
92
93
  return class extends BaseClass {
93
- readonly _data: RichStruct = { fields: {} }
94
+ readonly _data: RichStruct = create(RichStructSchema, { fields: {} })
94
95
  static entityName = entityName
95
96
 
96
97
  constructor(...args: any[]) {
@@ -13,14 +13,14 @@ import {
13
13
  UpdateValues
14
14
  } from './types.js'
15
15
  import {
16
- DBRequest,
17
- DBRequest_DBUpdate,
18
- Entity as EntityStruct,
16
+ DBRequest_DBUpdateSchema,
17
+ type Entity as EntityStruct,
19
18
  EntityUpdateData_Operator,
20
- RichValue,
19
+ type RichValue,
21
20
  DBRequest_DBOperator,
22
- DBResponse
21
+ type DBResponse
23
22
  } from '@sentio/protos'
23
+ import { type MessageInitShape } from '@bufbuild/protobuf'
24
24
  import { IStoreContext, PluginManager } from '@sentio/runtime'
25
25
  import { Cursor } from './cursor.js'
26
26
  import { serializeRichValue } from './util.js'
@@ -76,15 +76,16 @@ export class Store {
76
76
  const entityName = getEntityName(entity)
77
77
 
78
78
  const promise = this.context.sendRequest({
79
- get: {
79
+ case: 'get',
80
+ value: {
80
81
  entity: entityName,
81
82
  id: id.toString()
82
83
  }
83
84
  })
84
85
 
85
86
  const data = (await promise) as DBResponse
86
- if (data.entityList?.entities[0]) {
87
- const entityData = data.entityList?.entities[0]
87
+ if (data.value.case === 'entityList' && data.value.value.entities[0]) {
88
+ const entityData = data.value.value.entities[0]
88
89
  return this.newEntity(entity, entityData)
89
90
  }
90
91
 
@@ -116,32 +117,34 @@ export class Store {
116
117
  }
117
118
 
118
119
  await this.context.sendRequest({
119
- delete: request
120
+ case: 'delete',
121
+ value: request
120
122
  })
121
123
  }
122
124
 
123
125
  async update<T extends Entity>(entity: EntityClass<T>, values: UpdateValues<any>): Promise<void> {
124
126
  if (values.id) {
125
- const update: DBRequest_DBUpdate = {
127
+ const update: MessageInitShape<typeof DBRequest_DBUpdateSchema> = {
126
128
  entity: [getEntityName(entity)],
127
129
  id: [values.id.toString()],
128
130
  entityData: [{ fields: {} }]
129
131
  }
132
+ const fields = update.entityData![0].fields!
130
133
  for (const [key, value] of Object.entries(values)) {
131
134
  if (key !== 'id') {
132
135
  const field = getEntityField(entity, key)
133
136
  if (value instanceof AddOp) {
134
- update.entityData[0].fields[field] = {
137
+ fields[field] = {
135
138
  op: EntityUpdateData_Operator.ADD,
136
139
  value: serializeRichValue(value.value)
137
140
  }
138
141
  } else if (value instanceof MultiplyOp) {
139
- update.entityData[0].fields[field] = {
142
+ fields[field] = {
140
143
  op: EntityUpdateData_Operator.MULTIPLY,
141
144
  value: serializeRichValue(value.value)
142
145
  }
143
146
  } else if (value !== undefined) {
144
- update.entityData[0].fields[field] = {
147
+ fields[field] = {
145
148
  op: EntityUpdateData_Operator.SET,
146
149
  value: serializeRichValue(value)
147
150
  }
@@ -149,7 +152,8 @@ export class Store {
149
152
  }
150
153
  }
151
154
  await this.context.sendRequest({
152
- update
155
+ case: 'update',
156
+ value: update
153
157
  })
154
158
  } else {
155
159
  throw new Error('Update must have id field')
@@ -158,15 +162,15 @@ export class Store {
158
162
 
159
163
  async upsert<T extends Entity>(entity: T | T[]): Promise<void> {
160
164
  const entities = Array.isArray(entity) ? entity : [entity]
161
- const request = {
162
- upsert: {
165
+ await this.context.sendRequest({
166
+ case: 'upsert',
167
+ value: {
163
168
  entity: entities.map((e) => getEntityName(e)),
164
169
  // data: entities.map((e) => serialize(e.data)),
165
170
  id: entities.map((e) => e.id.toString()),
166
171
  entityData: entities.map((e: any) => e._data)
167
172
  }
168
- } as DBRequest
169
- await this.context.sendRequest(request)
173
+ })
170
174
  }
171
175
 
172
176
  async *listIterator<T extends Entity, P extends keyof T, O extends Operators<T[P]>>(
@@ -177,7 +181,8 @@ export class Store {
177
181
 
178
182
  while (true) {
179
183
  const response: DBResponse = await this.listRequest(entity, filters || [], cursor)
180
- for (const data of response.entityList?.entities || []) {
184
+ const entities = response.value.case === 'entityList' ? response.value.value.entities : []
185
+ for (const data of entities) {
181
186
  yield this.newEntity(entity, data)
182
187
  }
183
188
  if (!response.nextCursor) {
@@ -196,7 +201,8 @@ export class Store {
196
201
 
197
202
  while (true) {
198
203
  const response: DBResponse = await this.listRequest(entity, filters || [], cursor, batchSize)
199
- const entities = (response.entityList?.entities || []).map((data) => this.newEntity(entity, data))
204
+ const list = response.value.case === 'entityList' ? response.value.value.entities : []
205
+ const entities = list.map((data) => this.newEntity(entity, data))
200
206
  yield entities
201
207
  if (!response.nextCursor) {
202
208
  break
@@ -213,7 +219,8 @@ export class Store {
213
219
  ): Promise<DBResponse> {
214
220
  const response = (await this.context.sendRequest(
215
221
  {
216
- list: {
222
+ case: 'list',
223
+ value: {
217
224
  entity: getEntityName(entity),
218
225
  cursor,
219
226
  pageSize,
@@ -259,7 +266,8 @@ export class Store {
259
266
  if (cursor) {
260
267
  const response = await this.listRequest(entity, filters || [], cursor.cursor, cursor.pageSize)
261
268
  cursor.cursor = response.nextCursor
262
- return response.entityList?.entities.map((data) => this.newEntity(entity, data)) || []
269
+ const list = response.value.case === 'entityList' ? response.value.value.entities : []
270
+ return list.map((data) => this.newEntity(entity, data))
263
271
  }
264
272
  // TODO Array.fromAsync when upgrade to node 22
265
273
  return this.fromAsync(this.listIterator(entity, filters ?? []))
@@ -1,4 +1,4 @@
1
- import { RichStruct, RichValue } from '@sentio/protos'
1
+ import { type RichStruct, type RichValue, timestampDate } from '@sentio/protos'
2
2
  import { BigDecimalConverter, BigIntConverter } from './convert.js'
3
3
  import { getEntityName, Store } from './store.js'
4
4
  import { PluginManager } from '@sentio/runtime'
@@ -70,38 +70,29 @@ export abstract class AbstractEntity {
70
70
  }
71
71
 
72
72
  function toJSValue(value: RichValue): any {
73
- if (value.nullValue != null) {
74
- return null
75
- }
76
- if (value.bytesValue != null) {
77
- return value.bytesValue
78
- }
79
- if (value.stringValue != null) {
80
- return value.stringValue
81
- }
82
- if (value.bigdecimalValue != null) {
83
- return BigDecimalConverter.to(value)
84
- }
85
- if (value.bigintValue != null) {
86
- return BigIntConverter.to(value)
87
- }
88
- if (value.boolValue != null) {
89
- return value.boolValue
90
- }
91
- if (value.timestampValue != null) {
92
- return value.timestampValue
93
- }
94
- if (value.floatValue != null) {
95
- return value.floatValue
96
- }
97
- if (value.intValue != null) {
98
- return value.intValue
99
- }
100
- if (value.listValue != null) {
101
- return value.listValue.values.map(toJSValue)
102
- }
103
- if (value.int64Value) {
104
- return value.int64Value
73
+ switch (value.value.case) {
74
+ case 'nullValue':
75
+ return null
76
+ case 'bytesValue':
77
+ return value.value.value
78
+ case 'stringValue':
79
+ return value.value.value
80
+ case 'bigdecimalValue':
81
+ return BigDecimalConverter.to(value)
82
+ case 'bigintValue':
83
+ return BigIntConverter.to(value)
84
+ case 'boolValue':
85
+ return value.value.value
86
+ case 'timestampValue':
87
+ return timestampDate(value.value.value)
88
+ case 'floatValue':
89
+ return value.value.value
90
+ case 'intValue':
91
+ return value.value.value
92
+ case 'listValue':
93
+ return value.value.value.values.map(toJSValue)
94
+ case 'int64Value':
95
+ return value.value.value
105
96
  }
106
97
  throw new Error('Unknown value type:' + JSON.stringify(value))
107
98
  }
package/src/store/util.ts CHANGED
@@ -1,25 +1,24 @@
1
- import type { RichValue } from '@sentio/protos'
1
+ import { type RichValue, RichValueSchema, RichValue_NullValue, timestampFromDate } from '@sentio/protos'
2
+ import { create } from '@bufbuild/protobuf'
2
3
  import { toBigInteger, toBigDecimal } from '../core/numberish.js'
3
4
  import { BigDecimal } from '@sentio/bigdecimal'
4
5
 
5
6
  export function serializeRichValue(v: any): RichValue {
6
7
  if (v == null) {
7
- return { nullValue: 0 }
8
+ return create(RichValueSchema, { value: { case: 'nullValue', value: RichValue_NullValue.NULL_VALUE } })
8
9
  }
9
10
  if (typeof v == 'boolean') {
10
- return { boolValue: v }
11
+ return create(RichValueSchema, { value: { case: 'boolValue', value: v } })
11
12
  }
12
13
  if (typeof v == 'string') {
13
- return { stringValue: v }
14
+ return create(RichValueSchema, { value: { case: 'stringValue', value: v } })
14
15
  }
15
16
 
16
17
  if (typeof v == 'number') {
17
- return { floatValue: v }
18
+ return create(RichValueSchema, { value: { case: 'floatValue', value: v } })
18
19
  }
19
20
  if (typeof v == 'bigint') {
20
- return {
21
- bigintValue: toBigInteger(v)
22
- }
21
+ return create(RichValueSchema, { value: { case: 'bigintValue', value: toBigInteger(v) } })
23
22
  }
24
23
 
25
24
  if (BigDecimal.isBigNumber(v)) {
@@ -27,25 +26,21 @@ export function serializeRichValue(v: any): RichValue {
27
26
  }
28
27
 
29
28
  if (v instanceof Date) {
30
- return {
31
- timestampValue: v
32
- }
29
+ return create(RichValueSchema, { value: { case: 'timestampValue', value: timestampFromDate(v) } })
33
30
  }
34
31
 
35
32
  if (v instanceof Uint8Array) {
36
- return { bytesValue: v }
33
+ return create(RichValueSchema, { value: { case: 'bytesValue', value: v } })
37
34
  }
38
35
 
39
36
  if (Array.isArray(v)) {
40
- return {
41
- listValue: { values: v.map((v) => serializeRichValue(v)) }
42
- }
37
+ return create(RichValueSchema, {
38
+ value: { case: 'listValue', value: { values: v.map((v) => serializeRichValue(v)) } }
39
+ })
43
40
  }
44
41
  throw new Error('Unsupported type for serialization: ' + typeof v)
45
42
  }
46
43
 
47
44
  function serializeBigDecimal(v: BigDecimal): RichValue {
48
- return {
49
- bigdecimalValue: toBigDecimal(v)
50
- }
45
+ return create(RichValueSchema, { value: { case: 'bigdecimalValue', value: toBigDecimal(v) } })
51
46
  }
@@ -1,4 +1,5 @@
1
- import { RecordMetaData } from '@sentio/protos'
1
+ import { type RecordMetaData, RecordMetaDataSchema } from '@sentio/protos'
2
+ import { create } from '@bufbuild/protobuf'
2
3
  import { type Labels, normalizeLabels } from '../index.js'
3
4
  import { getClient, SuiNetwork } from './network.js'
4
5
  import type { GrpcTypes, SuiGrpcClient } from '@mysten/sui/grpc'
@@ -47,7 +48,7 @@ export class SuiContext extends MoveContext<SuiNetwork, ModuleWithAddress, SuiEv
47
48
  }
48
49
 
49
50
  getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
50
- return {
51
+ return create(RecordMetaDataSchema, {
51
52
  address: this.address,
52
53
  contractName: this.moduleName,
53
54
  blockNumber: this.checkpoint,
@@ -57,7 +58,7 @@ export class SuiContext extends MoveContext<SuiNetwork, ModuleWithAddress, SuiEv
57
58
  chainId: this.getChainId(),
58
59
  name: name,
59
60
  labels: normalizeLabels(labels)
60
- }
61
+ })
61
62
  }
62
63
 
63
64
  get client(): SuiGrpcClient {
@@ -101,7 +102,7 @@ export class SuiObjectChangeContext extends MoveContext<
101
102
  }
102
103
 
103
104
  getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
104
- return {
105
+ return create(RecordMetaDataSchema, {
105
106
  address: this.address,
106
107
  contractName: '*',
107
108
  blockNumber: this.checkpoint,
@@ -111,7 +112,7 @@ export class SuiObjectChangeContext extends MoveContext<
111
112
  chainId: this.getChainId(),
112
113
  name: name,
113
114
  labels: normalizeLabels(labels)
114
- }
115
+ })
115
116
  }
116
117
 
117
118
  get client(): SuiGrpcClient {
@@ -153,7 +154,7 @@ export class SuiAddressContext extends MoveAccountContext<
153
154
  }
154
155
 
155
156
  getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
156
- return {
157
+ return create(RecordMetaDataSchema, {
157
158
  address: this.address,
158
159
  contractName: this.contractName,
159
160
  blockNumber: this.checkpoint,
@@ -163,7 +164,7 @@ export class SuiAddressContext extends MoveAccountContext<
163
164
  chainId: this.getChainId(),
164
165
  name: name,
165
166
  labels: normalizeLabels(labels)
166
- }
167
+ })
167
168
  }
168
169
 
169
170
  get client(): SuiGrpcClient {