@sentio/sdk 2.59.0-rc.3 → 2.59.0-rc.31

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 (286) hide show
  1. package/lib/aptos/api.d.ts +1 -0
  2. package/lib/aptos/api.d.ts.map +1 -1
  3. package/lib/aptos/api.js +13 -1
  4. package/lib/aptos/api.js.map +1 -1
  5. package/lib/aptos/aptos-plugin.d.ts +8 -4
  6. package/lib/aptos/aptos-plugin.d.ts.map +1 -1
  7. package/lib/aptos/aptos-plugin.js +51 -8
  8. package/lib/aptos/aptos-plugin.js.map +1 -1
  9. package/lib/aptos/aptos-processor.d.ts +21 -19
  10. package/lib/aptos/aptos-processor.d.ts.map +1 -1
  11. package/lib/aptos/aptos-processor.js +102 -50
  12. package/lib/aptos/aptos-processor.js.map +1 -1
  13. package/lib/aptos/aptos-resource-processor-template.d.ts +5 -4
  14. package/lib/aptos/aptos-resource-processor-template.d.ts.map +1 -1
  15. package/lib/aptos/aptos-resource-processor-template.js +8 -8
  16. package/lib/aptos/aptos-resource-processor-template.js.map +1 -1
  17. package/lib/aptos/builtin/0x1.d.ts +803 -317
  18. package/lib/aptos/builtin/0x1.d.ts.map +1 -1
  19. package/lib/aptos/builtin/0x1.js +1458 -635
  20. package/lib/aptos/builtin/0x1.js.map +1 -1
  21. package/lib/aptos/builtin/0x3.d.ts +66 -65
  22. package/lib/aptos/builtin/0x3.d.ts.map +1 -1
  23. package/lib/aptos/builtin/0x3.js +131 -131
  24. package/lib/aptos/builtin/0x3.js.map +1 -1
  25. package/lib/aptos/builtin/0x4.d.ts +29 -28
  26. package/lib/aptos/builtin/0x4.d.ts.map +1 -1
  27. package/lib/aptos/builtin/0x4.js +57 -57
  28. package/lib/aptos/builtin/0x4.js.map +1 -1
  29. package/lib/aptos/codegen/codegen.js +31 -4
  30. package/lib/aptos/codegen/codegen.js.map +1 -1
  31. package/lib/aptos/data.d.ts +45 -0
  32. package/lib/aptos/data.d.ts.map +1 -0
  33. package/lib/aptos/data.js +99 -0
  34. package/lib/aptos/data.js.map +1 -0
  35. package/lib/aptos/index.d.ts +1 -0
  36. package/lib/aptos/index.d.ts.map +1 -1
  37. package/lib/aptos/index.js.map +1 -1
  38. package/lib/aptos/models.d.ts +1 -0
  39. package/lib/aptos/models.d.ts.map +1 -1
  40. package/lib/aptos/move-coder.d.ts +8 -2
  41. package/lib/aptos/move-coder.d.ts.map +1 -1
  42. package/lib/aptos/move-coder.js +84 -1
  43. package/lib/aptos/move-coder.js.map +1 -1
  44. package/lib/aptos/network.d.ts +1 -0
  45. package/lib/aptos/network.d.ts.map +1 -1
  46. package/lib/aptos/network.js +1 -0
  47. package/lib/aptos/network.js.map +1 -1
  48. package/lib/btc/btc-plugin.d.ts +4 -1
  49. package/lib/btc/btc-plugin.d.ts.map +1 -1
  50. package/lib/btc/btc-plugin.js +27 -0
  51. package/lib/btc/btc-plugin.js.map +1 -1
  52. package/lib/btc/btc-processor.d.ts +6 -5
  53. package/lib/btc/btc-processor.d.ts.map +1 -1
  54. package/lib/btc/btc-processor.js +35 -9
  55. package/lib/btc/btc-processor.js.map +1 -1
  56. package/lib/btc/types.d.ts +2 -1
  57. package/lib/btc/types.d.ts.map +1 -1
  58. package/lib/core/base-context.d.ts +4 -2
  59. package/lib/core/base-context.d.ts.map +1 -1
  60. package/lib/core/base-context.js +8 -3
  61. package/lib/core/base-context.js.map +1 -1
  62. package/lib/core/event-logger.d.ts +5 -0
  63. package/lib/core/event-logger.d.ts.map +1 -1
  64. package/lib/core/event-logger.js +36 -1
  65. package/lib/core/event-logger.js.map +1 -1
  66. package/lib/core/handler-options.d.ts +25 -0
  67. package/lib/core/handler-options.d.ts.map +1 -0
  68. package/lib/core/handler-options.js +21 -0
  69. package/lib/core/handler-options.js.map +1 -0
  70. package/lib/core/index.d.ts +3 -1
  71. package/lib/core/index.d.ts.map +1 -1
  72. package/lib/core/index.js +3 -1
  73. package/lib/core/index.js.map +1 -1
  74. package/lib/core/meter.d.ts +45 -2
  75. package/lib/core/meter.d.ts.map +1 -1
  76. package/lib/core/meter.js +124 -2
  77. package/lib/core/meter.js.map +1 -1
  78. package/lib/core/numberish.d.ts +2 -1
  79. package/lib/core/numberish.d.ts.map +1 -1
  80. package/lib/core/numberish.js +35 -1
  81. package/lib/core/numberish.js.map +1 -1
  82. package/lib/core/partition-handler-manager.d.ts +44 -0
  83. package/lib/core/partition-handler-manager.d.ts.map +1 -0
  84. package/lib/core/partition-handler-manager.js +76 -0
  85. package/lib/core/partition-handler-manager.js.map +1 -0
  86. package/lib/cosmos/cosmos-processor.d.ts +3 -2
  87. package/lib/cosmos/cosmos-processor.d.ts.map +1 -1
  88. package/lib/cosmos/cosmos-processor.js +11 -1
  89. package/lib/cosmos/cosmos-processor.js.map +1 -1
  90. package/lib/cosmos/types.d.ts +1 -0
  91. package/lib/cosmos/types.d.ts.map +1 -1
  92. package/lib/eth/base-processor.d.ts +23 -17
  93. package/lib/eth/base-processor.d.ts.map +1 -1
  94. package/lib/eth/base-processor.js +173 -34
  95. package/lib/eth/base-processor.js.map +1 -1
  96. package/lib/eth/bind-options.d.ts +6 -0
  97. package/lib/eth/bind-options.d.ts.map +1 -1
  98. package/lib/eth/bind-options.js +2 -0
  99. package/lib/eth/bind-options.js.map +1 -1
  100. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts +32 -31
  101. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts.map +1 -1
  102. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +62 -62
  103. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
  104. package/lib/eth/builtin/internal/erc1155-processor.d.ts +17 -16
  105. package/lib/eth/builtin/internal/erc1155-processor.d.ts.map +1 -1
  106. package/lib/eth/builtin/internal/erc1155-processor.js +32 -32
  107. package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
  108. package/lib/eth/builtin/internal/erc20-processor.d.ts +25 -24
  109. package/lib/eth/builtin/internal/erc20-processor.d.ts.map +1 -1
  110. package/lib/eth/builtin/internal/erc20-processor.js +48 -48
  111. package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
  112. package/lib/eth/builtin/internal/erc20bytes-processor.d.ts +14 -13
  113. package/lib/eth/builtin/internal/erc20bytes-processor.d.ts.map +1 -1
  114. package/lib/eth/builtin/internal/erc20bytes-processor.js +26 -26
  115. package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
  116. package/lib/eth/builtin/internal/erc721-processor.d.ts +21 -20
  117. package/lib/eth/builtin/internal/erc721-processor.d.ts.map +1 -1
  118. package/lib/eth/builtin/internal/erc721-processor.js +40 -40
  119. package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
  120. package/lib/eth/builtin/internal/weth9-processor.d.ts +20 -19
  121. package/lib/eth/builtin/internal/weth9-processor.d.ts.map +1 -1
  122. package/lib/eth/builtin/internal/weth9-processor.js +38 -38
  123. package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
  124. package/lib/eth/codegen/event-handler.js +2 -2
  125. package/lib/eth/codegen/event-handler.js.map +1 -1
  126. package/lib/eth/codegen/file.d.ts.map +1 -1
  127. package/lib/eth/codegen/file.js +1 -0
  128. package/lib/eth/codegen/file.js.map +1 -1
  129. package/lib/eth/codegen/functions-handler.js +2 -2
  130. package/lib/eth/codegen/functions-handler.js.map +1 -1
  131. package/lib/eth/eth-plugin.d.ts +5 -1
  132. package/lib/eth/eth-plugin.d.ts.map +1 -1
  133. package/lib/eth/eth-plugin.js +53 -5
  134. package/lib/eth/eth-plugin.js.map +1 -1
  135. package/lib/eth/eth.d.ts +2 -7
  136. package/lib/eth/eth.d.ts.map +1 -1
  137. package/lib/eth/eth.js +8 -1
  138. package/lib/eth/eth.js.map +1 -1
  139. package/lib/fuel/codegen/codegen.js +5 -5
  140. package/lib/fuel/codegen/codegen.js.map +1 -1
  141. package/lib/fuel/fuel-plugin.d.ts +4 -1
  142. package/lib/fuel/fuel-plugin.d.ts.map +1 -1
  143. package/lib/fuel/fuel-plugin.js +41 -0
  144. package/lib/fuel/fuel-plugin.js.map +1 -1
  145. package/lib/fuel/fuel-processor-template.d.ts +7 -4
  146. package/lib/fuel/fuel-processor-template.d.ts.map +1 -1
  147. package/lib/fuel/fuel-processor-template.js +11 -9
  148. package/lib/fuel/fuel-processor-template.js.map +1 -1
  149. package/lib/fuel/fuel-processor.d.ts +7 -7
  150. package/lib/fuel/fuel-processor.d.ts.map +1 -1
  151. package/lib/fuel/fuel-processor.js +91 -28
  152. package/lib/fuel/fuel-processor.js.map +1 -1
  153. package/lib/fuel/types.d.ts +3 -0
  154. package/lib/fuel/types.d.ts.map +1 -1
  155. package/lib/move/filter.d.ts +5 -0
  156. package/lib/move/filter.d.ts.map +1 -1
  157. package/lib/move/filter.js +5 -0
  158. package/lib/move/filter.js.map +1 -1
  159. package/lib/move/shared-network-codegen.d.ts.map +1 -1
  160. package/lib/move/shared-network-codegen.js +5 -4
  161. package/lib/move/shared-network-codegen.js.map +1 -1
  162. package/lib/solana/solana-processor.d.ts +10 -4
  163. package/lib/solana/solana-processor.d.ts.map +1 -1
  164. package/lib/solana/solana-processor.js +13 -4
  165. package/lib/solana/solana-processor.js.map +1 -1
  166. package/lib/stark/starknet-processor.d.ts +3 -1
  167. package/lib/stark/starknet-processor.d.ts.map +1 -1
  168. package/lib/stark/starknet-processor.js +32 -14
  169. package/lib/stark/starknet-processor.js.map +1 -1
  170. package/lib/store/codegen.d.ts.map +1 -1
  171. package/lib/store/codegen.js +36 -2
  172. package/lib/store/codegen.js.map +1 -1
  173. package/lib/store/schema.d.ts.map +1 -1
  174. package/lib/store/schema.js +3 -1
  175. package/lib/store/schema.js.map +1 -1
  176. package/lib/store/store.d.ts +4 -3
  177. package/lib/store/store.d.ts.map +1 -1
  178. package/lib/store/store.js +41 -1
  179. package/lib/store/store.js.map +1 -1
  180. package/lib/store/types.d.ts +20 -1
  181. package/lib/store/types.d.ts.map +1 -1
  182. package/lib/store/types.js +22 -0
  183. package/lib/store/types.js.map +1 -1
  184. package/lib/sui/builtin/0x1.d.ts +11 -6
  185. package/lib/sui/builtin/0x1.d.ts.map +1 -1
  186. package/lib/sui/builtin/0x1.js +13 -13
  187. package/lib/sui/builtin/0x1.js.map +1 -1
  188. package/lib/sui/builtin/0x2.d.ts +123 -59
  189. package/lib/sui/builtin/0x2.d.ts.map +1 -1
  190. package/lib/sui/builtin/0x2.js +397 -119
  191. package/lib/sui/builtin/0x2.js.map +1 -1
  192. package/lib/sui/builtin/0x3.d.ts +89 -61
  193. package/lib/sui/builtin/0x3.d.ts.map +1 -1
  194. package/lib/sui/builtin/0x3.js +222 -104
  195. package/lib/sui/builtin/0x3.js.map +1 -1
  196. package/lib/sui/models.d.ts +1 -0
  197. package/lib/sui/models.d.ts.map +1 -1
  198. package/lib/sui/sui-object-processor-template.js +1 -1
  199. package/lib/sui/sui-object-processor-template.js.map +1 -1
  200. package/lib/sui/sui-object-processor.d.ts +2 -0
  201. package/lib/sui/sui-object-processor.d.ts.map +1 -1
  202. package/lib/sui/sui-object-processor.js +4 -0
  203. package/lib/sui/sui-object-processor.js.map +1 -1
  204. package/lib/sui/sui-plugin.d.ts +6 -3
  205. package/lib/sui/sui-plugin.d.ts.map +1 -1
  206. package/lib/sui/sui-plugin.js +68 -24
  207. package/lib/sui/sui-plugin.js.map +1 -1
  208. package/lib/sui/sui-processor.d.ts +6 -4
  209. package/lib/sui/sui-processor.d.ts.map +1 -1
  210. package/lib/sui/sui-processor.js +48 -11
  211. package/lib/sui/sui-processor.js.map +1 -1
  212. package/lib/testing/eth-facet.d.ts +2 -1
  213. package/lib/testing/eth-facet.d.ts.map +1 -1
  214. package/lib/testing/eth-facet.js.map +1 -1
  215. package/lib/utils/block.d.ts +2 -0
  216. package/lib/utils/block.d.ts.map +1 -1
  217. package/lib/utils/block.js +13 -0
  218. package/lib/utils/block.js.map +1 -1
  219. package/package.json +9 -8
  220. package/src/aptos/abis/0x1.json +9650 -5284
  221. package/src/aptos/abis/0x3.json +13 -13
  222. package/src/aptos/abis/0x4.json +42 -42
  223. package/src/aptos/api.ts +13 -1
  224. package/src/aptos/aptos-plugin.ts +62 -13
  225. package/src/aptos/aptos-processor.ts +114 -74
  226. package/src/aptos/aptos-resource-processor-template.ts +9 -8
  227. package/src/aptos/builtin/0x1.ts +3105 -705
  228. package/src/aptos/builtin/0x3.ts +304 -131
  229. package/src/aptos/builtin/0x4.ts +125 -57
  230. package/src/aptos/codegen/codegen.ts +40 -5
  231. package/src/aptos/data.ts +123 -0
  232. package/src/aptos/index.ts +2 -0
  233. package/src/aptos/models.ts +2 -0
  234. package/src/aptos/move-coder.ts +96 -3
  235. package/src/aptos/network.ts +1 -0
  236. package/src/btc/btc-plugin.ts +38 -0
  237. package/src/btc/btc-processor.ts +35 -10
  238. package/src/btc/types.ts +2 -1
  239. package/src/core/base-context.ts +8 -3
  240. package/src/core/event-logger.ts +45 -1
  241. package/src/core/handler-options.ts +40 -0
  242. package/src/core/index.ts +17 -1
  243. package/src/core/meter.ts +159 -4
  244. package/src/core/numberish.ts +34 -1
  245. package/src/core/partition-handler-manager.ts +94 -0
  246. package/src/cosmos/cosmos-processor.ts +12 -1
  247. package/src/cosmos/types.ts +1 -0
  248. package/src/eth/base-processor.ts +163 -41
  249. package/src/eth/bind-options.ts +7 -0
  250. package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +118 -62
  251. package/src/eth/builtin/internal/erc1155-processor.ts +76 -32
  252. package/src/eth/builtin/internal/erc20-processor.ts +79 -48
  253. package/src/eth/builtin/internal/erc20bytes-processor.ts +47 -26
  254. package/src/eth/builtin/internal/erc721-processor.ts +77 -40
  255. package/src/eth/builtin/internal/weth9-processor.ts +79 -38
  256. package/src/eth/codegen/event-handler.ts +2 -2
  257. package/src/eth/codegen/file.ts +1 -0
  258. package/src/eth/codegen/functions-handler.ts +2 -2
  259. package/src/eth/eth-plugin.ts +76 -10
  260. package/src/eth/eth.ts +12 -1
  261. package/src/fuel/codegen/codegen.ts +5 -5
  262. package/src/fuel/fuel-plugin.ts +56 -0
  263. package/src/fuel/fuel-processor-template.ts +17 -10
  264. package/src/fuel/fuel-processor.ts +90 -22
  265. package/src/fuel/types.ts +3 -0
  266. package/src/move/filter.ts +5 -0
  267. package/src/move/shared-network-codegen.ts +5 -4
  268. package/src/solana/solana-processor.ts +28 -6
  269. package/src/stark/starknet-processor.ts +31 -13
  270. package/src/store/codegen.ts +50 -2
  271. package/src/store/schema.ts +3 -1
  272. package/src/store/store.ts +57 -4
  273. package/src/store/types.ts +30 -1
  274. package/src/sui/abis/0x1.json +8 -0
  275. package/src/sui/abis/0x2.json +437 -0
  276. package/src/sui/abis/0x3.json +116 -5
  277. package/src/sui/builtin/0x1.ts +28 -13
  278. package/src/sui/builtin/0x2.ts +631 -119
  279. package/src/sui/builtin/0x3.ts +450 -116
  280. package/src/sui/models.ts +2 -0
  281. package/src/sui/sui-object-processor-template.ts +1 -1
  282. package/src/sui/sui-object-processor.ts +6 -0
  283. package/src/sui/sui-plugin.ts +77 -26
  284. package/src/sui/sui-processor.ts +50 -11
  285. package/src/testing/eth-facet.ts +2 -1
  286. package/src/utils/block.ts +15 -0
