@sentio/sdk 2.40.0 → 2.40.1-rc.10
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.
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +71 -115
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc1155-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc1155-processor.js +26 -40
- package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc20-processor.js +56 -88
- package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20bytes-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc20bytes-processor.js +29 -43
- package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc721-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc721-processor.js +44 -68
- package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
- package/lib/eth/builtin/internal/weth9-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/weth9-processor.js +35 -53
- package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
- package/lib/eth/codegen/file.d.ts.map +1 -1
- package/lib/eth/codegen/file.js +5 -1
- package/lib/eth/codegen/file.js.map +1 -1
- package/lib/eth/codegen/function-calls.d.ts +1 -0
- package/lib/eth/codegen/function-calls.d.ts.map +1 -1
- package/lib/eth/codegen/function-calls.js +5 -3
- package/lib/eth/codegen/function-calls.js.map +1 -1
- package/lib/eth/codegen/types.d.ts.map +1 -1
- package/lib/eth/codegen/types.js +23 -6
- package/lib/eth/codegen/types.js.map +1 -1
- package/lib/store/cache.d.ts +0 -3
- package/lib/store/cache.d.ts.map +1 -1
- package/lib/store/cache.js.map +1 -1
- package/lib/store/codegen.d.ts.map +1 -1
- package/lib/store/codegen.js +51 -34
- package/lib/store/codegen.js.map +1 -1
- package/lib/store/store.d.ts +3 -3
- package/lib/store/store.d.ts.map +1 -1
- package/lib/store/store.js +2 -2
- package/lib/store/store.js.map +1 -1
- package/lib/store/types.d.ts +6 -0
- package/lib/store/types.d.ts.map +1 -1
- package/lib/store/types.js +49 -1
- package/lib/store/types.js.map +1 -1
- package/package.json +5 -8
- package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +72 -115
- package/src/eth/builtin/internal/erc1155-processor.ts +27 -40
- package/src/eth/builtin/internal/erc20-processor.ts +57 -88
- package/src/eth/builtin/internal/erc20bytes-processor.ts +30 -43
- package/src/eth/builtin/internal/erc721-processor.ts +45 -68
- package/src/eth/builtin/internal/weth9-processor.ts +36 -53
- package/src/eth/codegen/file.ts +5 -0
- package/src/eth/codegen/function-calls.ts +6 -3
- package/src/eth/codegen/types.ts +32 -7
- package/src/store/cache.ts +0 -4
- package/src/store/codegen.ts +53 -34
- package/src/store/store.ts +5 -5
- package/src/store/types.ts +57 -0
package/src/store/codegen.ts
CHANGED
@@ -34,6 +34,7 @@ interface Class {
|
|
34
34
|
name: string
|
35
35
|
fields: Field[]
|
36
36
|
annotations: string[]
|
37
|
+
parent?: string
|
37
38
|
interfaces: string[]
|
38
39
|
}
|
39
40
|
|
@@ -98,7 +99,7 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
|
|
98
99
|
},
|
99
100
|
{
|
100
101
|
module: '@sentio/sdk/store',
|
101
|
-
types: ['Entity', 'Required', 'One', 'Many', 'Column', 'ListColumn']
|
102
|
+
types: ['Entity', 'Required', 'One', 'Many', 'Column', 'ListColumn', 'AbstractEntity']
|
102
103
|
},
|
103
104
|
{
|
104
105
|
module: '@sentio/bigdecimal',
|
@@ -134,44 +135,60 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
|
|
134
135
|
})
|
135
136
|
}
|
136
137
|
}
|
138
|
+
|
137
139
|
for (const t of Object.values(schema.getTypeMap())) {
|
138
140
|
if (t.name.startsWith('__')) {
|
139
141
|
continue
|
140
142
|
}
|
141
143
|
|
142
144
|
if (t instanceof GraphQLObjectType) {
|
143
|
-
|
144
|
-
|
145
|
-
const
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
145
|
+
if (isEntity(t)) {
|
146
|
+
const fields: Field[] = []
|
147
|
+
for (const f of Object.values(t.getFields())) {
|
148
|
+
const type = genType(f.type)
|
149
|
+
const annotations: string[] = []
|
150
|
+
addTypeAnnotations(f.type, annotations)
|
151
|
+
if (isRelationType(f.type)) {
|
152
|
+
fields.push({
|
153
|
+
name: f.name,
|
154
|
+
type: `Promise<${type}>`,
|
155
|
+
annotations
|
156
|
+
})
|
157
|
+
const isMany = type.startsWith('Array')
|
158
|
+
fields.push({
|
159
|
+
name: f.name + 'ID' + (isMany ? 's' : ''),
|
160
|
+
type: isMany ? `Array<ID | undefined>` : `ID`,
|
161
|
+
annotations: []
|
162
|
+
})
|
163
|
+
} else {
|
164
|
+
fields.push({
|
165
|
+
name: f.name,
|
166
|
+
optional: !f.type.toString().endsWith('!'),
|
167
|
+
type: type.replace(' | undefined', ''),
|
168
|
+
annotations
|
169
|
+
})
|
170
|
+
}
|
171
|
+
}
|
172
|
+
classes.push({
|
173
|
+
name: t.name,
|
174
|
+
fields,
|
175
|
+
annotations: [`@Entity("${t.name}")`],
|
176
|
+
parent: 'AbstractEntity',
|
177
|
+
interfaces: t.getInterfaces().map((i) => i.name)
|
178
|
+
})
|
179
|
+
} else {
|
180
|
+
classes.push({
|
181
|
+
name: t.name,
|
182
|
+
fields: Object.values(t.getFields()).map((f) => ({
|
162
183
|
name: f.name,
|
163
184
|
optional: !f.type.toString().endsWith('!'),
|
164
|
-
type: type.replace(' | undefined', ''),
|
165
|
-
annotations
|
166
|
-
})
|
167
|
-
|
185
|
+
type: genType(f.type).replace(' | undefined', ''),
|
186
|
+
annotations: []
|
187
|
+
})),
|
188
|
+
annotations: [],
|
189
|
+
interfaces: t.getInterfaces().map((i) => i.name)
|
190
|
+
})
|
168
191
|
}
|
169
|
-
classes.push({
|
170
|
-
name: t.name,
|
171
|
-
fields,
|
172
|
-
annotations: [`@Entity("${t.name}")`],
|
173
|
-
interfaces: t.getInterfaces().map((i) => i.name)
|
174
|
-
})
|
175
192
|
}
|
176
193
|
}
|
177
194
|
|
@@ -201,13 +218,11 @@ ${classes
|
|
201
218
|
.map(
|
202
219
|
(c) => `
|
203
220
|
${c.annotations.join('\n')}
|
204
|
-
export class ${c.name} ${c.interfaces.length > 0 ? `implements ${c.interfaces.join(', ')}` : ''} {
|
221
|
+
export class ${c.name} ${c.parent ? `extends ${c.parent}` : ''} ${c.interfaces.length > 0 ? `implements ${c.interfaces.join(', ')}` : ''} {
|
205
222
|
${c.fields
|
206
223
|
.map((f) => `${f.annotations.map((a) => `\n\t${a}`).join('')}\n\t${f.name}${f.optional ? '?' : ''}: ${f.type}`)
|
207
224
|
.join('\n')}
|
208
|
-
|
209
|
-
constructor(data: Partial<${c.name}>) {}
|
210
|
-
|
225
|
+
${c.annotations.some((a) => a.startsWith('@Entity')) ? `constructor(data: Partial<${c.name}>) {super()}` : ''}
|
211
226
|
}`
|
212
227
|
)
|
213
228
|
.join('\n')}
|
@@ -256,3 +271,7 @@ function isRelationType(type: GraphQLOutputType): boolean {
|
|
256
271
|
return false
|
257
272
|
}
|
258
273
|
}
|
274
|
+
|
275
|
+
function isEntity(t: GraphQLObjectType) {
|
276
|
+
return t.astNode?.directives?.some((d) => d.name.value == 'entity')
|
277
|
+
}
|
package/src/store/store.ts
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
import { StoreContext } from './context.js'
|
2
2
|
import { DatabaseSchema } from '../core/index.js'
|
3
3
|
import { BigDecimal } from '@sentio/bigdecimal'
|
4
|
-
import { Bytes, Float, ID, Int, Timestamp } from './types.js'
|
4
|
+
import { AbstractEntity as Entity, Bytes, Float, ID, Int, Timestamp } from './types.js'
|
5
5
|
import type { DBRequest, Entity as EntityStruct, RichValue } from '@sentio/protos'
|
6
6
|
import { DBRequest_DBOperator, DBResponse } from '@sentio/protos'
|
7
7
|
import { toBigInteger } from './convert.js'
|
8
8
|
import { PluginManager } from '@sentio/runtime'
|
9
9
|
import { Cursor } from './cursor.js'
|
10
|
-
import {
|
10
|
+
import { LocalCache } from './cache.js'
|
11
11
|
|
12
12
|
export interface EntityClass<T> {
|
13
13
|
new (data: Partial<T>): T
|
14
14
|
}
|
15
15
|
|
16
|
-
function getEntityName<T>(entity: EntityClass<T> | T | string): string {
|
16
|
+
export function getEntityName<T>(entity: EntityClass<T> | T | string): string {
|
17
17
|
if (entity == null) {
|
18
18
|
throw new Error("can't figure out entityName from undefined")
|
19
19
|
}
|
@@ -182,7 +182,7 @@ export class Store {
|
|
182
182
|
|
183
183
|
async list<T extends Entity, P extends keyof T, O extends Operators<T[P]>>(
|
184
184
|
entity: EntityClass<T>,
|
185
|
-
filters
|
185
|
+
filters?: ListFilter<T, P, O>[],
|
186
186
|
cursor?: Cursor
|
187
187
|
) {
|
188
188
|
if (cursor) {
|
@@ -191,7 +191,7 @@ export class Store {
|
|
191
191
|
return response.entityList?.entities.map((data) => this.newEntity(entity, data)) || []
|
192
192
|
}
|
193
193
|
// TODO Array.fromAsync when upgrade to node 22
|
194
|
-
return this.fromAsync(this.listIterator(entity, filters))
|
194
|
+
return this.fromAsync(this.listIterator(entity, filters ?? []))
|
195
195
|
}
|
196
196
|
|
197
197
|
private async fromAsync<T>(gen: AsyncIterable<T>): Promise<T[]> {
|
package/src/store/types.ts
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
import { RichStruct, RichValue } from '@sentio/protos'
|
2
|
+
import { BigDecimalConverter, BigIntConverter } from './convert.js'
|
3
|
+
import { getEntityName } from './store.js'
|
4
|
+
|
1
5
|
export type ID = string | Uint8Array
|
2
6
|
export type String = string
|
3
7
|
export type Int = number
|
@@ -6,3 +10,56 @@ export type Boolean = boolean
|
|
6
10
|
export type Timestamp = Date
|
7
11
|
export type Bytes = Uint8Array
|
8
12
|
export type BigInt = bigint
|
13
|
+
|
14
|
+
export abstract class AbstractEntity {
|
15
|
+
abstract id: ID
|
16
|
+
private readonly _data: RichStruct
|
17
|
+
|
18
|
+
toJSON() {
|
19
|
+
const obj: any = {}
|
20
|
+
|
21
|
+
for (const [field, value] of Object.entries(this._data.fields)) {
|
22
|
+
obj[field] = toJSValue(value)
|
23
|
+
}
|
24
|
+
return obj
|
25
|
+
}
|
26
|
+
|
27
|
+
toString() {
|
28
|
+
const obj = this.toJSON()
|
29
|
+
return `${getEntityName(this)} ${JSON.stringify(obj)}`
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
function toJSValue(value: RichValue): any {
|
34
|
+
if (value.nullValue) {
|
35
|
+
return null
|
36
|
+
}
|
37
|
+
if (value.bytesValue) {
|
38
|
+
return value.bytesValue
|
39
|
+
}
|
40
|
+
if (value.stringValue) {
|
41
|
+
return value.stringValue
|
42
|
+
}
|
43
|
+
if (value.bigdecimalValue) {
|
44
|
+
return BigDecimalConverter.to(value)
|
45
|
+
}
|
46
|
+
if (value.bigintValue) {
|
47
|
+
return BigIntConverter.to(value)
|
48
|
+
}
|
49
|
+
if (value.boolValue) {
|
50
|
+
return value.boolValue
|
51
|
+
}
|
52
|
+
if (value.timestampValue) {
|
53
|
+
return value.timestampValue
|
54
|
+
}
|
55
|
+
if (value.floatValue) {
|
56
|
+
return value.floatValue
|
57
|
+
}
|
58
|
+
if (value.intValue) {
|
59
|
+
return value.intValue
|
60
|
+
}
|
61
|
+
if (value.listValue) {
|
62
|
+
return value.listValue.values.map(toJSValue)
|
63
|
+
}
|
64
|
+
throw new Error('Unknown value type:' + JSON.stringify(value))
|
65
|
+
}
|