@sentio/sdk 2.59.0-rc.2 → 2.59.0-rc.20

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 (144) 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.map +1 -1
  6. package/lib/aptos/aptos-plugin.js +11 -5
  7. package/lib/aptos/aptos-plugin.js.map +1 -1
  8. package/lib/aptos/aptos-processor.d.ts +1 -0
  9. package/lib/aptos/aptos-processor.d.ts.map +1 -1
  10. package/lib/aptos/aptos-processor.js +1 -0
  11. package/lib/aptos/aptos-processor.js.map +1 -1
  12. package/lib/aptos/builtin/0x1.d.ts +485 -0
  13. package/lib/aptos/builtin/0x1.d.ts.map +1 -1
  14. package/lib/aptos/builtin/0x1.js +824 -1
  15. package/lib/aptos/builtin/0x1.js.map +1 -1
  16. package/lib/aptos/builtin/0x3.d.ts.map +1 -1
  17. package/lib/aptos/builtin/0x3.js +1 -1
  18. package/lib/aptos/builtin/0x3.js.map +1 -1
  19. package/lib/aptos/builtin/0x4.d.ts.map +1 -1
  20. package/lib/aptos/builtin/0x4.js +1 -1
  21. package/lib/aptos/builtin/0x4.js.map +1 -1
  22. package/lib/aptos/codegen/codegen.js +7 -7
  23. package/lib/aptos/codegen/codegen.js.map +1 -1
  24. package/lib/aptos/move-coder.d.ts +8 -2
  25. package/lib/aptos/move-coder.d.ts.map +1 -1
  26. package/lib/aptos/move-coder.js +84 -1
  27. package/lib/aptos/move-coder.js.map +1 -1
  28. package/lib/aptos/network.d.ts +1 -0
  29. package/lib/aptos/network.d.ts.map +1 -1
  30. package/lib/aptos/network.js +1 -0
  31. package/lib/aptos/network.js.map +1 -1
  32. package/lib/core/base-context.d.ts +2 -1
  33. package/lib/core/base-context.d.ts.map +1 -1
  34. package/lib/core/base-context.js +5 -2
  35. package/lib/core/base-context.js.map +1 -1
  36. package/lib/core/event-logger.d.ts +5 -0
  37. package/lib/core/event-logger.d.ts.map +1 -1
  38. package/lib/core/event-logger.js +36 -1
  39. package/lib/core/event-logger.js.map +1 -1
  40. package/lib/core/meter.d.ts +31 -3
  41. package/lib/core/meter.d.ts.map +1 -1
  42. package/lib/core/meter.js +93 -2
  43. package/lib/core/meter.js.map +1 -1
  44. package/lib/core/numberish.d.ts +2 -1
  45. package/lib/core/numberish.d.ts.map +1 -1
  46. package/lib/core/numberish.js +35 -1
  47. package/lib/core/numberish.js.map +1 -1
  48. package/lib/eth/base-processor.d.ts +3 -3
  49. package/lib/eth/base-processor.d.ts.map +1 -1
  50. package/lib/eth/base-processor.js +22 -8
  51. package/lib/eth/base-processor.js.map +1 -1
  52. package/lib/eth/bind-options.d.ts +6 -0
  53. package/lib/eth/bind-options.d.ts.map +1 -1
  54. package/lib/eth/bind-options.js +2 -0
  55. package/lib/eth/bind-options.js.map +1 -1
  56. package/lib/eth/eth-plugin.d.ts.map +1 -1
  57. package/lib/eth/eth-plugin.js +12 -5
  58. package/lib/eth/eth-plugin.js.map +1 -1
  59. package/lib/fuel/fuel-processor.d.ts.map +1 -1
  60. package/lib/fuel/fuel-processor.js +1 -9
  61. package/lib/fuel/fuel-processor.js.map +1 -1
  62. package/lib/stark/starknet-processor.d.ts.map +1 -1
  63. package/lib/stark/starknet-processor.js +5 -12
  64. package/lib/stark/starknet-processor.js.map +1 -1
  65. package/lib/store/codegen.d.ts.map +1 -1
  66. package/lib/store/codegen.js +36 -2
  67. package/lib/store/codegen.js.map +1 -1
  68. package/lib/store/schema.d.ts.map +1 -1
  69. package/lib/store/schema.js +3 -1
  70. package/lib/store/schema.js.map +1 -1
  71. package/lib/store/store.d.ts +4 -3
  72. package/lib/store/store.d.ts.map +1 -1
  73. package/lib/store/store.js +41 -1
  74. package/lib/store/store.js.map +1 -1
  75. package/lib/store/types.d.ts +20 -1
  76. package/lib/store/types.d.ts.map +1 -1
  77. package/lib/store/types.js +22 -0
  78. package/lib/store/types.js.map +1 -1
  79. package/lib/sui/builtin/0x1.d.ts +4 -0
  80. package/lib/sui/builtin/0x1.d.ts.map +1 -1
  81. package/lib/sui/builtin/0x1.js +1 -1
  82. package/lib/sui/builtin/0x1.js.map +1 -1
  83. package/lib/sui/builtin/0x2.d.ts +63 -0
  84. package/lib/sui/builtin/0x2.d.ts.map +1 -1
  85. package/lib/sui/builtin/0x2.js +279 -1
  86. package/lib/sui/builtin/0x2.js.map +1 -1
  87. package/lib/sui/builtin/0x3.d.ts +41 -14
  88. package/lib/sui/builtin/0x3.d.ts.map +1 -1
  89. package/lib/sui/builtin/0x3.js +128 -10
  90. package/lib/sui/builtin/0x3.js.map +1 -1
  91. package/lib/sui/sui-object-processor-template.js +1 -1
  92. package/lib/sui/sui-object-processor-template.js.map +1 -1
  93. package/lib/sui/sui-object-processor.d.ts +2 -0
  94. package/lib/sui/sui-object-processor.d.ts.map +1 -1
  95. package/lib/sui/sui-object-processor.js +4 -0
  96. package/lib/sui/sui-object-processor.js.map +1 -1
  97. package/lib/sui/sui-plugin.d.ts.map +1 -1
  98. package/lib/sui/sui-plugin.js +9 -4
  99. package/lib/sui/sui-plugin.js.map +1 -1
  100. package/lib/sui/sui-processor.d.ts +1 -0
  101. package/lib/sui/sui-processor.d.ts.map +1 -1
  102. package/lib/sui/sui-processor.js +1 -0
  103. package/lib/sui/sui-processor.js.map +1 -1
  104. package/lib/utils/block.d.ts +2 -0
  105. package/lib/utils/block.d.ts.map +1 -1
  106. package/lib/utils/block.js +13 -0
  107. package/lib/utils/block.js.map +1 -1
  108. package/package.json +9 -8
  109. package/src/aptos/abis/0x1.json +9650 -5284
  110. package/src/aptos/abis/0x3.json +13 -13
  111. package/src/aptos/abis/0x4.json +42 -42
  112. package/src/aptos/api.ts +13 -1
  113. package/src/aptos/aptos-plugin.ts +11 -5
  114. package/src/aptos/aptos-processor.ts +2 -0
  115. package/src/aptos/builtin/0x1.ts +1566 -67
  116. package/src/aptos/builtin/0x3.ts +2 -1
  117. package/src/aptos/builtin/0x4.ts +2 -1
  118. package/src/aptos/codegen/codegen.ts +9 -7
  119. package/src/aptos/move-coder.ts +96 -3
  120. package/src/aptos/network.ts +1 -0
  121. package/src/core/base-context.ts +5 -2
  122. package/src/core/event-logger.ts +45 -1
  123. package/src/core/meter.ts +120 -5
  124. package/src/core/numberish.ts +34 -1
  125. package/src/eth/base-processor.ts +23 -9
  126. package/src/eth/bind-options.ts +7 -0
  127. package/src/eth/eth-plugin.ts +22 -5
  128. package/src/fuel/fuel-processor.ts +1 -9
  129. package/src/stark/starknet-processor.ts +4 -12
  130. package/src/store/codegen.ts +50 -2
  131. package/src/store/schema.ts +3 -1
  132. package/src/store/store.ts +57 -4
  133. package/src/store/types.ts +30 -1
  134. package/src/sui/abis/0x1.json +8 -0
  135. package/src/sui/abis/0x2.json +437 -0
  136. package/src/sui/abis/0x3.json +116 -5
  137. package/src/sui/builtin/0x1.ts +6 -1
  138. package/src/sui/builtin/0x2.ts +413 -1
  139. package/src/sui/builtin/0x3.ts +211 -22
  140. package/src/sui/sui-object-processor-template.ts +1 -1
  141. package/src/sui/sui-object-processor.ts +6 -0
  142. package/src/sui/sui-plugin.ts +9 -4
  143. package/src/sui/sui-processor.ts +2 -0
  144. 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
@@ -690,6 +690,14 @@
690
690
  }
691
691
  }
692
692
  },
693
+ "bool": {
694
+ "fileFormatVersion": 6,
695
+ "address": "0x1",
696
+ "name": "bool",
697
+ "friends": [],
698
+ "structs": {},
699
+ "exposedFunctions": {}
700
+ },
693
701
  "debug": {
694
702
  "fileFormatVersion": 6,
695
703
  "address": "0x1",