@sentio/sdk 2.59.0-rc.4 → 2.59.0-rc.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) 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 +333 -332
  18. package/lib/aptos/builtin/0x1.d.ts.map +1 -1
  19. package/lib/aptos/builtin/0x1.js +664 -664
  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 +130 -130
  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 +56 -56
  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 +10 -5
  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 +7 -6
  185. package/lib/sui/builtin/0x1.d.ts.map +1 -1
  186. package/lib/sui/builtin/0x1.js +12 -12
  187. package/lib/sui/builtin/0x1.js.map +1 -1
  188. package/lib/sui/builtin/0x2.d.ts +61 -60
  189. package/lib/sui/builtin/0x2.d.ts.map +1 -1
  190. package/lib/sui/builtin/0x2.js +120 -120
  191. package/lib/sui/builtin/0x2.js.map +1 -1
  192. package/lib/sui/builtin/0x3.d.ts +49 -48
  193. package/lib/sui/builtin/0x3.d.ts.map +1 -1
  194. package/lib/sui/builtin/0x3.js +96 -96
  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 +7 -6
  220. package/src/aptos/api.ts +13 -1
  221. package/src/aptos/aptos-plugin.ts +62 -13
  222. package/src/aptos/aptos-processor.ts +114 -74
  223. package/src/aptos/aptos-resource-processor-template.ts +9 -8
  224. package/src/aptos/builtin/0x1.ts +1566 -664
  225. package/src/aptos/builtin/0x3.ts +303 -130
  226. package/src/aptos/builtin/0x4.ts +124 -56
  227. package/src/aptos/codegen/codegen.ts +40 -5
  228. package/src/aptos/data.ts +123 -0
  229. package/src/aptos/index.ts +2 -0
  230. package/src/aptos/models.ts +2 -0
  231. package/src/aptos/move-coder.ts +96 -3
  232. package/src/aptos/network.ts +1 -0
  233. package/src/btc/btc-plugin.ts +38 -0
  234. package/src/btc/btc-processor.ts +35 -10
  235. package/src/btc/types.ts +2 -1
  236. package/src/core/base-context.ts +10 -5
  237. package/src/core/event-logger.ts +45 -1
  238. package/src/core/handler-options.ts +40 -0
  239. package/src/core/index.ts +17 -1
  240. package/src/core/meter.ts +159 -4
  241. package/src/core/numberish.ts +34 -1
  242. package/src/core/partition-handler-manager.ts +94 -0
  243. package/src/cosmos/cosmos-processor.ts +12 -1
  244. package/src/cosmos/types.ts +1 -0
  245. package/src/eth/base-processor.ts +163 -41
  246. package/src/eth/bind-options.ts +7 -0
  247. package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +118 -62
  248. package/src/eth/builtin/internal/erc1155-processor.ts +76 -32
  249. package/src/eth/builtin/internal/erc20-processor.ts +79 -48
  250. package/src/eth/builtin/internal/erc20bytes-processor.ts +47 -26
  251. package/src/eth/builtin/internal/erc721-processor.ts +77 -40
  252. package/src/eth/builtin/internal/weth9-processor.ts +79 -38
  253. package/src/eth/codegen/event-handler.ts +2 -2
  254. package/src/eth/codegen/file.ts +1 -0
  255. package/src/eth/codegen/functions-handler.ts +2 -2
  256. package/src/eth/eth-plugin.ts +76 -10
  257. package/src/eth/eth.ts +12 -1
  258. package/src/fuel/codegen/codegen.ts +5 -5
  259. package/src/fuel/fuel-plugin.ts +56 -0
  260. package/src/fuel/fuel-processor-template.ts +17 -10
  261. package/src/fuel/fuel-processor.ts +90 -22
  262. package/src/fuel/types.ts +3 -0
  263. package/src/move/filter.ts +5 -0
  264. package/src/move/shared-network-codegen.ts +5 -4
  265. package/src/solana/solana-processor.ts +28 -6
  266. package/src/stark/starknet-processor.ts +31 -13
  267. package/src/store/codegen.ts +50 -2
  268. package/src/store/schema.ts +3 -1
  269. package/src/store/store.ts +57 -4
  270. package/src/store/types.ts +30 -1
  271. package/src/sui/builtin/0x1.ts +22 -12
  272. package/src/sui/builtin/0x2.ts +220 -120
  273. package/src/sui/builtin/0x3.ts +241 -96
  274. package/src/sui/models.ts +2 -0
  275. package/src/sui/sui-object-processor-template.ts +1 -1
  276. package/src/sui/sui-object-processor.ts +6 -0
  277. package/src/sui/sui-plugin.ts +77 -26
  278. package/src/sui/sui-processor.ts +50 -11
  279. package/src/testing/eth-facet.ts +2 -1
  280. package/src/utils/block.ts +15 -0