package/src/core/index.ts CHANGED
@@ -3,7 +3,18 @@ export type { PromiseOrValue, PromiseOrVoid } from './promises.js'
3
3
  export type { PartiallyOptional } from './partial-optional.js'
4
4
  export { BaseContext } from './base-context.js'
5
5
  export { normalizeLabels } from './normalization.js'
6
- export { CounterBinding, Meter, type Labels, GaugeBinding, Counter, Gauge, MetricOptions } from './meter.js'
6
+ export {
7
+ CounterBinding,
8
+ Meter,
9
+ type Labels,
10
+ GaugeBinding,
11
+ Counter,
12
+ Gauge,
13
+ MetricOptions,
14
+ CounterNew,
15
+ GaugeNew,
16
+ MeterNew
17
+ } from './meter.js'
7
18
  export { Exporter } from './exporter.js'
8
19
  export * from './event-logger.js'
9
20
  export { type Numberish, toBigInteger, toMetricValue } from './numberish.js'
@@ -11,3 +22,8 @@ export { type Numberish, toBigInteger, toMetricValue } from './numberish.js'
11
22
  export { CorePlugin } from './core-plugin.js'
12
23
  export { DatabaseSchema } from './database-schema.js'
13
24
  export * from './constants.js'
25
+ export { type HandlerOptions, type PartitionHandler, mergeHandlerOptions } from './handler-options.js'
26
+ export {
27
+ PartitionHandlerManager,
28
+ type PartitionHandler as PartitionHandlerFunction
29
+ } from './partition-handler-manager.js'
package/src/core/meter.ts CHANGED
@@ -1,7 +1,13 @@
1
1
  import { BaseContext } from './base-context.js'
