@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
package/src/aptos/data.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Data_AptEvent, Data_AptCall, Data_AptResource } from '@sentio/protos'
1
+ import { type Data_AptEvent, type Data_AptCall, type Data_AptResource } from '@sentio/protos'
2
2
  import { UserTransactionResponse, MoveResource } from '@aptos-labs/ts-sdk'
3
3
  import { MoveCoder, decodeResourceChange, ResourceChange } from '@typemove/aptos'
4
4
 
@@ -18,7 +18,7 @@ type Data_AptResource_Ext = Data_AptResource & {
18
18
  _decodedResources?: ResourceChange<any>[]
19
19
  }
20
20
 
21
- export class AptEvent implements Data_AptEvent {
21
+ export class AptEvent {
22
22
  constructor(readonly data: Data_AptEvent_Ext) {}
23
23
 
24
24
  get rawEvent(): string {
@@ -57,7 +57,7 @@ export class AptEvent implements Data_AptEvent {
57
57
  }
58
58
  }
59
59
 
60
- export class AptCall implements Data_AptCall {
60
+ export class AptCall {
61
61
  constructor(readonly data: Data_AptCall_Ext) {}
62
62
 
63
63
  get rawTransaction(): string {
@@ -88,7 +88,7 @@ export class AptCall implements Data_AptCall {
88
88
  }
89
89
  }
90
90
 
91
- export class AptResource implements Data_AptResource {
91
+ export class AptResource {
92
92
  constructor(readonly data: Data_AptResource_Ext) {}
93
93
 
94
94
  get version(): bigint {
@@ -1,10 +1,17 @@
1
- import { ProcessResult, RecordMetaData, TemplateInstance } from '@sentio/protos'
1
+ import {
2
+ type ProcessResult,
3
+ ProcessResultSchema,
4
+ type RecordMetaData,
5
+ RecordMetaDataSchema,
6
+ type TemplateInstance
7
+ } from '@sentio/protos'
8
+ import { create, type MessageInitShape } from '@bufbuild/protobuf'
2
9
  import { EventLoggerBinding } from './event-logger.js'
3
10
  import { Meter, Labels } from './meter.js'
4
11
  import { ChainId } from '@sentio/chain'
5
12
  import { mergeProcessResultsInPlace, PluginManager } from '@sentio/runtime'
6
13
  import { Required } from 'utility-types'
7
- import { ServerError, Status } from 'nice-grpc'
14
+ import { ConnectError, Code } from '@connectrpc/connect'
8
15
  import { Store } from '../store/store.js'
9
16
  import { MemoryCache } from '../store/cache.js'
10
17
 
@@ -16,7 +23,7 @@ export abstract class BaseContext {
16
23
  baseLabels: Labels
17
24
  private active: boolean
18
25
 
19
- private _res: Required<ProcessResult, 'states'> = {
26
+ private _res: Required<ProcessResult, 'states'> = create(ProcessResultSchema, {
20
27
  counters: [],
21
28
  events: [],
22
29
  exports: [],
@@ -25,13 +32,13 @@ export abstract class BaseContext {
25
32
  configUpdated: false
26
33
  },
27
34
  timeseriesResult: []
28
- }
35
+ }) as Required<ProcessResult, 'states'>
29
36
 
30
- public update(res: Partial<ProcessResult>) {
37
+ public update(res: MessageInitShape<typeof ProcessResultSchema>) {
31
38
  if (this.active) {
32
- mergeProcessResultsInPlace(this._res, [ProcessResult.fromPartial(res)])
39
+ mergeProcessResultsInPlace(this._res, [create(ProcessResultSchema, res)])
33
40
  } else {
34
- throw new ServerError(Status.INTERNAL, 'context not active, possible async function invoke without await')
41
+ throw new ConnectError('context not active, possible async function invoke without await', Code.Internal)
35
42
  }
36
43
  }
37
44
 
@@ -48,7 +55,7 @@ export abstract class BaseContext {
48
55
  this.active = false
49
56
  return this._res
50
57
  } else {
51
- throw new ServerError(Status.INTERNAL, "Can't get result from same context twice")
58
+ throw new ConnectError("Can't get result from same context twice", Code.Internal)
52
59
  }
53
60
  }
54
61
 
@@ -58,19 +65,19 @@ export abstract class BaseContext {
58
65
  if (Object.keys(labels).length === 0) {
59
66
  let metadata = this.metadataCache.get(name)
60
67
  if (!metadata) {
61
- metadata = {
68
+ metadata = create(RecordMetaDataSchema, {
62
69
  ...this.baseLabels,
63
70
  ...this.getMetaDataInternal(name, labels)
64
- }
71
+ })
65
72
  this.metadataCache.set(name, metadata)
66
73
  }
67
74
  return metadata
68
75
  }
69
76
 
70
- return {
77
+ return create(RecordMetaDataSchema, {
71
78
  ...this.baseLabels,
72
79
  ...this.getMetaDataInternal(name, labels)
73
- }
80
+ })
74
81
  }
75
82
 
76
83
  protected abstract getMetaDataInternal(name: string, labels: Labels): RecordMetaData
@@ -1,5 +1,6 @@
1
1
  import { GLOBAL_CONFIG, Plugin, PluginManager } from '@sentio/runtime'
2
- import { InitResponse, ProcessConfigResponse } from '@sentio/protos'
2
+ import { DataBaseSchemaSchema, ExportConfigSchema, InitResponse, ProcessConfigResponse } from '@sentio/protos'
3
+ import { create } from '@bufbuild/protobuf'
3
4
 
4
5
  import { MetricState } from './meter.js'
5
6
  import { ExporterState } from './exporter.js'
@@ -30,10 +31,12 @@ export class CorePlugin extends Plugin {
30
31
  }
31
32
 
32
33
  for (const exporter of ExporterState.INSTANCE.getValues()) {
33
- config.exportConfigs.push({
34
- name: exporter.name,
35
- channel: exporter.channel
36
- })
34
+ config.exportConfigs.push(
35
+ create(ExportConfigSchema, {
36
+ name: exporter.name,
37
+ channel: exporter.channel
38
+ })
39
+ )
37
40
  }
38
41
 
39
42
  const schemas = DatabaseSchemaState.INSTANCE.getValues()
@@ -50,9 +53,9 @@ type MemoryCacheItem @cache(sizeMB: ${GLOBAL_CONFIG.cache.size || 100}) {
50
53
  }
51
54
 
52
55
  if (mergedSources.trim().length > 0) {
53
- config.dbSchema = {
56
+ config.dbSchema = create(DataBaseSchemaSchema, {
54
57
  gqlSchema: mergedSources
55
- }
58
+ })
56
59
  }
57
60
  }
58
61
  }
@@ -1,16 +1,24 @@
1
1
  import { BaseContext } from './base-context.js'
2
2
  import {
3
- CoinID,
4
- EventLogConfig,
3
+ type CoinID,
4
+ CoinIDSchema,
5
+ CoinID_AddressIdentifierSchema,
6
+ type EventLogConfig,
7
+ EventLogConfigSchema,
5
8
  EventLogConfig_BasicFieldType,
6
- EventLogConfig_Field,
7
- EventLogConfig_StructFieldType,
8
- EventTrackingResult,
9
+ type EventLogConfig_Field,
10
+ EventLogConfig_FieldSchema,
11
+ EventLogConfig_StructFieldTypeSchema,
12
+ type EventTrackingResult,
13
+ EventTrackingResultSchema,
9
14
  LogLevel,
10
- RichStruct,
11
- TimeseriesResult,
15
+ type RichStruct,
16
+ RichStructSchema,
17
+ type TimeseriesResult,
18
+ TimeseriesResultSchema,
12
19
  TimeseriesResult_TimeseriesType
13
20
  } from '@sentio/protos'
21
+ import { create } from '@bufbuild/protobuf'
14
22
  import { normalizeAttribute, normalizeLabels, normalizeToRichStruct } from './normalization.js'
15
23
  import { MapStateStorage, processMetrics } from '@sentio/runtime'
16
24
  import { BN } from 'fuels'
@@ -53,7 +61,10 @@ export class EventLoggerBinding {
53
61
  export type BasicFieldType = EventLogConfig_BasicFieldType
54
62
  export const BasicFieldType = EventLogConfig_BasicFieldType
55
63
 
56
- export type FieldType = CoinID | BasicFieldType | Fields
64
+ // User-facing coin descriptor (plain shape, matching the legacy CoinID surface).
65
+ export type CoinFieldType = { symbol: string } | { address: { address: string; chain: string } }
66
+
67
+ export type FieldType = CoinFieldType | BasicFieldType | Fields
57
68
 
58
69
  export type Fields = { [key: string]: FieldType }
59
70
 
@@ -61,30 +72,48 @@ export interface EventLogOptions {
61
72
  fields: Fields
62
73
  }
63
74
 
75
+ function toCoinIDField(value: CoinFieldType): CoinID {
76
+ if ('symbol' in value && value.symbol) {
77
+ return create(CoinIDSchema, { id: { case: 'symbol', value: value.symbol } })
78
+ }
79
+ const address = (value as { address: { address: string; chain: string } }).address
80
+ return create(CoinIDSchema, {
81
+ id: {
82
+ case: 'address',
83
+ value: create(CoinID_AddressIdentifierSchema, {
84
+ address: address.address,
85
+ chain: address.chain
86
+ })
87
+ }
88
+ })
89
+ }
90
+
64
91
  export function fieldsToProtos(fields: Fields): EventLogConfig_Field[] {
65
92
  const fieldsProto: EventLogConfig_Field[] = []
66
93
  for (const [key, value] of Object.entries(fields)) {
67
- let basicType: BasicFieldType | undefined
68
- let coinType: CoinID | undefined
69
- let structType: EventLogConfig_StructFieldType | undefined
94
+ let type: EventLogConfig_Field['type']
70
95
 
71
96
  if (typeof value === 'number') {
72
- basicType = value
97
+ type = { case: 'basicType', value }
73
98
  } else {
74
- if (value.address || value.symbol) {
75
- coinType = value
99
+ const coin = value as CoinFieldType
100
+ if (('address' in coin && coin.address) || ('symbol' in coin && coin.symbol)) {
101
+ type = { case: 'coinType', value: toCoinIDField(coin) }
76
102
  } else {
77
- structType = EventLogConfig_StructFieldType.create({
78
- fields: fieldsToProtos(value as Fields)
79
- })
103
+ type = {
104
+ case: 'structType',
105
+ value: create(EventLogConfig_StructFieldTypeSchema, {
106
+ fields: fieldsToProtos(value as Fields)
107
+ })
108
+ }
80
109
  }
81
110
  }
82
- fieldsProto.push({
83
- name: key,
84
- basicType,
85
- coinType,
86
- structType
87
- })
111
+ fieldsProto.push(
112
+ create(EventLogConfig_FieldSchema, {
113
+ name: key,
114
+ type
115
+ })
116
+ )
88
117
  }
89
118
  return fieldsProto
90
119
  }
@@ -100,10 +129,10 @@ export class EventLogger {
100
129
 
101
130
  static register(eventName: string, options?: EventLogOptions): EventLogger {
102
131
  checkEventName(eventName)
103
- let config = EventLogConfig.create()
132
+ let config = create(EventLogConfigSchema)
104
133
 
105
134
  if (options?.fields) {
106
- config = EventLogConfig.create({
135
+ config = create(EventLogConfigSchema, {
107
136
  name: eventName,
108
137
  fields: fieldsToProtos(options.fields)
109
138
  })
@@ -128,24 +157,24 @@ function checkEventName(eventName: string) {
128
157
  function emit<T>(ctx: BaseContext, eventName: string, event: Event<T>) {
129
158
  const { distinctId, severity, message, ...payload } = event
130
159
 
131
- const data: RichStruct = {
160
+ const data: RichStruct = create(RichStructSchema, {
132
161
  fields: {
133
162
  severity: {
134
- stringValue: (severity || LogLevel.INFO).toString()
163
+ value: { case: 'stringValue', value: (severity || LogLevel.INFO).toString() }
135
164
  },
136
165
  message: {
137
- stringValue: message || ''
166
+ value: { case: 'stringValue', value: message || '' }
138
167
  },
139
168
  // don't rename to distinctEntityId in new events.
140
169
  distinctId: {
141
- stringValue: distinctId || ''
170
+ value: { case: 'stringValue', value: distinctId || '' }
142
171
  },
143
172
  ...normalizeToRichStruct(ctx.baseLabels, payload).fields
144
173
  }
145
- }
174
+ })
146
175
 
147
176
  // legacy v2 events, deprecating
148
- const eventRes: EventTrackingResult = {
177
+ const eventRes: EventTrackingResult = create(EventTrackingResultSchema, {
149
178
  metadata: ctx.getMetaData(eventName, {}),
150
179
  severity: severity || LogLevel.INFO,
151
180
  message: message || '',
@@ -157,14 +186,14 @@ function emit<T>(ctx: BaseContext, eventName: string, event: Event<T>) {
157
186
  runtimeInfo: undefined,
158
187
  noMetric: true,
159
188
  attributes2: normalizeToRichStruct(ctx.baseLabels, payload)
160
- }
189
+ })
161
190
 
162
- const res: TimeseriesResult = {
191
+ const res: TimeseriesResult = create(TimeseriesResultSchema, {
163
192
  metadata: ctx.getMetaData(eventName, {}),
164
193
  type: TimeseriesResult_TimeseriesType.EVENT,
165
194
  data,
166
195
  runtimeInfo: undefined
167
- }
196
+ })
168
197
 
169
198
  processMetrics.process_eventemit_count.add(1)
170
199
  ctx.update({ timeseriesResult: [res], events: [eventRes] })
@@ -1,7 +1,8 @@
1
1
  import { BaseContext } from './base-context.js'
2
- import { ExportResult } from '@sentio/protos'
2
+ import { ExportResult, ExportResultSchema } from '@sentio/protos'
3
3
  import { NamedResultDescriptor } from './metadata.js'
4
4
  import { MapStateStorage } from '@sentio/runtime'
5
+ import { create } from '@bufbuild/protobuf'
5
6
 
6
7
  export type Export = Record<string, any>
7
8
 
@@ -22,11 +23,11 @@ export class Exporter extends NamedResultDescriptor {
22
23
  }
23
24
 
24
25
  emit(ctx: BaseContext, data: Export) {
25
- const res: ExportResult = {
26
+ const res: ExportResult = create(ExportResultSchema, {
26
27
  metadata: ctx.getMetaData(this.name, {}),
27
28
  payload: JSON.stringify(data),
28
- runtimeInfo: undefined,
29
- }
29
+ runtimeInfo: undefined
30
+ })
30
31
  ctx.update({ exports: [res] })
31
32
  }
32
33
  }
@@ -9,7 +9,7 @@ export type PartitionHandler<D> = (data: D) => string | Promise<string>
9
9
  * @template F The fetch configuration type (e.g., EthFetchConfig, MoveFetchConfig)
10
10
  * @template D The data type that will be processed (e.g., Event, Transaction, Block)
11
11
  */
12
- export type HandlerOptions<F, D> = Partial<F> & {
12
+ export type HandlerOptions<F, D> = Omit<Partial<F>, '$typeName' | '$unknown'> & {
13
13
  /**
14
14
  * Optional partition key for data partitioning.
15
15
  * Can be a static string or a function that computes the key from the data.
@@ -1,6 +1,6 @@
1
- import { ServerError, Status } from 'nice-grpc'
1
+ import { ConnectError, Code } from '@connectrpc/connect'
2
2
  import { ChainId } from '@sentio/chain'
3
- import { ProcessResult } from '@sentio/protos'
3
+ import { type ProcessResult } from '@sentio/protos'
4
4
 
5
5
  export type HandlerFunction = (...args: any[]) => Promise<ProcessResult>
6
6
 
@@ -37,7 +37,7 @@ export class HandlerRegister {
37
37
  getHandlerById(chainId: ChainId | string, id: number): HandlerFunction {
38
38
  const entries = this.handlerByChain.get(chainId)
39
39
  if (!entries || id < 0 || id >= entries.length) {
40
- throw new ServerError(Status.INTERNAL, `Handler with ID ${id} not found.`)
40
+ throw new ConnectError(`Handler with ID ${id} not found.`, Code.Internal)
41
41
  }
42
42
  return entries[id].handler
43
43
  }
package/src/core/meter.ts CHANGED
@@ -2,12 +2,14 @@ import { BaseContext } from './base-context.js'
2
2
  import { Numberish, toMetricValue, toTimeSeriesData } from './numberish.js'
3
3
  import { NamedResultDescriptor } from './metadata.js'
4
4
  import {
5
- AggregationConfig,
5
+ AggregationConfigSchema,
6
6
  AggregationType,
7
- MetricConfig,
7
+ type MetricConfig,
8
+ MetricConfigSchema,
8
9
  MetricType,
9
10
  TimeseriesResult_TimeseriesType
10
11
  } from '@sentio/protos'
12
+ import { create, type MessageInitShape } from '@bufbuild/protobuf'
11
13
  import { MapStateStorage, processMetrics } from '@sentio/runtime'
12
14
 
13
15
  export type Labels = { [key: string]: string }
@@ -17,7 +19,7 @@ export class MetricOptions {
17
19
  description?: string
18
20
  sparse?: boolean
19
21
  // persistentBetweenVersion?: boolean
20
- aggregationConfig?: Partial<AggregationConfig>
22
+ aggregationConfig?: MessageInitShape<typeof AggregationConfigSchema>
21
23
  }
22
24
 
23
25
  export class CounterOptions {
@@ -37,9 +39,9 @@ export class CounterOptions {
37
39
  export class Metric extends NamedResultDescriptor {
38
40
  config: MetricConfig
39
41
 
40
- constructor(type: MetricType, name: string, option?: MetricConfig) {
42
+ constructor(type: MetricType, name: string, option?: MessageInitShape<typeof MetricConfigSchema>) {
41
43
  super(name)
42
- this.config = MetricConfig.fromPartial({ ...option, name: this.name, type })
44
+ this.config = create(MetricConfigSchema, { ...option, name: this.name, type })
43
45
  const aggregationConfig = this.config.aggregationConfig
44
46
  if (aggregationConfig && aggregationConfig.intervalInMinutes.length) {
45
47
  if (aggregationConfig.intervalInMinutes.length > 1) {
@@ -90,7 +92,7 @@ export class Counter extends Metric {
90
92
  super(
91
93
  MetricType.COUNTER,
92
94
  name,
93
- MetricConfig.fromPartial({
95
+ create(MetricConfigSchema, {
94
96
  ...option,
95
97
  aggregationConfig: {
96
98
  intervalInMinutes: option?.resolutionConfig ? [option?.resolutionConfig?.intervalInMinutes] : []
@@ -162,7 +164,7 @@ export class Gauge extends Metric {
162
164
  }
163
165
 
164
166
  protected constructor(name: string, option?: MetricOptions) {
165
- super(MetricType.GAUGE, name, MetricConfig.fromPartial({ ...option }))
167
+ super(MetricType.GAUGE, name, create(MetricConfigSchema, { ...option }))
166
168
  }
167
169
 
168
170
  record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {
@@ -1,7 +1,20 @@
1
1
  import { Labels } from './meter.js'
2
2
  import { BigDecimal } from './big-decimal.js'
3
3
  import { BN } from 'fuels'
4
- import { CoinID, RichStruct, RichValue, RichValue_NullValue, TokenAmount } from '@sentio/protos'
4
+ import {
5
+ type CoinID,
6
+ CoinIDSchema,
7
+ CoinID_AddressIdentifierSchema,
8
+ type RichStruct,
9
+ RichStructSchema,
10
+ type RichValue,
11
+ RichValueSchema,
12
+ RichValue_NullValue,
13
+ type TokenAmount,
14
+ TokenAmountSchema,
15
+ timestampFromDate
16
+ } from '@sentio/protos'
17
+ import { create } from '@bufbuild/protobuf'
5
18
  import { toBigInteger, toBigDecimal } from './numberish.js'
6
19
 
7
20
  export const SENTIO_BIGINT_STRING_SUFFIX = ':sto_bi'
@@ -107,73 +120,78 @@ export function normalizeAttribute(record: Record<string, any>): any {
107
120
 
108
121
  function normalizeToRichValue(value: any): RichValue {
109
122
  if (value == null) {
110
- return { nullValue: RichValue_NullValue.NULL_VALUE }
123
+ return create(RichValueSchema, { value: { case: 'nullValue', value: RichValue_NullValue.NULL_VALUE } })
111
124
  }
112
125
  switch (typeof value) {
113
126
  case 'string':
114
- return { stringValue: value }
127
+ return create(RichValueSchema, { value: { case: 'stringValue', value } })
115
128
  case 'bigint':
116
129
  const v = BigInt(value)
117
- return { bigintValue: toBigInteger(v) }
130
+ return create(RichValueSchema, { value: { case: 'bigintValue', value: toBigInteger(v) } })
118
131
  case 'number':
119
132
  if (isNaN(value) || !isFinite(value)) {
120
133
  throw new Error("can't submit NaN or Infinity value")
121
134
  }
122
- return { bigdecimalValue: toBigDecimal(new BigDecimal(value)) }
135
+ return create(RichValueSchema, {
136
+ value: { case: 'bigdecimalValue', value: toBigDecimal(new BigDecimal(value)) }
137
+ })
123
138
  case 'function':
124
- return { nullValue: RichValue_NullValue.UNRECOGNIZED }
139
+ return create(RichValueSchema, { value: { case: 'nullValue', value: RichValue_NullValue.NULL_VALUE } })
125
140
  case 'symbol':
126
- return { stringValue: String(value) }
141
+ return create(RichValueSchema, { value: { case: 'stringValue', value: String(value) } })
127
142
  case 'boolean':
128
- return { boolValue: value }
143
+ return create(RichValueSchema, { value: { case: 'boolValue', value } })
129
144
  default:
130
145
  if (value instanceof Uint8Array) {
131
- return { bytesValue: value }
146
+ return create(RichValueSchema, { value: { case: 'bytesValue', value } })
132
147
  }
133
148
  if (value instanceof Date) {
134
- return { timestampValue: value }
149
+ return create(RichValueSchema, { value: { case: 'timestampValue', value: timestampFromDate(value) } })
135
150
  }
136
151
  if (value instanceof BigDecimal) {
137
- return { bigdecimalValue: toBigDecimal(value) }
152
+ return create(RichValueSchema, { value: { case: 'bigdecimalValue', value: toBigDecimal(value) } })
138
153
  }
139
154
  if (BN.isBN(value)) {
140
155
  const value1 = new BigDecimal(value.toString())
141
156
  if (value1.isNaN() || !value1.isFinite()) {
142
157
  throw new Error("can't submit NaN or Infinity value")
143
158
  }
144
- return { bigdecimalValue: toBigDecimal(value1) }
159
+ return create(RichValueSchema, { value: { case: 'bigdecimalValue', value: toBigDecimal(value1) } })
145
160
  }
146
161
  if (Array.isArray(value)) {
147
- return {
148
- listValue: {
149
- values: value.map((v) => normalizeToRichValue(v))
162
+ return create(RichValueSchema, {
163
+ value: {
164
+ case: 'listValue',
165
+ value: {
166
+ values: value.map((v) => normalizeToRichValue(v))
167
+ }
150
168
  }
151
- }
169
+ })
152
170
  }
153
171
  if (value instanceof Promise) {
154
172
  console.error('Cannot submit promise')
155
- return { nullValue: RichValue_NullValue.UNRECOGNIZED }
173
+ return create(RichValueSchema, { value: { case: 'nullValue', value: RichValue_NullValue.NULL_VALUE } })
156
174
  }
157
175
  if (typeof value === 'object') {
158
176
  const tokenAmount = toTokenAmount(value)
159
177
  if (tokenAmount) {
160
- return { tokenValue: tokenAmount }
178
+ return create(RichValueSchema, { value: { case: 'tokenValue', value: tokenAmount } })
161
179
  }
162
180
 
163
- return {
164
- structValue: normalizeToRichStruct(value)
165
- }
181
+ return create(RichValueSchema, {
182
+ value: { case: 'structValue', value: normalizeToRichStruct(value) }
183
+ })
166
184
  }
167
185
 
168
186
  console.warn('Cannot submit unsupported type ' + typeof value)
169
- return { nullValue: RichValue_NullValue.UNRECOGNIZED }
187
+ return create(RichValueSchema, { value: { case: 'nullValue', value: RichValue_NullValue.NULL_VALUE } })
170
188
  }
171
189
  }
172
190
 
173
191
  export function normalizeToRichStruct(...objs: any[]): RichStruct {
174
- const ret: RichStruct = {
192
+ const ret: RichStruct = create(RichStructSchema, {
175
193
  fields: {}
176
- }
194
+ })
177
195
  for (const obj of objs) {
178
196
  for (const [key, value] of Object.entries(obj)) {
179
197
  try {
@@ -189,7 +207,7 @@ export function normalizeToRichStruct(...objs: any[]): RichStruct {
189
207
  }
190
208
 
191
209
  function toTokenAmount(value: any): TokenAmount | undefined {
192
- const ret = TokenAmount.create()
210
+ const ret = create(TokenAmountSchema)
193
211
 
194
212
  for (const key of Object.getOwnPropertyNames(value)) {
195
213
  switch (key) {
@@ -211,7 +229,7 @@ function toTokenAmount(value: any): TokenAmount | undefined {
211
229
  break
212
230
  case 'specifiedAt':
213
231
  if (value.specifiedAt instanceof Date) {
214
- ret.specifiedAt = value.specifiedAt
232
+ ret.specifiedAt = timestampFromDate(value.specifiedAt)
215
233
  } else {
216
234
  return undefined
217
235
  }
@@ -225,13 +243,17 @@ function toTokenAmount(value: any): TokenAmount | undefined {
225
243
  }
226
244
 
227
245
  function toCoinID(coin: any): CoinID | undefined {
228
- const ret = CoinID.create()
246
+ const ret = create(CoinIDSchema)
229
247
  if (typeof coin.symbol === 'string') {
230
- return (ret.symbol = coin.symbol)
248
+ ret.id = { case: 'symbol', value: coin.symbol }
249
+ return ret
231
250
  } else if (coin.hasOwnProperty('address')) {
232
- ret.address = {
233
- address: coin.address.address,
234
- chain: coin.address.chain
251
+ ret.id = {
252
+ case: 'address',
253
+ value: create(CoinID_AddressIdentifierSchema, {
254
+ address: coin.address.address,
255
+ chain: coin.address.chain
256
+ })
235
257
  }
236
258
  } else {
237
259
  return undefined