{"version":3,"file":"storage-get-threads-by-resource.mjs","names":[],"sources":["../../../src/codemods/v1/storage-get-threads-by-resource.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\nimport { trackMultipleClassInstances, transformMethodCalls } from '../lib/utils';\n\n/**\n * Migrates storage.getThreadsByResourceId() to storage.listThreads() with filter wrapping.\n *\n * Before:\n * const threads = await storage.getThreadsByResourceId({ resourceId: 'res-123' });\n *\n * After:\n * const threads = await storage.listThreads({ filter: { resourceId: 'res-123' }});\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  const count = transformMethodCalls(j, root, storageInstances, 'getThreadsByResourceId', path => {\n    // Rename method to listThreads\n    if (path.value.callee.type === 'MemberExpression' && path.value.callee.property.type === 'Identifier') {\n      path.value.callee.property.name = 'listThreads';\n    }\n\n    // Wrap resourceId in filter object\n    const args = path.value.arguments;\n    if (args.length === 1 && args[0].type === 'ObjectExpression') {\n      const objArg = args[0];\n      const properties = objArg.properties;\n\n      // Find the resourceId property\n      let resourceIdProp: any = null;\n      const otherProps: any[] = [];\n\n      properties.forEach((prop: any) => {\n        if (\n          (prop.type === 'ObjectProperty' || prop.type === 'Property') &&\n          prop.key?.type === 'Identifier' &&\n          prop.key.name === 'resourceId'\n        ) {\n          resourceIdProp = prop;\n        } else {\n          otherProps.push(prop);\n        }\n      });\n\n      if (resourceIdProp && resourceIdProp.value) {\n        // Create the new filter object\n        const filterProp = j.property('init', j.identifier('filter'), j.objectExpression([resourceIdProp]));\n\n        // Update arguments with filter first, then other props\n        path.value.arguments = [j.objectExpression([filterProp, ...otherProps])];\n      }\n    }\n  });\n\n  if (count > 0) {\n    context.hasChanges = true;\n    context.messages.push(\n      `Migrated ${count} getThreadsByResourceId call(s) to listThreads with filter wrapping on storage instances`,\n    );\n  }\n});\n"],"mappings":";;;;;;;;;;;;AAYA,IAAA,0CAAe,mBAAmB,WAAW,MAAM,UAAU,YAAY;CACvE,MAAM,EAAE,GAAG,SAAS;CAOpB,MAAM,QAAQ,qBAAqB,GAAG,MAFb,4BAA4B,GAAG,MAAM;EAH1C;EAAiB;EAAe;EAAW;EAAiB;EAAgB;CAGzB,CAEZ,GAAG,2BAA0B,SAAQ;EAE9F,IAAI,KAAK,MAAM,OAAO,SAAS,sBAAsB,KAAK,MAAM,OAAO,SAAS,SAAS,cACvF,KAAK,MAAM,OAAO,SAAS,OAAO;EAIpC,MAAM,OAAO,KAAK,MAAM;EACxB,IAAI,KAAK,WAAW,KAAK,KAAK,EAAE,CAAC,SAAS,oBAAoB;GAE5D,MAAM,aADS,KAAK,EACK,CAAC;GAG1B,IAAI,iBAAsB;GAC1B,MAAM,aAAoB,CAAC;GAE3B,WAAW,SAAS,SAAc;IAChC,KACG,KAAK,SAAS,oBAAoB,KAAK,SAAS,eACjD,KAAK,KAAK,SAAS,gBACnB,KAAK,IAAI,SAAS,cAElB,iBAAiB;SAEjB,WAAW,KAAK,IAAI;GAExB,CAAC;GAED,IAAI,kBAAkB,eAAe,OAAO;IAE1C,MAAM,aAAa,EAAE,SAAS,QAAQ,EAAE,WAAW,QAAQ,GAAG,EAAE,iBAAiB,CAAC,cAAc,CAAC,CAAC;IAGlG,KAAK,MAAM,YAAY,CAAC,EAAE,iBAAiB,CAAC,YAAY,GAAG,UAAU,CAAC,CAAC;GACzE;EACF;CACF,CAAC;CAED,IAAI,QAAQ,GAAG;EACb,QAAQ,aAAa;EACrB,QAAQ,SAAS,KACf,YAAY,MAAM,yFACpB;CACF;AACF,CAAC"}