{"version":3,"file":"storage-get-messages-paginated.mjs","names":[],"sources":["../../../src/codemods/v1/storage-get-messages-paginated.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\nimport { trackMultipleClassInstances } from '../lib/utils';\n\n/**\n * Renames storage.getMessagesPaginated() to storage.listMessages() and updates pagination parameters.\n * Changes offset/limit to page/perPage for more intuitive pagination.\n *\n * Before:\n * await storage.getMessagesPaginated({\n *   threadId: 'thread-123',\n *   offset: 0,\n *   limit: 20,\n * });\n *\n * After:\n * await storage.listMessages({\n *   threadId: 'thread-123',\n *   page: 0,\n *   perPage: 20,\n * });\n */\nexport default createTransformer((_fileInfo, _api, _options, context) => {\n  const { j, root } = context;\n\n  const storeTypes = ['PostgresStore', 'LibSQLStore', 'PgStore', 'DynamoDBStore', 'MongoDBStore', 'MSSQLStore'];\n\n  // Track all store instances in a single optimized pass\n  const storageInstances = trackMultipleClassInstances(j, root, storeTypes);\n\n  if (storageInstances.size === 0) return;\n\n  // Single pass: rename method 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    if (callee.property.type !== 'Identifier') return;\n    if (!storageInstances.has(callee.object.name)) return;\n    if (callee.property.name !== 'getMessagesPaginated') return;\n\n    // Rename method\n    callee.property.name = 'listMessages';\n\n    // Transform offset/limit to page/perPage\n    const args = path.value.arguments;\n    const firstArg = args[0];\n    if (firstArg && firstArg.type === 'ObjectExpression' && firstArg.properties) {\n      firstArg.properties.forEach((prop: any) => {\n        if (\n          (prop.type === 'Property' || prop.type === 'ObjectProperty') &&\n          prop.key &&\n          prop.key.type === 'Identifier'\n        ) {\n          if (prop.key.name === 'offset') prop.key.name = 'page';\n          if (prop.key.name === 'limit') prop.key.name = 'perPage';\n        }\n      });\n    }\n\n    context.hasChanges = true;\n  });\n\n  if (context.hasChanges) {\n    context.messages.push('Renamed getMessagesPaginated to listMessages and offset/limit to page/perPage');\n  }\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,IAAA,yCAAe,mBAAmB,WAAW,MAAM,UAAU,YAAY;CACvE,MAAM,EAAE,GAAG,SAAS;CAKpB,MAAM,mBAAmB,4BAA4B,GAAG,MAAM;EAH1C;EAAiB;EAAe;EAAW;EAAiB;EAAgB;CAGzB,CAAC;CAExE,IAAI,iBAAiB,SAAS,GAAG;CAGjC,KAAK,KAAK,EAAE,cAAc,CAAC,CAAC,SAAQ,SAAQ;EAC1C,MAAM,EAAE,WAAW,KAAK;EACxB,IAAI,OAAO,SAAS,oBAAoB;EACxC,IAAI,OAAO,OAAO,SAAS,cAAc;EACzC,IAAI,OAAO,SAAS,SAAS,cAAc;EAC3C,IAAI,CAAC,iBAAiB,IAAI,OAAO,OAAO,IAAI,GAAG;EAC/C,IAAI,OAAO,SAAS,SAAS,wBAAwB;EAGrD,OAAO,SAAS,OAAO;EAIvB,MAAM,WADO,KAAK,MAAM,UACF;EACtB,IAAI,YAAY,SAAS,SAAS,sBAAsB,SAAS,YAC/D,SAAS,WAAW,SAAS,SAAc;GACzC,KACG,KAAK,SAAS,cAAc,KAAK,SAAS,qBAC3C,KAAK,OACL,KAAK,IAAI,SAAS,cAClB;IACA,IAAI,KAAK,IAAI,SAAS,UAAU,KAAK,IAAI,OAAO;IAChD,IAAI,KAAK,IAAI,SAAS,SAAS,KAAK,IAAI,OAAO;GACjD;EACF,CAAC;EAGH,QAAQ,aAAa;CACvB,CAAC;CAED,IAAI,QAAQ,YACV,QAAQ,SAAS,KAAK,+EAA+E;AAEzG,CAAC"}