{"version":3,"file":"memory-message-v2-type.mjs","names":[],"sources":["../../../src/codemods/v1/memory-message-v2-type.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\n\n/**\n * Renames MastraMessageV2 type to MastraDBMessage.\n * This better describes the purpose as the database message format.\n *\n * Before:\n * import { MastraMessageV2 } from '@mastra/core';\n * function processMessage(message: MastraMessageV2) {}\n *\n * After:\n * import { MastraDBMessage } from '@mastra/core';\n * function processMessage(message: MastraDBMessage) {}\n */\nexport default createTransformer((_fileInfo, _api, _options, context) => {\n  const { j, root } = context;\n\n  const oldTypeName = 'MastraMessageV2';\n  const newTypeName = 'MastraDBMessage';\n\n  // Track which local names should be rewritten (only non-aliased imports)\n  const localNamesToRewrite = new Set<string>();\n\n  // Transform import specifiers from @mastra/core\n  root\n    .find(j.ImportDeclaration)\n    .filter(path => {\n      const source = path.value.source.value;\n      return typeof source === 'string' && source === '@mastra/core';\n    })\n    .forEach(path => {\n      if (!path.value.specifiers) return;\n\n      path.value.specifiers.forEach((specifier: any) => {\n        if (\n          specifier.type === 'ImportSpecifier' &&\n          specifier.imported.type === 'Identifier' &&\n          specifier.imported.name === oldTypeName\n        ) {\n          const localName = specifier.local?.name || oldTypeName;\n          const isAliased = localName !== oldTypeName;\n\n          // Rename the imported name\n          specifier.imported.name = newTypeName;\n\n          // Only update local name and track for rewriting if not aliased\n          if (!isAliased) {\n            if (specifier.local) {\n              specifier.local.name = newTypeName;\n            }\n            // Track the old local name (oldTypeName) to rewrite all its usages\n            localNamesToRewrite.add(oldTypeName);\n          }\n          // If aliased, leave the local name intact and don't track for rewriting\n\n          context.hasChanges = true;\n        }\n      });\n    });\n\n  // Only transform usages for non-aliased imports\n  if (localNamesToRewrite.size > 0) {\n    // Transform all references that need to be rewritten\n    localNamesToRewrite.forEach(oldLocalName => {\n      root.find(j.Identifier, { name: oldLocalName }).forEach(path => {\n        // Skip identifiers that are part of import declarations\n        const parent = path.parent;\n        if (parent && parent.value.type === 'ImportSpecifier') {\n          return;\n        }\n\n        path.value.name = newTypeName;\n        context.hasChanges = true;\n      });\n    });\n  }\n\n  if (context.hasChanges) {\n    context.messages.push('Renamed MastraMessageV2 type to MastraDBMessage');\n  }\n});\n"],"mappings":";;;;;;;;;;;;;;AAcA,IAAA,iCAAe,mBAAmB,WAAW,MAAM,UAAU,YAAY;CACvE,MAAM,EAAE,GAAG,SAAS;CAEpB,MAAM,cAAc;CACpB,MAAM,cAAc;CAGpB,MAAM,sCAAsB,IAAI,IAAY;CAG5C,KACG,KAAK,EAAE,iBAAiB,CAAC,CACzB,QAAO,SAAQ;EACd,MAAM,SAAS,KAAK,MAAM,OAAO;EACjC,OAAO,OAAO,WAAW,YAAY,WAAW;CAClD,CAAC,CAAC,CACD,SAAQ,SAAQ;EACf,IAAI,CAAC,KAAK,MAAM,YAAY;EAE5B,KAAK,MAAM,WAAW,SAAS,cAAmB;GAChD,IACE,UAAU,SAAS,qBACnB,UAAU,SAAS,SAAS,gBAC5B,UAAU,SAAS,SAAS,aAC5B;IAEA,MAAM,aADY,UAAU,OAAO,QAAQ,iBACX;IAGhC,UAAU,SAAS,OAAO;IAG1B,IAAI,CAAC,WAAW;KACd,IAAI,UAAU,OACZ,UAAU,MAAM,OAAO;KAGzB,oBAAoB,IAAI,WAAW;IACrC;IAGA,QAAQ,aAAa;GACvB;EACF,CAAC;CACH,CAAC;CAGH,IAAI,oBAAoB,OAAO,GAE7B,oBAAoB,SAAQ,iBAAgB;EAC1C,KAAK,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC,CAAC,CAAC,SAAQ,SAAQ;GAE9D,MAAM,SAAS,KAAK;GACpB,IAAI,UAAU,OAAO,MAAM,SAAS,mBAClC;GAGF,KAAK,MAAM,OAAO;GAClB,QAAQ,aAAa;EACvB,CAAC;CACH,CAAC;CAGH,IAAI,QAAQ,YACV,QAAQ,SAAS,KAAK,iDAAiD;AAE3E,CAAC"}