{"version":3,"file":"mastra-required-id.mjs","names":[],"sources":["../../../../src/codemods/v1/not-implemented/mastra-required-id.ts"],"sourcesContent":["/* eslint-disable no-warning-comments */\nimport type { ASTPath } from 'jscodeshift';\n\nimport { insertCommentOnce } from '../../lib/add-comment';\nimport { createTransformer } from '../../lib/create-transformer';\n\n/**\n * Adds FIXME comments to Mastra primitives that now require an `id` parameter.\n * This includes storages, vector stores, agents, workflows, tools, scorers, and MCP servers.\n *\n * Before:\n * const agent = new Agent({ name: 'Support Agent' });\n * const tool = createTool({ description: 'Get weather' });\n *\n * After:\n * /* FIXME(mastra): Add a unique `id` parameter. See: ... *\\/\n * const agent = new Agent({ name: 'Support Agent' });\n * /* FIXME(mastra): Add a unique `id` parameter. See: ... *\\/\n * const tool = createTool({ description: 'Get weather' });\n */\nexport default createTransformer((fileInfo, api, options, context) => {\n  const { j, root } = context;\n\n  const COMMENT_MESSAGE =\n    'FIXME(mastra): Add a unique `id` parameter. See: https://mastra.ai/guides/migrations/upgrade-to-v1/mastra#required-id-parameter-for-all-mastra-primitives';\n\n  const STATEMENT_TYPES = new Set([\n    'VariableDeclaration',\n    'ExpressionStatement',\n    'ReturnStatement',\n    'ExportDefaultDeclaration',\n    'ExportNamedDeclaration',\n    'Program',\n  ]);\n\n  // List of class names that require id\n  const storageClasses = [\n    'LibSQLStore',\n    'PostgresStore',\n    'D1Store',\n    'MongoDBStore',\n    'DynamoDBStore',\n    'LibSQLVector',\n    'PgVector',\n    'ChromaVector',\n    'PineconeVector',\n    'QdrantVector',\n    'LanceVector',\n    'Agent',\n    'MCPServer',\n  ];\n\n  // List of function names that require id\n  const createFunctions = ['createWorkflow', 'createTool', 'createScorer'];\n\n  /**\n   * Checks if an expression's arguments contain an object with an 'id' property\n   */\n  function hasIdProperty(args: ASTPath<any>['value']['arguments']): boolean {\n    return args.some((arg: ASTPath<any>['value']) => {\n      if (arg.type === 'ObjectExpression') {\n        return arg.properties?.some(\n          (prop: ASTPath<any>['value']) =>\n            (prop.type === 'Property' || prop.type === 'ObjectProperty') &&\n            prop.key?.type === 'Identifier' &&\n            prop.key.name === 'id',\n        );\n      }\n      return false;\n    });\n  }\n\n  /**\n   * Adds a FIXME comment to the appropriate node based on the expression's context.\n   * - If nested in an object property, adds comment to the property\n   * - If nested in an array, adds comment to the expression itself\n   * - Otherwise, walks up to find the parent statement and adds comment there\n   */\n  function addCommentToAppropriateNode(path: ASTPath<any>): void {\n    let parent = path.parent;\n\n    // If the direct parent is an object property, add comment to that property\n    if (parent?.value && (parent.value.type === 'Property' || parent.value.type === 'ObjectProperty')) {\n      if (insertCommentOnce(parent.value, j, COMMENT_MESSAGE)) {\n        context.hasChanges = true;\n      }\n      return;\n    }\n\n    // If the parent is an array, add comment directly to the expression\n    if (parent?.value?.type === 'ArrayExpression') {\n      if (insertCommentOnce(path.value, j, COMMENT_MESSAGE)) {\n        context.hasChanges = true;\n      }\n      return;\n    }\n\n    // Find the parent statement to add comment\n    while (parent && !STATEMENT_TYPES.has(parent.value.type)) {\n      parent = parent.parent;\n    }\n\n    if (parent?.value) {\n      // For export declarations, add comment to the export itself\n      let targetNode = parent.value;\n      if (\n        targetNode.type !== 'ExportDefaultDeclaration' &&\n        targetNode.type !== 'ExportNamedDeclaration' &&\n        parent.parent &&\n        (parent.parent.value.type === 'ExportDefaultDeclaration' ||\n          parent.parent.value.type === 'ExportNamedDeclaration')\n      ) {\n        targetNode = parent.parent.value;\n      }\n\n      if (insertCommentOnce(targetNode, j, COMMENT_MESSAGE)) {\n        context.hasChanges = true;\n      }\n    }\n  }\n\n  // Find NewExpression for classes\n  root.find(j.NewExpression).forEach(path => {\n    if (path.value.callee.type === 'Identifier') {\n      const className = path.value.callee.name;\n\n      if (storageClasses.includes(className) && !hasIdProperty(path.value.arguments)) {\n        addCommentToAppropriateNode(path);\n      }\n    }\n  });\n\n  // Find CallExpression for create functions\n  root.find(j.CallExpression).forEach(path => {\n    if (path.value.callee.type === 'Identifier') {\n      const functionName = path.value.callee.name;\n\n      if (createFunctions.includes(functionName) && !hasIdProperty(path.value.arguments)) {\n        addCommentToAppropriateNode(path);\n      }\n    }\n  });\n\n  if (context.hasChanges) {\n    context.messages.push(`Not Implemented ${fileInfo.path}: Mastra primitives now require a unique id parameter.`);\n  }\n});\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,IAAA,6BAAe,mBAAmB,UAAU,KAAK,SAAS,YAAY;CACpE,MAAM,EAAE,GAAG,SAAS;CAEpB,MAAM,kBACJ;CAEF,MAAM,kCAAkB,IAAI,IAAI;EAC9B;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAGD,MAAM,iBAAiB;EACrB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CAGA,MAAM,kBAAkB;EAAC;EAAkB;EAAc;CAAc;;;;CAKvE,SAAS,cAAc,MAAmD;EACxE,OAAO,KAAK,MAAM,QAA+B;GAC/C,IAAI,IAAI,SAAS,oBACf,OAAO,IAAI,YAAY,MACpB,UACE,KAAK,SAAS,cAAc,KAAK,SAAS,qBAC3C,KAAK,KAAK,SAAS,gBACnB,KAAK,IAAI,SAAS,IACtB;GAEF,OAAO;EACT,CAAC;CACH;;;;;;;CAQA,SAAS,4BAA4B,MAA0B;EAC7D,IAAI,SAAS,KAAK;EAGlB,IAAI,QAAQ,UAAU,OAAO,MAAM,SAAS,cAAc,OAAO,MAAM,SAAS,mBAAmB;GACjG,IAAI,kBAAkB,OAAO,OAAO,GAAG,eAAe,GACpD,QAAQ,aAAa;GAEvB;EACF;EAGA,IAAI,QAAQ,OAAO,SAAS,mBAAmB;GAC7C,IAAI,kBAAkB,KAAK,OAAO,GAAG,eAAe,GAClD,QAAQ,aAAa;GAEvB;EACF;EAGA,OAAO,UAAU,CAAC,gBAAgB,IAAI,OAAO,MAAM,IAAI,GACrD,SAAS,OAAO;EAGlB,IAAI,QAAQ,OAAO;GAEjB,IAAI,aAAa,OAAO;GACxB,IACE,WAAW,SAAS,8BACpB,W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