@@ -48,6 +48,8 @@ interface Class {
48
48
  annotations: string[]
49
49
  parent?: string
50
50
  interfaces: string[]
51
+ timeseries?: boolean
52
+ immutable?: boolean
51
53
  }
52
54
 
53
55
  interface Interface {
@@ -111,7 +113,7 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
111
113
  },
112
114
  {
113
115
  module: '@sentio/sdk/store',
114
- types: ['Entity', 'Required', 'One', 'Many', 'Column', 'ListColumn', 'AbstractEntity']
116
+ types: ['Entity', 'Required', 'One', 'Many', 'Column', 'ListColumn', 'AbstractEntity', 'getStore', 'UpdateValues']
115
117
  },
116
118
  {
117
119
  module: '@sentio/bigdecimal',
@@ -154,6 +156,18 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
154
156
  }
155
157
 
156
158
  if (t instanceof GraphQLObjectType) {
159
+ if (isTimeseries(t)) {
160
+ // check id is int8
161
+ const idField = t.getFields()['id']
162
+ if (!idField || !isNonNullType(idField.type) || idField.type.toString() !== 'Int8!') {
163
+ throw new Error(`Timeseries entity ${t.name} must have an id field of type Int8!`)
164
+ }
165
+ // check if it has a timestamp field
166
+ const timestampField = t.getFields()['timestamp']
167
+ if (!timestampField || !isNonNullType(timestampField.type) || timestampField.type.toString() !== 'Timestamp!') {
168
+ throw new Error(`Timeseries entity ${t.name} must have a timestamp field of type Timestamp!`)
169
+ }
170
+ }
157
171
  if (isEntity(t)) {
158
172
  const fields: Field[] = []
159
173
  const methods: Method[] = []
@@ -177,7 +191,7 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
177
191
  methods.push({
178
192
  name: f.name,
179
193
  returnType: `Promise<${type}>`,
180
- body: `return this.store.get(${elemType(f.type)}, [{field: '${derivedField}', op: '=', value: this.id}])?.[0]`,
194
+ body: `return this.store.list(${elemType(f.type)}, [{field: '${derivedField}', op: '=', value: this.id}]).then((r) => r?.[0])`,
181
195
  annotations: []
182
196
  })
183
197
  }
@@ -228,6 +242,8 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
228
242
  }
