@sentio/sdk 3.9.0-rc.9 → 4.0.0-rc.1

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 (45) hide show
  1. package/lib/aptos/aptos-processor.d.ts +3 -3
  2. package/lib/aptos/aptos-processor.d.ts.map +1 -1
  3. package/lib/aptos/aptos-processor.js.map +1 -1
  4. package/lib/eth/base-processor-template.d.ts.map +1 -1
  5. package/lib/eth/base-processor-template.js +2 -0
  6. package/lib/eth/base-processor-template.js.map +1 -1
  7. package/lib/eth/base-processor.d.ts +2 -2
  8. package/lib/eth/base-processor.d.ts.map +1 -1
  9. package/lib/eth/base-processor.js.map +1 -1
  10. package/lib/fuel/fuel-processor-template.d.ts.map +1 -1
  11. package/lib/fuel/fuel-processor-template.js +2 -0
  12. package/lib/fuel/fuel-processor-template.js.map +1 -1
  13. package/lib/iota/iota-processor.d.ts +2 -2
  14. package/lib/iota/iota-processor.d.ts.map +1 -1
  15. package/lib/iota/iota-processor.js +2 -2
  16. package/lib/iota/iota-processor.js.map +1 -1
  17. package/lib/solana/codegen/codegen.d.ts +1 -1
  18. package/lib/solana/codegen/codegen.d.ts.map +1 -1
  19. package/lib/solana/codegen/codegen.js +2 -2
  20. package/lib/solana/codegen/codegen.js.map +1 -1
  21. package/lib/solana/solana-processor.d.ts +2 -2
  22. package/lib/solana/solana-processor.d.ts.map +1 -1
  23. package/lib/solana/solana-processor.js.map +1 -1
  24. package/lib/store/codegen.js +2 -2
  25. package/lib/store/codegen.js.map +1 -1
  26. package/lib/store/store.js.map +1 -1
  27. package/lib/sui/sui-processor.d.ts +2 -2
  28. package/lib/sui/sui-processor.d.ts.map +1 -1
  29. package/lib/sui/sui-processor.js +2 -2
  30. package/lib/sui/sui-processor.js.map +1 -1
  31. package/lib/testing/memory-database.d.ts.map +1 -1
  32. package/lib/testing/memory-database.js +4 -1
  33. package/lib/testing/memory-database.js.map +1 -1
  34. package/package.json +12 -12
  35. package/src/aptos/aptos-processor.ts +9 -9
  36. package/src/eth/base-processor-template.ts +5 -1
  37. package/src/eth/base-processor.ts +11 -11
  38. package/src/fuel/fuel-processor-template.ts +3 -1
  39. package/src/iota/iota-processor.ts +10 -10
  40. package/src/solana/codegen/codegen.ts +2 -2
  41. package/src/solana/solana-processor.ts +9 -5
  42. package/src/store/codegen.ts +2 -2
  43. package/src/store/store.ts +1 -1
  44. package/src/sui/sui-processor.ts +10 -10
  45. package/src/testing/memory-database.ts +4 -1
@@ -12,12 +12,12 @@ import {
12
12
  } from '@anchor-lang/core'
13
13
  import { recursiveCodegen } from '../../core/codegen.js'
14
14
 
