{"version":3,"file":"client-offset-limit.mjs","names":[],"sources":["../../../src/codemods/v1/client-offset-limit.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\nimport { trackClassInstances, transformObjectProperties } from '../lib/utils';\n\n/**\n * Renames pagination properties from offset/limit to page/perPage.\n * This provides a more intuitive pagination model aligned with web pagination patterns.\n *\n * Before:\n * await client.listMemoryThreads({ offset: 0, limit: 20 });\n * await client.getTraces({ pagination: { offset: 0, limit: 40 } });\n *\n * After:\n * await client.listMemoryThreads({ page: 0, perPage: 20 });\n * await client.getTraces({ pagination: { page: 0, perPage: 40 } });\n */\nexport default createTransformer((_fileInfo, _api, _options, context) => {\n  const { j, root } = context;\n\n  // Map of old property names to new property names\n  const propertyRenames: Record<string, string> = {\n    offset: 'page',\n    limit: 'perPage',\n  };\n\n  // Track MastraClient instances and objects returned from client methods in a single pass\n  const clientInstances = trackClassInstances(j, root, 'MastraClient');\n  const clientObjects = new Set<string>();\n\n  // Early return if no client instances found\n  if (clientInstances.size === 0) return;\n\n  // Single pass: Find objects returned from client method calls AND transform properties\n  root.find(j.CallExpression).forEach(path => {\n    const { callee } = path.value;\n    if (callee.type !== 'MemberExpression') return;\n    if (callee.object.type !== 'Identifier') return;\n\n    // Check if it's called on a MastraClient instance or tracked client object\n    const isClientInstance = clientInstances.has(callee.object.name);\n    const isClientObject = clientObjects.has(callee.object.name);\n\n    if (isClientInstance) {\n      // Track objects returned from client method calls\n      const parent = path.parent.value;\n      if (parent.type === 'VariableDeclarator' && parent.id.type === 'Identifier') {\n        clientObjects.add(parent.id.name);\n      }\n    }\n\n    if (isClientInstance || isClientObject) {\n      // Transform offset/limit properties in the arguments of this call\n      path.value.arguments.forEach(arg => {\n        if (arg.type === 'ObjectExpression') {\n          const count = transformObjectProperties(arg, propertyRenames);\n          if (count > 0) {\n            context.hasChanges = true;\n          }\n        }\n      });\n    }\n  });\n\n  if (context.hasChanges) {\n    context.messages.push('Renamed pagination properties from offset/limit to page/perPage');\n  }\n});\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAA,8BAAe,mBAAmB,WAAW,MAAM,UAAU,YAAY;CACvE,MAAM,EAAE,GAAG,SAAS;CAGpB,MAAM,kBAA0C;EAC9C,QAAQ;EACR,OAAO;CACT;CAGA,MAAM,kBAAkB,oBAAoB,GAAG,MAAM,cAAc;CACnE,MAAM,gCAAgB,IAAI,IAAY;CAGtC,IAAI,gBAAgB,SAAS,GAAG;CAGhC,KAAK,KAAK,EAAE,cAAc,CAAC,CAAC,SAAQ,SAAQ;EAC1C,MAAM,EAAE,WAAW,KAAK;EACxB,IAAI,OAAO,SAAS,oBAAoB;EACxC,IAAI,OAAO,OAAO,SAAS,cAAc;EAGzC,MAAM,mBAAmB,gBAAgB,IAAI,OAAO,OAAO,IAAI;EAC/D,MAAM,iBAAiB,cAAc,IAAI,OAAO,OAAO,IAAI;EAE3D,IAAI,kBAAkB;GAEpB,MAAM,SAAS,KAAK,OAAO;GAC3B,IAAI,OAAO,SAAS,wBAAwB,OAAO,GAAG,SAAS,cAC7D,cAAc,IAAI,OAAO,GAAG,IAAI;EAEpC;EAEA,IAAI,oBAAoB,gBAEtB,KAAK,MAAM,UAAU,SAAQ,QAAO;GAClC,IAAI,IAAI,SAAS,oBACD;QAAA,0BAA0B,KAAK,eACrC,IAAI,GACV,QAAQ,aAAa;GAAA;EAG3B,CAAC;CAEL,CAAC;CAED,IAAI,QAAQ,YACV,QAAQ,SAAS,KAAK,iEAAiE;AAE3F,CAAC"}