@sentio/sdk 2.59.0-rc.9 → 2.59.0
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/aptos/api.d.ts +1 -0
- package/lib/aptos/api.d.ts.map +1 -1
- package/lib/aptos/api.js +13 -1
- package/lib/aptos/api.js.map +1 -1
- package/lib/aptos/aptos-plugin.d.ts +8 -4
- package/lib/aptos/aptos-plugin.d.ts.map +1 -1
- package/lib/aptos/aptos-plugin.js +40 -3
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/aptos/aptos-processor.d.ts +20 -19
- package/lib/aptos/aptos-processor.d.ts.map +1 -1
- package/lib/aptos/aptos-processor.js +101 -50
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/aptos-resource-processor-template.d.ts +5 -4
- package/lib/aptos/aptos-resource-processor-template.d.ts.map +1 -1
- package/lib/aptos/aptos-resource-processor-template.js +8 -8
- package/lib/aptos/aptos-resource-processor-template.js.map +1 -1
- package/lib/aptos/builtin/0x1.d.ts +333 -332
- package/lib/aptos/builtin/0x1.d.ts.map +1 -1
- package/lib/aptos/builtin/0x1.js +664 -664
- package/lib/aptos/builtin/0x1.js.map +1 -1
- package/lib/aptos/builtin/0x3.d.ts +66 -65
- package/lib/aptos/builtin/0x3.d.ts.map +1 -1
- package/lib/aptos/builtin/0x3.js +130 -130
- package/lib/aptos/builtin/0x3.js.map +1 -1
- package/lib/aptos/builtin/0x4.d.ts +29 -28
- package/lib/aptos/builtin/0x4.d.ts.map +1 -1
- package/lib/aptos/builtin/0x4.js +56 -56
- package/lib/aptos/builtin/0x4.js.map +1 -1
- package/lib/aptos/codegen/codegen.js +27 -0
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/aptos/data.d.ts +45 -0
- package/lib/aptos/data.d.ts.map +1 -0
- package/lib/aptos/data.js +99 -0
- package/lib/aptos/data.js.map +1 -0
- package/lib/aptos/index.d.ts +1 -0
- package/lib/aptos/index.d.ts.map +1 -1
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/models.d.ts +1 -0
- package/lib/aptos/models.d.ts.map +1 -1
- package/lib/aptos/move-coder.d.ts +8 -2
- package/lib/aptos/move-coder.d.ts.map +1 -1
- package/lib/aptos/move-coder.js +84 -1
- package/lib/aptos/move-coder.js.map +1 -1
- package/lib/btc/btc-plugin.d.ts +4 -1
- package/lib/btc/btc-plugin.d.ts.map +1 -1
- package/lib/btc/btc-plugin.js +27 -0
- package/lib/btc/btc-plugin.js.map +1 -1
- package/lib/btc/btc-processor.d.ts +6 -5
- package/lib/btc/btc-processor.d.ts.map +1 -1
- package/lib/btc/btc-processor.js +35 -9
- package/lib/btc/btc-processor.js.map +1 -1
- package/lib/btc/types.d.ts +2 -1
- package/lib/btc/types.d.ts.map +1 -1
- package/lib/core/base-context.d.ts +4 -2
- package/lib/core/base-context.d.ts.map +1 -1
- package/lib/core/base-context.js +10 -5
- package/lib/core/base-context.js.map +1 -1
- package/lib/core/event-logger.d.ts +5 -0
- package/lib/core/event-logger.d.ts.map +1 -1
- package/lib/core/event-logger.js +36 -1
- package/lib/core/event-logger.js.map +1 -1
- package/lib/core/handler-options.d.ts +25 -0
- package/lib/core/handler-options.d.ts.map +1 -0
- package/lib/core/handler-options.js +21 -0
- package/lib/core/handler-options.js.map +1 -0
- package/lib/core/index.d.ts +3 -1
- package/lib/core/index.d.ts.map +1 -1
- package/lib/core/index.js +3 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/meter.d.ts +45 -2
- package/lib/core/meter.d.ts.map +1 -1
- package/lib/core/meter.js +124 -2
- package/lib/core/meter.js.map +1 -1
- package/lib/core/numberish.d.ts +2 -1
- package/lib/core/numberish.d.ts.map +1 -1
- package/lib/core/numberish.js +35 -1
- package/lib/core/numberish.js.map +1 -1
- package/lib/core/partition-handler-manager.d.ts +44 -0
- package/lib/core/partition-handler-manager.d.ts.map +1 -0
- package/lib/core/partition-handler-manager.js +76 -0
- package/lib/core/partition-handler-manager.js.map +1 -0
- package/lib/cosmos/cosmos-processor.d.ts +3 -2
- package/lib/cosmos/cosmos-processor.d.ts.map +1 -1
- package/lib/cosmos/cosmos-processor.js +11 -1
- package/lib/cosmos/cosmos-processor.js.map +1 -1
- package/lib/cosmos/types.d.ts +1 -0
- package/lib/cosmos/types.d.ts.map +1 -1
- package/lib/eth/base-processor.d.ts +18 -13
- package/lib/eth/base-processor.d.ts.map +1 -1
- package/lib/eth/base-processor.js +151 -26
- package/lib/eth/base-processor.js.map +1 -1
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts +32 -31
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +62 -62
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc1155-processor.d.ts +17 -16
- package/lib/eth/builtin/internal/erc1155-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc1155-processor.js +32 -32
- package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20-processor.d.ts +25 -24
- package/lib/eth/builtin/internal/erc20-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc20-processor.js +48 -48
- package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20bytes-processor.d.ts +14 -13
- package/lib/eth/builtin/internal/erc20bytes-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc20bytes-processor.js +26 -26
- package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc721-processor.d.ts +21 -20
- package/lib/eth/builtin/internal/erc721-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc721-processor.js +40 -40
- package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
- package/lib/eth/builtin/internal/weth9-processor.d.ts +20 -19
- package/lib/eth/builtin/internal/weth9-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/weth9-processor.js +38 -38
- package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
- package/lib/eth/codegen/event-handler.js +2 -2
- package/lib/eth/codegen/event-handler.js.map +1 -1
- package/lib/eth/codegen/file.d.ts.map +1 -1
- package/lib/eth/codegen/file.js +1 -0
- package/lib/eth/codegen/file.js.map +1 -1
- package/lib/eth/codegen/functions-handler.js +2 -2
- package/lib/eth/codegen/functions-handler.js.map +1 -1
- package/lib/eth/eth-plugin.d.ts +4 -1
- package/lib/eth/eth-plugin.d.ts.map +1 -1
- package/lib/eth/eth-plugin.js +42 -1
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/eth/eth.d.ts +2 -7
- package/lib/eth/eth.d.ts.map +1 -1
- package/lib/eth/eth.js +8 -1
- package/lib/eth/eth.js.map +1 -1
- package/lib/fuel/codegen/codegen.js +5 -5
- package/lib/fuel/codegen/codegen.js.map +1 -1
- package/lib/fuel/fuel-plugin.d.ts +4 -1
- package/lib/fuel/fuel-plugin.d.ts.map +1 -1
- package/lib/fuel/fuel-plugin.js +41 -0
- package/lib/fuel/fuel-plugin.js.map +1 -1
- package/lib/fuel/fuel-processor-template.d.ts +7 -4
- package/lib/fuel/fuel-processor-template.d.ts.map +1 -1
- package/lib/fuel/fuel-processor-template.js +11 -9
- package/lib/fuel/fuel-processor-template.js.map +1 -1
- package/lib/fuel/fuel-processor.d.ts +7 -7
- package/lib/fuel/fuel-processor.d.ts.map +1 -1
- package/lib/fuel/fuel-processor.js +91 -28
- package/lib/fuel/fuel-processor.js.map +1 -1
- package/lib/fuel/types.d.ts +3 -0
- package/lib/fuel/types.d.ts.map +1 -1
- package/lib/move/filter.d.ts +5 -0
- package/lib/move/filter.d.ts.map +1 -1
- package/lib/move/filter.js +5 -0
- package/lib/move/filter.js.map +1 -1
- package/lib/move/shared-network-codegen.d.ts.map +1 -1
- package/lib/move/shared-network-codegen.js +5 -4
- package/lib/move/shared-network-codegen.js.map +1 -1
- package/lib/solana/solana-processor.d.ts +10 -4
- package/lib/solana/solana-processor.d.ts.map +1 -1
- package/lib/solana/solana-processor.js +13 -4
- package/lib/solana/solana-processor.js.map +1 -1
- package/lib/stark/starknet-processor.d.ts +3 -1
- package/lib/stark/starknet-processor.d.ts.map +1 -1
- package/lib/stark/starknet-processor.js +32 -14
- package/lib/stark/starknet-processor.js.map +1 -1
- package/lib/store/codegen.d.ts.map +1 -1
- package/lib/store/codegen.js +36 -2
- package/lib/store/codegen.js.map +1 -1
- package/lib/store/schema.d.ts.map +1 -1
- package/lib/store/schema.js +3 -1
- package/lib/store/schema.js.map +1 -1
- package/lib/store/store.d.ts +4 -3
- package/lib/store/store.d.ts.map +1 -1
- package/lib/store/store.js +41 -1
- package/lib/store/store.js.map +1 -1
- package/lib/store/types.d.ts +20 -1
- package/lib/store/types.d.ts.map +1 -1
- package/lib/store/types.js +22 -0
- package/lib/store/types.js.map +1 -1
- package/lib/sui/builtin/0x1.d.ts +7 -6
- package/lib/sui/builtin/0x1.d.ts.map +1 -1
- package/lib/sui/builtin/0x1.js +12 -12
- package/lib/sui/builtin/0x1.js.map +1 -1
- package/lib/sui/builtin/0x2.d.ts +61 -60
- package/lib/sui/builtin/0x2.d.ts.map +1 -1
- package/lib/sui/builtin/0x2.js +120 -120
- package/lib/sui/builtin/0x2.js.map +1 -1
- package/lib/sui/builtin/0x3.d.ts +49 -48
- package/lib/sui/builtin/0x3.d.ts.map +1 -1
- package/lib/sui/builtin/0x3.js +96 -96
- package/lib/sui/builtin/0x3.js.map +1 -1
- package/lib/sui/models.d.ts +1 -0
- package/lib/sui/models.d.ts.map +1 -1
- package/lib/sui/sui-plugin.d.ts +6 -3
- package/lib/sui/sui-plugin.d.ts.map +1 -1
- package/lib/sui/sui-plugin.js +59 -20
- package/lib/sui/sui-plugin.js.map +1 -1
- package/lib/sui/sui-processor.d.ts +5 -4
- package/lib/sui/sui-processor.d.ts.map +1 -1
- package/lib/sui/sui-processor.js +47 -11
- package/lib/sui/sui-processor.js.map +1 -1
- package/package.json +4 -4
- package/src/aptos/api.ts +13 -1
- package/src/aptos/aptos-plugin.ts +51 -8
- package/src/aptos/aptos-processor.ts +112 -74
- package/src/aptos/aptos-resource-processor-template.ts +9 -8
- package/src/aptos/builtin/0x1.ts +1565 -664
- package/src/aptos/builtin/0x3.ts +302 -130
- package/src/aptos/builtin/0x4.ts +123 -56
- package/src/aptos/codegen/codegen.ts +34 -1
- package/src/aptos/data.ts +123 -0
- package/src/aptos/index.ts +2 -0
- package/src/aptos/models.ts +2 -0
- package/src/aptos/move-coder.ts +96 -3
- package/src/btc/btc-plugin.ts +38 -0
- package/src/btc/btc-processor.ts +35 -10
- package/src/btc/types.ts +2 -1
- package/src/core/base-context.ts +10 -5
- package/src/core/event-logger.ts +45 -1
- package/src/core/handler-options.ts +40 -0
- package/src/core/index.ts +17 -1
- package/src/core/meter.ts +159 -4
- package/src/core/numberish.ts +34 -1
- package/src/core/partition-handler-manager.ts +94 -0
- package/src/cosmos/cosmos-processor.ts +12 -1
- package/src/cosmos/types.ts +1 -0
- package/src/eth/base-processor.ts +139 -28
- package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +118 -62
- package/src/eth/builtin/internal/erc1155-processor.ts +76 -32
- package/src/eth/builtin/internal/erc20-processor.ts +79 -48
- package/src/eth/builtin/internal/erc20bytes-processor.ts +47 -26
- package/src/eth/builtin/internal/erc721-processor.ts +77 -40
- package/src/eth/builtin/internal/weth9-processor.ts +79 -38
- package/src/eth/codegen/event-handler.ts +2 -2
- package/src/eth/codegen/file.ts +1 -0
- package/src/eth/codegen/functions-handler.ts +2 -2
- package/src/eth/eth-plugin.ts +55 -3
- package/src/eth/eth.ts +12 -1
- package/src/fuel/codegen/codegen.ts +5 -5
- package/src/fuel/fuel-plugin.ts +56 -0
- package/src/fuel/fuel-processor-template.ts +17 -10
- package/src/fuel/fuel-processor.ts +90 -22
- package/src/fuel/types.ts +3 -0
- package/src/move/filter.ts +5 -0
- package/src/move/shared-network-codegen.ts +5 -4
- package/src/solana/solana-processor.ts +28 -6
- package/src/stark/starknet-processor.ts +31 -13
- package/src/store/codegen.ts +50 -2
- package/src/store/schema.ts +3 -1
- package/src/store/store.ts +57 -4
- package/src/store/types.ts +30 -1
- package/src/sui/builtin/0x1.ts +22 -12
- package/src/sui/builtin/0x2.ts +220 -120
- package/src/sui/builtin/0x3.ts +241 -96
- package/src/sui/models.ts +2 -0
- package/src/sui/sui-plugin.ts +68 -22
- package/src/sui/sui-processor.ts +48 -11
@@ -8,6 +8,7 @@ import { FuelBlock, FuelLog, FuelTransaction } from './types.js'
|
|
8
8
|
import { DEFAULT_FUEL_FETCH_CONFIG, FuelFetchConfig } from './transaction.js'
|
9
9
|
import { FuelProcessor, FuelProcessorConfig, getOptionsSignature } from './fuel-processor.js'
|
10
10
|
import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
|
11
|
+
import { HandlerOptions } from '../core/index.js'
|
11
12
|
|
12
13
|
export class FuelProcessorTemplateProcessorState extends ListStateStorage<FuelBaseProcessorTemplate<Contract>> {
|
13
14
|
static INSTANCE = new FuelProcessorTemplateProcessorState()
|
@@ -21,6 +22,7 @@ export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
|
|
21
22
|
handler: (block: FuelBlock, ctx: FuelContractContext<TContract>) => PromiseOrVoid
|
22
23
|
blockInterval?: HandleInterval
|
23
24
|
timeIntervalInMinutes?: HandleInterval
|
25
|
+
handlerOptions?: HandlerOptions<object, FuelBlock>
|
24
26
|
// fetchConfig?: FuelFetchConfig
|
25
27
|
}[] = []
|
26
28
|
|
@@ -28,13 +30,14 @@ export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
|
|
28
30
|
logIdFilter: string | string[]
|
29
31
|
handlerName: string
|
30
32
|
handler: (logs: FuelLog<any>, ctx: FuelContractContext<TContract>) => PromiseOrVoid
|
33
|
+
handlerOptions?: HandlerOptions<object, FuelLog<any>>
|
31
34
|
// fetchConfig?: FuelFetchConfig
|
32
35
|
}[] = []
|
33
36
|
|
34
37
|
transactionHandlers: {
|
35
38
|
handlerName: string
|
36
39
|
handler: (transaction: FuelTransaction, ctx: FuelContractContext<TContract>) => PromiseOrVoid
|
37
|
-
|
40
|
+
handlerOptions?: HandlerOptions<FuelFetchConfig, FuelTransaction>
|
38
41
|
}[] = []
|
39
42
|
|
40
43
|
constructor() {
|
@@ -62,13 +65,13 @@ export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
|
|
62
65
|
const processor = this.bindInternal({ ...options, chainId: ctx.chainId })
|
63
66
|
|
64
67
|
for (const eh of this.logHandlers) {
|
65
|
-
processor.onLog(eh.logIdFilter, eh.handler, eh.handlerName)
|
68
|
+
processor.onLog(eh.logIdFilter, eh.handler, eh.handlerOptions, eh.handlerName)
|
66
69
|
}
|
67
70
|
for (const bh of this.blockHandlers) {
|
68
|
-
processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval, bh.handlerName)
|
71
|
+
processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval, bh.handlerOptions, bh.handlerName)
|
69
72
|
}
|
70
73
|
for (const th of this.transactionHandlers) {
|
71
|
-
processor.onTransaction(th.handler,
|
74
|
+
processor.onTransaction(th.handler, th.handlerOptions, th.handlerName)
|
72
75
|
}
|
73
76
|
|
74
77
|
const instance: TemplateInstance = {
|
@@ -94,13 +97,15 @@ export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
|
|
94
97
|
|
95
98
|
protected onLog<T>(
|
96
99
|
logIdFilter: string | string[],
|
97
|
-
handler: (logs: FuelLog<T>, ctx: FuelContractContext<TContract>) => PromiseOrVoid
|
100
|
+
handler: (logs: FuelLog<T>, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
|
101
|
+
handlerOptions: HandlerOptions<object, FuelLog<T>> = {}
|
98
102
|
// fetchConfig?: Partial<FuelFetchConfig>
|
99
103
|
) {
|
100
104
|
this.logHandlers.push({
|
101
105
|
logIdFilter,
|
102
106
|
handlerName: getHandlerName(),
|
103
|
-
handler
|
107
|
+
handler,
|
108
|
+
handlerOptions
|
104
109
|
// fetchConfig: { ...fetchConfig}
|
105
110
|
})
|
106
111
|
return this
|
@@ -140,14 +145,16 @@ export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
|
|
140
145
|
public onInterval(
|
141
146
|
handler: (block: FuelBlock, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
|
142
147
|
timeInterval: HandleInterval | undefined,
|
143
|
-
blockInterval: HandleInterval | undefined
|
148
|
+
blockInterval: HandleInterval | undefined,
|
149
|
+
handlerOptions: HandlerOptions<object, FuelBlock> = {}
|
144
150
|
// fetchConfig?: FuelFetchConfig
|
145
151
|
) {
|
146
152
|
this.blockHandlers.push({
|
147
153
|
handlerName: getHandlerName(),
|
148
154
|
handler,
|
149
155
|
timeIntervalInMinutes: timeInterval,
|
150
|
-
blockInterval
|
156
|
+
blockInterval,
|
157
|
+
handlerOptions
|
151
158
|
// fetchConfig: { ...fetchConfig }
|
152
159
|
})
|
153
160
|
return this
|
@@ -155,12 +162,12 @@ export abstract class FuelBaseProcessorTemplate<TContract extends Contract> {
|
|
155
162
|
|
156
163
|
protected onTransaction(
|
157
164
|
handler: (transaction: FuelTransaction, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
|
158
|
-
|
165
|
+
handlerOptions: HandlerOptions<FuelFetchConfig, FuelTransaction> = DEFAULT_FUEL_FETCH_CONFIG
|
159
166
|
) {
|
160
167
|
this.transactionHandlers.push({
|
161
168
|
handlerName: getHandlerName(),
|
162
169
|
handler,
|
163
|
-
|
170
|
+
handlerOptions
|
164
171
|
})
|
165
172
|
return this
|
166
173
|
}
|
@@ -27,7 +27,7 @@ import {
|
|
27
27
|
FuelTransaction,
|
28
28
|
ReceiptHandler
|
29
29
|
} from './types.js'
|
30
|
-
import { PromiseOrVoid } from '../core/index.js'
|
30
|
+
import { PromiseOrVoid, HandlerOptions } from '../core/index.js'
|
31
31
|
import { ServerError, Status } from 'nice-grpc'
|
32
32
|
import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
|
33
33
|
|
@@ -88,7 +88,7 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
|
|
88
88
|
|
89
89
|
public onTransaction(
|
90
90
|
handler: (transaction: FuelTransaction, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
|
91
|
-
|
91
|
+
handlerOptions?: HandlerOptions<FuelFetchConfig, FuelTransaction>,
|
92
92
|
handlerName = getHandlerName()
|
93
93
|
) {
|
94
94
|
const callHandler = {
|
@@ -115,7 +115,21 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
|
|
115
115
|
},
|
116
116
|
fetchConfig: {
|
117
117
|
filters: [],
|
118
|
-
...
|
118
|
+
...handlerOptions
|
119
|
+
},
|
120
|
+
partitionHandler: async (call: Data_FuelTransaction): Promise<string | undefined> => {
|
121
|
+
const p = handlerOptions?.partitionKey
|
122
|
+
if (!p) return undefined
|
123
|
+
if (typeof p === 'function') {
|
124
|
+
const abiMap = this.config.abi
|
125
|
+
? {
|
126
|
+
[this.config.address]: this.config.abi
|
127
|
+
}
|
128
|
+
: {}
|
129
|
+
const tx = await decodeFuelTransactionWithAbi(call.transaction, abiMap, this.provider)
|
130
|
+
return p(tx)
|
131
|
+
}
|
132
|
+
return p
|
119
133
|
}
|
120
134
|
}
|
121
135
|
this.txHandlers.push(callHandler)
|
@@ -184,15 +198,7 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
|
|
184
198
|
return ctx.stopAndGetResult()
|
185
199
|
} catch (e) {
|
186
200
|
console.error(e)
|
187
|
-
return {
|
188
|
-
gauges: [],
|
189
|
-
counters: [],
|
190
|
-
events: [],
|
191
|
-
exports: [],
|
192
|
-
states: {
|
193
|
-
configUpdated: false
|
194
|
-
}
|
195
|
-
}
|
201
|
+
return ProcessResult.fromPartial({})
|
196
202
|
}
|
197
203
|
},
|
198
204
|
fetchConfig: {
|
@@ -206,6 +212,7 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
|
|
206
212
|
public onLog<T>(
|
207
213
|
logIdFilter: string | string[],
|
208
214
|
handler: (logs: FuelLog<T>, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
|
215
|
+
handlerOptions?: HandlerOptions<object, FuelLog<T>>,
|
209
216
|
handlerName = getHandlerName()
|
210
217
|
) {
|
211
218
|
const logIds = new Set(Array.isArray(logIdFilter) ? logIdFilter : [logIdFilter])
|
@@ -244,6 +251,25 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
|
|
244
251
|
log: {
|
245
252
|
logIds: Array.from(logIds)
|
246
253
|
}
|
254
|
+
},
|
255
|
+
partitionHandler: async (data: Data_FuelReceipt): Promise<string | undefined> => {
|
256
|
+
const p = handlerOptions?.partitionKey
|
257
|
+
if (!p) return undefined
|
258
|
+
if (typeof p === 'function') {
|
259
|
+
try {
|
260
|
+
const tx = await decodeFuelTransaction(data.transaction, this.provider)
|
261
|
+
const index = Number(data.receiptIndex)
|
262
|
+
const receipt = tx.receipts[index]
|
263
|
+
const log = decodeLog(receipt, this.config.abi)
|
264
|
+
if (log) {
|
265
|
+
return p({ receiptIndex: index, ...log })
|
266
|
+
}
|
267
|
+
} catch (e) {
|
268
|
+
console.error(e)
|
269
|
+
}
|
270
|
+
return undefined
|
271
|
+
}
|
272
|
+
return p
|
247
273
|
}
|
248
274
|
} as ReceiptHandler
|
249
275
|
this.receiptHandlers.push(logHandler)
|
@@ -255,7 +281,8 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
|
|
255
281
|
*/
|
256
282
|
public onTransfer(
|
257
283
|
filter: ContractTransferFilter,
|
258
|
-
handler: (transfer: ReceiptTransfer | ReceiptTransferOut, ctx: FuelContractContext<TContract>) => PromiseOrVoid
|
284
|
+
handler: (transfer: ReceiptTransfer | ReceiptTransferOut, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
|
285
|
+
handlerOptions?: HandlerOptions<object, ReceiptTransfer | ReceiptTransferOut>
|
259
286
|
) {
|
260
287
|
const { from, to, assetId } = filter
|
261
288
|
const h = {
|
@@ -288,6 +315,22 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
|
|
288
315
|
to,
|
289
316
|
assetId
|
290
317
|
}
|
318
|
+
},
|
319
|
+
partitionHandler: async (data: Data_FuelReceipt): Promise<string | undefined> => {
|
320
|
+
const p = handlerOptions?.partitionKey
|
321
|
+
if (!p) return undefined
|
322
|
+
if (typeof p === 'function') {
|
323
|
+
try {
|
324
|
+
const tx = await decodeFuelTransaction(data.transaction, this.provider)
|
325
|
+
const index = Number(data.receiptIndex)
|
326
|
+
const receipt = tx.receipts[index] as ReceiptTransfer | ReceiptTransferOut
|
327
|
+
return p(receipt)
|
328
|
+
} catch (e) {
|
329
|
+
console.error(e)
|
330
|
+
}
|
331
|
+
return undefined
|
332
|
+
}
|
333
|
+
return p
|
291
334
|
}
|
292
335
|
} as ReceiptHandler
|
293
336
|
this.receiptHandlers.push(h)
|
@@ -298,8 +341,8 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
|
|
298
341
|
handler: (block: FuelBlock, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
|
299
342
|
timeInterval: HandleInterval | undefined,
|
300
343
|
blockInterval: HandleInterval | undefined,
|
344
|
+
handlerOptions?: HandlerOptions<object, FuelBlock>,
|
301
345
|
handlerName = getHandlerName()
|
302
|
-
// fetchConfig: Partial<FuelFetchConfig> | undefined
|
303
346
|
): this {
|
304
347
|
if (timeInterval) {
|
305
348
|
if (timeInterval.backfillInterval < timeInterval.recentInterval) {
|
@@ -346,6 +389,31 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
|
|
346
389
|
)
|
347
390
|
await handler(block, ctx)
|
348
391
|
return ctx.stopAndGetResult()
|
392
|
+
},
|
393
|
+
partitionHandler: async (data: Data_FuelBlock): Promise<string | undefined> => {
|
394
|
+
const p = handlerOptions?.partitionKey
|
395
|
+
if (!p) return undefined
|
396
|
+
if (typeof p === 'function') {
|
397
|
+
const header = data.block
|
398
|
+
if (!header) return undefined
|
399
|
+
const block: FuelBlock = {
|
400
|
+
id: header.id,
|
401
|
+
height: bn(header.height),
|
402
|
+
time: header.time,
|
403
|
+
header: {
|
404
|
+
applicationHash: header.applicationHash,
|
405
|
+
daHeight: bn(header.daHeight),
|
406
|
+
eventInboxRoot: header.eventInboxRoot,
|
407
|
+
messageOutboxRoot: header.messageOutboxRoot,
|
408
|
+
prevRoot: header.prevRoot,
|
409
|
+
stateTransitionBytecodeVersion: header.stateTransitionBytecodeVersion,
|
410
|
+
transactionsCount: header.transactionsCount,
|
411
|
+
transactionsRoot: header.transactionsRoot
|
412
|
+
}
|
413
|
+
}
|
414
|
+
return p(block)
|
415
|
+
}
|
416
|
+
return p
|
349
417
|
}
|
350
418
|
})
|
351
419
|
return this
|
@@ -354,8 +422,8 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
|
|
354
422
|
public onBlockInterval(
|
355
423
|
handler: (block: FuelBlock, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
|
356
424
|
blockInterval = 250,
|
357
|
-
backfillBlockInterval = 1000
|
358
|
-
|
425
|
+
backfillBlockInterval = 1000,
|
426
|
+
handlerOptions?: HandlerOptions<object, FuelBlock>
|
359
427
|
): this {
|
360
428
|
return this.onInterval(
|
361
429
|
handler,
|
@@ -363,22 +431,22 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
|
|
363
431
|
{
|
364
432
|
recentInterval: blockInterval,
|
365
433
|
backfillInterval: backfillBlockInterval
|
366
|
-
}
|
367
|
-
|
434
|
+
},
|
435
|
+
handlerOptions
|
368
436
|
)
|
369
437
|
}
|
370
438
|
|
371
439
|
public onTimeInterval(
|
372
440
|
handler: (block: FuelBlock, ctx: FuelContractContext<TContract>) => PromiseOrVoid,
|
373
441
|
timeIntervalInMinutes = 60,
|
374
|
-
backfillTimeIntervalInMinutes = 240
|
375
|
-
|
442
|
+
backfillTimeIntervalInMinutes = 240,
|
443
|
+
handlerOptions?: HandlerOptions<object, FuelBlock>
|
376
444
|
): this {
|
377
445
|
return this.onInterval(
|
378
446
|
handler,
|
379
447
|
{ recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },
|
380
|
-
undefined
|
381
|
-
|
448
|
+
undefined,
|
449
|
+
handlerOptions
|
382
450
|
)
|
383
451
|
}
|
384
452
|
}
|
package/src/fuel/types.ts
CHANGED
@@ -29,12 +29,14 @@ export type CallHandler<T> = {
|
|
29
29
|
handler: (call: T) => Promise<ProcessResult>
|
30
30
|
fetchConfig?: Partial<FuelCallHandlerConfig>
|
31
31
|
assetConfig?: Partial<FuelAssetHandlerConfig>
|
32
|
+
partitionHandler?: (call: T) => Promise<string | undefined>
|
32
33
|
}
|
33
34
|
|
34
35
|
export type ReceiptHandler = {
|
35
36
|
handlerName: string
|
36
37
|
handler: (receipt: Data_FuelReceipt) => Promise<ProcessResult>
|
37
38
|
receiptConfig?: Partial<FuelReceiptHandlerConfig>
|
39
|
+
partitionHandler?: (receipt: Data_FuelReceipt) => Promise<string | undefined>
|
38
40
|
}
|
39
41
|
|
40
42
|
export type BlockHandler = {
|
@@ -43,6 +45,7 @@ export type BlockHandler = {
|
|
43
45
|
handler: (block: Data_FuelBlock) => Promise<ProcessResult>
|
44
46
|
handlerName: string
|
45
47
|
fetchConfig?: Partial<OnIntervalConfig>
|
48
|
+
partitionHandler?: (block: Data_FuelBlock) => Promise<string | undefined>
|
46
49
|
}
|
47
50
|
|
48
51
|
export interface FuelLog<T> {
|
package/src/move/filter.ts
CHANGED
@@ -38,6 +38,7 @@ export class EventHandler<T> {
|
|
38
38
|
handlerName: string
|
39
39
|
handler: (event: T) => Promise<ProcessResult>
|
40
40
|
fetchConfig: MoveFetchConfig
|
41
|
+
partitionHandler?: (event: T) => Promise<string | undefined>
|
41
42
|
}
|
42
43
|
|
43
44
|
export class CallHandler<T> {
|
@@ -45,6 +46,7 @@ export class CallHandler<T> {
|
|
45
46
|
handlerName: string
|
46
47
|
handler: (call: T) => Promise<ProcessResult>
|
47
48
|
fetchConfig: MoveFetchConfig
|
49
|
+
partitionHandler?: (call: T) => Promise<string | undefined>
|
48
50
|
}
|
49
51
|
|
50
52
|
export class ObjectChangeHandler<T> {
|
@@ -57,6 +59,7 @@ export class ResourceChangeHandler<T> {
|
|
57
59
|
handlerName: string
|
58
60
|
handler: (call: T) => Promise<ProcessResult>
|
59
61
|
type: string
|
62
|
+
partitionHandler?: (call: T) => Promise<string | undefined>
|
60
63
|
}
|
61
64
|
|
62
65
|
export class ResourceIntervalHandler {
|
@@ -66,6 +69,7 @@ export class ResourceIntervalHandler {
|
|
66
69
|
handler: (resource: Data_AptResource) => Promise<ProcessResult>
|
67
70
|
handlerName: string
|
68
71
|
fetchConfig: MoveAccountFetchConfig
|
72
|
+
partitionHandler?: (resource: Data_AptResource) => Promise<string | undefined>
|
69
73
|
}
|
70
74
|
|
71
75
|
export class TransactionIntervalHandler {
|
@@ -74,4 +78,5 @@ export class TransactionIntervalHandler {
|
|
74
78
|
handler: (tx: Data_AptCall) => Promise<ProcessResult>
|
75
79
|
handlerName: string
|
76
80
|
fetchConfig: MoveFetchConfig
|
81
|
+
partitionHandler?: (tx: Data_AptCall) => Promise<string | undefined>
|
77
82
|
}
|
@@ -96,12 +96,12 @@ export abstract class SharedNetworkCodegen<NetworkType, ModuleTypes, StructType>
|
|
96
96
|
|
97
97
|
const camelFuncName = upperFirst(camel(func.name))
|
98
98
|
const source = `
|
99
|
-
onEntry${camelFuncName}(func: (call: ${moduleName}.${camelFuncName}Payload, ctx: ${this.PREFIX}Context) => void, filter?: CallFilter,
|
99
|
+
onEntry${camelFuncName}(func: (call: ${moduleName}.${camelFuncName}Payload, ctx: ${this.PREFIX}Context) => void, filter?: CallFilter, handlerOptions?: HandlerOptions<MoveFetchConfig, ${moduleName}.${camelFuncName}Payload>): ${moduleName} {
|
100
100
|
this.onEntryFunctionCall(func, {
|
101
101
|
...filter,
|
102
102
|
function: '${module.name}::${func.name}'
|
103
103
|
},
|
104
|
-
|
104
|
+
handlerOptions)
|
105
105
|
return this
|
106
106
|
}`
|
107
107
|
|
@@ -113,8 +113,8 @@ export abstract class SharedNetworkCodegen<NetworkType, ModuleTypes, StructType>
|
|
113
113
|
const source = `
|
114
114
|
onEvent${struct.name}(func: (event: ${moduleName}.${normalizeToJSName(struct.name)}Instance, ctx: ${
|
115
115
|
this.PREFIX
|
116
|
-
}Context) => void,
|
117
|
-
this.onMoveEvent(func, {...eventFilter ?? {}, type: '${module.name}::${struct.name}' },
|
116
|
+
}Context) => void, handlerOptions?: HandlerOptions<MoveFetchConfig, ${moduleName}.${normalizeToJSName(struct.name)}Instance>, eventFilter?: Omit<EventFilter, "type"|"account">): ${moduleName} {
|
117
|
+
this.onMoveEvent(func, {...eventFilter ?? {}, type: '${module.name}::${struct.name}' }, handlerOptions)
|
118
118
|
return this
|
119
119
|
}`
|
120
120
|
return source
|
@@ -123,6 +123,7 @@ onEvent${struct.name}(func: (event: ${moduleName}.${normalizeToJSName(struct.nam
|
|
123
123
|
generateImports() {
|
124
124
|
return `
|
125
125
|
import { CallFilter, MoveFetchConfig, EventFilter } from "@sentio/sdk/move"
|
126
|
+
import { HandlerOptions } from "@sentio/sdk"
|
126
127
|
import {
|
127
128
|
${this.PREFIX}BindOptions, ${this.PREFIX}BaseProcessor,
|
128
129
|
${this.PREFIX}Network, TypedFunctionPayload,
|
@@ -5,6 +5,7 @@ import { SolanaBindOptions } from './solana-options.js'
|
|
5
5
|
import { ListStateStorage } from '@sentio/runtime'
|
6
6
|
import { Labels } from '../core/index.js'
|
7
7
|
import { SolanaChainId } from '@sentio/chain'
|
8
|
+
import { HandlerOptions } from '../core/handler-options.js'
|
8
9
|
|
9
10
|
type IndexConfigure = {
|
10
11
|
startSlot: bigint
|
@@ -17,12 +18,17 @@ export interface InstructionCoder {
|
|
17
18
|
|
18
19
|
export type SolanaInstructionHandler = (instruction: Instruction, ctx: SolanaContext, accounts?: string[]) => void
|
19
20
|
|
21
|
+
export interface InstructionHandlerEntry {
|
22
|
+
handler: SolanaInstructionHandler
|
23
|
+
handlerOptions?: HandlerOptions<object, Instruction>
|
24
|
+
}
|
25
|
+
|
20
26
|
export class SolanaProcessorState extends ListStateStorage<SolanaBaseProcessor> {
|
21
27
|
static INSTANCE: SolanaProcessorState = new SolanaProcessorState()
|
22
28
|
}
|
23
29
|
|
24
30
|
export class SolanaBaseProcessor {
|
25
|
-
public instructionHandlerMap: Map<string,
|
31
|
+
public instructionHandlerMap: Map<string, InstructionHandlerEntry> = new Map()
|
26
32
|
address: string
|
27
33
|
endpoint: string
|
28
34
|
contractName: string
|
@@ -61,8 +67,12 @@ export class SolanaBaseProcessor {
|
|
61
67
|
SolanaProcessorState.INSTANCE.addValue(this)
|
62
68
|
}
|
63
69
|
|
64
|
-
public onInstruction(
|
65
|
-
|
70
|
+
public onInstruction(
|
71
|
+
instructionName: string,
|
72
|
+
handler: SolanaInstructionHandler,
|
73
|
+
handlerOptions?: HandlerOptions<object, Instruction>
|
74
|
+
) {
|
75
|
+
this.instructionHandlerMap.set(instructionName, { handler, handlerOptions })
|
66
76
|
return this
|
67
77
|
}
|
68
78
|
|
@@ -78,21 +88,33 @@ export class SolanaBaseProcessor {
|
|
78
88
|
return null
|
79
89
|
}
|
80
90
|
|
81
|
-
public getInstructionHandler(parsedInstruction: Instruction):
|
91
|
+
public getInstructionHandler(parsedInstruction: Instruction): InstructionHandlerEntry | undefined {
|
82
92
|
return this.instructionHandlerMap.get(parsedInstruction.name)
|
83
93
|
}
|
84
94
|
|
85
95
|
public async handleInstruction(
|
86
96
|
parsedInstruction: Instruction,
|
87
97
|
accounts: string[],
|
88
|
-
|
98
|
+
handlerEntry: InstructionHandlerEntry,
|
89
99
|
slot: bigint
|
90
100
|
): Promise<ProcessResult> {
|
91
101
|
const ctx = new SolanaContext(this.contractName, this.network, this.address, slot, this.baseLabels)
|
92
|
-
await handler(parsedInstruction, ctx, accounts)
|
102
|
+
await handlerEntry.handler(parsedInstruction, ctx, accounts)
|
93
103
|
return ctx.stopAndGetResult()
|
94
104
|
}
|
95
105
|
|
106
|
+
public async getPartitionKey(
|
107
|
+
parsedInstruction: Instruction,
|
108
|
+
handlerEntry: InstructionHandlerEntry
|
109
|
+
): Promise<string | undefined> {
|
110
|
+
const p = handlerEntry.handlerOptions?.partitionKey
|
111
|
+
if (!p) return undefined
|
112
|
+
if (typeof p === 'function') {
|
113
|
+
return p(parsedInstruction)
|
114
|
+
}
|
115
|
+
return p
|
116
|
+
}
|
117
|
+
|
96
118
|
public startSlot(startSlot: bigint | number) {
|
97
119
|
this.config.startSlot = BigInt(startSlot)
|
98
120
|
return this
|
@@ -1,12 +1,13 @@
|
|
1
1
|
import { Data_StarknetEvent, ProcessResult } from '@sentio/protos'
|
2
2
|
import { StarknetChainId } from '@sentio/chain'
|
3
|
-
import { CallData,
|
3
|
+
import { CallData, events, ParsedEvent, RpcProvider } from 'starknet'
|
4
4
|
import { StarknetContext } from './context.js'
|
5
5
|
import { StarknetEvent } from './event.js'
|
6
6
|
import { ListStateStorage, mergeProcessResults } from '@sentio/runtime'
|
7
7
|
import { StarknetProcessorConfig } from './types.js'
|
8
8
|
import { StarknetContractView } from './contract.js'
|
9
9
|
import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
|
10
|
+
import { HandlerOptions } from '../core/handler-options.js'
|
10
11
|
|
11
12
|
export class StarknetProcessor {
|
12
13
|
callHandlers: CallHandler<Data_StarknetEvent>[] = []
|
@@ -42,7 +43,8 @@ export class StarknetProcessor {
|
|
42
43
|
|
43
44
|
public onEvent(
|
44
45
|
event: string | string[],
|
45
|
-
handler: (events: StarknetEvent<ParsedEvent>, ctx: StarknetContext<StarknetContractView>) => void | Promise<void
|
46
|
+
handler: (events: StarknetEvent<ParsedEvent>, ctx: StarknetContext<StarknetContractView>) => void | Promise<void>,
|
47
|
+
handlerOptions?: HandlerOptions<object, StarknetEvent<ParsedEvent>>
|
46
48
|
) {
|
47
49
|
const eventFilter = Array.isArray(event) ? event : [event]
|
48
50
|
if (!this.config.abi) {
|
@@ -83,18 +85,33 @@ export class StarknetProcessor {
|
|
83
85
|
return mergeProcessResults(results)
|
84
86
|
} catch (e) {
|
85
87
|
console.error(e)
|
86
|
-
return {
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
88
|
+
return ProcessResult.fromPartial({})
|
89
|
+
}
|
90
|
+
},
|
91
|
+
eventFilter,
|
92
|
+
partitionHandler: async (call: Data_StarknetEvent): Promise<string | undefined> => {
|
93
|
+
const p = handlerOptions?.partitionKey
|
94
|
+
if (!p) return undefined
|
95
|
+
if (typeof p === 'function') {
|
96
|
+
try {
|
97
|
+
const eventData = [call.result] as any[]
|
98
|
+
const abiEvents = events.getAbiEvents(abi)
|
99
|
+
const abiStructs = CallData.getAbiStruct(abi)
|
100
|
+
const abiEnums = CallData.getAbiEnum(abi)
|
101
|
+
const parsedEvents = events.parseEvents(eventData, abiEvents, abiStructs, abiEnums)
|
102
|
+
if (parsedEvents.length > 0) {
|
103
|
+
const { from_address, transaction_hash } = call.result!
|
104
|
+
const e = new StarknetEvent(from_address, transaction_hash, parsedEvents[0])
|
105
|
+
return p(e)
|
93
106
|
}
|
107
|
+
return undefined
|
108
|
+
} catch (e) {
|
109
|
+
console.error(e)
|
110
|
+
return undefined
|
94
111
|
}
|
95
112
|
}
|
96
|
-
|
97
|
-
|
113
|
+
return p
|
114
|
+
}
|
98
115
|
}
|
99
116
|
this.callHandlers.push(callHandler)
|
100
117
|
return this
|
@@ -105,14 +122,15 @@ export type CallHandler<T> = {
|
|
105
122
|
handlerName: string
|
106
123
|
handler: (call: T) => Promise<ProcessResult>
|
107
124
|
eventFilter?: string[]
|
125
|
+
partitionHandler?: (call: T) => Promise<string | undefined>
|
108
126
|
}
|
109
127
|
|
110
128
|
function getRpcEndpoint(chainId: StarknetChainId | string) {
|
111
129
|
switch (chainId) {
|
112
130
|
case StarknetChainId.STARKNET_MAINNET:
|
113
|
-
return
|
131
|
+
return 'https://starknet-mainnet.g.alchemy.com/starknet/version/rpc/v0_8/8sD5yitBslIYCPFzSq_Q1ObJHqPlZxFw'
|
114
132
|
default:
|
115
|
-
return
|
133
|
+
return 'https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_8/8sD5yitBslIYCPFzSq_Q1ObJHqPlZxFw'
|
116
134
|
}
|
117
135
|
}
|
118
136
|
|
package/src/store/codegen.ts
CHANGED
@@ -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.
|
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
|
}
|