import { API , FileInfo , Options } from 'jscodeshift' ; import { addNamedImport } from '@codemods/add-named-import' ; export function getObjectId ( file , api , options ) { const j = api . jscodeshift ; const root = j ( file . source ) ; const printOptions = options . printOptions || { quote : 'single' , trailingComma : false , lineTerminator : '\n' } ; let hasObjectId = false ; root . find ( j . MemberExpression ) . filter ( ( path ) => { if ( path . node . object . type === 'CallExpression' ) { if ( path . node . object . callee . name === 'fromGlobalId' ) { if ( path . node . property . type === 'Identifier' ) { if ( path . node . property . name === 'id' ) { return true ; } } } } return false ; } ) . forEach ( ( path ) => { const args = path . node . object . arguments ; if ( ! hasObjectId ) { hasObjectId = true ; } j ( path ) . replaceWith ( j . callExpression ( j . identifier ( 'getObjectId' ) , args ) ) ; return path . node ; } ) ; if ( hasObjectId ) { addNamedImport ( { root , j , importName : '@repo/graphql' , specifier : 'getObjectId' } ) ; } return root . toSource ( printOptions ) ; } export const parser = 'tsx' ; export default getObjectId ;