15
- export function codegen(abisDir: string, targetPath = path.join('src', 'types', 'solana'), genExample = false) {
15
+ export async function codegen(abisDir: string, targetPath = path.join('src', 'types', 'solana'), genExample = false) {
16
16
  if (!fs.existsSync(abisDir)) {
17
17
  return
18
18
  }
19
19
 
20
- const numFiles = recursiveCodegen(abisDir, targetPath, codegenInternal)
20
+ const numFiles = await recursiveCodegen(abisDir, targetPath, codegenInternal)
21
21
 
22
22
  console.log(chalk.green(`Generated ${numFiles} for Solana`))
23
23
  }
@@ -18,7 +18,11 @@ export interface InstructionCoder {
18
18
  decode(ix: Buffer | string, encoding?: 'hex' | 'base58'): Instruction | null
19
19
  }
20
20
 
21
- export type SolanaInstructionHandler = (instruction: Instruction, ctx: SolanaContext, accounts?: string[]) => void
21
+ export type SolanaInstructionHandler<T extends Instruction = Instruction> = (
22
+ instruction: T,
23
+ ctx: SolanaContext,
24
+ accounts: string[]
25
+ ) => void
22
26
 
23
27
  export interface InstructionHandlerEntry {
24
28
  handler: SolanaInstructionHandler
@@ -79,12 +83,12 @@ export class SolanaBaseProcessor {
79
83
  SolanaProcessorState.INSTANCE.addValue(this)
80
84
  }
81
85
 
82
- public onInstruction(
86
+ public onInstruction<T extends Instruction = Instruction>(
83
87
  instructionName: string,
84
- handler: SolanaInstructionHandler,
85
- handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
88
+ handler: SolanaInstructionHandler<T>,
89
+ handlerOptions?: HandlerOptions<SolanaFetchConfig, T>
86
90
  ) {
87
- this.instructionHandlerMap.set(instructionName, { handler, handlerOptions })
91
+ this.instructionHandlerMap.set(instructionName, { handler, handlerOptions } as InstructionHandlerEntry)
88
92
  return this
89
93
  }
90
94
 
@@ -210,7 +210,7 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
210
210
  })
211
211
  fields.push({
212
212
  name: f.name + 'ID' + (isMany ? 's' : ''),
213
- type: isMany ? `Array<ID | undefined>` : `ID`,
213
+ type: isMany ? `Array<ID>` : `ID`,
214
214
  annotations: []
215
215
  })
216
216
  if (isMany) {
@@ -317,7 +317,7 @@ export class ${c.name} ${c.parent ? `extends ${c.parent}` : ''} ${c.interfaces.l
317
317
  ${c.fields
318
318
  .map((f) => `${f.annotations.map((a) => `\n\t${a}`).join('')}\n\t${f.name}${f.optional ? '?' : ''}: ${f.type}`)
319
319
  .join('\n')}
320
- ${isEntity ? `constructor(data: ${c.name}ConstructorInput) {super()}` : ''}
320
+ ${isEntity ? `constructor(data: Partial<${c.name}ConstructorInput>) {super()}` : ''}
321
321
  ${(c.methods ?? []).map(genMethod).join('\n')}
322
322
 
323
323
  ${
@@ -96,7 +96,7 @@ export class Store {
96
96
  entity: [] as string[],
97
97
  id: [] as string[]
98
98
  }
99
- const entityName = getEntityName(entity)
99
+ const entityName = getEntityName(entity as EntityClass<T> | T)
100
100
  if (id) {
101
101
  if (Array.isArray(id)) {
102
102
  for (const i of id) {
@@ -76,10 +76,10 @@ export class SuiBaseProcessor {
76
76
  return this.config.network
77
77
  }
78
78
 
79
- protected onMoveEvent(
80
- handler: (event: SuiEventInput, ctx: SuiContext) => PromiseOrVoid,
79
+ protected onMoveEvent<T extends SuiEventInput = SuiEventInput>(
80
+ handler: (event: T, ctx: SuiContext) => PromiseOrVoid,
81
81
  filter: EventFilter | EventFilter[],
82
- handlerOptions?: HandlerOptions<MoveFetchConfig, SuiEventInput>
82
+ handlerOptions?: HandlerOptions<MoveFetchConfig, T>
83
83
  ): SuiBaseProcessor {
84
84
  let _filters: EventFilter[] = []
85
85
  const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...handlerOptions })
@@ -118,8 +118,8 @@ export class SuiBaseProcessor {
118
118
  processor.config.baseLabels
119
119
  )
120
120
 
121
- const decoded = await processor.coder.decodeEvent<any>(evt)
122
- await handler(decoded || evt, ctx)
121
+ const decoded = await processor.coder.decodeEvent<T>(evt)
122
+ await handler((decoded || evt) as T, ctx)
123
123
 
124
124
  return ctx.stopAndGetResult()
125
125
  },
@@ -131,7 +131,7 @@ export class SuiBaseProcessor {
131
131
  if (typeof p === 'function') {
132
132
  const evt = JSON.parse(data.rawEvent) as SuiEventInput
133
133
  const decoded = await processor.coder.decodeEvent<any>(evt)
134
- return p(decoded || evt)
134
+ return p((decoded || evt) as T)
135
135
  }
136
136
  return p
137
137
  }
@@ -139,10 +139,10 @@ export class SuiBaseProcessor {
139
139
  return this
140
140
  }
141
141
 
142
- protected onEntryFunctionCall(
143
- handler: (call: GrpcTypes.MoveCall, ctx: SuiContext) => PromiseOrVoid,
142
+ protected onEntryFunctionCall<T extends GrpcTypes.MoveCall = GrpcTypes.MoveCall>(
143
+ handler: (call: T, ctx: SuiContext) => PromiseOrVoid,
144
144
  filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],
145
- handlerOptions?: HandlerOptions<MoveFetchConfig, GrpcTypes.MoveCall>
145
+ handlerOptions?: HandlerOptions<MoveFetchConfig, T>
146
146
  ): SuiBaseProcessor {
147
147
  let _filters: FunctionNameAndCallFilter[] = []
148
148
  const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...handlerOptions })
@@ -205,7 +205,7 @@ export class SuiBaseProcessor {
205
205
  const calls = getMoveCalls(tx)
206
206
  // For simplicity, use the first call for partitioning
207
207
  if (calls.length > 0) {
208
- return p(calls[0])
208
+ return p(calls[0] as T)
209
209
  }
210
210
  return undefined
211
211
  }
@@ -43,7 +43,10 @@ export class MemoryDatabase {
43
43
  }
44
44
 
45
45
  start() {
46
- this.dbContext.subject.subscribe(this.processRequest.bind(this))
46
+ // The subject is typed `DeepPartial<ProcessStreamResponse>`, but at runtime it always carries a
47
+ // full response. Match the subscriber's parameter type and narrow inside (a bound method with the
48
+ // narrower `ProcessStreamResponse` parameter is rejected under `strictFunctionTypes`).
49
+ this.dbContext.subject.subscribe((request) => this.processRequest(request as ProcessStreamResponse))
47
50
  }
48
51
 
49
52
  stop() {