2
- import { Numberish, toMetricValue } from './numberish.js'
2
+ import { Numberish, toMetricValue, toTimeSeriesData } from './numberish.js'
3
3
  import { NamedResultDescriptor } from './metadata.js'
4
- import { AggregationConfig, AggregationType, MetricConfig, MetricType } from '@sentio/protos'
4
+ import {
5
+ AggregationConfig,
6
+ AggregationType,
7
+ MetricConfig,
8
+ MetricType,
9
+ TimeseriesResult_TimeseriesType
10
+ } from '@sentio/protos'
5
11
  import { MapStateStorage, processMetrics } from '@sentio/runtime'
6
12
 
7
13
  export type Labels = { [key: string]: string }
@@ -30,6 +36,7 @@ export class CounterOptions {
30
36
 
31
37
  export class Metric extends NamedResultDescriptor {
32
38
  config: MetricConfig
39
+
33
40
  constructor(type: MetricType, name: string, option?: MetricConfig) {
34
41
  super(name)
35
42
  this.config = MetricConfig.fromPartial({ ...option, name: this.name, type })
@@ -67,6 +74,28 @@ export class MetricState extends MapStateStorage<Metric> {
67
74
  }
68
75
  }
69
76
 
77
+ export class MetricStateNew extends MapStateStorage<Metric> {
78
+ static INSTANCE = new MetricStateNew()
79
+
80
+ getOrRegisterMetric(type: MetricType, name: string, option?: CounterOptions | MetricOptions): Metric {
81
+ const metricMap = this.getOrRegister()
82
+ let metric = metricMap.get(name)
83
+ if (metric && metric.config.type !== type) {
84
+ throw Error(`redefine ${name} of metric type ${type} that is previously ${metric.config.type}`)
85
+ }
86
+
87
+ if (!metric) {
88
+ if (type === MetricType.COUNTER) {
89
+ metric = CounterNew._create(name, option)
90
+ } else {
91
+ metric = GaugeNew._create(name, option)
92
+ }
93
+ }
94
+ metricMap.set(name, metric)
95
+ return metric
96
+ }
97
+ }
98
+
70
99
  export class Counter extends Metric {
71
100
  static register(name: string, option?: CounterOptions): Counter {
72
101
  return MetricState.INSTANCE.getOrRegisterMetric(MetricType.COUNTER, name, option) as Counter
@@ -79,7 +108,7 @@ export class Counter extends Metric {
79
108
  return new Counter(name, option)
80
109
  }
81
110
 
82
- private constructor(name: string, option?: CounterOptions) {
111
+ protected constructor(name: string, option?: CounterOptions) {
83
112
  super(
84
113
  MetricType.COUNTER,
85
114
  name,
@@ -145,7 +174,7 @@ export class Gauge extends Metric {
145
174
  return new Gauge(name, option)
146
175
  }
147
176
 
148
- private constructor(name: string, option?: MetricOptions) {
177
+ protected constructor(name: string, option?: MetricOptions) {
149
178
  super(MetricType.GAUGE, name, MetricConfig.fromPartial({ ...option }))
150
179
  }
151
180
 
@@ -192,3 +221,129 @@ export class Meter {
192
221
  return new GaugeBinding(name, this.ctx)
193
222
  }
194
223
  }
224
+
225
+ export class MeterNew {
226
+ private readonly ctx: BaseContext
227
+
228
+ constructor(ctx: BaseContext) {
229
+ this.ctx = ctx
230
+ }
231
+
232
+ Counter(name: string) {
233
+ return new CounterNewBinding(name, this.ctx)
234
+ }
235
+
236
+ Gauge(name: string) {
237
+ return new GaugeNewBinding(name, this.ctx)
238
+ }
239
+ }
240
+
241
+ export class CounterNew extends Counter {
242
+ static register(name: string, option?: CounterOptions): CounterNew {
243
+ return MetricStateNew.INSTANCE.getOrRegisterMetric(MetricType.COUNTER, name, option) as CounterNew
244
+ }
245
+
246
+ /**
247
+ * internal use only, to create a metric use {@link register} instead
248
+ */
249
+ static _create(name: string, option?: CounterOptions): CounterNew {
250
+ return new CounterNew(name, option)
251
+ }
252
+
253
+ private constructor(name: string, option?: CounterOptions) {
254
+ super(
255
+ name,
256
+ MetricConfig.fromPartial({
257
+ ...option,
258
+ aggregationConfig: {
259
+ intervalInMinutes: option?.resolutionConfig ? [option?.resolutionConfig?.intervalInMinutes] : []
260
+ }
261
+ })
262
+ )
263
+ }
264
+
265
+ add(ctx: BaseContext, value: Numberish, labels: Labels = {}) {
266
+ this.recordNew(ctx, value, labels, true)
267
+ }
268
+
269
+ sub(ctx: BaseContext, value: Numberish, labels: Labels = {}) {
270
+ this.recordNew(ctx, value, labels, false)
271
+ }
272
+
273
+ private recordNew(ctx: BaseContext, value: Numberish, labels: Labels, add: boolean) {
274
+ processMetrics.process_metricrecord_count.add(1)
275
+ ctx.update({
276
+ timeseriesResult: [
277
+ {
278
+ metadata: ctx.getMetaData(this.name, labels),
279
+ type: TimeseriesResult_TimeseriesType.COUNTER,
280
+ data: toTimeSeriesData(value, labels, !add),
281
+ runtimeInfo: undefined
282
+ }
283
+ ]
284
+ })
285
+ }
286
+ }
287
+
288
+ export class GaugeNewBinding {
289
+ private readonly gauge: GaugeNew
290
+ private readonly ctx: BaseContext
291
+
292
+ constructor(name: string, ctx: BaseContext) {
293
+ this.gauge = GaugeNew._create(name)
294
+ this.ctx = ctx
295
+ }
296
+
297
+ record(value: Numberish, labels: Labels = {}) {
298
+ this.gauge.record(this.ctx, value, labels)
299
+ }
300
+ }
301
+
302
+ export class CounterNewBinding {
303
+ private readonly counter: CounterNew
304
+ private readonly ctx: BaseContext
305
+
306
+ constructor(name: string, ctx: BaseContext) {
307
+ this.counter = CounterNew._create(name)
308
+ this.ctx = ctx
309
+ }
310
+
311
+ add(value: Numberish, labels: Labels = {}) {
312
+ this.counter.add(this.ctx, value, labels)
313
+ }
314
+
315
+ sub(value: Numberish, labels: Labels = {}) {
316
+ this.counter.sub(this.ctx, value, labels)
317
+ }
318
+ }
319
+
320
+ export class GaugeNew extends Gauge {
321
+ static register(name: string, option?: MetricOptions): Gauge {
322
+ return MetricStateNew.INSTANCE.getOrRegisterMetric(MetricType.GAUGE, name, option) as Gauge
323
+ }
324
+
325
+ /**
326
+ * internal use only, to create a metric use {@link register} instead
327
+ */
328
+ static _create(name: string, option?: MetricOptions): GaugeNew {
329
+ return new GaugeNew(name, option)
330
+ }
331
+
332
+ private constructor(name: string, option?: MetricOptions) {
333
+ super(name, MetricConfig.fromPartial({ ...option }))
334
+ }
335
+
336
+ record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {
337
+ processMetrics.process_metricrecord_count.add(1)
338
+ ctx.update({
339
+ timeseriesResult: [
340
+ {
341
+ metadata: ctx.getMetaData(this.name, labels),
342
+ type: TimeseriesResult_TimeseriesType.GAUGE,
343
+ data: toTimeSeriesData(value, labels, false),
344
+ runtimeInfo: undefined
345
+ }
346
+ ]
347
+ })
348
+ }
349
+ }
@@ -1,4 +1,4 @@
1
- import { BigDecimalRichValue, BigInteger, MetricValue } from '@sentio/protos'
1
+ import { BigDecimalRichValue, BigInteger, MetricValue, RichStruct, RichValue_NullValue } from '@sentio/protos'
2
2
  import { BigDecimal } from './big-decimal.js'
3
3
 
4
4
  export type Numberish = number | bigint | BigDecimal | string
@@ -120,3 +120,36 @@ export function toBigDecimal(value: BigDecimal): BigDecimalRichValue {
120
120
  exp: exp
121
121
  }
122
122
  }
123
+
124
+ export function toTimeSeriesData(value: Numberish, labels: Record<string, string>, neg: boolean) {
125
+ const mv = toMetricValue(value)
126
+ const data: RichStruct = {
127
+ fields: {
128
+ value: {}
129
+ }
130
+ }
131
+
132
+ for (const key in labels) {
133
+ if (labels[key] == null) {
134
+ data.fields[key] = { nullValue: RichValue_NullValue.NULL_VALUE }
135
+ } else {
136
+ data.fields[key] = { stringValue: labels[key] }
137
+ }
138
+ }
139
+
140
+ if (mv.bigInteger != null) {
141
+ mv.bigInteger.negative = neg ? !mv.bigInteger.negative : mv.bigInteger.negative
142
+ data.fields.value.bigintValue = mv.bigInteger
143
+ } else if (mv.bigDecimal != null) {
144
+ let v = new BigDecimal(mv.bigDecimal)
145
+ if (neg) {
146
+ v = v.negated()
147
+ }
148
+ data.fields.value.bigdecimalValue = toBigDecimal(v)
149
+ } else if (mv.doubleValue != null) {
150
+ data.fields.value.floatValue = neg ? -mv.doubleValue : mv.doubleValue
151
+ } else {
152
+ data.fields.value.nullValue = RichValue_NullValue.NULL_VALUE
153
+ }
154
+ return data
155
+ }
@@ -0,0 +1,94 @@
1
+ import {
2
+ HandlerType,
3
+ ProcessStreamResponse_Partitions_Partition,
4
+ ProcessStreamResponse_Partitions_Partition_SysValue
5
+ } from '@sentio/protos'
6
+ import { ServerError, Status } from 'nice-grpc'
7
+
8
+ /**
9
+ * Type for partition handler functions that can process any data type
10
+ */
11
+ export type PartitionHandler = (request: any) => Promise<string | undefined>
12
+
13
+ /**
14
+ * Generic manager for handling partition logic across all chain plugins.
15
+ * Provides a unified interface for registering, storing, and processing partition handlers.
16
+ * Chain-specific logic should remain in individual plugins.
17
+ */
18
+ export class PartitionHandlerManager {
19
+ private partitionHandlers: Map<HandlerType, Record<number, PartitionHandler>> = new Map()
20
+
21
+ /**
22
+ * Register a partition handler for a specific handler type and ID
23
+ * @param handlerType The type of handler (e.g., HandlerType.ETH_LOG, HandlerType.APT_EVENT)
24
+ * @param handlerId The unique ID for this handler instance
25
+ * @param partitionHandler The partition handler function (optional)
26
+ */
27
+ registerPartitionHandler(handlerType: HandlerType, handlerId: number, partitionHandler?: PartitionHandler): void {
28
+ if (partitionHandler) {
29
+ const existingHandlers = this.partitionHandlers.get(handlerType) || {}
30
+ existingHandlers[handlerId] = partitionHandler
31
+ this.partitionHandlers.set(handlerType, existingHandlers)
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Process partition logic for a specific handler type
37
+ * @param handlerType The type of handler being processed
38
+ * @param handlerIds Array of handler IDs to process
39
+ * @param data The data to pass to partition handlers
40
+ * @returns Record mapping handler IDs to partition results
41
+ */
42
+ async processPartitionForHandlerType(
43
+ handlerType: HandlerType,
44
+ handlerIds: number[],
45
+ data: any
46
+ ): Promise<Record<number, ProcessStreamResponse_Partitions_Partition>> {
47
+ const result: Record<number, ProcessStreamResponse_Partitions_Partition> = {}
48
+
49
+ for (const handlerId of handlerIds) {
50
+ const partitionHandler = this.partitionHandlers.get(handlerType)?.[handlerId]
51
+ if (partitionHandler && data) {
52
+ try {
53
+ const partitionValue = await partitionHandler(data)
54
+ result[handlerId] = {
55
+ userValue: partitionValue
56
+ }
57
+ } catch (error) {
58
+ // If partition handler fails, fall back to unrecognized
59
+ throw new ServerError(Status.INVALID_ARGUMENT, 'compute partition key failed, error:' + error.message)
60
+ }
61
+ } else {
62
+ result[handlerId] = {
63
+ sysValue: ProcessStreamResponse_Partitions_Partition_SysValue.UNRECOGNIZED
64
+ }
65
+ }
66
+ }
67
+
68
+ return result
69
+ }
70
+
71
+ /**
72
+ * Clear all partition handlers (useful for testing or reinitialization)
73
+ */
74
+ clear(): void {
75
+ this.partitionHandlers.clear()
76
+ }
77
+
78
+ /**
79
+ * Get all registered handler types
80
+ * @returns Array of handler types that have registered partition handlers
81
+ */
82
+ getRegisteredHandlerTypes(): HandlerType[] {
83
+ return Array.from(this.partitionHandlers.keys())
84
+ }
85
+
86
+ /**
87
+ * Get the number of registered handlers for a specific handler type
88
+ * @param handlerType The handler type to check
89
+ * @returns Number of registered handlers for this type
90
+ */
91
+ getHandlerCount(handlerType: HandlerType): number {
92
+ return Object.keys(this.partitionHandlers.get(handlerType) || {}).length
93
+ }
94
+ }
@@ -3,6 +3,7 @@ import { Data_CosmosCall } from '@sentio/protos'
3
3
  import { CosmosContext } from './context.js'
4
4
  import { CosmosEvent, CosmosTransaction, CosmosTxLog } from './transaction.js'
5
5
  import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
6
+ import { HandlerOptions } from '../core/handler-options.js'
6
7
 
7
8
  export class CosmosProcessor {
8
9
  callHandlers: CallHandler<Data_CosmosCall>[] = []
@@ -19,7 +20,8 @@ export class CosmosProcessor {
19
20
 
20
21
  public onLogEvent(
21
22
  logFilters: string[] | string,
22
- handler: (log: CosmosTxLog, event: CosmosEvent, context: CosmosContext) => void | Promise<void>
23
+ handler: (log: CosmosTxLog, event: CosmosEvent, context: CosmosContext) => void | Promise<void>,
24
+ handlerOptions?: HandlerOptions<object, CosmosTransaction>
23
25
  ) {
24
26
  const filter = Array.isArray(logFilters) ? logFilters : [logFilters]
25
27
  const callHandler = {
@@ -39,6 +41,15 @@ export class CosmosProcessor {
39
41
  },
40
42
  logConfig: {
41
43
  logFilters: filter
44
+ },
45
+ partitionHandler: async (call: Data_CosmosCall): Promise<string | undefined> => {
46
+ const p = handlerOptions?.partitionKey
47
+ if (!p) return undefined
48
+ if (typeof p === 'function') {
49
+ const transaction = call.transaction as CosmosTransaction
50
+ return p(transaction)
51
+ }
52
+ return p
42
53
  }
43
54
  }
44
55
  this.callHandlers.push(callHandler)
@@ -13,6 +13,7 @@ export type CallHandler<T> = {
13
13
  logConfig?: {
14
14
  logFilters: string[]
15
15
  }
16
+ partitionHandler?: (call: T) => Promise<string | undefined>
16
17
  }
17
18
 
18
19
  export type CosmosProcessorConfig = {