11import * as util from '../codegen/util.js' ;
22
33/**
4- * Map of value types that need to be changeType 'd to their corresponding AssemblyScript type
4+ * Map of value types that need to be changetype 'd to their corresponding AssemblyScript type
55 */
66export const VALUE_TYPECAST_MAP : Record < string , string > = {
77 'address[]' : 'Bytes[]' ,
@@ -18,7 +18,7 @@ export const generateFieldAssignment = (
1818
1919 if ( type in VALUE_TYPECAST_MAP ) {
2020 const castTo = VALUE_TYPECAST_MAP [ type ] ;
21- rightSide = `changeType <${ castTo } >(${ rightSide } )` ;
21+ rightSide = `changetype <${ castTo } >(${ rightSide } )` ;
2222 imports . push ( castTo . replace ( '[]' , '' ) ) ;
2323 }
2424
@@ -85,11 +85,13 @@ export const generateEventFieldAssignments = (
8585 ) ;
8686
8787export const generateEventIndexingHandlers = ( events : any [ ] , contractName : string ) => {
88- const allImports : string [ ] = [ ] ;
89- const eventHandlers = events . map ( event => {
90- const { assignments, imports } = generateEventFieldAssignments ( event , contractName ) ;
91- allImports . push ( ...imports ) ;
88+ const eventFieldAssignments = events . map ( event => ( {
89+ event,
90+ ...generateEventFieldAssignments ( event , contractName ) ,
91+ } ) ) ;
92+ const allImports = [ ...new Set ( eventFieldAssignments . map ( ( { imports } ) => imports ) . flat ( ) ) ] ;
9293
94+ const eventHandlers = eventFieldAssignments . map ( ( { event, assignments } ) => {
9395 return `
9496 export function handle${ event . _alias } (event: ${ event . _alias } Event): void {
9597 let entity = new ${ event . _alias } (event.transaction.hash.concatI32(event.logIndex.toI32()))
@@ -111,7 +113,7 @@ export const generateEventIndexingHandlers = (events: any[], contractName: strin
111113 import { ${ events . map ( event => event . _alias ) } } from '../generated/schema'
112114 ${
113115 allImports . length > 0
114- ? `import { ${ [ ... new Set ( allImports ) ] . join ( ', ' ) } } from '@graphprotocol/graph-ts'`
116+ ? `import { ${ allImports . join ( ', ' ) } } from '@graphprotocol/graph-ts'`
115117 : ''
116118 }
117119
0 commit comments