229
243
  classes.push({
230
244
  name: t.name,
245
+ timeseries: isTimeseries(t),
246
+ immutable: isImmutable(t),
231
247
  fields,
232
248
  methods,
233
249
  annotations: [`@Entity("${t.name}")`],
@@ -282,6 +298,12 @@ interface ${c.name}ConstructorInput {
282
298
  ${c.fields
283
299
  .filter((f) => !f.type.startsWith('Promise<')) // Filter out Promise fields
284
300
  .map((f) => {
301
+ if (c.timeseries && f.name == 'timestamp') {
302
+ return ` timestamp?: Timestamp;`
303
+ }
304
+ if (c.timeseries && f.name == 'id') {
305
+ return ` id?: Int8;`
306
+ }
285
307
  const isRequired = f.annotations.some((a) => a.includes('@Required'))
286
308
  return ` ${f.private ? 'private ' : ''}${f.name}${isRequired ? '' : '?'}: ${f.type.replace(' | undefined', '')};`
287
309
  })
@@ -297,6 +319,14 @@ ${c.fields
297
319
  .join('\n')}
298
320
  ${isEntity ? `constructor(data: ${c.name}ConstructorInput) {super()}` : ''}
299
321
  ${(c.methods ?? []).map(genMethod).join('\n')}
322
+
323
+ ${
324
+ isEntity && !c.immutable
325
+ ? `static update(values: UpdateValues<${c.name}ConstructorInput>): Promise<void> {
326
+ return getStore().update(${c.name}, values)
327
+ }`
328
+ : ``
329
+ }
300
330
  }`
301
331
  })
302
332
  .join('\n')}
@@ -367,6 +397,24 @@ function isEntity(t: GraphQLObjectType) {
367
397
  return t.astNode?.directives?.some((d) => d.name.value == 'entity')
368
398
  }
369
399
 
400
+ function isTimeseries(t: GraphQLObjectType) {
401
+ return t.astNode?.directives?.some(
402
+ (d) =>
403
+ d.name.value == 'entity' &&
404
+ d.arguments?.some((a) => a.name.value == 'timeseries' && a.value.kind == 'BooleanValue' && a.value.value == true)
405
+ )
406
+ }
407
+
408
+ function isImmutable(t: GraphQLObjectType) {
409
+ return (
410
+ t.astNode?.directives?.some(
411
+ (d) =>
412
+ d.name.value == 'entity' &&
413
+ d.arguments?.some((a) => a.name.value == 'immutable' && a.value.kind == 'BooleanValue' && a.value.value == true)
414
+ ) || isTimeseries(t)
415
+ )
416
+ }
417
+
370
418
  function isDerived(f: GraphQLField<any, any>) {
371
419
  return f.astNode?.directives?.some((d) => d.name.value == 'derivedFrom')
372
420
  }
@@ -6,7 +6,7 @@ const customScalars = ['BigInt', 'BigDecimal', 'Timestamp', 'JSON', 'Bytes', 'ID
6
6
 
7
7
  const baseSchema = buildASTSchema(
8
8
  parse(`
9
- directive @entity(immutable: Boolean! = false, sparse: Boolean! = false) on OBJECT
9
+ directive @entity(immutable: Boolean! = false, sparse: Boolean! = false, timeseries: Boolean! = false) on OBJECT
10
10
  directive @query on INTERFACE
11
11
  directive @derivedFrom(field: String!) on FIELD_DEFINITION
12
12
  directive @unique on FIELD_DEFINITION
@@ -16,6 +16,8 @@ const baseSchema = buildASTSchema(
16
16
  directive @byteWeight(value: Float!) on FIELD_DEFINITION
17
17
  directive @variant on OBJECT # legacy
18
18
  directive @jsonField on OBJECT # legacy
19
+ directive @aggregation(intervals: [String!]! = ["hour"], source: String!) on OBJECT
20
+ directive @aggregate(fn: String!, arg: String, cumulative: Boolean = false) on FIELD_DEFINITION
19
21
  ${customScalars.map((name) => 'scalar ' + name).join('\n')}
20
22
  `)
21
23
  )
@@ -1,7 +1,24 @@
1
1
  import { DatabaseSchema } from '../core/index.js'
2
2
  import { BigDecimal } from '@sentio/bigdecimal'
3
- import { AbstractEntity, AbstractEntity as Entity, Bytes, Float, ID, Int, Timestamp } from './types.js'
4
- import type { DBRequest, Entity as EntityStruct, RichValue } from '@sentio/protos'
3
+ import {
4
+ AbstractEntity,
5
+ AbstractEntity as Entity,
6
+ Bytes,
7
+ Float,
8
+ ID,
9
+ Int,
10
+ Timestamp,
11
+ AddOp,
12
+ MultiplyOp,
13
+ UpdateValues
14
+ } from './types.js'
15
+ import {
16
+ DBRequest,
17
+ DBRequest_DBUpdate,
18
+ Entity as EntityStruct,
19
+ EntityUpdateData_Operator,
20
+ RichValue
21
+ } from '@sentio/protos'
5
22
  import { DBRequest_DBOperator, DBResponse } from '@sentio/protos'
6
23
  import { IStoreContext, PluginManager } from '@sentio/runtime'
7
24
  import { Cursor } from './cursor.js'
@@ -102,6 +119,42 @@ export class Store {
102
119
  })
103
120
  }
104
121
 
122
+ async update<T extends Entity>(entity: EntityClass<T>, values: UpdateValues<any>): Promise<void> {
123
+ if (values.id) {
124
+ const update: DBRequest_DBUpdate = {
125
+ entity: [getEntityName(entity)],
126
+ id: [values.id.toString()],
127
+ entityData: [{ fields: {} }]
128
+ }
129
+ for (const [key, value] of Object.entries(values)) {
130
+ if (key !== 'id') {
131
+ const field = getEntityField(entity, key)
132
+ if (value instanceof AddOp) {
133
+ update.entityData[0].fields[field] = {
134
+ op: EntityUpdateData_Operator.ADD,
135
+ value: serializeRichValue(value.value)
136
+ }
137
+ } else if (value instanceof MultiplyOp) {
138
+ update.entityData[0].fields[field] = {
139
+ op: EntityUpdateData_Operator.MULTIPLY,
140
+ value: serializeRichValue(value.value)
141
+ }
142
+ } else if (value !== undefined) {
143
+ update.entityData[0].fields[field] = {
144
+ op: EntityUpdateData_Operator.SET,
145
+ value: serializeRichValue(value)
146
+ }
147
+ }
148
+ }
149
+ }
150
+ await this.context.sendRequest({
151
+ update
152
+ })
153
+ } else {
154
+ throw new Error('Update must have id field')
155
+ }
156
+ }
157
+
105
158
  async upsert<T extends Entity>(entity: T | T[]): Promise<void> {
106
159
  const entities = Array.isArray(entity) ? entity : [entity]
107
160
  const request = {
@@ -250,7 +303,7 @@ export type Operators<T> =
250
303
  : T extends Bytes
251
304
  ? '=' | '!=' | 'in' | 'not in'
252
305
  : T extends ID
253
- ? '=' | '!=' | 'like' | 'not like' | 'in' | 'not in'
306
+ ? '=' | '!=' | 'like' | 'not like' | 'in' | 'not in' | '<' | '<=' | '>' | '>='
254
307
  : T extends string
255
308
  ? '=' | '!=' | 'like' | 'not like' | 'in' | 'not in'
256
309
  : T extends Timestamp
@@ -321,5 +374,5 @@ export function getStore() {
321
374
  if (dbContext) {
322
375
  return new Store(dbContext)
323
376
  }
324
- return undefined
377
+ throw new Error('Store not found in context, please ensure you are calling this in a handler function')
325
378
  }
@@ -2,8 +2,9 @@ import { RichStruct, RichValue } 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'
5
+ import { BigDecimal } from '@sentio/bigdecimal'
5
6
 
6
- export type ID = string | Uint8Array
7
+ export type ID = string | Uint8Array | Int8
7
8
  export type String = string
8
9
  export type Int = number
9
10
  export type Int8 = bigint
@@ -13,6 +14,34 @@ export type Timestamp = Date
13
14
  export type Bytes = Uint8Array
14
15
  export type BigInt = bigint
15
16
 
17
+ export type ValueType = String | Int | Int8 | Float | Boolean | Timestamp | Bytes | BigInt | BigDecimal | null
18
+
19
+ export abstract class UpdateOp<T> {}
20
+
21
+ export class AddOp<T> extends UpdateOp<T> {
22
+ constructor(readonly value: T) {
23
+ super()
24
+ }
25
+ }
26
+
27
+ export class MultiplyOp<T> extends UpdateOp<T> {
28
+ constructor(readonly value: T) {
29
+ super()
30
+ }
31
+ }
32
+
33
+ export type UpdateValues<T> = {
34
+ [K in keyof T]?: T[K] | UpdateOp<T[K]>
35
+ } & { id: ID }
36
+
37
+ export function add<K extends ValueType>(value: K): UpdateOp<K> {
38
+ return new AddOp<K>(value)
39
+ }
40
+
41
+ export function multiply<K extends ValueType>(value: K): UpdateOp<K> {
42
+ return new MultiplyOp<K>(value)
43
+ }
44
+
16
45
  export abstract class AbstractEntity {
17
46
  abstract id: ID
18
47
  private readonly _data: RichStruct
@@ -36,6 +36,7 @@ import {
36
36
  } from "@typemove/sui";
37
37
 
38
38
  import { CallFilter, MoveFetchConfig, EventFilter } from "@sentio/sdk/move";
39
+ import { HandlerOptions } from "@sentio/sdk";
39
40
  import {
40
41
  SuiBindOptions,
41
42
  SuiBaseProcessor,
@@ -722,13 +723,16 @@ export class bit_vector extends SuiBaseProcessor {
722
723
 
723
724
  onEventBitVector(
724
725
  func: (event: bit_vector.BitVectorInstance, ctx: SuiContext) => void,
725
- fetchConfig?: Partial<MoveFetchConfig>,
726
+ handlerOptions?: HandlerOptions<
727
+ MoveFetchConfig,
728
+ bit_vector.BitVectorInstance
729
+ >,
726
730
  eventFilter?: Omit<EventFilter, "type" | "account">,
727
731
  ): bit_vector {
728
732
  this.onMoveEvent(
729
733
  func,
730
734
  { ...(eventFilter ?? {}), type: "bit_vector::BitVector" },
731
- fetchConfig,
735
+ handlerOptions,
732
736
  );
733
737
  return this;
734
738
  }
@@ -1066,13 +1070,16 @@ export class fixed_point32 extends SuiBaseProcessor {
1066
1070
 
1067
1071
  onEventFixedPoint32(
1068
1072
  func: (event: fixed_point32.FixedPoint32Instance, ctx: SuiContext) => void,
1069
- fetchConfig?: Partial<MoveFetchConfig>,
1073
+ handlerOptions?: HandlerOptions<
1074
+ MoveFetchConfig,
1075
+ fixed_point32.FixedPoint32Instance
1076
+ >,
1070
1077
  eventFilter?: Omit<EventFilter, "type" | "account">,
1071
1078
  ): fixed_point32 {
1072
1079
  this.onMoveEvent(
1073
1080
  func,
1074
1081
  { ...(eventFilter ?? {}), type: "fixed_point32::FixedPoint32" },
1075
- fetchConfig,
1082
+ handlerOptions,
1076
1083
  );
1077
1084
  return this;
1078
1085
  }
@@ -2003,13 +2010,13 @@ export class string$ extends SuiBaseProcessor {
2003
2010
 
2004
2011
  onEventString(
2005
2012
  func: (event: string$.StringInstance, ctx: SuiContext) => void,
2006
- fetchConfig?: Partial<MoveFetchConfig>,
2013
+ handlerOptions?: HandlerOptions<MoveFetchConfig, string$.StringInstance>,
2007
2014
  eventFilter?: Omit<EventFilter, "type" | "account">,
2008
2015
  ): string$ {
2009
2016
  this.onMoveEvent(
2010
2017
  func,
2011
2018
  { ...(eventFilter ?? {}), type: "string::String" },
2012
- fetchConfig,
2019
+ handlerOptions,
2013
2020
  );
2014
2021
  return this;
2015
2022
  }
@@ -2509,13 +2516,16 @@ export class type_name extends SuiBaseProcessor {
2509
2516
 
2510
2517
  onEventTypeName(
2511
2518
  func: (event: type_name.TypeNameInstance, ctx: SuiContext) => void,
2512
- fetchConfig?: Partial<MoveFetchConfig>,
2519
+ handlerOptions?: HandlerOptions<
2520
+ MoveFetchConfig,
2521
+ type_name.TypeNameInstance
2522
+ >,
2513
2523
  eventFilter?: Omit<EventFilter, "type" | "account">,
2514
2524
  ): type_name {
2515
2525
  this.onMoveEvent(
2516
2526
  func,
2517
2527
  { ...(eventFilter ?? {}), type: "type_name::TypeName" },
2518
- fetchConfig,
2528
+ handlerOptions,
2519
2529
  );
2520
2530
  return this;
2521
2531
  }
@@ -4578,13 +4588,13 @@ export class uq32_32 extends SuiBaseProcessor {
4578
4588
 
4579
4589
  onEventUQ32_32(
4580
4590
  func: (event: uq32_32.UQ32_32Instance, ctx: SuiContext) => void,
4581
- fetchConfig?: Partial<MoveFetchConfig>,
4591
+ handlerOptions?: HandlerOptions<MoveFetchConfig, uq32_32.UQ32_32Instance>,
4582
4592
  eventFilter?: Omit<EventFilter, "type" | "account">,
4583
4593
  ): uq32_32 {
4584
4594
  this.onMoveEvent(
4585
4595
  func,
4586
4596
  { ...(eventFilter ?? {}), type: "uq32_32::UQ32_32" },
4587
- fetchConfig,
4597
+ handlerOptions,
4588
4598
  );
4589
4599
  return this;
4590
4600
  }
@@ -5092,13 +5102,13 @@ export class uq64_64 extends SuiBaseProcessor {
5092
5102
 
5093
5103
  onEventUQ64_64(
5094
5104
  func: (event: uq64_64.UQ64_64Instance, ctx: SuiContext) => void,
5095
- fetchConfig?: Partial<MoveFetchConfig>,
5105
+ handlerOptions?: HandlerOptions<MoveFetchConfig, uq64_64.UQ64_64Instance>,
5096
5106
  eventFilter?: Omit<EventFilter, "type" | "account">,
5097
5107
  ): uq64_64 {
5098
5108
  this.onMoveEvent(
5099
5109
  func,
5100
5110
  { ...(eventFilter ?? {}), type: "uq64_64::UQ64_64" },
5101
- fetchConfig,
5111
+ handlerOptions,
5102
5112
  );
5103
5113
  return this;
5104
5114
  }