{"version":3,"file":"discover.mjs","sources":["../../src/migrations/discover.ts"],"sourcesContent":["import path from 'path';\n\nimport fse from 'fs-extra';\n\n/**\n * Discover user migration files in a directory.\n * Matches umzug's non-recursive `*.{js,sql}` glob (fast-glob defaults:\n * `dot: false`, `onlyFiles: true`, `followSymbolicLinks: true`) with\n * alphabetical ordering.\n */\nexport const discoverMigrationFiles = (dir: string): string[] => {\n  if (!fse.existsSync(dir)) {\n    return [];\n  }\n\n  return fse\n    .readdirSync(dir, { withFileTypes: true })\n    .filter((entry) => {\n      if (entry.name.startsWith('.')) {\n        return false;\n      }\n\n      if (!entry.name.endsWith('.js') && !entry.name.endsWith('.sql')) {\n        return false;\n      }\n\n      // Regular files: accept without stat so a TOCTOU race (file removed\n      // between readdir and stat) surfaces later instead of being swallowed.\n      if (entry.isFile()) {\n        return true;\n      }\n\n      // Dirent#isFile() is false for symlinks; only then follow the target\n      // (umzug/fast-glob followSymbolicLinks: include symlink→file, skip\n      // symlink→directory and broken links).\n      if (entry.isSymbolicLink()) {\n        try {\n          return fse.statSync(path.join(dir, entry.name)).isFile();\n        } catch {\n          return false;\n        }\n      }\n\n      return false;\n    })\n    .map((entry) => path.resolve(dir, entry.name))\n    .sort();\n};\n"],"names":["discoverMigrationFiles","dir","fse","existsSync","readdirSync","withFileTypes","filter","entry","name","startsWith","endsWith","isFile","isSymbolicLink","statSync","path","join","map","resolve","sort"],"mappings":";;;AAIA;;;;;IAMO,MAAMA,sBAAAA,GAAyB,CAACC,GAAAA,GAAAA;AACrC,IAAA,IAAI,CAACC,GAAAA,CAAIC,UAAU,CAACF,GAAAA,CAAAA,EAAM;AACxB,QAAA,OAAO,EAAE;AACX,IAAA;IAEA,OAAOC,GAAAA,CACJE,WAAW,CAACH,GAAAA,EAAK;QAAEI,aAAAA,EAAe;KAAK,CAAA,CACvCC,MAAM,CAAC,CAACC,KAAAA,GAAAA;AACP,QAAA,IAAIA,KAAAA,CAAMC,IAAI,CAACC,UAAU,CAAC,GAAA,CAAA,EAAM;YAC9B,OAAO,KAAA;AACT,QAAA;AAEA,QAAA,IAAI,CAACF,KAAAA,CAAMC,IAAI,CAACE,QAAQ,CAAC,KAAA,CAAA,IAAU,CAACH,KAAAA,CAAMC,IAAI,CAACE,QAAQ,CAAC,MAAA,CAAA,EAAS;YAC/D,OAAO,KAAA;AACT,QAAA;;;QAIA,IAAIH,KAAAA,CAAMI,MAAM,EAAA,EAAI;YAClB,OAAO,IAAA;AACT,QAAA;;;;QAKA,IAAIJ,KAAAA,CAAMK,cAAc,EAAA,EAAI;YAC1B,IAAI;gBACF,OAAOV,GAAAA,CAAIW,QAAQ,CAACC,IAAAA,CAAKC,IAAI,CAACd,GAAAA,EAAKM,KAAAA,CAAMC,IAAI,CAAA,CAAA,CAAGG,MAAM,EAAA;AACxD,YAAA,CAAA,CAAE,OAAM;gBACN,OAAO,KAAA;AACT,YAAA;AACF,QAAA;QAEA,OAAO,KAAA;IACT,CAAA,CAAA,CACCK,GAAG,CAAC,CAACT,KAAAA,GAAUO,IAAAA,CAAKG,OAAO,CAAChB,GAAAA,EAAKM,KAAAA,CAAMC,IAAI,CAAA,CAAA,CAC3CU,IAAI,EAAA;AACT;;;;"}